Sellerpromotionbooth.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 Sellerpromotionbooth 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') . '/sellerpromotionbooth.lang.php');
  18. if (intval(config('ds_config.promotion_allow')) !== 1) {
  19. $this->error(lang('promotion_unavailable'), (string) url('Seller/index'));
  20. }
  21. }
  22. /**
  23. * 套餐商品列表
  24. */
  25. public function index()
  26. {
  27. $pbooth_model = model('pbooth');
  28. // 更新套餐状态
  29. $where = array();
  30. $where[] = array('store_id', '=', session('store_id'));
  31. $where[] = array('boothquota_endtime', '<', TIMESTAMP);
  32. $pbooth_model->editBoothClose($where);
  33. $isPlatformStore = check_platform_store() ? true : false;
  34. View::assign('isPlatformStore', $isPlatformStore);
  35. $hasList = $isPlatformStore;
  36. if (!$isPlatformStore) {
  37. // 检查是否已购买套餐
  38. $where = array();
  39. $where[] = array('store_id', '=', session('store_id'));
  40. $booth_quota = $pbooth_model->getBoothquotaInfo($where);
  41. View::assign('booth_quota', $booth_quota);
  42. if (!empty($booth_quota)) {
  43. $hasList = true;
  44. } elseif (intval(config('ds_config.promotion_booth_price')) == 0) {
  45. $hasList = true;
  46. } else {
  47. $update = array('boothgoods_state' => $pbooth_model::STATE0);
  48. $pbooth_model->editBooth($update, $where);
  49. }
  50. }
  51. if ($hasList) {
  52. // 查询已选择商品
  53. $boothgoods_list = $pbooth_model->getBoothgoodsList(array(array('store_id', '=', session('store_id'))), 'goods_id');
  54. if (!empty($boothgoods_list)) {
  55. $goodsid_array = array();
  56. foreach ($boothgoods_list as $val) {
  57. $goodsid_array[] = $val['goods_id'];
  58. }
  59. $goods_list = model('goods')->getGoodsList(array(array('goods_id', 'in', $goodsid_array)), 'goods_id,goods_name,goods_image,goods_price,store_id,gc_id');
  60. if (!empty($goods_list)) {
  61. $gcid_array = array(); // 商品分类id
  62. foreach ($goods_list as $key => $val) {
  63. $gcid_array[] = $val['gc_id'];
  64. $goods_list[$key]['goods_image'] = goods_thumb($val);
  65. $goods_list[$key]['url'] = (string) url('Goods/index', array('goods_id' => $val['goods_id']));
  66. }
  67. $goodsclass_list = model('goodsclass')->getGoodsclassListByIds($gcid_array);
  68. $goodsclass_list = array_under_reset($goodsclass_list, 'gc_id');
  69. View::assign('goods_list', $goods_list);
  70. View::assign('goodsclass_list', $goodsclass_list);
  71. }
  72. }
  73. }
  74. $this->setSellerCurMenu('Sellerpromotionbooth');
  75. $this->setSellerCurItem('index');
  76. return View::fetch($this->template_dir . 'index');
  77. }
  78. /**
  79. * 选择商品
  80. */
  81. public function booth_select_goods()
  82. {
  83. $goods_model = model('goods');
  84. $condition = array();
  85. $condition[] = array('store_id', '=', session('store_id'));
  86. $goods_name = input('post.goods_name');
  87. if ($goods_name != '') {
  88. $condition[] = array('goods_name', 'like', '%' . $goods_name . '%');
  89. }
  90. $goods_list = $goods_model->getGoodsOnlineList($condition, '*', 10);
  91. View::assign('goods_list', $goods_list);
  92. View::assign('show_page', $goods_model->page_info->render());
  93. echo View::fetch($this->template_dir . 'select_goods');
  94. }
  95. /**
  96. * 购买套餐
  97. */
  98. public function booth_quota_add()
  99. {
  100. if (request()->isPost()) {
  101. if (intval(config('ds_config.promotion_booth_price')) == 0) {
  102. ds_json_encode(10001, lang('param_error'));
  103. }
  104. $quantity = intval(input('post.booth_quota_quantity')); // 购买的数量(月)
  105. $price_quantity = $quantity * intval(config('ds_config.promotion_booth_price')); // 扣款数
  106. if ($quantity <= 0 || $quantity > 12) {
  107. ds_json_encode(10001, lang('param_error'));
  108. }
  109. // 实例化模型
  110. $pbooth_model = model('pbooth');
  111. $data = array();
  112. $data['store_id'] = session('store_id');
  113. $data['store_name'] = session('store_name');
  114. $data['boothquota_starttime'] = TIMESTAMP;
  115. $data['boothquota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  116. $data['boothquota_state'] = 1;
  117. $return = $pbooth_model->addBoothquota($data);
  118. if ($return) {
  119. // 添加店铺费用记录
  120. $this->recordStorecost($price_quantity, '购买推荐展位');
  121. // 添加任务队列
  122. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  123. $this->addcron(array('cron_exetime' => $end_time, 'cron_value' => serialize(intval(session('store_id'))), 'cron_type' => 'editBoothClose'), true);
  124. $this->recordSellerlog('购买' . $quantity . '套推荐展位,单位元');
  125. ds_json_encode(10000, lang('ds_common_op_succ'));
  126. } else {
  127. ds_json_encode(10001, lang('ds_common_op_fail'));
  128. }
  129. }
  130. // 输出导航
  131. $this->setSellerCurMenu('Sellerpromotionbooth');
  132. $this->setSellerCurItem('booth_quota_add');
  133. return View::fetch($this->template_dir . 'quota_add');
  134. }
  135. /**
  136. * 套餐续费
  137. */
  138. public function booth_renew()
  139. {
  140. if (request()->isPost()) {
  141. if (intval(config('ds_config.promotion_booth_price')) == 0) {
  142. ds_json_encode(10001, lang('param_error'));
  143. }
  144. $pbooth_model = model('pbooth');
  145. $quantity = intval(input('post.booth_quota_quantity')); // 购买数量(月)
  146. $price_quantity = $quantity * intval(config('ds_config.promotion_booth_price')); // 扣款数
  147. if ($quantity <= 0 || $quantity > 12) {
  148. ds_json_encode(10001, lang('param_error'));
  149. }
  150. $condition = array();
  151. $condition[] = array('store_id', '=', session('store_id'));
  152. $booth_quota = $pbooth_model->getBoothquotaInfo($condition);
  153. if ($booth_quota['boothquota_endtime'] > TIMESTAMP) {
  154. // 套餐未超时(结束时间+购买时间)
  155. $update['boothquota_endtime'] = intval($booth_quota['boothquota_endtime']) + 60 * 60 * 24 * 30 * $quantity;
  156. } else {
  157. // 套餐已超时(当前时间+购买时间)
  158. $update['boothquota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  159. }
  160. $return = $pbooth_model->editBoothquotaOpen($update, $condition);
  161. if ($return) {
  162. // 添加店铺费用记录
  163. $this->recordStorecost($price_quantity, '购买推荐展位');
  164. // 添加任务队列
  165. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  166. $this->addcron(array('cron_exetime' => $end_time, 'cron_value' => serialize(intval(session('store_id'))), 'cron_type' => 'editBoothClose'), true);
  167. $this->recordSellerlog('续费' . $quantity . '套推荐展位,单位元');
  168. ds_json_encode(10000, lang('ds_common_op_succ'));
  169. } else {
  170. ds_json_encode(10001, lang('ds_common_op_fail'));
  171. }
  172. }
  173. $this->setSellerCurMenu('Sellerpromotionbooth');
  174. $this->setSellerCurItem('booth_renew');
  175. return View::fetch($this->template_dir . 'quota_add');
  176. }
  177. /**
  178. * 选择商品
  179. */
  180. public function choosed_goods()
  181. {
  182. $data = array();
  183. $data['result'] = 'true';
  184. $gid = input('param.gid');
  185. if ($gid <= 0) {
  186. $data = array('result' => 'false', 'msg' => lang('param_error'));
  187. $this->_echoJson($data);
  188. }
  189. // 验证商品是否存在
  190. $goods_info = model('goods')->getGoodsInfoByID($gid);
  191. if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
  192. $data = array('result' => 'false', 'msg' => lang('param_error'));
  193. $this->_echoJson($data);
  194. }
  195. $pbooth_model = model('pbooth');
  196. if (!check_platform_store()) {
  197. // 验证套餐时候过期
  198. $booth_info = $pbooth_model->getBoothquotaInfo(array(
  199. array('store_id', '=', session('store_id')),
  200. array('boothquota_endtime', '>', TIMESTAMP)
  201. ), 'boothquota_id');
  202. if (empty($booth_info)) {
  203. if (intval(config('ds_config.promotion_booth_price')) != 0) {
  204. $data = array('result' => 'false', 'msg' => lang('boothquota_expire'));
  205. $this->_echoJson($data);
  206. }
  207. }
  208. }
  209. // 验证已添加商品数量,及选择商品是否已经被添加过
  210. $bootgoods_info = $pbooth_model->getBoothgoodsList(array(array('store_id', '=', session('store_id'))), 'goods_id');
  211. // 已添加商品总数
  212. if (count($bootgoods_info) >= config('ds_config.promotion_booth_goods_sum')) {
  213. $data = array('result' => 'false', 'msg' => sprintf(lang('promotion_booth_goods_sum_error'), config('ds_config.promotion_booth_goods_sum')));
  214. $this->_echoJson($data);
  215. }
  216. // 商品是否已经被添加
  217. $bootgoods_info = array_under_reset($bootgoods_info, 'goods_id');
  218. if (isset($bootgoods_info[$gid])) {
  219. $data = array('result' => 'false', 'msg' => lang('goods_already_add'));
  220. $this->_echoJson($data);
  221. }
  222. // 保存到推荐展位商品表
  223. $insert = array();
  224. $insert['store_id'] = session('store_id');
  225. $insert['goods_id'] = $goods_info['goods_id'];
  226. $insert['gc_id'] = $goods_info['gc_id'];
  227. $pbooth_model->addBoothgoods($insert);
  228. $this->recordSellerlog('添加推荐展位商品,商品id:' . $goods_info['goods_id']);
  229. // 输出商品信息
  230. $goods_info['goods_image'] = goods_thumb($goods_info);
  231. $goods_info['url'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  232. $goods_class = model('goodsclass')->getGoodsclassInfoById($goods_info['gc_id']);
  233. $goods_info['gc_name'] = $goods_class['gc_name'];
  234. $goods_info['result'] = 'true';
  235. $data['msg'] = lang('add_success');
  236. $data['goods_info'] = $goods_info;
  237. $this->_echoJson($data);
  238. }
  239. /**
  240. * 删除选择商品
  241. */
  242. public function del_choosed_goods()
  243. {
  244. $gid = input('param.gid');
  245. if ($gid <= 0) {
  246. $data = array('result' => 'false', 'msg' => lang('param_error'));
  247. $this->_echoJson($data);
  248. }
  249. $result = model('pbooth')->delBoothgoods(array('goods_id' => $gid, 'store_id' => session('store_id')));
  250. if ($result) {
  251. $this->recordSellerlog('删除推荐展位商品,商品id:' . $gid);
  252. $data = array('result' => 'true', 'msg' => lang('ds_common_del_succ'));
  253. } else {
  254. $data = array('result' => 'false', 'msg' => lang('ds_common_del_fail'));
  255. }
  256. $this->_echoJson($data);
  257. }
  258. /**
  259. * 输出JSON
  260. * @param array $data
  261. */
  262. private function _echoJson($data)
  263. {
  264. echo json_encode($data);
  265. exit();
  266. }
  267. /**
  268. * 用户中心右边,小导航
  269. *
  270. * @param string $menu_type 导航类型
  271. * @param string $name 当前导航的name
  272. * @return
  273. */
  274. protected function getSellerItemList()
  275. {
  276. $menu_array = array();
  277. switch (request()->action()) {
  278. case 'index':
  279. $menu_array = array(
  280. array(
  281. 'name' => 'index', 'text' => lang('recommended_stand'),
  282. 'url' => (string) url('Sellerpromotionbooth/index')
  283. )
  284. );
  285. break;
  286. case 'booth_quota_add':
  287. $menu_array = array(
  288. array(
  289. 'name' => 'index', 'text' => lang('recommended_stand'),
  290. 'url' => (string) url('Sellerpromotionbooth/index')
  291. ), array(
  292. 'name' => 'booth_quota_add', 'text' => lang('purchased_packages'),
  293. 'url' => (string) url('Sellerpromotionbooth/booth_quota_add')
  294. )
  295. );
  296. break;
  297. case 'booth_renew':
  298. $menu_array = array(
  299. array(
  300. 'name' => 'index', 'text' => lang('recommended_stand'),
  301. 'url' => (string) url('Sellerpromotionbooth/index')
  302. ), array(
  303. 'name' => 'booth_renew', 'text' => lang('subscription_fee'), 'url' => (string) url('Sellerpromotionbooth/booth_renew')
  304. )
  305. );
  306. break;
  307. }
  308. return $menu_array;
  309. }
  310. }