Sellerpromotionbooth.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellerpromotionbooth extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerpromotionbooth.lang.php');
  21. if (intval(config('ds_config.promotion_allow')) !== 1) {
  22. $this->error(lang('promotion_unavailable'), (string) url('Seller/index'));
  23. }
  24. }
  25. /**
  26. * 套餐商品列表
  27. */
  28. public function index() {
  29. $pbooth_model = model('pbooth');
  30. // 更新套餐状态
  31. $where = array();
  32. $where[] = array('store_id', '=', session('store_id'));
  33. $where[] = array('boothquota_endtime', '<', TIMESTAMP);
  34. $pbooth_model->editBoothClose($where);
  35. $isPlatformStore = check_platform_store() ? true : false;
  36. View::assign('isPlatformStore', $isPlatformStore);
  37. $hasList = $isPlatformStore;
  38. if (!$isPlatformStore) {
  39. // 检查是否已购买套餐
  40. $where = array();
  41. $where[] = array('store_id', '=', session('store_id'));
  42. $booth_quota = $pbooth_model->getBoothquotaInfo($where);
  43. View::assign('booth_quota', $booth_quota);
  44. if (!empty($booth_quota)) {
  45. $hasList = true;
  46. } elseif (intval(config('ds_config.promotion_booth_price')) == 0) {
  47. $hasList = true;
  48. } else {
  49. $update = array('boothgoods_state' => $pbooth_model::STATE0);
  50. $pbooth_model->editBooth($update, $where);
  51. }
  52. }
  53. if ($hasList) {
  54. // 查询已选择商品
  55. $boothgoods_list = $pbooth_model->getBoothgoodsList(array(array('store_id' ,'=', session('store_id'))), 'goods_id');
  56. if (!empty($boothgoods_list)) {
  57. $goodsid_array = array();
  58. foreach ($boothgoods_list as $val) {
  59. $goodsid_array[] = $val['goods_id'];
  60. }
  61. $goods_list = model('goods')->getGoodsList(array(array('goods_id', 'in', $goodsid_array)), 'goods_id,goods_name,goods_image,goods_price,store_id,gc_id');
  62. if (!empty($goods_list)) {
  63. $gcid_array = array(); // 商品分类id
  64. foreach ($goods_list as $key => $val) {
  65. $gcid_array[] = $val['gc_id'];
  66. $goods_list[$key]['goods_image'] = goods_thumb($val);
  67. $goods_list[$key]['url'] = (string) url('Goods/index', array('goods_id' => $val['goods_id']));
  68. }
  69. $goodsclass_list = model('goodsclass')->getGoodsclassListByIds($gcid_array);
  70. $goodsclass_list = array_under_reset($goodsclass_list, 'gc_id');
  71. View::assign('goods_list', $goods_list);
  72. View::assign('goodsclass_list', $goodsclass_list);
  73. }
  74. }
  75. }
  76. $this->setSellerCurMenu('Sellerpromotionbooth');
  77. $this->setSellerCurItem('index');
  78. return View::fetch($this->template_dir . 'index');
  79. }
  80. /**
  81. * 选择商品
  82. */
  83. public function booth_select_goods() {
  84. $goods_model = model('goods');
  85. $condition = array();
  86. $condition[] = array('store_id', '=', session('store_id'));
  87. $goods_name = input('post.goods_name');
  88. if ($goods_name != '') {
  89. $condition[] = array('goods_name', 'like', '%' . $goods_name . '%');
  90. }
  91. $goods_list = $goods_model->getGoodsOnlineList($condition, '*', 10);
  92. View::assign('goods_list', $goods_list);
  93. View::assign('show_page', $goods_model->page_info->render());
  94. echo View::fetch($this->template_dir . 'select_goods');
  95. }
  96. /**
  97. * 购买套餐
  98. */
  99. public function booth_quota_add() {
  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('exetime' => $end_time, 'exeid' => session('store_id'), 'type' => 4), 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. if (request()->isPost()) {
  140. if (intval(config('ds_config.promotion_booth_price')) == 0) {
  141. ds_json_encode(10001, lang('param_error'));
  142. }
  143. $pbooth_model = model('pbooth');
  144. $quantity = intval(input('post.booth_quota_quantity')); // 购买数量(月)
  145. $price_quantity = $quantity * intval(config('ds_config.promotion_booth_price')); // 扣款数
  146. if ($quantity <= 0 || $quantity > 12) {
  147. ds_json_encode(10001, lang('param_error'));
  148. }
  149. $condition = array();
  150. $condition[] = array('store_id','=',session('store_id'));
  151. $booth_quota = $pbooth_model->getBoothquotaInfo($condition);
  152. if ($booth_quota['boothquota_endtime'] > TIMESTAMP) {
  153. // 套餐未超时(结束时间+购买时间)
  154. $update['boothquota_endtime'] = intval($booth_quota['boothquota_endtime']) + 60 * 60 * 24 * 30 * $quantity;
  155. } else {
  156. // 套餐已超时(当前时间+购买时间)
  157. $update['boothquota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  158. }
  159. $return = $pbooth_model->editBoothquotaOpen($update, $condition);
  160. if ($return) {
  161. // 添加店铺费用记录
  162. $this->recordStorecost($price_quantity, '购买推荐展位');
  163. // 添加任务队列
  164. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  165. $this->addcron(array('exetime' => $end_time, 'exeid' => session('store_id'), 'type' => 4), true);
  166. $this->recordSellerlog('续费' . $quantity . '套推荐展位,单位元');
  167. ds_json_encode(10000, lang('ds_common_op_succ'));
  168. } else {
  169. ds_json_encode(10001, lang('ds_common_op_fail'));
  170. }
  171. }
  172. $this->setSellerCurMenu('Sellerpromotionbooth');
  173. $this->setSellerCurItem('booth_renew');
  174. return View::fetch($this->template_dir . 'quota_add');
  175. }
  176. /**
  177. * 选择商品
  178. */
  179. public function choosed_goods() {
  180. $gid = input('param.gid');
  181. if ($gid <= 0) {
  182. $data = array('result' => 'false', 'msg' => lang('param_error'));
  183. $this->_echoJson($data);
  184. }
  185. // 验证商品是否存在
  186. $goods_info = model('goods')->getGoodsInfoByID($gid);
  187. if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
  188. $data = array('result' => 'false', 'msg' => lang('param_error'));
  189. $this->_echoJson($data);
  190. }
  191. $pbooth_model = model('pbooth');
  192. if (!check_platform_store()) {
  193. // 验证套餐时候过期
  194. $booth_info = $pbooth_model->getBoothquotaInfo(array(
  195. array('store_id', '=', session('store_id')),
  196. array('boothquota_endtime', '>', TIMESTAMP)
  197. ), 'boothquota_id');
  198. if (empty($booth_info)) {
  199. if (intval(config('ds_config.promotion_booth_price')) != 0) {
  200. $data = array('result' => 'false', 'msg' => lang('boothquota_expire'));
  201. $this->_echoJson($data);
  202. }
  203. }
  204. }
  205. // 验证已添加商品数量,及选择商品是否已经被添加过
  206. $bootgoods_info = $pbooth_model->getBoothgoodsList(array(array('store_id' ,'=', session('store_id'))), 'goods_id');
  207. // 已添加商品总数
  208. if (count($bootgoods_info) >= config('ds_config.promotion_booth_goods_sum')) {
  209. $data = array('result' => 'false', 'msg' => sprintf(lang('promotion_booth_goods_sum_error'), config('ds_config.promotion_booth_goods_sum')));
  210. $this->_echoJson($data);
  211. }
  212. // 商品是否已经被添加
  213. $bootgoods_info = array_under_reset($bootgoods_info, 'goods_id');
  214. if (isset($bootgoods_info[$gid])) {
  215. $data = array('result' => 'false', 'msg' => lang('goods_already_add'));
  216. $this->_echoJson($data);
  217. }
  218. // 保存到推荐展位商品表
  219. $insert = array();
  220. $insert['store_id'] = session('store_id');
  221. $insert['goods_id'] = $goods_info['goods_id'];
  222. $insert['gc_id'] = $goods_info['gc_id'];
  223. $pbooth_model->addBoothgoods($insert);
  224. $this->recordSellerlog('添加推荐展位商品,商品id:' . $goods_info['goods_id']);
  225. // 输出商品信息
  226. $goods_info['goods_image'] = goods_thumb($goods_info);
  227. $goods_info['url'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  228. $goods_class = model('goodsclass')->getGoodsclassInfoById($goods_info['gc_id']);
  229. $goods_info['gc_name'] = $goods_class['gc_name'];
  230. $goods_info['result'] = 'true';
  231. $this->_echoJson($goods_info);
  232. }
  233. /**
  234. * 删除选择商品
  235. */
  236. public function del_choosed_goods() {
  237. $gid = input('param.gid');
  238. if ($gid <= 0) {
  239. $data = array('result' => 'false', 'msg' => lang('param_error'));
  240. $this->_echoJson($data);
  241. }
  242. $result = model('pbooth')->delBoothgoods(array('goods_id' => $gid, 'store_id' => session('store_id')));
  243. if ($result) {
  244. $this->recordSellerlog('删除推荐展位商品,商品id:' . $gid);
  245. $data = array('result' => 'true');
  246. } else {
  247. $data = array('result' => 'false', 'msg' => lang('ds_common_del_fail'));
  248. }
  249. $this->_echoJson($data);
  250. }
  251. /**
  252. * 输出JSON
  253. * @param array $data
  254. */
  255. private function _echoJson($data) {
  256. echo json_encode($data);
  257. exit();
  258. }
  259. /**
  260. * 用户中心右边,小导航
  261. *
  262. * @param string $menu_type 导航类型
  263. * @param string $name 当前导航的name
  264. * @return
  265. */
  266. protected function getSellerItemList() {
  267. $menu_array = array();
  268. switch (request()->action()) {
  269. case 'index':
  270. $menu_array = array(
  271. array(
  272. 'name' => 'index', 'text' => lang('recommended_stand'),
  273. 'url' => (string) url('Sellerpromotionbooth/index')
  274. )
  275. );
  276. break;
  277. case 'booth_quota_add':
  278. $menu_array = array(
  279. array(
  280. 'name' => 'index', 'text' => lang('recommended_stand'),
  281. 'url' => (string) url('Sellerpromotionbooth/index')
  282. ), array(
  283. 'name' => 'booth_quota_add', 'text' => lang('purchased_packages'),
  284. 'url' => (string) url('Sellerpromotionbooth/booth_quota_add')
  285. )
  286. );
  287. break;
  288. case 'booth_renew':
  289. $menu_array = array(
  290. array(
  291. 'name' => 'index', 'text' => lang('recommended_stand'),
  292. 'url' => (string) url('Sellerpromotionbooth/index')
  293. ), array(
  294. 'name' => 'booth_renew', 'text' => lang('subscription_fee'), 'url' => (string) url('Sellerpromotionbooth/booth_renew')
  295. )
  296. );
  297. break;
  298. }
  299. return $menu_array;
  300. }
  301. }