Groupbuy.php 21 KB

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