Sellerpromotionbooth.php 14 KB

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