Sellerpromotionmansong.php 15 KB

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