Pbooth.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * 推荐展位管理
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 数据层模型
  14. */
  15. class Pbooth extends BaseModel
  16. {
  17. const STATE1 = 1; // 开启
  18. const STATE0 = 0; // 关闭
  19. public $page_info;
  20. /**
  21. * 展位套餐列表
  22. * @access public
  23. * @author csdeshang
  24. * @param array $condition 条件
  25. * @param string $field 字段
  26. * @param int $pagesize 分页
  27. * @param string $order 排序
  28. * @return array
  29. */
  30. public function getBoothquotaList($condition, $field = '*', $pagesize = 0, $order = 'boothquota_id desc')
  31. {
  32. if ($pagesize) {
  33. $res = Db::name('pboothquota')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  34. $this->page_info = $res;
  35. return $res->items();
  36. } else {
  37. return Db::name('pboothquota')->field($field)->where($condition)->order($order)->select()->toArray();
  38. }
  39. }
  40. /**
  41. * 展位套餐详细信息
  42. * @access public
  43. * @author csdeshang
  44. * @param array $condition 条件
  45. * @param string $field 字段
  46. * @return array
  47. */
  48. public function getBoothquotaInfo($condition, $field = '*')
  49. {
  50. return Db::name('pboothquota')->field($field)->where($condition)->find();
  51. }
  52. /**
  53. * 展位套餐详细信息
  54. * @access public
  55. * @author csdeshang
  56. * @param int $store_id 店铺ID
  57. * @param string $field 字段
  58. * @return array
  59. */
  60. public function getBoothquotaInfoCurrent($store_id)
  61. {
  62. $condition = array();
  63. $condition[] = array('store_id', '=', $store_id);
  64. $condition[] = array('boothquota_endtime', '>', TIMESTAMP);
  65. $condition[] = array('boothquota_state', '=', 1);
  66. return $this->getBoothquotaInfo($condition);
  67. }
  68. /**
  69. * 保存推荐展位套餐
  70. * @access public
  71. * @author csdeshang
  72. * @param array $data 参数内容
  73. * @return boolean
  74. */
  75. public function addBoothquota($data)
  76. {
  77. return Db::name('pboothquota')->insertGetId($data);
  78. }
  79. /**
  80. * 表示推荐展位套餐
  81. * @access public
  82. * @author csdeshang
  83. * @param array $update 更新数据
  84. * @param array $condition 条件
  85. * @return array
  86. */
  87. public function editBoothquota($update, $condition)
  88. {
  89. return Db::name('pboothquota')->where($condition)->update($update);
  90. }
  91. /**
  92. * 编辑推荐展位套餐
  93. * @access public
  94. * @author csdeshang
  95. * @param array $update 更新数据
  96. * @param array $condition 条件
  97. * @return array
  98. */
  99. public function editBoothquotaOpen($update, $condition)
  100. {
  101. $update['boothquota_state'] = self::STATE1;
  102. return Db::name('pboothquota')->where($condition)->update($update);
  103. }
  104. /**
  105. * 商品列表
  106. * @access public
  107. * @author csdeshang
  108. * @access public
  109. * @author csdeshang
  110. * @param array $condition 条件
  111. * @param string $field 字段
  112. * @param int $pagesize 分页
  113. * @param int $limit 限制
  114. * @param string $order 排序
  115. * @return array
  116. */
  117. public function getBoothgoodsList($condition, $field = '*', $pagesize = 0, $limit = 0, $order = 'boothgoods_id asc')
  118. {
  119. // $condition = $this->_getRecursiveClass($condition);
  120. if ($pagesize) {
  121. $res = Db::name('pboothgoods')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  122. $this->page_info = $res;
  123. return $res->items();
  124. } else {
  125. return Db::name('pboothgoods')->field($field)->where($condition)->limit($limit)->order($order)->select()->toArray();
  126. }
  127. }
  128. /**
  129. * 保存套餐商品信息
  130. * @access public
  131. * @author csdeshang
  132. * @param array $data 数据
  133. * @return boolean
  134. */
  135. public function addBoothgoods($data)
  136. {
  137. return Db::name('pboothgoods')->insertGetId($data);
  138. }
  139. /**
  140. * 编辑套餐商品信息
  141. * @access public
  142. * @author csdeshang
  143. * @param array $update 更新数据
  144. * @param array $condition 更新条件
  145. */
  146. public function editBooth($update, $condition)
  147. {
  148. return Db::name('pboothgoods')->where($condition)->update($update);
  149. }
  150. /**
  151. * 更新套餐为关闭状态
  152. * @access public
  153. * @author csdeshang
  154. * @param array $condition 条件
  155. * @return boolean
  156. */
  157. public function editBoothClose($condition)
  158. {
  159. $quota_list = $this->getBoothquotaList($condition);
  160. if (empty($quota_list)) {
  161. return true;
  162. }
  163. $storeid_array = array();
  164. foreach ($quota_list as $val) {
  165. $storeid_array[] = $val['store_id'];
  166. }
  167. $where = array(array('store_id', 'in', $storeid_array));
  168. $update = array('boothquota_state' => self::STATE0);
  169. $this->editBoothquota($update, $where);
  170. $update = array('boothgoods_state' => self::STATE0);
  171. $this->editBooth($update, $where);
  172. return true;
  173. }
  174. /**
  175. * 删除套餐商品
  176. * @access public
  177. * @author csdeshang
  178. * @param array $condition 条件
  179. * @return boolean
  180. */
  181. public function delBoothgoods($condition)
  182. {
  183. return Db::name('pboothgoods')->where($condition)->delete();
  184. }
  185. /**
  186. * 获得商品子分类的ID
  187. * @access public
  188. * @author csdeshang
  189. * @param array $condition 查询条件
  190. * @return array
  191. */
  192. public function _getRecursiveClass($condition, $gc_id)
  193. {
  194. if (!is_array($gc_id)) {
  195. $gc_list = model('goodsclass')->getGoodsclassForCacheModel();
  196. if (isset($gc_list[$gc_id])) {
  197. $all_gc_id[] = $gc_id;
  198. $gcchild_id = empty($gc_list[$gc_id]['child']) ? array() : explode(',', $gc_list[$gc_id]['child']);
  199. $gcchildchild_id = empty($gc_list[$gc_id]['childchild']) ? array() : explode(',', $gc_list[$gc_id]['childchild']);
  200. $all_gc_id = array_merge($all_gc_id, $gcchild_id, $gcchildchild_id);
  201. $condition[] = array('gc_id', 'in', $all_gc_id);
  202. }
  203. }
  204. return $condition;
  205. }
  206. }