Sellerpromotionbooth.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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('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. 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('cron_exetime' => $end_time, 'cron_value' => serialize(intval(session('store_id'))), 'cron_type' => 'editBoothClose'), 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. $data = array();
  181. $data['result'] = 'true';
  182. $gid = input('param.gid');
  183. if ($gid <= 0) {
  184. $data = array('result' => 'false', 'msg' => lang('param_error'));
  185. $this->_echoJson($data);
  186. }
  187. // 验证商品是否存在
  188. $goods_info = model('goods')->getGoodsInfoByID($gid);
  189. if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
  190. $data = array('result' => 'false', 'msg' => lang('param_error'));
  191. $this->_echoJson($data);
  192. }
  193. $pbooth_model = model('pbooth');
  194. if (!check_platform_store()) {
  195. // 验证套餐时候过期
  196. $booth_info = $pbooth_model->getBoothquotaInfo(array(
  197. array('store_id', '=', session('store_id')),
  198. array('boothquota_endtime', '>', TIMESTAMP)
  199. ), 'boothquota_id');
  200. if (empty($booth_info)) {
  201. if (intval(config('ds_config.promotion_booth_price')) != 0) {
  202. $data = array('result' => 'false', 'msg' => lang('boothquota_expire'));
  203. $this->_echoJson($data);
  204. }
  205. }
  206. }
  207. // 验证已添加商品数量,及选择商品是否已经被添加过
  208. $bootgoods_info = $pbooth_model->getBoothgoodsList(array(array('store_id' ,'=', session('store_id'))), 'goods_id');
  209. // 已添加商品总数
  210. if (count($bootgoods_info) >= config('ds_config.promotion_booth_goods_sum')) {
  211. $data = array('result' => 'false', 'msg' => sprintf(lang('promotion_booth_goods_sum_error'), config('ds_config.promotion_booth_goods_sum')));
  212. $this->_echoJson($data);
  213. }
  214. // 商品是否已经被添加
  215. $bootgoods_info = array_under_reset($bootgoods_info, 'goods_id');
  216. if (isset($bootgoods_info[$gid])) {
  217. $data = array('result' => 'false', 'msg' => lang('goods_already_add'));
  218. $this->_echoJson($data);
  219. }
  220. // 保存到推荐展位商品表
  221. $insert = array();
  222. $insert['store_id'] = session('store_id');
  223. $insert['goods_id'] = $goods_info['goods_id'];
  224. $insert['gc_id'] = $goods_info['gc_id'];
  225. $pbooth_model->addBoothgoods($insert);
  226. $this->recordSellerlog('添加推荐展位商品,商品id:' . $goods_info['goods_id']);
  227. // 输出商品信息
  228. $goods_info['goods_image'] = goods_thumb($goods_info);
  229. $goods_info['url'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  230. $goods_class = model('goodsclass')->getGoodsclassInfoById($goods_info['gc_id']);
  231. $goods_info['gc_name'] = $goods_class['gc_name'];
  232. $goods_info['result'] = 'true';
  233. $data['msg'] = lang('add_success');
  234. $data['goods_info'] = $goods_info;
  235. $this->_echoJson($data);
  236. }
  237. /**
  238. * 删除选择商品
  239. */
  240. public function del_choosed_goods() {
  241. $gid = input('param.gid');
  242. if ($gid <= 0) {
  243. $data = array('result' => 'false', 'msg' => lang('param_error'));
  244. $this->_echoJson($data);
  245. }
  246. $result = model('pbooth')->delBoothgoods(array('goods_id' => $gid, 'store_id' => session('store_id')));
  247. if ($result) {
  248. $this->recordSellerlog('删除推荐展位商品,商品id:' . $gid);
  249. $data = array('result' => 'true','msg' => lang('ds_common_del_succ'));
  250. } else {
  251. $data = array('result' => 'false', 'msg' => lang('ds_common_del_fail'));
  252. }
  253. $this->_echoJson($data);
  254. }
  255. /**
  256. * 输出JSON
  257. * @param array $data
  258. */
  259. private function _echoJson($data) {
  260. echo json_encode($data);
  261. exit();
  262. }
  263. /**
  264. * 用户中心右边,小导航
  265. *
  266. * @param string $menu_type 导航类型
  267. * @param string $name 当前导航的name
  268. * @return
  269. */
  270. protected function getSellerItemList() {
  271. $menu_array = array();
  272. switch (request()->action()) {
  273. case 'index':
  274. $menu_array = array(
  275. array(
  276. 'name' => 'index', 'text' => lang('recommended_stand'),
  277. 'url' => (string) url('Sellerpromotionbooth/index')
  278. )
  279. );
  280. break;
  281. case 'booth_quota_add':
  282. $menu_array = array(
  283. array(
  284. 'name' => 'index', 'text' => lang('recommended_stand'),
  285. 'url' => (string) url('Sellerpromotionbooth/index')
  286. ), array(
  287. 'name' => 'booth_quota_add', 'text' => lang('purchased_packages'),
  288. 'url' => (string) url('Sellerpromotionbooth/booth_quota_add')
  289. )
  290. );
  291. break;
  292. case 'booth_renew':
  293. $menu_array = array(
  294. array(
  295. 'name' => 'index', 'text' => lang('recommended_stand'),
  296. 'url' => (string) url('Sellerpromotionbooth/index')
  297. ), array(
  298. 'name' => 'booth_renew', 'text' => lang('subscription_fee'), 'url' => (string) url('Sellerpromotionbooth/booth_renew')
  299. )
  300. );
  301. break;
  302. }
  303. return $menu_array;
  304. }
  305. }