p_booth.model.php 6.0 KB

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