Selleractivity.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Selleractivity extends BaseSeller {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleractivity.lang.php');
  20. }
  21. /**
  22. * 活动管理
  23. */
  24. public function index() {
  25. $activity_model = model('activity');
  26. //活动为商品活动,并且为开启状态
  27. $condition = array();
  28. $condition[] = array('activity_type', '=', 1);
  29. $condition[] = array('activity_startdate', '<=', TIMESTAMP);
  30. $condition[] = array('activity_enddate', '>=', TIMESTAMP);
  31. $condition[] = array('activity_state', '=', 1);
  32. $activity_list = $activity_model->getActivityList($condition, 10, 'activity_sort asc');
  33. /**
  34. * 页面输出
  35. */
  36. //halt($list);
  37. View::assign('activity_list', $activity_list);
  38. View::assign('show_page', $activity_model->page_info->render());
  39. $this->setSellerCurMenu('Selleractivity');
  40. $this->setSellerCurItem('index');
  41. return View::fetch($this->template_dir . 'index');
  42. }
  43. /**
  44. * 参与活动
  45. */
  46. public function activity_apply() {
  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. $item_id_array = input('post.item_id/a'); #获取POST数组
  121. if (empty($item_id_array)) {
  122. ds_json_encode(10001, lang('store_activity_choose_goods'));
  123. }
  124. $activity_id = intval(input('post.activity_id'));
  125. if ($activity_id <= 0) {
  126. ds_json_encode(10001, lang('param_error'));
  127. }
  128. //根据页面参数查询活动内容信息,如果不存在则添加,存在则根据状态进行修改
  129. $activity_model = model('activity');
  130. $activity = $activity_model->getOneActivityById($activity_id);
  131. //活动类型必须是商品并且活动没有关闭并且活动进行中
  132. if (empty($activity) || $activity['activity_type'] != '1' || $activity['activity_state'] != '1' || $activity['activity_startdate'] > TIMESTAMP || $activity['activity_enddate'] < TIMESTAMP) {
  133. ds_json_encode(10001, lang('store_activity_not_exists'));
  134. }
  135. $activitydetail_model = model('activitydetail');
  136. $list = $activitydetail_model->getActivitydetailList(array('store_id' => session('store_id'), 'activity_id' => "$activity_id"));
  137. $ids = array(); //已经存在的活动内容编号
  138. $ids_state2 = array(); //已经存在的被拒绝的活动编号
  139. if (is_array($list) and ! empty($list)) {
  140. foreach ($list as $ad) {
  141. $ids[] = $ad['item_id'];
  142. if ($ad['activitydetail_state'] == '2') {
  143. $ids_state2[] = $ad['item_id'];
  144. }
  145. }
  146. }
  147. //根据查询条件查询商品列表
  148. foreach ($item_id_array as $item_id) {
  149. $item_id = intval($item_id);
  150. if (!in_array($item_id, $ids)) {
  151. $input = array();
  152. $input['activity_id'] = $activity_id;
  153. $goods = model('goods');
  154. $item = $goods->getGoodsOnlineInfoByID($item_id);
  155. if (empty($item) || $item['store_id'] != session('store_id')) {
  156. continue;
  157. }
  158. $input['item_name'] = $item['goods_name'];
  159. $input['item_id'] = $item_id;
  160. $input['store_id'] = $item['store_id'];
  161. $input['store_name'] = $item['store_name'];
  162. $activitydetail_model->addActivitydetail($input);
  163. } elseif (in_array($item_id, $ids_state2)) {
  164. $input = array();
  165. $input['activitydetail_state'] = '0'; //将重新审核状态去除
  166. $activitydetail_model->editActivitydetail($input, array('item_id' => $item_id));
  167. }
  168. }
  169. ds_json_encode(10000, lang('store_activity_submitted'));
  170. }
  171. /**
  172. * 用户中心右边,小导航
  173. *
  174. * @param string $menu_type 导航类型
  175. * @param string $menu_key 当前导航的menu_key
  176. * @return
  177. */
  178. protected function getSellerItemList() {
  179. $menu_array = array(
  180. array(
  181. 'name' => 'index', 'text' => lang('ds_member_path_activity_list'),
  182. 'url' => (string) url('Selleractivity/index')
  183. )
  184. );
  185. if (request()->action() == 'activity_apply') {
  186. $menu_array[] = array(
  187. 'name' => 'activity_apply', 'text' => lang('ds_member_path_join_activity'),
  188. 'url' => ''
  189. );
  190. }
  191. return $menu_array;
  192. }
  193. }