Pbooth.php 7.1 KB

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