Sellerpromotionmansong.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellerpromotionmansong extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerpromotionmansong.lang.php');
  21. //检查满就送是否开启
  22. if (intval(config('ds_config.promotion_allow')) !== 1) {
  23. $this->error(lang('promotion_unavailable'), 'seller/index');
  24. }
  25. }
  26. /**
  27. * 发布的满就送活动列表
  28. * */
  29. public function index() {
  30. $mansongquota_model = model('pmansongquota');
  31. $pmansong_model = model('pmansong');
  32. $isPlatformStore = check_platform_store() ? true : false;
  33. View::assign('isPlatformStore', $isPlatformStore);
  34. $current_mansong_quota = $mansongquota_model->getMansongquotaCurrent(session('store_id'));
  35. View::assign('current_mansong_quota', $current_mansong_quota);
  36. $condition = array();
  37. $condition[] = array('store_id', '=', session('store_id'));
  38. if ((input('param.mansong_name'))) {
  39. $condition[] = array('mansong_name', 'like', '%' . input('param.mansong_name') . '%');
  40. }
  41. if ((input('param.state'))) {
  42. $condition[] = array('mansong_state', '=', intval(input('param.state')));
  43. }
  44. $mansong_list = $pmansong_model->getMansongList($condition, 10, 'mansong_state desc, mansong_endtime desc');
  45. View::assign('mansong_list', $mansong_list);
  46. View::assign('show_page', $pmansong_model->page_info->render());
  47. View::assign('mansong_state_array', $pmansong_model->getMansongStateArray());
  48. $this->setSellerCurMenu('Sellerpromotionmansong');
  49. $this->setSellerCurItem('mansong_list');
  50. return View::fetch($this->template_dir . 'index');
  51. }
  52. /**
  53. * 添加满就送活动
  54. * */
  55. public function mansong_add() {
  56. $mansongquota_model = model('pmansongquota');
  57. $pmansong_model = model('pmansong');
  58. $start_time = $pmansong_model->getMansongNewStartTime(session('store_id'));
  59. $end_time = TIMESTAMP;
  60. $isPlatformStore = check_platform_store() ? true : false;
  61. View::assign('isPlatformStore', $isPlatformStore);
  62. if (!$isPlatformStore) {
  63. //检查当前套餐是否可用
  64. $current_mansong_quota = $mansongquota_model->getMansongquotaCurrent(session('store_id'));
  65. if (empty($current_mansong_quota)) {
  66. if (intval(config('ds_config.promotion_mansong_price')) != 0) {
  67. $this->error(lang('mansong_quota_current_error'));
  68. } else {
  69. $current_mansong_quota = array('mansongquota_starttime' => TIMESTAMP, 'mansongquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  70. }
  71. }
  72. if (empty($start_time)) {
  73. $start_time = $current_mansong_quota['mansongquota_starttime'];
  74. }
  75. $end_time = $current_mansong_quota['mansongquota_endtime'];
  76. }
  77. if (empty($start_time))
  78. $start_time = TIMESTAMP;
  79. View::assign('start_time', $start_time);
  80. View::assign('end_time', $end_time);
  81. //输出导航
  82. $this->setSellerCurMenu('Sellerpromotionmansong');
  83. $this->setSellerCurItem('mansong_add');
  84. return View::fetch($this->template_dir . 'mansong_add');
  85. }
  86. /**
  87. * 保存添加的满就送活动
  88. * */
  89. public function mansong_save() {
  90. $mansong_name = trim(input('post.mansong_name'));
  91. $start_time = strtotime(input('post.start_time'));
  92. $end_time = strtotime(input('post.end_time'));
  93. $mansongquota_model = model('pmansongquota');
  94. $pmansong_model = model('pmansong');
  95. $mansongrule_model = model('pmansongrule');
  96. if ($start_time >= $end_time) {
  97. ds_json_encode(10001, lang('greater_than_start_time'));
  98. }
  99. if (empty($mansong_name)) {
  100. ds_json_encode(10001, lang('mansong_name_error'));
  101. }
  102. $start_time_limit = $pmansong_model->getMansongNewStartTime(session('store_id'));
  103. if (!empty($start_time_limit) && $start_time_limit > $start_time) {
  104. $start_time = $start_time_limit;
  105. }
  106. if (!check_platform_store()) {
  107. //检查当前套餐是否可用
  108. $current_mansong_quota = $mansongquota_model->getMansongquotaCurrent(session('store_id'));
  109. if (empty($current_mansong_quota)) {
  110. if (intval(config('ds_config.promotion_mansong_price')) != 0) {
  111. ds_json_encode(10001, lang('mansong_quota_current_error'));
  112. } else {
  113. $current_mansong_quota = array('mansongquota_starttime' => TIMESTAMP, 'mansongquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
  114. }
  115. }
  116. //验证输入
  117. $quota_start_time = intval($current_mansong_quota['mansongquota_starttime']);
  118. $quota_end_time = intval($current_mansong_quota['mansongquota_endtime']);
  119. if ($start_time < $quota_start_time) {
  120. ds_json_encode(10001, sprintf(lang('mansong_add_start_time_explain'), date('Y-m-d', $current_mansong_quota['mansongquota_starttime'])));
  121. }
  122. if ($end_time > $quota_end_time) {
  123. ds_json_encode(10001, sprintf(lang('mansong_add_end_time_explain'), date('Y-m-d', $current_mansong_quota['mansongquota_endtime'])));
  124. }
  125. }
  126. if($end_time<TIMESTAMP){
  127. ds_json_encode(10001, sprintf(lang('mansong_add_end_time_explain'), date('Y-m-d')));
  128. }
  129. if (empty(input('post.mansong_rule/a'))) {
  130. ds_json_encode(10001, lang('mansong_rule_empty'));
  131. }
  132. $param = array();
  133. $param['mansong_name'] = $mansong_name;
  134. $param['mansong_starttime'] = $start_time;
  135. $param['mansong_endtime'] = $end_time;
  136. $param['store_id'] = session('store_id');
  137. $param['store_name'] = session('store_name');
  138. $param['member_id'] = session('member_id');
  139. $param['member_name'] = session('member_name');
  140. $param['mansongquota_id'] = isset($current_mansong_quota['mansongquota_id']) ? $current_mansong_quota['mansongquota_id'] : 0;
  141. $param['mansong_remark'] = trim(input('post.remark'));
  142. $mansong_id = $pmansong_model->addMansong($param);
  143. if ($mansong_id) {
  144. $mansong_rule_array = array();
  145. foreach (input('post.mansong_rule/a') as $value) {
  146. list($price, $discount, $goods_id) = explode(',', $value);
  147. $mansong_rule = array();
  148. $mansong_rule['mansong_id'] = $mansong_id;
  149. $mansong_rule['mansongrule_price'] = $price;
  150. $mansong_rule['mansongrule_discount'] = $discount;
  151. $mansong_rule['goods_id'] = $goods_id;
  152. $mansong_rule_array[] = $mansong_rule;
  153. }
  154. //生成规则
  155. $result = $mansongrule_model->addMansongruleArray($mansong_rule_array);
  156. $this->recordSellerlog('添加满即送活动,活动名称:' . $mansong_name);
  157. // 自动发布动态
  158. // mansong_name,start_time,end_time,store_id
  159. $data_array = array();
  160. $data_array['mansong_name'] = $param['mansong_name'];
  161. $data_array['mansong_starttime'] = $param['mansong_starttime'];
  162. $data_array['mansong_endtime'] = $param['mansong_endtime'];
  163. $data_array['store_id'] = session('store_id');
  164. $this->storeAutoShare($data_array, 'mansong');
  165. ds_json_encode(10000, lang('mansong_add_success'));
  166. } else {
  167. ds_json_encode(10001, lang('mansong_add_fail'));
  168. }
  169. }
  170. /**
  171. * 满就送活动详细信息
  172. * */
  173. public function mansong_detail() {
  174. $mansong_id = intval(input('param.mansong_id'));
  175. $pmansong_model = model('pmansong');
  176. $mansongrule_model = model('pmansongrule');
  177. $mansong_info = $pmansong_model->getMansongInfoByID($mansong_id, session('store_id'));
  178. if (empty($mansong_info)) {
  179. $this->error(lang('param_error'));
  180. }
  181. View::assign('mansong_info', $mansong_info);
  182. $param = array();
  183. $param['mansong_id'] = $mansong_id;
  184. $rule_list = $mansongrule_model->getMansongruleListByID($mansong_id);
  185. View::assign('rule_list', $rule_list);
  186. //输出导航
  187. $this->setSellerCurMenu('Sellerpromotionmansong');
  188. return View::fetch($this->template_dir . 'mansong_detail');
  189. }
  190. /**
  191. * 满就送活动删除
  192. * */
  193. public function mansong_del() {
  194. $mansong_id = intval(input('post.mansong_id'));
  195. $pmansong_model = model('pmansong');
  196. $mansong_info = $pmansong_model->getMansongInfoByID($mansong_id, session('store_id'));
  197. if (empty($mansong_info)) {
  198. ds_json_encode(10001, lang('param_error'));
  199. }
  200. $condition = array();
  201. $condition[] = array('mansong_id','=',$mansong_id);
  202. $result = $pmansong_model->delMansong($condition);
  203. if ($result) {
  204. $this->recordSellerlog('删除满即送活动,活动名称:' . $mansong_info['mansong_name']);
  205. ds_json_encode(10000, lang('ds_common_op_succ'));
  206. } else {
  207. ds_json_encode(10001, lang('ds_common_op_fail'));
  208. }
  209. }
  210. /**
  211. * 满就送套餐购买
  212. * */
  213. public function mansong_quota_add() {
  214. $this->setSellerCurMenu('Sellerpromotionmansong');
  215. $this->setSellerCurItem('mansong_quota_add');
  216. return View::fetch($this->template_dir . 'quota_add');
  217. }
  218. /**
  219. * 满就送套餐购买保存
  220. * */
  221. public function mansong_quota_add_save() {
  222. if (intval(config('ds_config.promotion_mansong_price')) == 0) {
  223. ds_json_encode(10001, lang('param_error'));
  224. }
  225. $mansong_quota_quantity = intval(input('post.mansong_quota_quantity'));
  226. if ($mansong_quota_quantity <= 0 || $mansong_quota_quantity > 12) {
  227. ds_json_encode(10001, lang('mansong_quota_quantity_error'));
  228. }
  229. //获取当前价格
  230. $current_price = intval(config('ds_config.promotion_mansong_price'));
  231. //获取该用户已有套餐
  232. $mansongquota_model = model('pmansongquota');
  233. $current_mansong_quota = $mansongquota_model->getMansongquotaCurrent(session('store_id'));
  234. $mansong_add_time = 86400 * 30 * $mansong_quota_quantity;
  235. if (empty($current_mansong_quota)) {
  236. //生成套餐
  237. $param = array();
  238. $param['member_id'] = session('member_id');
  239. $param['member_name'] = session('member_name');
  240. $param['store_id'] = session('store_id');
  241. $param['store_name'] = session('store_name');
  242. $param['mansongquota_starttime'] = TIMESTAMP;
  243. $param['mansongquota_endtime'] = TIMESTAMP + $mansong_add_time;
  244. $mansongquota_model->addMansongquota($param);
  245. } else {
  246. $param = array();
  247. $param['mansongquota_endtime'] = Db::raw('mansongquota_endtime+' . $mansong_add_time);
  248. $mansongquota_model->editMansongquota($param, array('mansongquota_id' => $current_mansong_quota['mansongquota_id']));
  249. }
  250. //记录店铺费用
  251. $this->recordStorecost($current_price * $mansong_quota_quantity, '购买满即送');
  252. $this->recordSellerlog('购买' . $mansong_quota_quantity . '份满即送套餐,单价' . $current_price . lang('ds_yuan'));
  253. ds_json_encode(10000, lang('mansong_quota_add_success'));
  254. }
  255. /**
  256. * 选择活动商品
  257. * */
  258. public function search_goods() {
  259. $goods_model = model('goods');
  260. $condition = array();
  261. $condition[] = array('store_id', '=', session('store_id'));
  262. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  263. $goods_list = $goods_model->getGeneralGoodsList($condition, '*', 8);
  264. View::assign('goods_list', $goods_list);
  265. View::assign('show_page', $goods_model->page_info->render());
  266. echo View::fetch($this->template_dir . 'mansong_goods');
  267. }
  268. /**
  269. * 用户中心右边,小导航
  270. *
  271. * @param string $menu_type 导航类型
  272. * @param string $name 当前导航的name
  273. * @param array $array 附加菜单
  274. * @return
  275. */
  276. protected function getSellerItemList() {
  277. $menu_array = array(
  278. array(
  279. 'name' => 'mansong_list', 'text' => lang('promotion_active_list'),
  280. 'url' => (string) url('Sellerpromotionmansong/index')
  281. ),
  282. );
  283. switch (request()->action()) {
  284. case 'mansong_add':
  285. $menu_array[] = array(
  286. 'name' => 'mansong_add', 'text' => lang('promotion_join_active'),
  287. 'url' => (string) url('Sellerpromotionmansong/mansong_add')
  288. );
  289. break;
  290. case 'mansong_quota_add':
  291. $menu_array[] = array(
  292. 'name' => 'mansong_quota_add', 'text' => lang('promotion_buy_product'),
  293. 'url' => (string) url('Sellerpromotionmansong/mansong_quota_add')
  294. );
  295. break;
  296. case 'mansong_detail':
  297. $menu_array[] = array(
  298. 'name' => 'mansong_detail', 'text' => lang('mansong_active_content'),
  299. 'url' => (string) url('Sellerpromotionmansong/mansong_detail', array('mansong_id' => input('param.mansong_id')))
  300. );
  301. break;
  302. }
  303. return $menu_array;
  304. }
  305. }