store_promotion_booth.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. /**
  3. * 推荐展位管理
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class store_promotion_boothControl extends BaseSellerControl {
  7. public function __construct() {
  8. parent::__construct();
  9. //检查是否开启
  10. if (intval(C('promotion_allow')) !== 1) {
  11. showMessage(Language::get('promotion_unavailable'), urlShop('seller_center', 'index'),'','error');
  12. }
  13. }
  14. public function indexOp() {
  15. $this->booth_goods_listOp();
  16. }
  17. /**
  18. * 套餐商品列表
  19. */
  20. public function booth_goods_listOp() {
  21. $model_booth = Model('p_booth');
  22. // 更新套餐状态
  23. $where = array();
  24. $where['store_id'] = $_SESSION['store_id'];
  25. $where['booth_quota_endtime'] = array('lt', TIMESTAMP);
  26. $model_booth->editBoothClose($where);
  27. $hasList = false;
  28. if (checkPlatformStore()) {
  29. Tpl::output('isOwnShop', true);
  30. $hasList = true;
  31. } else {
  32. // 检查是否已购买套餐
  33. $where = array();
  34. $where['store_id'] = $_SESSION['store_id'];
  35. $booth_quota = $model_booth->getBoothQuotaInfo($where);
  36. Tpl::output('booth_quota', $booth_quota);
  37. if (!empty($booth_quota)) {
  38. $hasList = true;
  39. }
  40. }
  41. if ($hasList) {
  42. // 查询已选择商品
  43. $boothgoods_list = $model_booth->getBoothGoodsList(array('store_id' => $_SESSION['store_id']), 'goods_id');
  44. if (!empty($boothgoods_list)) {
  45. $goodsid_array = array();
  46. foreach ($boothgoods_list as $val) {
  47. $goodsid_array[] = $val['goods_id'];
  48. }
  49. $goods_list = Model('goods')->getGoodsList(array('goods_id' => array('in', $goodsid_array)), 'goods_id,goods_name,goods_image,goods_price,store_id,gc_id');
  50. if (!empty($goods_list)) {
  51. $gcid_array = array(); // 商品分类id
  52. foreach ($goods_list as $key => $val) {
  53. $gcid_array[] = $val['gc_id'];
  54. $goods_list[$key]['goods_image'] = thumb($val);
  55. $goods_list[$key]['url'] = urlShop('goods', 'index', array('goods_id' => $val['goods_id']));
  56. }
  57. $goodsclass_list = Model('goods_class')->getGoodsClassListByIds($gcid_array);
  58. $goodsclass_list = array_under_reset($goodsclass_list, 'gc_id');
  59. Tpl::output('goods_list', $goods_list);
  60. Tpl::output('goodsclass_list', $goodsclass_list);
  61. }
  62. }
  63. }
  64. $this->profile_menu('booth_goods_list', 'booth_goods_list');
  65. Tpl::showpage('store_promotion_booth.goods_list');
  66. }
  67. /**
  68. * 选择商品
  69. */
  70. public function booth_select_goodsOp() {
  71. $model_goods = Model('goods');
  72. $condition = array();
  73. $condition['store_id'] = $_SESSION['store_id'];
  74. if ($_POST['goods_name'] != '') {
  75. $condition['goods_name'] = array('like', '%'.$_POST['goods_name'].'%');
  76. }
  77. $goods_list = $model_goods->getGoodsOnlineList($condition, '*', 10);
  78. Tpl::output('goods_list', $goods_list);
  79. Tpl::output('show_page', $model_goods->showpage());
  80. Tpl::showpage('store_promotion_booth.select_goods', 'null_layout');
  81. }
  82. /**
  83. * 购买套餐
  84. */
  85. public function booth_quota_addOp() {
  86. if (chksubmit()) {
  87. $quantity = intval($_POST['booth_quota_quantity']); // 购买数量(月)
  88. $price_quantity = $quantity * intval(C('promotion_booth_price')); // 扣款数
  89. if ($quantity <= 0 || $quantity > 12) {
  90. showDialog('参数错误,购买失败。', urlShop('store_promotion_booth', 'booth_quota_add'), '', 'error' );
  91. }
  92. // 实例化模型
  93. $model_booth = Model('p_booth');
  94. $data = array();
  95. $data['store_id'] = $_SESSION['store_id'];
  96. $data['store_name'] = $_SESSION['store_name'];
  97. $data['booth_quota_starttime'] = TIMESTAMP;
  98. $data['booth_quota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  99. $data['booth_state'] = 1;
  100. $return = $model_booth->addBoothQuota($data);
  101. if ($return) {
  102. // 添加店铺费用记录
  103. $this->recordStoreCost($price_quantity, '购买推荐展位');
  104. // 添加任务队列
  105. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  106. $this->addcron(array('exetime' => $end_time, 'exeid' => $_SESSION['store_id'], 'type' => 4), true);
  107. $this->recordSellerLog('购买'.$quantity.'套推荐展位,单位元');
  108. showDialog('购买成功', urlShop('store_promotion_booth', 'booth_goods_list'), 'succ');
  109. } else {
  110. showDialog('购买失败', urlShop('store_promotion_booth', 'booth_quota_add'));
  111. }
  112. }
  113. // 输出导航
  114. self::profile_menu('booth_quota_add', 'booth_quota_add');
  115. Tpl::showpage('store_promotion_booth.quota_add');
  116. }
  117. /**
  118. * 套餐续费
  119. */
  120. public function booth_renewOp() {
  121. if (chksubmit()) {
  122. $model_booth = Model('p_booth');
  123. $quantity = intval($_POST['booth_quota_quantity']); // 购买数量(月)
  124. $price_quantity = $quantity * intval(C('promotion_booth_price')); // 扣款数
  125. if ($quantity <= 0 || $quantity > 12) {
  126. showDialog('参数错误,购买失败。', urlShop('store_promotion_booth', 'booth_quota_add'), '', 'error' );
  127. }
  128. $where = array();
  129. $where['store_id'] = $_SESSION ['store_id'];
  130. $booth_quota = $model_booth->getBoothQuotaInfo($where);
  131. if ($booth_quota['booth_quota_endtime'] > TIMESTAMP) {
  132. // 套餐未超时(结束时间+购买时间)
  133. $update['booth_quota_endtime'] = intval($booth_quota['booth_quota_endtime']) + 60 * 60 * 24 * 30 * $quantity;
  134. } else {
  135. // 套餐已超时(当前时间+购买时间)
  136. $update['booth_quota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  137. }
  138. $return = $model_booth->editBoothQuotaOpen($update, $where);
  139. if ($return) {
  140. // 添加店铺费用记录
  141. $this->recordStoreCost($price_quantity, '购买推荐展位');
  142. // 添加任务队列
  143. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  144. $this->addcron(array('exetime' => $end_time, 'exeid' => $_SESSION['store_id'], 'type' => 4), true);
  145. $this->recordSellerLog('续费'.$quantity.'套推荐展位,单位元');
  146. showDialog('购买成功', urlShop('store_promotion_booth', 'booth_list'), 'succ');
  147. } else {
  148. showDialog('购买失败', urlShop('store_promotion_booth', 'booth_quota_add'));
  149. }
  150. }
  151. self::profile_menu('booth_renew', 'booth_renew');
  152. Tpl::showpage('store_promotion_booth.quota_add');
  153. }
  154. /**
  155. * 选择商品
  156. */
  157. public function choosed_goodsOp() {
  158. $gid = $_GET['gid'];
  159. if ($gid <= 0) {
  160. $data = array('result' => 'false', 'msg' => '参数错误');
  161. $this->_echoJson($data);
  162. }
  163. // 验证商品是否存在
  164. $goods_info = Model('goods')->getGoodsInfoByID($gid, 'goods_id,goods_name,goods_image,goods_price,store_id,gc_id');
  165. if (empty($goods_info) || $goods_info['store_id'] != $_SESSION['store_id']) {
  166. $data = array('result' => 'false', 'msg' => '参数错误');
  167. $this->_echoJson($data);
  168. }
  169. $model_booth = Model('p_booth');
  170. if (!checkPlatformStore()) {
  171. // 验证套餐时候过期
  172. $booth_info = $model_booth->getBoothQuotaInfo(array('store_id' => $_SESSION['store_id'], 'booth_quota_endtime' => array('gt', TIMESTAMP)), 'booth_quota_id');
  173. if (empty($booth_info)) {
  174. $data = array('result' => 'false', 'msg' => '套餐过期请重新购买套餐');
  175. $this->_echoJson($data);
  176. }
  177. }
  178. // 验证已添加商品数量,及选择商品是否已经被添加过
  179. $bootgoods_info = $model_booth->getBoothGoodsList(array('store_id' => $_SESSION['store_id']), 'goods_id');
  180. // 已添加商品总数
  181. if (count($bootgoods_info) >= C('promotion_booth_goods_sum')) {
  182. $data = array('result' => 'false', 'msg' => '只能添加'.C('promotion_booth_goods_sum').'个商品');
  183. $this->_echoJson($data);
  184. }
  185. // 商品是否已经被添加
  186. $bootgoods_info = array_under_reset($bootgoods_info, 'goods_id');
  187. if (isset($bootgoods_info[$gid])) {
  188. $data = array('result' => 'false', 'msg' => '商品已经添加,请选择其他商品');
  189. $this->_echoJson($data);
  190. }
  191. // 保存到推荐展位商品表
  192. $insert = array();
  193. $insert['store_id'] = $_SESSION['store_id'];
  194. $insert['goods_id'] = $goods_info['goods_id'];
  195. $insert['gc_id'] = $goods_info['gc_id'];
  196. $model_booth->addBoothGoods($insert);
  197. $this->recordSellerLog('添加推荐展位商品,商品id:'.$goods_info['goods_id']);
  198. // 输出商品信息
  199. $goods_info['goods_image'] = thumb($goods_info);
  200. $goods_info['url'] = urlShop('goods', 'index', array('goods_id' => $goods_info['goods_id']));
  201. $goods_class = Model('goods_class')->getGoodsClassInfoById($goods_info['gc_id']);
  202. $goods_info['gc_name'] = $goods_class['gc_name'];
  203. $goods_info['result'] = 'true';
  204. $this->_echoJson($goods_info);
  205. }
  206. /**
  207. * 删除选择商品
  208. */
  209. public function del_choosed_goodsOp() {
  210. $gid = $_GET['gid'];
  211. if ($gid <= 0) {
  212. $data = array('result' => 'false', 'msg' => '参数错误');
  213. $this->_echoJson($data);
  214. }
  215. $result = Model('p_booth')->delBoothGoods(array('goods_id' => $gid, 'store_id' => $_SESSION['store_id']));
  216. if ($result) {
  217. $this->recordSellerLog('删除推荐展位商品,商品id:'.$gid);
  218. $data = array('result' => 'true');
  219. } else {
  220. $data = array('result' => 'false', 'msg' => '删除失败');
  221. }
  222. $this->_echoJson($data);
  223. }
  224. /**
  225. * 输出JSON
  226. * @param array $data
  227. */
  228. private function _echoJson($data) {
  229. if (strtoupper(CHARSET) == 'GBK'){
  230. $data = Language::getUTF8($data);//网站GBK使用编码时,转换为UTF-8,防止json输出汉字问题
  231. }
  232. echo json_encode($data);exit();
  233. }
  234. /**
  235. * 用户中心右边,小导航
  236. *
  237. * @param string $menu_type 导航类型
  238. * @param string $menu_key 当前导航的menu_key
  239. * @return
  240. */
  241. private function profile_menu($menu_type,$menu_key='') {
  242. $menu_array = array();
  243. switch ($menu_type) {
  244. case 'booth_goods_list':
  245. $menu_array = array(
  246. 1=>array('menu_key'=>'booth_goods_list', 'menu_name'=>'商品列表', 'menu_url'=>urlShop('store_promotion_booth', 'booth_goods_list'))
  247. );
  248. break;
  249. case 'booth_quota_add':
  250. $menu_array = array(
  251. 1=>array('menu_key'=>'booth_goods_list', 'menu_name'=>'商品列表', 'menu_url'=>urlShop('store_promotion_booth', 'booth_goods_list')),
  252. 2=>array('menu_key'=>'booth_quota_add', 'menu_name'=>'购买套餐', 'menu_url'=>urlShop('store_promotion_booth', 'booth_quota_add'))
  253. );
  254. break;
  255. case 'booth_renew':
  256. $menu_array = array(
  257. 1=>array('menu_key'=>'booth_goods_list', 'menu_name'=>'商品列表', 'menu_url'=>urlShop('store_promotion_booth', 'booth_goods_list')),
  258. 2=>array('menu_key'=>'booth_renew', 'menu_name'=>'套餐续费', 'menu_url'=>urlShop('store_promotion_booth', 'booth_renew'))
  259. );
  260. break;
  261. }
  262. Tpl::output('member_menu',$menu_array);
  263. Tpl::output('menu_key',$menu_key);
  264. }
  265. }