Sellerpromotionpintuan.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. /**
  3. * 卖家拼团管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. * ============================================================================
  11. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Sellerpromotionpintuan extends BaseSeller {
  22. public function initialize() {
  23. parent::initialize();
  24. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerpromotionpintuan.lang.php');
  25. if (intval(config('ds_config.promotion_allow')) !== 1) {
  26. $this->error(lang('promotion_unavailable'), 'seller/index');
  27. }
  28. }
  29. public function index() {
  30. $pintuanquota_model = model('ppintuanquota');
  31. $ppintuan_model = model('ppintuan');
  32. if (check_platform_store()) {
  33. View::assign('isPlatformStore', true);
  34. } else {
  35. $current_pintuan_quota = $pintuanquota_model->getPintuanquotaCurrent(session('store_id'));
  36. View::assign('current_pintuan_quota', $current_pintuan_quota);
  37. }
  38. $condition = array();
  39. $condition[] = array('store_id', '=', session('store_id'));
  40. if ((input('param.pintuan_name'))) {
  41. $condition[] = array('pintuan_name', 'like', '%' . input('param.pintuan_name') . '%');
  42. }
  43. if (input('param.state') != '') {
  44. $condition[] = array('pintuan_state', '=', intval(input('param.state')));
  45. }
  46. $pintuan_list = $ppintuan_model->getPintuanList($condition, 10, 'pintuan_state desc, pintuan_end_time desc');
  47. View::assign('pintuan_list', $pintuan_list);
  48. View::assign('show_page', $ppintuan_model->page_info->render());
  49. View::assign('pintuan_state_array', $ppintuan_model->getPintuanStateArray());
  50. $this->setSellerCurMenu('Sellerpromotionpintuan');
  51. $this->setSellerCurItem('pintuan_list');
  52. return View::fetch($this->template_dir . 'index');
  53. }
  54. /**
  55. * 添加拼团活动
  56. * */
  57. public function pintuan_add() {
  58. if (!request()->isPost()) {
  59. if (check_platform_store()) {
  60. View::assign('isPlatformStore', true);
  61. } else {
  62. View::assign('isPlatformStore', false);
  63. $pintuanquota_model = model('ppintuanquota');
  64. $current_pintuan_quota = $pintuanquota_model->getPintuanquotaCurrent(session('store_id'));
  65. if (empty($current_pintuan_quota)) {
  66. if (intval(config('ds_config.promotion_pintuan_price')) != 0) {
  67. $this->error(lang('pintuan_quota_current_error1'));
  68. } else {
  69. $current_pintuan_quota = array('pintuanquota_starttime' => TIMESTAMP, 'pintuanquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  70. }
  71. }
  72. View::assign('current_pintuan_quota', $current_pintuan_quota);
  73. }
  74. //输出导航
  75. $this->setSellerCurMenu('Sellerpromotionpintuan');
  76. $this->setSellerCurItem('pintuan_add');
  77. return View::fetch($this->template_dir . 'pintuan_add');
  78. } else {
  79. //验证输入
  80. $pintuan_name = trim(input('post.pintuan_name'));
  81. $start_time = strtotime(input('post.start_time'));
  82. $end_time = strtotime(input('post.end_time'));
  83. $pintuan_limit_number = intval(input('post.pintuan_limit_number'));
  84. if ($pintuan_limit_number <= 1) {
  85. $pintuan_limit_number = 2;
  86. }
  87. //成团时限
  88. $pintuan_limit_hour = intval(input('post.pintuan_limit_hour'));
  89. if ($pintuan_limit_hour <= 0) {
  90. $pintuan_limit_hour = 1;
  91. }
  92. //购买限制
  93. $pintuan_limit_quantity = intval(input('post.pintuan_limit_quantity'));
  94. if ($pintuan_limit_quantity <= 0) {
  95. $pintuan_limit_quantity = 1;
  96. }
  97. //购买折扣
  98. $pintuan_zhe = intval(input('post.pintuan_zhe'));
  99. if ($pintuan_zhe <= 0 || $pintuan_zhe >= 10) {
  100. $pintuan_zhe = 1;
  101. }
  102. if (empty($pintuan_name)) {
  103. ds_json_encode(10001, lang('pintuan_name_error'));
  104. }
  105. if ($start_time >= $end_time) {
  106. ds_json_encode(10001, lang('greater_than_start_time'));
  107. }
  108. if (!check_platform_store()) {
  109. //获取当前套餐
  110. $pintuanquota_model = model('ppintuanquota');
  111. $current_pintuan_quota = $pintuanquota_model->getPintuanquotaCurrent(session('store_id'));
  112. if (empty($current_pintuan_quota)) {
  113. if (intval(config('ds_config.promotion_pintuan_price')) != 0) {
  114. ds_json_encode(10001, lang('please_buy_package_first'));
  115. } else {
  116. $current_pintuan_quota = array('pintuanquota_starttime' => TIMESTAMP, 'pintuanquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  117. }
  118. }
  119. $quota_start_time = intval($current_pintuan_quota['pintuanquota_starttime']);
  120. $quota_end_time = intval($current_pintuan_quota['pintuanquota_endtime']);
  121. if ($start_time < $quota_start_time) {
  122. ds_json_encode(10001, sprintf(lang('pintuan_add_start_time_explain'), date('Y-m-d', $current_pintuan_quota['pintuanquota_starttime'])));
  123. }
  124. if ($end_time > $quota_end_time) {
  125. ds_json_encode(10001, sprintf(lang('pintuan_add_end_time_explain'), date('Y-m-d', $current_pintuan_quota['pintuanquota_endtime'])));
  126. }
  127. }
  128. if($end_time<TIMESTAMP){
  129. ds_json_encode(10001, sprintf(lang('pintuan_add_end_time_explain'), date('Y-m-d')));
  130. }
  131. //获取提交的数据
  132. $goods_id = intval(input('post.pintuan_goods_id'));
  133. if (empty($goods_id)) {
  134. ds_json_encode(10001, lang('param_error'));
  135. }
  136. $goods_model = model('goods');
  137. $goods_info = $goods_model->getGoodsInfoByID($goods_id);
  138. if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
  139. ds_json_encode(10001, lang('param_error'));
  140. }
  141. //判断此商品是否在拼团中,拼团中的商品是不可以参加活动
  142. $result = $this->_check_allow_pintuan($goods_info['goods_commonid']);
  143. if ($result != TRUE) {
  144. ds_json_encode(10001, $result['message']);
  145. }
  146. //生成活动
  147. $ppintuan_model = model('ppintuan');
  148. $param = array();
  149. $param['pintuan_name'] = $pintuan_name;
  150. $param['pintuanquota_id'] = isset($current_pintuan_quota['pintuanquota_id']) ? $current_pintuan_quota['pintuanquota_id'] : 0;
  151. $param['pintuan_starttime'] = $start_time;
  152. $param['pintuan_end_time'] = $end_time;
  153. $param['store_id'] = session('store_id');
  154. $param['store_name'] = session('store_name');
  155. $param['member_id'] = session('member_id');
  156. $param['member_name'] = session('member_name');
  157. $param['pintuan_zhe'] = $pintuan_zhe;
  158. $param['pintuan_limit_number'] = $pintuan_limit_number;
  159. $param['pintuan_limit_hour'] = $pintuan_limit_hour;
  160. $param['pintuan_limit_quantity'] = $pintuan_limit_quantity;
  161. $param['pintuan_goods_id'] = $goods_info['goods_id'];
  162. $param['pintuan_is_virtual'] = $goods_info['is_virtual'];
  163. $param['pintuan_goods_price'] = $goods_info['goods_price'];
  164. $param['pintuan_goods_name'] = $goods_info['goods_name'];
  165. $param['pintuan_goods_commonid'] = $goods_info['goods_commonid'];
  166. $param['pintuan_image'] = $goods_info['goods_image'];
  167. $result = $ppintuan_model->addPintuan($param);
  168. if ($result) {
  169. $this->recordSellerlog(lang('add_group_activities') . $pintuan_name . lang('activity_number') . $result);
  170. $ppintuan_model->_dGoodsPintuanCache($goods_info['goods_commonid']); #清除缓存
  171. ds_json_encode(10000, lang('pintuan_add_success'));
  172. } else {
  173. ds_json_encode(10001, lang('pintuan_add_fail'));
  174. }
  175. }
  176. }
  177. /**
  178. * 编辑拼团活动
  179. * */
  180. public function pintuan_edit() {
  181. if (!request()->isPost()) {
  182. if (check_platform_store()) {
  183. View::assign('isPlatformStore', true);
  184. } else {
  185. View::assign('isPlatformStore', false);
  186. }
  187. $ppintuan_model = model('ppintuan');
  188. $pintuan_info = $ppintuan_model->getPintuanInfoByID(input('param.pintuan_id'));
  189. if (empty($pintuan_info) || !$pintuan_info['editable']) {
  190. $this->error(lang('param_error'));
  191. }
  192. View::assign('pintuan_info', $pintuan_info);
  193. //输出导航
  194. $this->setSellerCurMenu('Sellerpromotionpintuan');
  195. $this->setSellerCurItem('pintuan_edit');
  196. return View::fetch($this->template_dir . 'pintuan_add');
  197. } else {
  198. $pintuan_id = input('param.pintuan_id');
  199. $ppintuan_model = model('ppintuan');
  200. $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id, session('store_id'));
  201. if (empty($pintuan_info) || !$pintuan_info['editable']) {
  202. $this->error(lang('param_error'));
  203. }
  204. //验证输入
  205. $pintuan_name = trim(input('post.pintuan_name'));
  206. if (empty($pintuan_name)) {
  207. ds_json_encode(10001, lang('pintuan_name_error'));
  208. }
  209. $pintuan_limit_number = intval(input('post.pintuan_limit_number'));
  210. if ($pintuan_limit_number <= 1) {
  211. $pintuan_limit_number = 2;
  212. }
  213. //成团时限
  214. $pintuan_limit_hour = intval(input('post.pintuan_limit_hour'));
  215. if ($pintuan_limit_hour <= 0) {
  216. $pintuan_limit_hour = 1;
  217. }
  218. //购买限制
  219. $pintuan_limit_quantity = intval(input('post.pintuan_limit_quantity'));
  220. if ($pintuan_limit_quantity <= 0) {
  221. $pintuan_limit_quantity = 1;
  222. }
  223. //购买折扣
  224. $pintuan_zhe = intval(input('post.pintuan_zhe'));
  225. if ($pintuan_zhe <= 0 || $pintuan_zhe >= 10) {
  226. $pintuan_zhe = 1;
  227. }
  228. //生成活动
  229. $param = array();
  230. $param['pintuan_name'] = $pintuan_name;
  231. $param['pintuan_zhe'] = $pintuan_zhe;
  232. $param['pintuan_limit_number'] = $pintuan_limit_number;
  233. $param['pintuan_limit_hour'] = $pintuan_limit_hour;
  234. $param['pintuan_limit_quantity'] = $pintuan_limit_quantity;
  235. $result = $ppintuan_model->editPintuan($param, array('pintuan_id' => $pintuan_id));
  236. if ($result) {
  237. $this->recordSellerlog(lang('edit_group_activities') . $pintuan_name . lang('activity_number') . $pintuan_id);
  238. $ppintuan_model->_dGoodsPintuanCache($pintuan_info['pintuan_goods_commonid']); #清除缓存
  239. ds_json_encode(10000, lang('ds_common_op_succ'));
  240. } else {
  241. ds_json_encode(10001, lang('ds_common_op_fail'));
  242. }
  243. }
  244. }
  245. /**
  246. * 拼团活动 提前结束
  247. */
  248. public function pintuan_end() {
  249. $pintuan_id = intval(input('post.pintuan_id'));
  250. $ppintuan_model = model('ppintuan');
  251. $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id, session('store_id'));
  252. if (!$pintuan_info) {
  253. ds_json_encode(10001, lang('param_error'));
  254. }
  255. /**
  256. * 指定拼团活动结束
  257. */
  258. $result = $ppintuan_model->endPintuan(array('pintuan_id' => $pintuan_id));
  259. if ($result) {
  260. $this->recordSellerlog(lang('group_activities_end_early') . $pintuan_info['pintuan_name'] . lang('activity_number') . $pintuan_id);
  261. $ppintuan_model->_dGoodsPintuanCache($pintuan_info['pintuan_goods_commonid']); #清除缓存
  262. ds_json_encode(10000, lang('ds_common_op_succ'));
  263. } else {
  264. ds_json_encode(10001, lang('ds_common_op_fail'));
  265. }
  266. }
  267. /**
  268. * 查看拼团开团信息
  269. * @return type
  270. */
  271. public function pintuan_manage() {
  272. $ppintuan_model = model('ppintuan');
  273. $ppintuangroup_model = model('ppintuangroup');
  274. $ppintuanorder_model = model('ppintuanorder');
  275. $pintuan_id = intval(input('param.pintuan_id'));
  276. //判断此拼团是否属于店铺
  277. $ppintuan = $ppintuan_model->getPintuanInfo(array('store_id' => session('store_id'), 'pintuan_id' => $pintuan_id));
  278. if (empty($ppintuan)) {
  279. $this->error(lang('param_error'));
  280. }
  281. $condition = array();
  282. $condition[] = array('pintuan_id','=',$pintuan_id);
  283. if (input('param.pintuangroup_state')) {
  284. $condition[] = array('pintuangroup_state','=',intval(input('param.pintuangroup_state')));
  285. }
  286. $ppintuangroup_list = $ppintuangroup_model->getPpintuangroupList($condition, 10); #获取开团信息
  287. foreach ($ppintuangroup_list as $key => $ppintuangroup) {
  288. //获取开团订单下的参团订单
  289. $condition = array();
  290. $condition[] = array('pintuangroup_id','=',$ppintuangroup['pintuangroup_id']);
  291. $ppintuangroup_list[$key]['order_list'] = $ppintuanorder_model->getPpintuanorderList($condition);
  292. }
  293. View::assign('show_page', $ppintuangroup_model->page_info->render());
  294. View::assign('pintuangroup_list', $ppintuangroup_list);
  295. View::assign('pintuangroup_state_array', $ppintuangroup_model->getPintuangroupStateArray());
  296. $this->setSellerCurMenu('Sellerpromotionpintuan');
  297. $this->setSellerCurItem('pintuan_manage');
  298. return View::fetch($this->template_dir . 'pintuan_manage');
  299. }
  300. /**
  301. * 拼团套餐购买
  302. * */
  303. public function pintuan_quota_add() {
  304. //输出导航
  305. $this->setSellerCurMenu('Sellerpromotionpintuan');
  306. $this->setSellerCurItem('pintuan_quota_add');
  307. return View::fetch($this->template_dir . 'pintuan_quota_add');
  308. }
  309. /**
  310. * 拼团套餐购买保存
  311. * */
  312. public function pintuan_quota_add_save() {
  313. if (intval(config('ds_config.promotion_pintuan_price')) == 0) {
  314. ds_json_encode(10001, lang('param_error'));
  315. }
  316. $pintuan_quota_quantity = intval(input('post.pintuan_quota_quantity'));
  317. if ($pintuan_quota_quantity <= 0 || $pintuan_quota_quantity > 12) {
  318. ds_json_encode(10001, lang('pintuan_quota_quantity_error'));
  319. }
  320. //获取当前价格
  321. $current_price = intval(config('ds_config.promotion_pintuan_price'));
  322. //获取该用户已有套餐
  323. $pintuanquota_model = model('ppintuanquota');
  324. $current_pintuan_quota = $pintuanquota_model->getPintuanquotaCurrent(session('store_id'));
  325. $pintuan_add_time = 86400 * 30 * $pintuan_quota_quantity;
  326. if (empty($current_pintuan_quota)) {
  327. //生成套餐
  328. $param = array();
  329. $param['member_id'] = session('member_id');
  330. $param['member_name'] = session('member_name');
  331. $param['store_id'] = session('store_id');
  332. $param['store_name'] = session('store_name');
  333. $param['pintuanquota_starttime'] = TIMESTAMP;
  334. $param['pintuanquota_endtime'] = TIMESTAMP + $pintuan_add_time;
  335. $pintuanquota_model->addPintuanquota($param);
  336. } else {
  337. $param = array();
  338. $param['pintuanquota_endtime'] = Db::raw('pintuanquota_endtime+' . $pintuan_add_time);
  339. $pintuanquota_model->editPintuanquota($param, array('pintuanquota_id' => $current_pintuan_quota['pintuanquota_id']));
  340. }
  341. //记录店铺费用
  342. $this->recordStorecost($current_price * $pintuan_quota_quantity, lang('buy_spell_group'));
  343. $this->recordSellerlog(lang('buy') . $pintuan_quota_quantity . lang('combo_pack') . $current_price . lang('ds_yuan'));
  344. ds_json_encode(10000, lang('pintuan_quota_add_success'));
  345. }
  346. /**
  347. * 选择活动商品
  348. * */
  349. public function search_goods() {
  350. $goods_model = model('goods');
  351. $condition = array();
  352. $condition[] = array('goods_lock', '=', 0);
  353. $condition[] = array('goods_state', '=', 1);
  354. $condition[] = array('goods_verify', '=', 1);
  355. $condition[] = array('store_id', '=', session('store_id'));
  356. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  357. $goods_list = $goods_model->getGoodsCommonListForPromotion($condition, '*', 8, '');
  358. View::assign('goods_list', $goods_list);
  359. View::assign('show_page', $goods_model->page_info->render());
  360. echo View::fetch($this->template_dir . 'search_goods');
  361. exit;
  362. }
  363. public function pintuan_goods_info() {
  364. $goods_commonid = intval(input('param.goods_commonid'));
  365. $data = array();
  366. $data['result'] = true;
  367. //判断此商品是否已经参加拼团,
  368. $result = $this->_check_allow_pintuan($goods_commonid);
  369. if ($result['result'] != TRUE) {
  370. echo json_encode($result);
  371. die;
  372. }
  373. //获取商品具体信息用于显示
  374. $goods_model = model('goods');
  375. $condition = array();
  376. $condition[]=array('goods_commonid','=',$goods_commonid);
  377. $goods_list = $goods_model->getGoodsOnlineList($condition);
  378. if (empty($goods_list)) {
  379. $data['result'] = false;
  380. $data['message'] = lang('param_error');
  381. echo json_encode($data);
  382. die;
  383. }
  384. $goods_info = $goods_list[0];
  385. $data['goods_id'] = $goods_info['goods_id'];
  386. $data['goods_name'] = $goods_info['goods_name'];
  387. $data['goods_price'] = $goods_info['goods_price'];
  388. $data['goods_image'] = goods_thumb($goods_info, 240);
  389. $data['goods_href'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  390. echo json_encode($data);
  391. die;
  392. }
  393. /*
  394. * 判断此商品是否已经参加拼团
  395. */
  396. private function _check_allow_pintuan($goods_commonid) {
  397. $condition = array();
  398. $condition[] = array('pintuan_goods_commonid','=',$goods_commonid);
  399. $condition[] = array('pintuan_state','=',1);
  400. $pintuan = model('ppintuan')->getPintuanInfo($condition);
  401. $result['result'] = TRUE;
  402. if (!empty($pintuan)) {
  403. $result['result'] = FALSE;
  404. $result['message'] = lang('goods_are_syndicate');
  405. }
  406. return $result;
  407. }
  408. protected function getSellerItemList() {
  409. $menu_array = array(
  410. array(
  411. 'name' => 'pintuan_list', 'text' => lang('pintuan_active_list'),
  412. 'url' => (string) url('Sellerpromotionpintuan/index')
  413. ),
  414. );
  415. switch (request()->action()) {
  416. case 'pintuan_add':
  417. $menu_array[] = array(
  418. 'name' => 'pintuan_add', 'text' => lang('pintuan_add'),
  419. 'url' => (string) url('Sellerpromotionpintuan/pintuan_add')
  420. );
  421. break;
  422. case 'pintuan_edit':
  423. $menu_array[] = array(
  424. 'name' => 'pintuan_edit', 'text' => lang('pintuan_edit'), 'url' => 'javascript:;'
  425. );
  426. break;
  427. case 'pintuan_quota_add':
  428. $menu_array[] = array(
  429. 'name' => 'pintuan_quota_add', 'text' => lang('pintuan_quota_add'),
  430. 'url' => (string) url('Sellerpromotionpintuan/pintuan_quota_add')
  431. );
  432. break;
  433. case 'pintuan_manage':
  434. $menu_array[] = array(
  435. 'name' => 'pintuan_manage', 'text' => lang('pintuan_manage'),
  436. 'url' => (string) url('Sellerpromotionpintuan/pintuan_manage', ['pintuan_id' => input('param.pintuan_id')])
  437. );
  438. break;
  439. }
  440. return $menu_array;
  441. }
  442. }