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