p_booth.model.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * 推荐展位管理
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class p_boothModel extends Model {
  11. const STATE1 = 1; // 开启
  12. const STATE0 = 0; // 关闭
  13. public function __construct() {
  14. parent::__construct();
  15. }
  16. /**
  17. * 展位套餐列表
  18. *
  19. * @param array $condition
  20. * @param string $field
  21. * @param int $page
  22. * @param string $order
  23. * @return array
  24. */
  25. public function getBoothQuotaList($condition, $field = '*', $page = 0, $order = 'booth_quota_id desc') {
  26. return $this->table('p_booth_quota')->field($field)->where($condition)->order($order)->page($page)->select();
  27. }
  28. /**
  29. * 展位套餐详细信息
  30. *
  31. * @param array $condition
  32. * @param string $field
  33. * @return array
  34. */
  35. public function getBoothQuotaInfo($condition, $field = '*') {
  36. return $this->table('p_booth_quota')->field($field)->where($condition)->find();
  37. }
  38. /**
  39. * 展位套餐详细信息
  40. *
  41. * @param int $store_id
  42. * @param string $field
  43. * @return array
  44. */
  45. public function getBoothQuotaInfoCurrent($store_id) {
  46. $condition['store_id'] = $store_id;
  47. $condition['booth_quota_endtime'] = array('gt', TIMESTAMP);
  48. $condition['booth_state'] = 1;
  49. return $this->getBoothQuotaInfo($condition);
  50. }
  51. /**
  52. * 保存推荐展位套餐
  53. *
  54. * @param array $insert
  55. * @param boolean $replace
  56. * @return boolean
  57. */
  58. public function addBoothQuota($insert, $replace = false) {
  59. return $this->table('p_booth_quota')->insert($insert, $replace);
  60. }
  61. /**
  62. * 表示推荐展位套餐
  63. * @param array $update
  64. * @param array $condition
  65. * @return array
  66. */
  67. public function editBoothQuota($update, $condition) {
  68. return $this->table('p_booth_quota')->where($condition)->update($update);
  69. }
  70. /**
  71. * 表示推荐展位套餐
  72. * @param array $update
  73. * @param array $condition
  74. * @return array
  75. */
  76. public function editBoothQuotaOpen($update, $condition) {
  77. $update['booth_state'] = self::STATE1;
  78. return $this->table('p_booth_quota')->where($condition)->update($update);
  79. }
  80. /**
  81. * 商品列表
  82. *
  83. * @param array $condition
  84. * @param string $field
  85. * @param int $page
  86. * @param int $limit
  87. * @param string $order
  88. * @return array
  89. */
  90. public function getBoothGoodsList($condition, $field = '*', $page = 0, $limit = 0, $order = 'booth_goods_id asc') {
  91. $condition = $this->_getRecursiveClass($condition);
  92. return $this->table('p_booth_goods')->field($field)->where($condition)->limit($limit)->order($order)->page($page)->select();
  93. }
  94. /**
  95. * 获取推荐展位商品详细信息
  96. * @param array $condition
  97. * @param string $field
  98. * @return array
  99. */
  100. public function getBoothGoodsInfo($condition, $field = '*') {
  101. return $this->table('p_booth_goods')->field($field)->find();
  102. }
  103. /**
  104. * 保存套餐商品信息
  105. * @param array $insert
  106. * @return boolean
  107. */
  108. public function addBoothGoods($insert) {
  109. return $this->table('p_booth_goods')->insert($insert);
  110. }
  111. /**
  112. * 编辑套餐商品信息
  113. *
  114. * @param array $update
  115. * @param array $condition
  116. */
  117. public function editBooth($update, $condition) {
  118. return $this->table('p_booth_goods')->where($condition)->update($update);
  119. }
  120. /**
  121. * 更新套餐为关闭状态
  122. * @param array $condition
  123. * @return boolean
  124. */
  125. public function editBoothClose($condition) {
  126. $quota_list = $this->getBoothQuotaList($condition);
  127. if (empty($quota_list)) {
  128. return true;
  129. }
  130. $storeid_array = array();
  131. foreach ($quota_list as $val) {
  132. $storeid_array[] = $val['store_id'];
  133. }
  134. $where = array('store_id' => array('in', $storeid_array));
  135. $update = array('booth_state' => self::STATE0);
  136. $this->editBoothQuota($update, $where);
  137. $this->editBooth($update, $where);
  138. return true;
  139. }
  140. /**
  141. * 删除套餐商品
  142. *
  143. * @param unknown $condition
  144. * @return boolean
  145. */
  146. public function delBoothGoods($condition) {
  147. return $this->table('p_booth_goods')->where($condition)->delete();
  148. }
  149. /**
  150. * 获得商品子分类的ID
  151. * @param array $condition
  152. * @return array
  153. */
  154. private function _getRecursiveClass($condition){
  155. if (isset($condition['gc_id']) && !is_array($condition['gc_id']) ) {
  156. $gc_list = Model('goods_class')->getGoodsClassForCacheModel();
  157. if (isset($gc_list[$condition['gc_id']])) {
  158. $gc_id[] = $condition['gc_id'];
  159. $gcchild_id = empty($gc_list[$condition['gc_id']]['child']) ? array() : explode(',', $gc_list[$condition['gc_id']]['child']);
  160. $gcchildchild_id = empty($gc_list[$condition['gc_id']]['childchild']) ? array() : explode(',', $gc_list[$condition['gc_id']]['childchild']);
  161. $gc_id = array_merge($gc_id, $gcchild_id, $gcchildchild_id);
  162. $condition['gc_id'] = array('in', $gc_id);
  163. }
  164. }
  165. return $condition;
  166. }
  167. }