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