Pbooth.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /**
  3. * 推荐展位管理
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Pbooth extends BaseModel
  20. {
  21. const STATE1 = 1; // 开启
  22. const STATE0 = 0; // 关闭
  23. public $page_info;
  24. /**
  25. * 展位套餐列表
  26. * @access public
  27. * @author csdeshang
  28. * @param array $condition 条件
  29. * @param string $field 字段
  30. * @param int $pagesize 分页
  31. * @param string $order 排序
  32. * @return array
  33. */
  34. public function getBoothquotaList($condition, $field = '*', $pagesize = 0, $order = 'boothquota_id desc')
  35. {
  36. if($pagesize){
  37. $res= Db::name('pboothquota')->field($field)->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  38. $this->page_info=$res;
  39. return $res->items();
  40. }else{
  41. return Db::name('pboothquota')->field($field)->where($condition)->order($order)->select()->toArray();
  42. }
  43. }
  44. /**
  45. * 展位套餐详细信息
  46. * @access public
  47. * @author csdeshang
  48. * @param array $condition 条件
  49. * @param string $field 字段
  50. * @return array
  51. */
  52. public function getBoothquotaInfo($condition, $field = '*')
  53. {
  54. return Db::name('pboothquota')->field($field)->where($condition)->find();
  55. }
  56. /**
  57. * 展位套餐详细信息
  58. * @access public
  59. * @author csdeshang
  60. * @param int $store_id 店铺ID
  61. * @param string $field 字段
  62. * @return array
  63. */
  64. public function getBoothquotaInfoCurrent($store_id)
  65. {
  66. $condition = array();
  67. $condition[] = array('store_id','=',$store_id);
  68. $condition[] = array('boothquota_endtime','>',TIMESTAMP);
  69. $condition[] = array('boothquota_state','=',1);
  70. return $this->getBoothquotaInfo($condition);
  71. }
  72. /**
  73. * 保存推荐展位套餐
  74. * @access public
  75. * @author csdeshang
  76. * @param array $data 参数内容
  77. * @return boolean
  78. */
  79. public function addBoothquota($data)
  80. {
  81. return Db::name('pboothquota')->insertGetId($data);
  82. }
  83. /**
  84. * 表示推荐展位套餐
  85. * @access public
  86. * @author csdeshang
  87. * @param array $update 更新数据
  88. * @param array $condition 条件
  89. * @return array
  90. */
  91. public function editBoothquota($update, $condition)
  92. {
  93. return Db::name('pboothquota')->where($condition)->update($update);
  94. }
  95. /**
  96. * 编辑推荐展位套餐
  97. * @access public
  98. * @author csdeshang
  99. * @param array $update 更新数据
  100. * @param array $condition 条件
  101. * @return array
  102. */
  103. public function editBoothquotaOpen($update, $condition)
  104. {
  105. $update['boothquota_state'] = self::STATE1;
  106. return Db::name('pboothquota')->where($condition)->update($update);
  107. }
  108. /**
  109. * 商品列表
  110. * @access public
  111. * @author csdeshang
  112. * @access public
  113. * @author csdeshang
  114. * @param array $condition 条件
  115. * @param string $field 字段
  116. * @param int $pagesize 分页
  117. * @param int $limit 限制
  118. * @param string $order 排序
  119. * @return array
  120. */
  121. public function getBoothgoodsList($condition, $field = '*', $pagesize = 0, $limit = 0, $order = 'boothgoods_id asc') {
  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. }