store_promotion_bundling.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. /**
  3. * 用户中心-优惠套装
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class store_promotion_bundlingControl extends BaseSellerControl {
  10. public function __construct() {
  11. parent::__construct();
  12. /**
  13. * 读取语言包
  14. */
  15. Language::read('member_layout,member_store_promotion_bundling');
  16. //检查是否开启
  17. if (intval(C('promotion_allow')) !== 1) {
  18. showMessage(Language::get('promotion_unavailable'), urlShop('seller_center', 'index'),'','error');
  19. }
  20. }
  21. public function indexOp() {
  22. $this->bundling_listOp();
  23. }
  24. /**
  25. * 发布的活动列表
  26. */
  27. public function bundling_listOp() {
  28. $model_bundling = Model('p_bundling');
  29. // 更新套装状态
  30. $where = array();
  31. $where['store_id'] = $_SESSION['store_id'];
  32. $where['bl_quota_endtime'] = array('lt', TIMESTAMP);
  33. $model_bundling->editBundlingQuotaClose($where);
  34. $hasList = false;
  35. if (checkPlatformStore()) {
  36. Tpl::output('isOwnShop', true);
  37. $hasList = true;
  38. } else {
  39. // 检查是否已购买套餐
  40. $where = array();
  41. $where['store_id'] = $_SESSION['store_id'];
  42. $bundling_quota = $model_bundling->getBundlingQuotaInfo($where);
  43. Tpl::output('bundling_quota', $bundling_quota);
  44. if (!empty($bundling_quota)) {
  45. // 计算已经发布活动、剩余活动数量
  46. $bundling_published = $model_bundling->getBundlingCount(array('store_id' => $_SESSION['store_id']));
  47. $bundling_surplus = intval(C('promotion_bundling_sum')) - intval($bundling_published);
  48. Tpl::output('bundling_published', $bundling_published);
  49. Tpl::output('bundling_surplus', $bundling_surplus);
  50. $hasList = true;
  51. }
  52. }
  53. if ($hasList) {
  54. // 查询活动
  55. $where = array();
  56. $where['store_id'] = $_SESSION['store_id'];
  57. if ($_GET['bundling_name'] != '') {
  58. $where['bl_name'] = array('like', '%' . trim($_GET['bundling_name']) . '%');
  59. }
  60. if (is_numeric($_GET['state'])) {
  61. $where['bl_state'] = $_GET['state'];
  62. }
  63. $bundling_list = $model_bundling->getBundlingList($where, '*', 'bl_id desc', 10, 0, $bundling_published);
  64. $bundling_list = array_under_reset($bundling_list, 'bl_id');
  65. Tpl::output('show_page',$model_bundling->showpage(2));
  66. if (!empty($bundling_list)) {
  67. $blid_array = array_keys($bundling_list);
  68. $bgoods_array = $model_bundling->getBundlingGoodsList(array('bl_id' => array('in', $blid_array), 'bl_appoint' => 1), 'bl_id,goods_id,count(*) as count', 'bl_appoint desc', 'bl_id');
  69. $bgoods_array = array_under_reset($bgoods_array, 'goods_id');
  70. if (!empty($bgoods_array)) {
  71. $goodsid_array = array_keys($bgoods_array);
  72. $goods_array = Model('goods')->getGoodsList(array('goods_id' => array('in', $goodsid_array)), 'goods_id,goods_image');
  73. $goods_array = array_under_reset($goods_array, 'goods_id');
  74. }
  75. $bgoods_array = array_under_reset($bgoods_array, 'bl_id');
  76. foreach ($bundling_list as $key => $val) {
  77. $bundling_list[$key]['goods_id'] = $bgoods_array[$val['bl_id']]['goods_id'];
  78. $bundling_list[$key]['count'] = $bgoods_array[$val['bl_id']]['count'];
  79. $bundling_list[$key]['img'] = thumb($goods_array[$bgoods_array[$val['bl_id']]['goods_id']], 60);
  80. }
  81. }
  82. Tpl::output('list', $bundling_list);
  83. // 状态数组
  84. $state_array = array(0=>Language::get('bundling_status_0') , 1=>Language::get('bundling_status_1'));
  85. Tpl::output('state_array', $state_array);
  86. }
  87. $this->profile_menu('bundling_list', 'bundling_list');
  88. Tpl::showpage('store_promotion_bundling.list');
  89. }
  90. /**
  91. * 套餐购买
  92. */
  93. public function bundling_quota_addOp() {
  94. if (chksubmit()) {
  95. $quantity = intval($_POST['bundling_quota_quantity']); // 购买数量(月)
  96. $price_quantity = $quantity * intval(C('promotion_bundling_price')); // 扣款数
  97. if ($quantity <= 0 || $quantity > 12) {
  98. showDialog(Language::get('bundling_quota_price_fail'), urlShop('store_promotion_bundling', 'bundling_quota_add'), '', 'error' );
  99. }
  100. // 实例化模型
  101. $model_bundling = Model('p_bundling');
  102. $data = array();
  103. $data['store_id'] = $_SESSION['store_id'];
  104. $data['store_name'] = $_SESSION['store_name'];
  105. $data['member_id'] = $_SESSION['member_id'];
  106. $data['member_name'] = $_SESSION['member_name'];
  107. $data['bl_quota_month'] = $quantity;
  108. $data['bl_quota_starttime'] = TIMESTAMP;
  109. $data['bl_quota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  110. $data['bl_state'] = 1;
  111. $return = $model_bundling->addBundlingQuota($data);
  112. if ($return) {
  113. // 添加店铺费用记录
  114. $this->recordStoreCost($price_quantity, '购买优惠套装');
  115. // 添加任务队列
  116. $end_time = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  117. $this->addcron(array('exetime' => $end_time, 'exeid' => $_SESSION['store_id'], 'type' => 3), true);
  118. $this->recordSellerLog('购买'.$quantity.'套优惠套装,单位元');
  119. showDialog(L('bundling_quota_price_succ'), urlShop('store_promotion_bundling', 'bundling_list'), 'succ');
  120. } else {
  121. showDialog(L('bundling_quota_price_fail'), urlShop('store_promotion_bundling', 'bundling_quota_add'));
  122. }
  123. }
  124. // 输出导航
  125. self::profile_menu('bundling_quota_add', 'bundling_quota_add');
  126. Tpl::showpage('store_promotion_bundling.quota_add');
  127. }
  128. /**
  129. * 套餐续费
  130. */
  131. public function bundling_renewOp() {
  132. if (chksubmit()) {
  133. $model_bundling = Model('p_bundling');
  134. $quantity = intval($_POST['bundling_quota_quantity']); // 购买数量(月)
  135. $price_quantity = $quantity * intval(C('promotion_bundling_price')); // 扣款数
  136. if ($quantity <= 0 || $quantity > 12) {
  137. showDialog(Language::get('bundling_quota_price_fail'), urlShop('store_promotion_bundling', 'bundling_quota_add'), '', 'error' );
  138. }
  139. $where = array();
  140. $where['store_id'] = $_SESSION ['store_id'];
  141. $bundling_quota = $model_bundling->getBundlingQuotaInfo($where);
  142. if ($bundling_quota['bl_quota_endtime'] > TIMESTAMP) {
  143. // 套餐未超时(结束时间+购买时间)
  144. $update['bl_quota_endtime'] = intval($bundling_quota['bl_quota_endtime']) + 60 * 60 * 24 * 30 * $quantity;
  145. } else {
  146. // 套餐已超时(当前时间+购买时间)
  147. $update['bl_quota_endtime'] = TIMESTAMP + 60 * 60 * 24 * 30 * $quantity;
  148. }
  149. $return = $model_bundling->editBundlingQuotaOpen($update, $where);
  150. if ($return) {
  151. // 添加店铺费用记录
  152. $this->recordStoreCost($price_quantity, '购买优惠套装');
  153. // 添加任务队列
  154. $this->addcron(array('exetime' => $update['bl_quota_endtime'], 'exeid' => $_SESSION['store_id'], 'type' => 3), true);
  155. $this->recordSellerLog('续费'.$quantity.'套优惠套装,单位元');
  156. showDialog(L('bundling_quota_price_succ'), urlShop('store_promotion_bundling', 'bundling_list'), 'succ');
  157. } else {
  158. showDialog(L('bundling_quota_price_fail'), urlShop('store_promotion_bundling', 'bundling_quota_add'));
  159. }
  160. }
  161. self::profile_menu('bundling_renew', 'bundling_renew');
  162. Tpl::showpage('store_promotion_bundling.quota_add');
  163. }
  164. /**
  165. * 套餐活动添加
  166. */
  167. public function bundling_addOp() {
  168. /**
  169. * 实例化模型
  170. */
  171. $model_bundling = Model('p_bundling');
  172. // 验证套餐数量
  173. if (intval(C('promotion_bundling_sum')) != 0 && !isset($_REQUEST['bundling_id'])) {
  174. $count = $model_bundling->getBundlingCount(array('store_id' => $_SESSION['store_id']));
  175. if (intval(C('promotion_bundling_sum')) <= intval($count)) {
  176. showMessage(L('bundling_add_fail_quantity_beyond'), '', '', 'error');
  177. }
  178. }
  179. if (chksubmit()) {
  180. // 插入套餐
  181. $data = array();
  182. if (isset($_POST['bundling_id'])) {
  183. $data['bl_id'] = intval($_POST['bundling_id']);
  184. }
  185. $data['bl_name'] = $_POST['bundling_name'];
  186. $data['store_id'] = $_SESSION['store_id'];
  187. $data['store_name'] = $_SESSION['store_name'];
  188. $data['bl_discount_price'] = $_POST['discount_price'];
  189. $data['bl_freight_choose'] = $_POST['bundling_freight_choose'];
  190. $data['bl_freight'] = $_POST['bundling_freight'];
  191. $data['bl_state'] = intval($_POST['state']);
  192. $return = $model_bundling->addBundling($data, true);
  193. if (!$return) {
  194. showDialog(L('nc_common_op_fail'), '', '', 'error');
  195. }
  196. // 插入套餐商品
  197. $model_goods = Model('goods');
  198. $data_goods = array();
  199. $appoint_goodsid = false;
  200. $model_bundling->delBundlingGoods(array('bl_id' => intval($_POST['bundling_id'])));
  201. if (!empty($_POST['goods']) && is_array($_POST['goods'])) {
  202. foreach ($_POST['goods'] as $key => $val) {
  203. // 验证是否为本店铺商品
  204. $goods_info = $model_goods->getGoodsInfoByID($val['gid'], 'goods_id,goods_name,goods_image,store_id');
  205. if (empty($goods_info) || $goods_info['store_id'] != $_SESSION['store_id']) {
  206. continue;
  207. }
  208. $data = array();
  209. $data['bl_id'] = isset($_POST['bundling_id']) ? intval($_POST['bundling_id']) : $return;
  210. $data['goods_id'] = $goods_info['goods_id'];
  211. $data['goods_name'] = $goods_info['goods_name'];
  212. $data['goods_image'] = $goods_info['goods_image'];
  213. $data['bl_goods_price'] = ncPriceFormat($val['price']);
  214. $data['bl_appoint'] = intval($val['appoint']);
  215. if (!$appoint_goodsid && intval($val['appoint']) == 1) {
  216. $appoint_goodsid = intval($val['gid']);
  217. }
  218. $data_goods[] = $data;
  219. }
  220. }
  221. // 插入数据
  222. $return = $model_bundling->addBundlingGoodsAll($data_goods);
  223. if (!isset($_POST['bundling_id']) && !$appoint_goodsid) {
  224. // 自动发布动态
  225. // bl_id,bl_name,image_path,bl_discount_price,bl_freight_choose,bl_freight,store_id
  226. $data_array = array();
  227. $data_array['bl_id'] = $return;
  228. $data_array['goods_id'] = $appoint_goodsid;
  229. $data_array['bl_name'] = $data['bl_name'];
  230. $data_array['bl_img'] = empty($_POST['image_path']) ? '' : $_POST['image_path'][0];
  231. $data_array['bl_discount_price'] = $data['bl_discount_price'];
  232. $data_array['bl_freight_choose'] = $data['bl_freight_choose'];
  233. $data_array['bl_freight'] = $data['bl_freight'];
  234. $data_array['store_id'] = $_SESSION['store_id'];
  235. $this->storeAutoShare($data_array, 'bundling');
  236. }
  237. $this->recordSellerLog('添加优惠套装,名称:'.$data['bl_name'] . ' id:'.$return);
  238. showDialog(L('nc_common_op_succ'), urlShop('store_promotion_bundling', 'bundling_list'), 'succ');
  239. }
  240. // 是否能使用编辑器
  241. if(checkPlatformStore()){ // 平台店铺可以使用编辑器
  242. $editor_multimedia = true;
  243. } else { // 三方店铺需要
  244. $editor_multimedia = false;
  245. if ($this->store_grade['sg_function'] == 'editor_multimedia') {
  246. $editor_multimedia = true;
  247. }
  248. }
  249. Tpl::output('editor_multimedia', $editor_multimedia);
  250. if (intval($_GET['bundling_id']) > 0) {
  251. $bundling_info = $model_bundling->getBundlingInfo(array('bl_id' => intval($_GET['bundling_id']), 'store_id' => $_SESSION['store_id']));
  252. Tpl::output('bundling_info', $bundling_info);
  253. // 验证是否属于自己的组合套餐
  254. if (empty($bundling_info['store_id'])) {
  255. showMessage(L( 'wrong_argument'), urlShop('store_promotion_bundling', 'bundling_list'), '', 'error' );
  256. }
  257. $b_goods_list = $model_bundling->getBundlingGoodsList(array('bl_id' => intval($_GET['bundling_id'])));
  258. if (!empty($b_goods_list)) {
  259. $goodsid_array = array();
  260. foreach ($b_goods_list as $val) {
  261. $goodsid_array[] = $val['goods_id'];
  262. }
  263. $goods_list = Model('goods')->getGoodsList(array('goods_id' => array('in', $goodsid_array)), 'goods_id,goods_price,goods_image,goods_name');
  264. Tpl::output('goods_list', array_under_reset($goods_list, 'goods_id'));
  265. }
  266. Tpl::output('b_goods_list', $b_goods_list);
  267. // 输出导航
  268. self::profile_menu('bundling_edit', 'bundling_edit');
  269. } else {
  270. // 输出导航
  271. self::profile_menu('bundling_add', 'bundling_add');
  272. }
  273. Tpl::showpage('store_promotion_bundling.add');
  274. }
  275. /**
  276. * 套餐活动添加商品
  277. */
  278. public function bundling_add_goodsOp() {
  279. /**
  280. * 实例化模型
  281. */
  282. $model_goods =Model('goods');
  283. // where条件
  284. $where = array ();
  285. $where['store_id'] = $_SESSION['store_id'];
  286. if (intval($_GET['stc_id']) > 0) {
  287. $where['goods_stcids'] = array('like', '%,' . intval($_GET['stc_id']) . ',%');
  288. }
  289. if (trim($_GET['keyword']) != '') {
  290. $where['goods_name'] = array('like', '%' . trim($_GET['keyword']) . '%');
  291. }
  292. $goods_list = $model_goods->getGoodsListForPromotion($where, '*', 8, 'bundling');
  293. Tpl::output('show_page', $model_goods->showpage(2));
  294. Tpl::output('goods_list', $goods_list);
  295. /**
  296. * 商品分类
  297. */
  298. $store_goods_class = Model('store_goods_class')->getClassTree(array('store_id' => $_SESSION['store_id'], 'stc_state' => '1'));
  299. Tpl::output('store_goods_class', $store_goods_class);
  300. Tpl::showpage('store_promotion_bundling.add_goods', 'null_layout');
  301. }
  302. /**
  303. * 删除优惠套装活动
  304. */
  305. public function drop_bundlingOp(){
  306. /**
  307. * 参数验证
  308. */
  309. $blids = trim($_GET['bundling_id']);
  310. if (empty($blids)) {
  311. showDialog(L('para_error'), '', 'error');
  312. }
  313. $return = Model('p_bundling')->delBundling($blids, $_SESSION['store_id']);
  314. if ($return) {
  315. $this->recordSellerLog('删除优惠套装,套餐id:'.$blids);
  316. showDialog(L('bundling_delete_success'), 'reload', 'succ');
  317. } else {
  318. showDialog(L('bundling_delete_fail'), '', 'error');
  319. }
  320. }
  321. /**
  322. * 用户中心右边,小导航
  323. *
  324. * @param string $menu_type 导航类型
  325. * @param string $menu_key 当前导航的menu_key
  326. * @return
  327. */
  328. private function profile_menu($menu_type,$menu_key='') {
  329. $menu_array = array();
  330. switch ($menu_type) {
  331. case 'bundling_list':
  332. case 'bundling_quota_list':
  333. $menu_array = array(
  334. 1=>array('menu_key'=>'bundling_list', 'menu_name'=>Language::get('bundling_list'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_list'))
  335. );
  336. break;
  337. case 'bundling_quota_add':
  338. $menu_array = array(
  339. 1=>array('menu_key'=>'bundling_list', 'menu_name'=>Language::get('bundling_list'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_list')),
  340. 2=>array('menu_key'=>'bundling_quota_add', 'menu_name'=>Language::get('bundling_quota_add'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_quota_add'))
  341. );
  342. break;
  343. case 'bundling_renew':
  344. $menu_array = array(
  345. 1=>array('menu_key'=>'bundling_list', 'menu_name'=>Language::get('bundling_list'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_list')),
  346. 2=>array('menu_key'=>'bundling_renew', 'menu_name'=>'套餐续费', 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_renew'))
  347. );
  348. break;
  349. case 'bundling_add':
  350. $menu_array = array(
  351. 1=>array('menu_key'=>'bundling_list', 'menu_name'=>Language::get('bundling_list'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_list')),
  352. 2=>array('menu_key'=>'bundling_add', 'menu_name'=>Language::get('bundling_add'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_add'))
  353. );
  354. break;
  355. case 'bundling_edit':
  356. $menu_array = array(
  357. 1=>array('menu_key'=>'bundling_list', 'menu_name'=>Language::get('bundling_list'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_list')),
  358. 2=>array('menu_key'=>'bundling_edit', 'menu_name'=>Language::get('bundling_edit'), 'menu_url'=>urlShop('store_promotion_bundling', 'bundling_edit'))
  359. );
  360. break;
  361. }
  362. Tpl::output('member_menu',$menu_array);
  363. Tpl::output('menu_key',$menu_key);
  364. }
  365. }