Groupbuy.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. /**
  3. * 抢购管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Groupbuy extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/groupbuy.lang.php');
  21. }
  22. /**
  23. * 进行中抢购列表,只可推荐
  24. *
  25. */
  26. public function index()
  27. {
  28. $groupbuy_model = model('groupbuy');
  29. $condition = array();
  30. if (!empty(input('param.groupbuy_name'))) {
  31. $condition[] = array('groupbuy_name', 'like', '%' . input('param.groupbuy_name') . '%');
  32. }
  33. if ((input('param.store_name'))) {
  34. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  35. }
  36. if ((input('param.groupbuy_state'))) {
  37. $condition[] = array('groupbuy_state', '=', input('param.groupbuy_state'));
  38. }
  39. $groupbuy_list = $groupbuy_model->getGroupbuyExtendList($condition, 10);
  40. View::assign('groupbuy_list', $groupbuy_list);
  41. View::assign('show_page', $groupbuy_model->page_info->render());
  42. View::assign('groupbuy_state_array', $groupbuy_model->getGroupbuyStateArray());
  43. $this->setAdminCurItem('index');
  44. // 输出自营店铺IDS
  45. View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
  46. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  47. View::assign('flippedOwnShopIds', '');
  48. return View::fetch();
  49. }
  50. /**
  51. * 审核通过
  52. */
  53. public function groupbuy_review_pass()
  54. {
  55. $groupbuy_id = intval(input('post.groupbuy_id'));
  56. if ($groupbuy_id <= 0) {
  57. $this->error(lang('param_error'));
  58. }
  59. $groupbuy_model = model('groupbuy');
  60. $result = $groupbuy_model->reviewPassGroupbuy($groupbuy_id);
  61. if ($result) {
  62. $this->log('通过抢购活动申请,抢购编号' . $groupbuy_id, null);
  63. // 添加队列
  64. $groupbuy_info = $groupbuy_model->getGroupbuyInfo(array('groupbuy_id' => $groupbuy_id));
  65. $this->addcron(array(
  66. 'cron_exetime' => $groupbuy_info['groupbuy_starttime'], 'cron_value' => serialize(intval($groupbuy_info['goods_commonid'])),
  67. 'cron_type' => 'editGoodsGroupbuyPrice'
  68. ));
  69. $this->addcron(array(
  70. 'cron_exetime' => $groupbuy_info['groupbuy_endtime'], 'cron_value' => serialize(intval($groupbuy_info['goods_commonid'])),
  71. 'cron_type' => 'editExpireGroupbuy'
  72. ));
  73. $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
  74. } else {
  75. $this->error(lang('ds_common_op_fail'));
  76. }
  77. }
  78. /**
  79. * 审核失败
  80. */
  81. public function groupbuy_review_fail()
  82. {
  83. $groupbuy_id = intval(input('post.groupbuy_id'));
  84. $groupbuy_model = model('groupbuy');
  85. $result = $groupbuy_model->reviewFailGroupbuy($groupbuy_id);
  86. if ($result) {
  87. $this->log('拒绝抢购活动申请,抢购编号' . $groupbuy_id, null);
  88. $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
  89. } else {
  90. $this->error(lang('ds_common_op_fail'));
  91. }
  92. }
  93. /**
  94. * 取消
  95. */
  96. public function groupbuy_cancel()
  97. {
  98. $groupbuy_id = intval(input('post.groupbuy_id'));
  99. $groupbuy_model = model('groupbuy');
  100. $result = $groupbuy_model->cancelGroupbuy($groupbuy_id);
  101. if ($result) {
  102. $this->log('取消抢购活动,抢购编号' . $groupbuy_id, null);
  103. $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
  104. } else {
  105. $this->error(lang('ds_common_op_fail'));
  106. }
  107. }
  108. /**
  109. * 删除
  110. */
  111. public function groupbuy_del()
  112. {
  113. $groupbuy_id = intval(input('param.groupbuy_id'));
  114. $groupbuy_model = model('groupbuy');
  115. $result = $groupbuy_model->delGroupbuy(array('groupbuy_id' => $groupbuy_id));
  116. if ($result) {
  117. $this->log('删除抢购活动,抢购编号' . $groupbuy_id, null);
  118. ds_json_encode(10000, lang('ds_common_op_succ'));
  119. } else {
  120. ds_json_encode(10001, lang('ds_common_op_fail'));
  121. }
  122. }
  123. /**
  124. * ajax修改抢购信息
  125. */
  126. public function ajax()
  127. {
  128. $result = true;
  129. $update_array = array();
  130. $condition = array();
  131. switch (input('param.branch')) {
  132. case 'gclass_sort':
  133. $groupbuyclass_model = model('groupbuyclass');
  134. $update_array['gclass_sort'] = input('param.value');
  135. $condition[] = array('gclass_id', '=', input('param.id'));
  136. $result = $groupbuyclass_model->editGroupbuyclass($update_array, $condition);
  137. // 删除抢购分类缓存
  138. model('groupbuy')->dropCachedData('groupbuy_classes');
  139. break;
  140. case 'gclass_name':
  141. $groupbuyclass_model = model('groupbuyclass');
  142. $update_array['gclass_name'] = input('param.value');
  143. $condition[] = array('gclass_id', '=', input('param.id'));
  144. $result = $groupbuyclass_model->editGroupbuyclass($update_array, $condition);
  145. // 删除抢购分类缓存
  146. model('groupbuy')->dropCachedData('groupbuy_classes');
  147. $this->log(lang('groupbuy_class_edit_success') . '[ID:' . input('param.id') . ']', null);
  148. break;
  149. case 'recommended':
  150. $groupbuy_model = model('groupbuy');
  151. $update_array['groupbuy_recommended'] = input('param.value');
  152. $condition[] = array('groupbuy_id', '=', input('param.id'));
  153. $result = $groupbuy_model->editGroupbuy($update_array, $condition);
  154. break;
  155. }
  156. echo 'true';
  157. exit;
  158. }
  159. /**
  160. * 套餐管理
  161. * */
  162. public function groupbuy_quota()
  163. {
  164. $groupbuyquota_model = model('groupbuyquota');
  165. $condition = array();
  166. $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
  167. $groupbuyquota_list = $groupbuyquota_model->getGroupbuyquotaList($condition, 10, 'groupbuyquota_endtime desc');
  168. View::assign('groupbuyquota_list', $groupbuyquota_list);
  169. View::assign('show_page', $groupbuyquota_model->page_info->render());
  170. $this->setAdminCurItem('groupbuy_quota');
  171. return View::fetch();
  172. }
  173. /**
  174. * 抢购类别列表
  175. */
  176. public function class_list()
  177. {
  178. $groupbuyclass_model = model('groupbuyclass');
  179. $groupbuyclass_list = $groupbuyclass_model->getTreeList();
  180. $this->setAdminCurItem('class_list');
  181. View::assign('groupbuyclass_list', $groupbuyclass_list);
  182. return View::fetch();
  183. }
  184. /**
  185. * 添加抢购分类页面
  186. */
  187. public function class_add()
  188. {
  189. $groupbuyclass_model = model('groupbuyclass');
  190. $param = array();
  191. $param['gclass_parent_id'] = 0;
  192. $groupbuyclass_list = $groupbuyclass_model->getGroupbuyclassList($param);
  193. View::assign('groupbuyclass_list', $groupbuyclass_list);
  194. $this->setAdminCurItem('class_add');
  195. View::assign('parent_id', input('param.parent_id'));
  196. return View::fetch();
  197. }
  198. /**
  199. * 保存添加的抢购类别
  200. */
  201. public function class_save()
  202. {
  203. $gclass_id = intval(input('post.gclass_id'));
  204. $param = array();
  205. $param['gclass_name'] = trim(input('post.input_gclass_name'));
  206. if (empty($param['gclass_name'])) {
  207. $this->error(lang('class_name_error'), '');
  208. }
  209. $param['gclass_sort'] = intval(input('post.input_sort'));
  210. $param['gclass_parent_id'] = intval(input('post.input_parent_id'));
  211. $groupbuyclass_model = model('groupbuyclass');
  212. // 删除抢购分类缓存
  213. model('groupbuy')->dropCachedData('groupbuy_classes');
  214. if (empty($gclass_id)) {
  215. //新增
  216. if ($groupbuyclass_model->addGroupbuyclass($param)) {
  217. $this->log(lang('groupbuy_class_add_success') . '[ID:' . $gclass_id . ']', null);
  218. dsLayerOpenSuccess(lang('groupbuy_class_add_success'));
  219. } else {
  220. $this->error(lang('groupbuy_class_add_fail'));
  221. }
  222. } else {
  223. //编辑
  224. if ($groupbuyclass_model->editGroupbuyclass($param, array('gclass_id' => $gclass_id))) {
  225. $this->log(lang('groupbuy_class_edit_success') . '[ID:' . $gclass_id . ']', null);
  226. dsLayerOpenSuccess(lang('groupbuy_class_edit_success'));
  227. } else {
  228. $this->error(lang('groupbuy_class_edit_fail'));
  229. }
  230. }
  231. }
  232. /**
  233. * 删除抢购类别
  234. */
  235. public function class_drop()
  236. {
  237. $gclass_id = trim(input('param.gclass_id'));
  238. if (empty($gclass_id)) {
  239. $this->error(lang('param_error'), '');
  240. }
  241. $groupbuyclass_model = model('groupbuyclass');
  242. //获得所有下级类别编号
  243. $all_gclass_id = $groupbuyclass_model->getAllClassId(explode(',', $gclass_id));
  244. $condition = array();
  245. $condition[] = array('gclass_id', 'in', implode(',', $all_gclass_id));
  246. if ($groupbuyclass_model->delGroupbuyclass($condition)) {
  247. // 删除抢购分类缓存
  248. model('groupbuy')->dropCachedData('groupbuy_classes');
  249. $this->log(lang('groupbuy_class_drop_success') . '[ID:' . implode(',', $all_gclass_id) . ']', null);
  250. ds_json_encode(10000, lang('groupbuy_class_drop_success'));
  251. } else {
  252. ds_json_encode(10001, lang('groupbuy_class_drop_fail'));
  253. }
  254. }
  255. /**
  256. * 抢购价格区间列表
  257. */
  258. public function price_list()
  259. {
  260. $groupbuypricerange_model = model('groupbuypricerange');
  261. $groupbuypricerange_list = $groupbuypricerange_model->getGroupbuypricerangeList();
  262. View::assign('groupbuypricerange_list', $groupbuypricerange_list);
  263. $this->setAdminCurItem('price_list');
  264. return View::fetch();
  265. }
  266. /**
  267. * 添加抢购价格区间页面
  268. */
  269. public function price_add()
  270. {
  271. $price_info = [
  272. 'gprange_id' => '', 'gprange_name' => '', 'gprange_start' => '', 'gprange_end' => '',
  273. ];
  274. View::assign('price_info', $price_info);
  275. $this->setAdminCurItem('price_add');
  276. return View::fetch();
  277. }
  278. /**
  279. * 编辑抢购价格区间页面
  280. */
  281. public function price_edit()
  282. {
  283. $gprange_id = intval(input('param.gprange_id'));
  284. if (empty($gprange_id)) {
  285. $this->error(lang('param_error'), '');
  286. }
  287. $groupbuypricerange_model = model('groupbuypricerange');
  288. $price_info = $groupbuypricerange_model->getOneGroupbuypricerange($gprange_id);
  289. if (empty($price_info)) {
  290. $this->error(lang('param_error'), '');
  291. }
  292. View::assign('price_info', $price_info);
  293. $this->setAdminCurItem('price_edit');
  294. return View::fetch('price_add');
  295. }
  296. /**
  297. * 保存添加的抢购价格区间
  298. */
  299. public function price_save()
  300. {
  301. $gprange_id = intval(input('post.gprange_id'));
  302. $param = array();
  303. $param['gprange_name'] = trim(input('post.gprange_name'));
  304. if (empty($param['gprange_name'])) {
  305. $this->error(lang('range_name_error'), '');
  306. }
  307. $param['gprange_start'] = intval(input('post.gprange_start'));
  308. $param['gprange_end'] = intval(input('post.gprange_end'));
  309. $groupbuypricerange_model = model('groupbuypricerange');
  310. if (empty($gprange_id)) {
  311. //新增
  312. if ($groupbuypricerange_model->addGroupbuypricerange($param)) {
  313. dkcache('groupbuy_price');
  314. $this->log(lang('groupbuy_price_range_add_success') . '[' . input('post.gprange_name') . ']', null);
  315. dsLayerOpenSuccess(lang('groupbuy_price_range_add_success'));
  316. } else {
  317. $this->error(lang('groupbuy_price_range_add_fail'));
  318. }
  319. } else {
  320. //编辑
  321. if ($groupbuypricerange_model->editGroupbuypricerange($param, array('gprange_id' => $gprange_id))) {
  322. dkcache('groupbuy_price');
  323. $this->log(lang('groupbuy_price_range_edit_success') . '[' . input('post.gprange_name') . ']', null);
  324. dsLayerOpenSuccess(lang('groupbuy_price_range_edit_success'));
  325. } else {
  326. // $this->error(lang('groupbuy_price_range_edit_fail'), (string)url('Groupbuy/price_list'));
  327. $this->error(lang('groupbuy_price_range_edit_fail'));
  328. }
  329. }
  330. }
  331. /**
  332. * 删除抢购价格区间
  333. */
  334. public function price_drop()
  335. {
  336. $gprange_id = input('param.gprange_id');
  337. $gprange_id_array = ds_delete_param($gprange_id);
  338. if ($gprange_id_array === FALSE) {
  339. $this->error(lang('param_error'));
  340. }
  341. $condition = array();
  342. $condition[] = array('gprange_id', 'in', $gprange_id_array);
  343. $groupbuypricerange_model = model('groupbuypricerange');
  344. if ($groupbuypricerange_model->delGroupbuypricerange($condition)) {
  345. dkcache('groupbuy_price');
  346. $this->log(lang('groupbuy_price_range_drop_success') . '[ID:' . $gprange_id . ']', null);
  347. ds_json_encode(10000, lang('groupbuy_price_range_drop_success'));
  348. } else {
  349. ds_json_encode(10001, lang('groupbuy_price_range_drop_fail'));
  350. }
  351. }
  352. /**
  353. * 设置
  354. * */
  355. public function groupbuy_setting()
  356. {
  357. if (!(request()->isPost())) {
  358. $setting = rkcache('config', true);
  359. View::assign('setting', $setting);
  360. return View::fetch();
  361. } else {
  362. $groupbuy_price = intval(input('post.groupbuy_price'));
  363. if ($groupbuy_price < 0) {
  364. $groupbuy_price = 0;
  365. }
  366. $groupbuy_review_day = intval(input('post.groupbuy_review_day'));
  367. if ($groupbuy_review_day < 0) {
  368. $groupbuy_review_day = 0;
  369. }
  370. $config_model = model('config');
  371. $update_array = array();
  372. $update_array['groupbuy_price'] = $groupbuy_price;
  373. $update_array['groupbuy_review_day'] = $groupbuy_review_day;
  374. $result = $config_model->editConfig($update_array);
  375. if ($result) {
  376. $this->log('修改抢购套餐价格为' . $groupbuy_price . '元');
  377. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  378. } else {
  379. $this->error(lang('ds_common_op_fail'));
  380. }
  381. }
  382. }
  383. /**
  384. * 幻灯片设置
  385. */
  386. public function slider()
  387. {
  388. $config_model = model('config');
  389. if (request()->isPost()) {
  390. $update = array();
  391. $fprefix = 'home/groupbuy/slider';
  392. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fprefix;
  393. if (!empty($_FILES['live_pic1']['name'])) {
  394. $res = ds_upload_pic($fprefix, 'live_pic1');
  395. if ($res['code']) {
  396. $file_name = $res['data']['file_name'];
  397. $update['live_pic1'] = $file_name;
  398. } else {
  399. $this->error($res['msg']);
  400. }
  401. }
  402. if (!empty(input('post.live_link1'))) {
  403. $update['live_link1'] = input('post.live_link1');
  404. }
  405. if (!empty($_FILES['live_pic2']['name'])) {
  406. $res = ds_upload_pic($fprefix, 'live_pic2');
  407. if ($res['code']) {
  408. $file_name = $res['data']['file_name'];
  409. $update['live_pic2'] = $file_name;
  410. } else {
  411. $this->error($res['msg']);
  412. }
  413. }
  414. if (!empty(input('post.live_link2'))) {
  415. $update['live_link2'] = input('post.live_link2');
  416. }
  417. if (!empty($_FILES['live_pic3']['name'])) {
  418. $res = ds_upload_pic($fprefix, 'live_pic3');
  419. if ($res['code']) {
  420. $file_name = $res['data']['file_name'];
  421. $update['live_pic3'] = $file_name;
  422. } else {
  423. $this->error($res['msg']);
  424. }
  425. }
  426. if (!empty(input('post.live_link3'))) {
  427. $update['live_link3'] = input('post.live_link3');
  428. }
  429. if (!empty($_FILES['live_pic4']['name'])) {
  430. $res = ds_upload_pic($fprefix, 'live_pic4');
  431. if ($res['code']) {
  432. $file_name = $res['data']['file_name'];
  433. $update['live_pic4'] = $file_name;
  434. } else {
  435. $this->error($res['msg']);
  436. }
  437. }
  438. if (!empty(input('post.live_link4'))) {
  439. $update['live_link4'] = input('post.live_link4');
  440. }
  441. $list_setting = rkcache('config', true);
  442. $result = $config_model->editConfig($update);
  443. if ($result) {
  444. if ($list_setting['live_pic1'] != '' && isset($update['live_pic1'])) {
  445. @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic1']);
  446. }
  447. if ($list_setting['live_pic2'] != '' && isset($update['live_pic2'])) {
  448. @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic2']);
  449. }
  450. if ($list_setting['live_pic3'] != '' && isset($update['live_pic3'])) {
  451. @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic3']);
  452. }
  453. if ($list_setting['live_pic4'] != '' && isset($update['live_pic4'])) {
  454. @unlink($upload_file . $list_setting['live_pic4']);
  455. }
  456. $this->log('修改抢购幻灯片设置', 1);
  457. $this->success(lang('ds_common_op_succ'));
  458. } else {
  459. $this->error(lang('ds_common_op_fail'));
  460. }
  461. } else {
  462. $list_setting = rkcache('config', true);
  463. View::assign('list_setting', $list_setting);
  464. $this->setAdminCurItem('slider');
  465. return View::fetch();
  466. }
  467. }
  468. /**
  469. * 幻灯片清空
  470. */
  471. public function slider_clear()
  472. {
  473. $config_model = model('config');
  474. $update = array();
  475. $update['live_pic1'] = '';
  476. $update['live_link1'] = '';
  477. $update['live_pic2'] = '';
  478. $update['live_link2'] = '';
  479. $update['live_pic3'] = '';
  480. $update['live_link3'] = '';
  481. $update['live_pic4'] = '';
  482. $update['live_link4'] = '';
  483. $res = $config_model->editConfig($update);
  484. if ($res) {
  485. $this->log('清空抢购幻灯片设置', 1);
  486. echo json_encode(array('result' => 'true'));
  487. } else {
  488. echo json_encode(array('result' => 'false'));
  489. }
  490. exit;
  491. }
  492. /**
  493. * 页面内导航菜单
  494. *
  495. * @param string $menu_key 当前导航的menu_key
  496. * @param array $array 附加菜单
  497. * @return
  498. */
  499. protected function getAdminItemList()
  500. {
  501. $menu_array = array(
  502. array(
  503. 'name' => 'index',
  504. 'text' => lang('ds_groupbuy'),
  505. 'url' => (string)url('Groupbuy/index')
  506. ), array(
  507. 'name' => 'groupbuy_quota',
  508. 'text' => lang('groupbuy_quota'),
  509. 'url' => (string)url('Groupbuy/groupbuy_quota')
  510. ), array(
  511. 'name' => 'class_list',
  512. 'text' => lang('groupbuy_class_list'),
  513. 'url' => (string)url('Groupbuy/class_list')
  514. ), array(
  515. 'name' => 'price_list',
  516. 'text' => lang('groupbuy_price_list'),
  517. 'url' => (string)url('Groupbuy/price_list')
  518. ), array(
  519. 'name' => 'groupbuy_setting',
  520. 'text' => lang('ds_set'),
  521. 'url' => "javascript:dsLayerOpen('" . (string)url('Groupbuy/groupbuy_setting') . "','" . lang('ds_set') . "')"
  522. ), array(
  523. 'name' => 'slider',
  524. 'text' => lang('groupbuy_slider'),
  525. 'url' => (string)url('Groupbuy/slider')
  526. ),
  527. );
  528. return $menu_array;
  529. }
  530. }