Selleractivity.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Selleractivity extends BaseSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleractivity.lang.php');
  21. }
  22. /**
  23. * 活动管理
  24. */
  25. public function index()
  26. {
  27. $activity_model = model('activity');
  28. //活动为商品活动,并且为开启状态
  29. $condition = array();
  30. $condition[] = array('activity_type', '=', 1);
  31. $condition[] = array('activity_startdate', '<=', TIMESTAMP);
  32. $condition[] = array('activity_enddate', '>=', TIMESTAMP);
  33. $condition[] = array('activity_state', '=', 1);
  34. $activity_list = $activity_model->getActivityList($condition, 10, 'activity_sort asc');
  35. /**
  36. * 页面输出
  37. */
  38. //halt($list);
  39. View::assign('activity_list', $activity_list);
  40. View::assign('show_page', $activity_model->page_info->render());
  41. $this->setSellerCurMenu('Selleractivity');
  42. $this->setSellerCurItem('index');
  43. return View::fetch($this->template_dir . 'index');
  44. }
  45. /**
  46. * 参与活动
  47. */
  48. public function activity_apply()
  49. {
  50. //根据活动编号查询活动信息
  51. $activity_id = intval(input('param.activity_id'));
  52. if ($activity_id <= 0) {
  53. $this->error(lang('param_error'), 'Selleractivity/index');
  54. }
  55. $activity_model = model('activity');
  56. $activity_info = $activity_model->getOneActivityById($activity_id);
  57. //活动类型必须是商品并且活动没有关闭并且活动进行中
  58. if (empty($activity_info) || $activity_info['activity_type'] != '1' || $activity_info['activity_state'] != 1 || $activity_info['activity_startdate'] > TIMESTAMP || $activity_info['activity_enddate'] < TIMESTAMP) {
  59. $this->error(lang('store_activity_not_exists'), 'Selleractivity/index');
  60. }
  61. View::assign('activity_info', $activity_info);
  62. $activitydetail_list = array(); //声明存放活动细节的数组
  63. //查询商品分类列表
  64. /* $gc = model('goodsclass');
  65. $gc_list = $gc->getTreeClassList(3);
  66. foreach ($gc_list as $k => $gc) {
  67. $gc_list[$k]['gc_name'] = '';
  68. $gc_list[$k]['gc_name'] = str_repeat("&nbsp;", $gc['deep'] * 2) . $gc['gc_name'];
  69. }
  70. View::assign('gc_list', $gc_list);
  71. //halt($gc_list); */
  72. //查询品牌列表
  73. $brand = model('brand');
  74. $brand_list = $brand->getBrandList(array());
  75. View::assign('brand_list', $brand_list);
  76. //查询活动细节信息
  77. $activitydetail_model = model('activitydetail');
  78. $condition = array();
  79. $condition[] = array('activitydetail.activity_id', '=', $activity_id);
  80. $condition[] = array('activitydetail.store_id', '=', session('store_id'));
  81. $condition[] = array('activitydetail.activitydetail_state', 'in', array('0', '1', '3'));
  82. $activitydetail_list = $activitydetail_model->getGoodsJoinList($condition);
  83. //构造通过与审核中商品的编号数组,以便在下方待选列表中,不显示这些内容
  84. $item_ids = array();
  85. if (is_array($activitydetail_list) and !empty($activitydetail_list)) {
  86. foreach ($activitydetail_list as $k => $v) {
  87. $item_ids[] = $v['item_id'];
  88. }
  89. }
  90. View::assign('activitydetail_list', $activitydetail_list);
  91. //根据查询条件查询商品列表
  92. $goods_model = model('goods');
  93. $condition = array();
  94. if (input('param.gc_id') != '') {
  95. $condition = $goods_model->_getRecursiveClass($condition, intval(input('param.gc_id')), 'goodscommon.');
  96. }
  97. if (input('param.brand_id') != '') {
  98. $condition[] = array('goodscommon.brand_id', '=', intval(input('param.brand_id')));
  99. }
  100. if (trim(input('param.name')) != '') {
  101. $condition[] = array('goodscommon.goods_name', 'like', '%' . trim(input('param.name')) . '%');
  102. }
  103. $condition[] = array('goodscommon.store_id', '=', session('store_id'));
  104. if (!empty($item_ids)) {
  105. $condition[] = array('goods.goods_id', 'not in', $item_ids);
  106. }
  107. $goods_list = $goods_model->getGoodsUnionList($condition, '*', 'goodscommon.goods_commonid desc', 'goodscommon.goods_commonid', 10);
  108. View::assign('goods_list', $goods_list);
  109. View::assign('show_page', $goods_model->page_info->render());
  110. View::assign('search', input('param.get'));
  111. /**
  112. * 页面输出
  113. */
  114. $this->setSellerCurMenu('Selleractivity');
  115. $this->setSellerCurItem('activity_apply');
  116. return View::fetch($this->template_dir . 'activity_apply');
  117. }
  118. /**
  119. * 活动申请保存
  120. */
  121. public function activity_apply_save()
  122. {
  123. //判断页面参数
  124. $item_id_array = input('post.item_id/a'); #获取POST数组
  125. if (empty($item_id_array)) {
  126. ds_json_encode(10001, lang('store_activity_choose_goods'));
  127. }
  128. $activity_id = intval(input('post.activity_id'));
  129. if ($activity_id <= 0) {
  130. ds_json_encode(10001, lang('param_error'));
  131. }
  132. //根据页面参数查询活动内容信息,如果不存在则添加,存在则根据状态进行修改
  133. $activity_model = model('activity');
  134. $activity = $activity_model->getOneActivityById($activity_id);
  135. //活动类型必须是商品并且活动没有关闭并且活动进行中
  136. if (empty($activity) || $activity['activity_type'] != '1' || $activity['activity_state'] != '1' || $activity['activity_startdate'] > TIMESTAMP || $activity['activity_enddate'] < TIMESTAMP) {
  137. ds_json_encode(10001, lang('store_activity_not_exists'));
  138. }
  139. $activitydetail_model = model('activitydetail');
  140. $list = $activitydetail_model->getActivitydetailList(array('store_id' => session('store_id'), 'activity_id' => "$activity_id"));
  141. $ids = array(); //已经存在的活动内容编号
  142. $ids_state2 = array(); //已经存在的被拒绝的活动编号
  143. if (is_array($list) and !empty($list)) {
  144. foreach ($list as $ad) {
  145. $ids[] = $ad['item_id'];
  146. if ($ad['activitydetail_state'] == '2') {
  147. $ids_state2[] = $ad['item_id'];
  148. }
  149. }
  150. }
  151. //根据查询条件查询商品列表
  152. foreach ($item_id_array as $item_id) {
  153. $item_id = intval($item_id);
  154. if (!in_array($item_id, $ids)) {
  155. $input = array();
  156. $input['activity_id'] = $activity_id;
  157. $goods = model('goods');
  158. $item = $goods->getGoodsOnlineInfoByID($item_id);
  159. if (empty($item) || $item['store_id'] != session('store_id')) {
  160. continue;
  161. }
  162. $input['item_name'] = $item['goods_name'];
  163. $input['item_id'] = $item_id;
  164. $input['store_id'] = $item['store_id'];
  165. $input['store_name'] = $item['store_name'];
  166. $activitydetail_model->addActivitydetail($input);
  167. } elseif (in_array($item_id, $ids_state2)) {
  168. $input = array();
  169. $input['activitydetail_state'] = '0'; //将重新审核状态去除
  170. $activitydetail_model->editActivitydetail($input, array('item_id' => $item_id));
  171. }
  172. }
  173. ds_json_encode(10000, lang('store_activity_submitted'));
  174. }
  175. /**
  176. * 用户中心右边,小导航
  177. *
  178. * @param string $menu_type 导航类型
  179. * @param string $menu_key 当前导航的menu_key
  180. * @return
  181. */
  182. protected function getSellerItemList()
  183. {
  184. $menu_array = array(
  185. array(
  186. 'name' => 'index', 'text' => lang('ds_member_path_activity_list'),
  187. 'url' => (string) url('Selleractivity/index')
  188. )
  189. );
  190. if (request()->action() == 'activity_apply') {
  191. $menu_array[] = array(
  192. 'name' => 'activity_apply', 'text' => lang('ds_member_path_join_activity'),
  193. 'url' => ''
  194. );
  195. }
  196. return $menu_array;
  197. }
  198. }