Groupbuy.php 21 KB

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