Sellerpromotionpintuan.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. //获取提交的数据
  129. $goods_id = intval(input('post.pintuan_goods_id'));
  130. if (empty($goods_id)) {
  131. ds_json_encode(10001, lang('param_error'));
  132. }
  133. $goods_model = model('goods');
  134. $goods_info = $goods_model->getGoodsInfoByID($goods_id);
  135. if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
  136. ds_json_encode(10001, lang('param_error'));
  137. }
  138. //判断此商品是否在拼团中,拼团中的商品是不可以参加活动
  139. $result = $this->_check_allow_pintuan($goods_info['goods_commonid']);
  140. if ($result != TRUE) {
  141. ds_json_encode(10001, $result['message']);
  142. }
  143. //生成活动
  144. $ppintuan_model = model('ppintuan');
  145. $param = array();
  146. $param['pintuan_name'] = $pintuan_name;
  147. $param['pintuanquota_id'] = isset($current_pintuan_quota['pintuanquota_id']) ? $current_pintuan_quota['pintuanquota_id'] : 0;
  148. $param['pintuan_starttime'] = $start_time;
  149. $param['pintuan_end_time'] = $end_time;
  150. $param['store_id'] = session('store_id');
  151. $param['store_name'] = session('store_name');
  152. $param['member_id'] = session('member_id');
  153. $param['member_name'] = session('member_name');
  154. $param['pintuan_zhe'] = $pintuan_zhe;
  155. $param['pintuan_limit_number'] = $pintuan_limit_number;
  156. $param['pintuan_limit_hour'] = $pintuan_limit_hour;
  157. $param['pintuan_limit_quantity'] = $pintuan_limit_quantity;
  158. $param['pintuan_goods_id'] = $goods_info['goods_id'];
  159. $param['pintuan_is_virtual'] = $goods_info['is_virtual'];
  160. $param['pintuan_goods_price'] = $goods_info['goods_price'];
  161. $param['pintuan_goods_name'] = $goods_info['goods_name'];
  162. $param['pintuan_goods_commonid'] = $goods_info['goods_commonid'];
  163. $param['pintuan_image'] = $goods_info['goods_image'];
  164. $result = $ppintuan_model->addPintuan($param);
  165. if ($result) {
  166. $this->recordSellerlog(lang('add_group_activities') . $pintuan_name . lang('activity_number') . $result);
  167. $ppintuan_model->_dGoodsPintuanCache($goods_info['goods_commonid']); #清除缓存
  168. ds_json_encode(10000, lang('pintuan_add_success'));
  169. } else {
  170. ds_json_encode(10001, lang('pintuan_add_fail'));
  171. }
  172. }
  173. }
  174. /**
  175. * 编辑拼团活动
  176. * */
  177. public function pintuan_edit() {
  178. if (!request()->isPost()) {
  179. if (check_platform_store()) {
  180. View::assign('isPlatformStore', true);
  181. } else {
  182. View::assign('isPlatformStore', false);
  183. }
  184. $ppintuan_model = model('ppintuan');
  185. $pintuan_info = $ppintuan_model->getPintuanInfoByID(input('param.pintuan_id'));
  186. if (empty($pintuan_info) || !$pintuan_info['editable']) {
  187. $this->error(lang('param_error'));
  188. }
  189. View::assign('pintuan_info', $pintuan_info);
  190. //输出导航
  191. $this->setSellerCurMenu('Sellerpromotionpintuan');
  192. $this->setSellerCurItem('pintuan_edit');
  193. return View::fetch($this->template_dir . 'pintuan_add');
  194. } else {
  195. $pintuan_id = input('param.pintuan_id');
  196. $ppintuan_model = model('ppintuan');
  197. $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id, session('store_id'));
  198. if (empty($pintuan_info) || !$pintuan_info['editable']) {
  199. $this->error(lang('param_error'));
  200. }
  201. //验证输入
  202. $pintuan_name = trim(input('post.pintuan_name'));
  203. if (empty($pintuan_name)) {
  204. ds_json_encode(10001, lang('pintuan_name_error'));
  205. }
  206. $pintuan_limit_number = intval(input('post.pintuan_limit_number'));
  207. if ($pintuan_limit_number <= 1) {
  208. $pintuan_limit_number = 2;
  209. }
  210. //成团时限
  211. $pintuan_limit_hour = intval(input('post.pintuan_limit_hour'));
  212. if ($pintuan_limit_hour <= 0) {
  213. $pintuan_limit_hour = 1;
  214. }
  215. //购买限制
  216. $pintuan_limit_quantity = intval(input('post.pintuan_limit_quantity'));
  217. if ($pintuan_limit_quantity <= 0) {
  218. $pintuan_limit_quantity = 1;
  219. }
  220. //购买折扣
  221. $pintuan_zhe = intval(input('post.pintuan_zhe'));
  222. if ($pintuan_zhe <= 0 || $pintuan_zhe >= 10) {
  223. $pintuan_zhe = 1;
  224. }
  225. //生成活动
  226. $param = array();
  227. $param['pintuan_name'] = $pintuan_name;
  228. $param['pintuan_zhe'] = $pintuan_zhe;
  229. $param['pintuan_limit_number'] = $pintuan_limit_number;
  230. $param['pintuan_limit_hour'] = $pintuan_limit_hour;
  231. $param['pintuan_limit_quantity'] = $pintuan_limit_quantity;
  232. $result = $ppintuan_model->editPintuan($param, array('pintuan_id' => $pintuan_id));
  233. if ($result) {
  234. $this->recordSellerlog(lang('edit_group_activities') . $pintuan_name . lang('activity_number') . $pintuan_id);
  235. $ppintuan_model->_dGoodsPintuanCache($pintuan_info['pintuan_goods_commonid']); #清除缓存
  236. ds_json_encode(10000, lang('ds_common_op_succ'));
  237. } else {
  238. ds_json_encode(10001, lang('ds_common_op_fail'));
  239. }
  240. }
  241. }
  242. /**
  243. * 拼团活动 提前结束
  244. */
  245. public function pintuan_end() {
  246. $pintuan_id = intval(input('post.pintuan_id'));
  247. $ppintuan_model = model('ppintuan');
  248. $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id, session('store_id'));
  249. if (!$pintuan_info) {
  250. ds_json_encode(10001, lang('param_error'));
  251. }
  252. /**
  253. * 指定拼团活动结束
  254. */
  255. $result = $ppintuan_model->endPintuan(array('pintuan_id' => $pintuan_id));
  256. if ($result) {
  257. $this->recordSellerlog(lang('group_activities_end_early') . $pintuan_info['pintuan_name'] . lang('activity_number') . $pintuan_id);
  258. $ppintuan_model->_dGoodsPintuanCache($pintuan_info['pintuan_goods_commonid']); #清除缓存
  259. ds_json_encode(10000, lang('ds_common_op_succ'));
  260. } else {
  261. ds_json_encode(10001, lang('ds_common_op_fail'));
  262. }
  263. }
  264. /**
  265. * 查看拼团开团信息
  266. * @return type
  267. */
  268. public function pintuan_manage() {
  269. $ppintuan_model = model('ppintuan');
  270. $ppintuangroup_model = model('ppintuangroup');
  271. $ppintuanorder_model = model('ppintuanorder');
  272. $pintuan_id = intval(input('param.pintuan_id'));
  273. //判断此拼团是否属于店铺
  274. $ppintuan = $ppintuan_model->getPintuanInfo(array('store_id' => session('store_id'), 'pintuan_id' => $pintuan_id));
  275. if (empty($ppintuan)) {
  276. $this->error(lang('param_error'));
  277. }
  278. $condition = array();
  279. $condition[] = array('pintuan_id','=',$pintuan_id);
  280. if (input('param.pintuangroup_state')) {
  281. $condition[] = array('pintuangroup_state','=',intval(input('param.pintuangroup_state')));
  282. }
  283. $ppintuangroup_list = $ppintuangroup_model->getPpintuangroupList($condition, 10); #获取开团信息
  284. foreach ($ppintuangroup_list as $key => $ppintuangroup) {
  285. //获取开团订单下的参团订单
  286. $condition = array();
  287. $condition[] = array('pintuangroup_id','=',$ppintuangroup['pintuangroup_id']);
  288. $ppintuangroup_list[$key]['order_list'] = $ppintuanorder_model->getPpintuanorderList($condition);
  289. }
  290. View::assign('show_page', $ppintuangroup_model->page_info->render());
  291. View::assign('pintuangroup_list', $ppintuangroup_list);
  292. View::assign('pintuangroup_state_array', $ppintuangroup_model->getPintuangroupStateArray());
  293. $this->setSellerCurMenu('Sellerpromotionpintuan');
  294. $this->setSellerCurItem('pintuan_manage');
  295. return View::fetch($this->template_dir . 'pintuan_manage');
  296. }
  297. /**
  298. * 拼团套餐购买
  299. * */
  300. public function pintuan_quota_add() {
  301. //输出导航
  302. $this->setSellerCurMenu('Sellerpromotionpintuan');
  303. $this->setSellerCurItem('pintuan_quota_add');
  304. return View::fetch($this->template_dir . 'pintuan_quota_add');
  305. }
  306. /**
  307. * 拼团套餐购买保存
  308. * */
  309. public function pintuan_quota_add_save() {
  310. if (intval(config('ds_config.promotion_pintuan_price')) == 0) {
  311. ds_json_encode(10001, lang('param_error'));
  312. }
  313. $pintuan_quota_quantity = intval(input('post.pintuan_quota_quantity'));
  314. if ($pintuan_quota_quantity <= 0 || $pintuan_quota_quantity > 12) {
  315. ds_json_encode(10001, lang('pintuan_quota_quantity_error'));
  316. }
  317. //获取当前价格
  318. $current_price = intval(config('ds_config.promotion_pintuan_price'));
  319. //获取该用户已有套餐
  320. $pintuanquota_model = model('ppintuanquota');
  321. $current_pintuan_quota = $pintuanquota_model->getPintuanquotaCurrent(session('store_id'));
  322. $pintuan_add_time = 86400 * 30 * $pintuan_quota_quantity;
  323. if (empty($current_pintuan_quota)) {
  324. //生成套餐
  325. $param = array();
  326. $param['member_id'] = session('member_id');
  327. $param['member_name'] = session('member_name');
  328. $param['store_id'] = session('store_id');
  329. $param['store_name'] = session('store_name');
  330. $param['pintuanquota_starttime'] = TIMESTAMP;
  331. $param['pintuanquota_endtime'] = TIMESTAMP + $pintuan_add_time;
  332. $pintuanquota_model->addPintuanquota($param);
  333. } else {
  334. $param = array();
  335. $param['pintuanquota_endtime'] = Db::raw('pintuanquota_endtime+' . $pintuan_add_time);
  336. $pintuanquota_model->editPintuanquota($param, array('pintuanquota_id' => $current_pintuan_quota['pintuanquota_id']));
  337. }
  338. //记录店铺费用
  339. $this->recordStorecost($current_price * $pintuan_quota_quantity, lang('buy_spell_group'));
  340. $this->recordSellerlog(lang('buy') . $pintuan_quota_quantity . lang('combo_pack') . $current_price . lang('ds_yuan'));
  341. ds_json_encode(10001, lang('pintuan_quota_add_success'));
  342. }
  343. /**
  344. * 选择活动商品
  345. * */
  346. public function search_goods() {
  347. $goods_model = model('goods');
  348. $condition = array();
  349. $condition[] = array('goods_lock', '=', 0);
  350. $condition[] = array('goods_state', '=', 1);
  351. $condition[] = array('goods_verify', '=', 1);
  352. $condition[] = array('store_id', '=', session('store_id'));
  353. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  354. $goods_list = $goods_model->getGoodsCommonListForPromotion($condition, '*', 8, '');
  355. View::assign('goods_list', $goods_list);
  356. View::assign('show_page', $goods_model->page_info->render());
  357. echo View::fetch($this->template_dir . 'search_goods');
  358. exit;
  359. }
  360. public function pintuan_goods_info() {
  361. $goods_commonid = intval(input('param.goods_commonid'));
  362. $data = array();
  363. $data['result'] = true;
  364. //判断此商品是否已经参加拼团,
  365. $result = $this->_check_allow_pintuan($goods_commonid);
  366. if ($result['result'] != TRUE) {
  367. echo json_encode($result);
  368. die;
  369. }
  370. //获取商品具体信息用于显示
  371. $goods_model = model('goods');
  372. $condition = array();
  373. $condition[]=array('goods_commonid','=',$goods_commonid);
  374. $goods_list = $goods_model->getGoodsOnlineList($condition);
  375. if (empty($goods_list)) {
  376. $data['result'] = false;
  377. $data['message'] = lang('param_error');
  378. echo json_encode($data);
  379. die;
  380. }
  381. $goods_info = $goods_list[0];
  382. $data['goods_id'] = $goods_info['goods_id'];
  383. $data['goods_name'] = $goods_info['goods_name'];
  384. $data['goods_price'] = $goods_info['goods_price'];
  385. $data['goods_image'] = goods_thumb($goods_info, 240);
  386. $data['goods_href'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  387. echo json_encode($data);
  388. die;
  389. }
  390. /*
  391. * 判断此商品是否已经参加拼团
  392. */
  393. private function _check_allow_pintuan($goods_commonid) {
  394. $condition = array();
  395. $condition[] = array('pintuan_goods_commonid','=',$goods_commonid);
  396. $condition[] = array('pintuan_state','=',1);
  397. $pintuan = model('ppintuan')->getPintuanInfo($condition);
  398. $result['result'] = TRUE;
  399. if (!empty($pintuan)) {
  400. $result['result'] = FALSE;
  401. $result['message'] = lang('goods_are_syndicate');
  402. }
  403. return $result;
  404. }
  405. protected function getSellerItemList() {
  406. $menu_array = array(
  407. array(
  408. 'name' => 'pintuan_list', 'text' => lang('pintuan_active_list'),
  409. 'url' => (string) url('Sellerpromotionpintuan/index')
  410. ),
  411. );
  412. switch (request()->action()) {
  413. case 'pintuan_add':
  414. $menu_array[] = array(
  415. 'name' => 'pintuan_add', 'text' => lang('pintuan_add'),
  416. 'url' => (string) url('Sellerpromotionpintuan/pintuan_add')
  417. );
  418. break;
  419. case 'pintuan_edit':
  420. $menu_array[] = array(
  421. 'name' => 'pintuan_edit', 'text' => lang('pintuan_edit'), 'url' => 'javascript:;'
  422. );
  423. break;
  424. case 'pintuan_quota_add':
  425. $menu_array[] = array(
  426. 'name' => 'pintuan_quota_add', 'text' => lang('pintuan_quota_add'),
  427. 'url' => (string) url('Sellerpromotionpintuan/pintuan_quota_add')
  428. );
  429. break;
  430. case 'pintuan_manage':
  431. $menu_array[] = array(
  432. 'name' => 'pintuan_manage', 'text' => lang('pintuan_manage'),
  433. 'url' => (string) url('Sellerpromotionpintuan/pintuan_manage', ['pintuan_id' => input('param.pintuan_id')])
  434. );
  435. break;
  436. }
  437. return $menu_array;
  438. }
  439. }