Sellerpromotionpintuan.php 21 KB

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