Marketmanage.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Db;
  5. use think\facade\Lang;
  6. /**
  7. * ============================================================================
  8. * DSMall多用户商城
  9. * ============================================================================
  10. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  11. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 营销活动管理 包含刮刮卡\大转盘\砸金蛋\生肖翻翻看
  17. */
  18. class Marketmanage extends AdminControl {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/marketmanage.lang.php');
  22. //营销活动类型
  23. $this->marketmanage_type_list = model('marketmanage')->marketmanage_type_list();
  24. View::assign('marketmanage_type_list', $this->marketmanage_type_list);
  25. $this->marketmanage_type = intval(input('param.type'));
  26. if (!array_key_exists($this->marketmanage_type, $this->marketmanage_type_list)) {
  27. $this->error(lang('param_error'));
  28. }
  29. View::assign('marketmanage_type', $this->marketmanage_type);
  30. }
  31. public function index() {
  32. $condition = array();
  33. $marketmanage_name = input('param.marketmanage_name');
  34. if (!empty($marketmanage_name)) {
  35. $condition[]=array('marketmanage_name','like', '%' . $marketmanage_name . '%');
  36. }
  37. $condition[]=array('marketmanage_type','=',$this->marketmanage_type);
  38. $marketmanage_model = model('marketmanage');
  39. $marketmanage_list = $marketmanage_model->getMarketmanageList($condition, 10);
  40. View::assign('marketmanage_list', $marketmanage_list);
  41. View::assign('show_page', $marketmanage_model->page_info->render());
  42. $this->setAdminCurItem('index');
  43. return View::fetch();
  44. }
  45. public function add() {
  46. if (!request()->isPost()) {
  47. $marketmanage = array(
  48. 'marketmanage_jointype'=>0,
  49. 'marketmanage_point'=>0,
  50. 'marketmanage_begintime' => TIMESTAMP,
  51. 'marketmanage_endtime' => TIMESTAMP+3600*24*7,
  52. );
  53. View::assign('marketmanage', $marketmanage);
  54. $marketmanageaward_list = array();
  55. for ($i = 1; $i <= 4; $i++) {
  56. $marketmanageaward_list[] = array(
  57. 'marketmanageaward_level' => $i,
  58. 'marketmanageaward_type' => 1,
  59. 'marketmanageaward_count' => 0,
  60. 'marketmanageaward_probability' => 0,
  61. 'marketmanageaward_point' => 0,
  62. 'bonus_id' => '',
  63. 'vouchertemplate_id' => ''
  64. );
  65. }
  66. View::assign('marketmanageaward_list', $marketmanageaward_list);
  67. //获取正在进行中的奖品红包活动
  68. $condition = array();
  69. $condition[] = array('bonus_type','=',3);
  70. $condition[] = array('bonus_state','=',1);
  71. $bonus_model = model('bonus');
  72. $bonus_list = $bonus_model->getBonusList($condition, '');
  73. View::assign('bonus_list', $bonus_list);
  74. //获取店铺的优惠券列表
  75. $condition = array();
  76. $condition[]=array('vouchertemplate_state','=',1);
  77. $condition[]=array('vouchertemplate_enddate','>', TIMESTAMP);
  78. $vouchertemplate_list = Db::name('vouchertemplate')->field('*')->where($condition)->limit(10)->select()->toArray();
  79. View::assign('vouchertemplate_list', $vouchertemplate_list);
  80. return View::fetch('form');
  81. } else {
  82. $data_marketmanageaward = array();
  83. $total_marketmanageaward_probability = 0;
  84. for ($i = 1; $i <= 4; $i++) {
  85. $marketmanageaward_probability = intval($_POST['probability_' . $i]);
  86. $total_marketmanageaward_probability +=$marketmanageaward_probability;
  87. $data_marketmanageaward[] = array(
  88. 'marketmanageaward_level' => $i,
  89. 'marketmanageaward_type' => intval($_POST['type_' . $i]),
  90. 'marketmanageaward_count' => intval($_POST['count_' . $i]),
  91. 'marketmanageaward_probability' => $marketmanageaward_probability,//中奖概率
  92. 'marketmanageaward_point'=>intval($_POST['point_' . $i]),
  93. 'bonus_id'=>isset($_POST['bonus_id_' . $i]) ? intval($_POST['bonus_id_' . $i]) : 0,
  94. 'vouchertemplate_id'=> isset($_POST['vouchertemplate_id_' . $i]) ? intval($_POST['vouchertemplate_id_' . $i]) : 0,
  95. );
  96. }
  97. //中奖概率之和应小于 400%
  98. if($total_marketmanageaward_probability>400){
  99. $this->error(lang('marketmanageaward_probability_error'));
  100. }
  101. $data_marketmanage = array(
  102. 'marketmanage_name' => input('param.marketmanage_name'),
  103. 'marketmanage_detail' => input('param.marketmanage_detail'),
  104. 'marketmanage_begintime' => strtotime(input('param.marketmanage_begintime')),
  105. 'marketmanage_endtime' => strtotime(input('param.marketmanage_endtime')),
  106. 'marketmanage_jointype' => intval(input('param.marketmanage_jointype')),
  107. 'marketmanage_joincount' => intval(input('param.marketmanage_joincount')),
  108. 'marketmanage_point' => intval(input('param.marketmanage_point_type')) == 0 ? 0 : intval(input('param.marketmanage_point')),
  109. 'marketmanage_addtime' => TIMESTAMP,
  110. 'marketmanage_failed' => input('param.marketmanage_failed'),
  111. 'marketmanage_type' => $this->marketmanage_type,
  112. );
  113. //添加营销活动
  114. $marketmanage_id = model('marketmanage')->addMarketmanage($data_marketmanage);
  115. //添加营销活动奖品记录
  116. if ($marketmanage_id > 0) {
  117. foreach ($data_marketmanageaward as $key => $marketmanageaward) {
  118. $data_marketmanageaward[$key]['marketmanage_id'] = $marketmanage_id;
  119. }
  120. Db::name('marketmanageaward')->insertAll($data_marketmanageaward);
  121. $this->log(lang('ds_add') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
  122. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  123. } else {
  124. $this->error(lang('ds_common_save_fail'));
  125. }
  126. }
  127. }
  128. public function edit() {
  129. $marketmanage_model = model('marketmanage');
  130. $condition = array();
  131. $marketmanage_id = intval(input('param.marketmanage_id'));
  132. if ($marketmanage_id <= 0) {
  133. $this->error(lang('param_error'));
  134. }
  135. $condition[] = array('marketmanage_id','=',$marketmanage_id);
  136. if (!request()->isPost()) {
  137. $marketmanage = $marketmanage_model->getOneMarketmanage($condition);
  138. View::assign('marketmanage', $marketmanage);
  139. View::assign('marketmanageaward_list', $marketmanage_model->getMarketmanageAwardList($condition));
  140. //获取正在进行中的奖品红包活动
  141. $condition = array();
  142. $condition[] = array('bonus_type','=',3);
  143. $condition[] = array('bonus_state','=',1);
  144. $bonus_model = model('bonus');
  145. $bonus_list = $bonus_model->getBonusList($condition, '');
  146. View::assign('bonus_list', $bonus_list);
  147. //获取店铺的优惠券列表
  148. $condition = array();
  149. $condition[] = array('vouchertemplate_state','=',1);
  150. $condition[]=array('vouchertemplate_enddate','>', TIMESTAMP);
  151. $vouchertemplate_list = Db::name('vouchertemplate')->field('*')->where($condition)->limit(10)->select()->toArray();
  152. View::assign('vouchertemplate_list', $vouchertemplate_list);
  153. return View::fetch('form');
  154. } else {
  155. $data_marketmanageaward = array();
  156. $total_marketmanageaward_probability = 0;
  157. for ($i = 1; $i <= 4; $i++) {
  158. $marketmanageaward_probability = intval($_POST['probability_' . $i]);
  159. $total_marketmanageaward_probability +=$marketmanageaward_probability;
  160. $data_marketmanageaward[] = array(
  161. 'marketmanageaward_id' => intval($_POST['id_' . $i]), //主键ID 稍后用于修改数据
  162. 'marketmanageaward_level' => $i,
  163. 'marketmanageaward_type' => intval($_POST['type_' . $i]),
  164. 'marketmanageaward_count' => intval($_POST['count_' . $i]),
  165. 'marketmanageaward_probability' => $marketmanageaward_probability,//中奖概率
  166. 'marketmanageaward_point' => intval($_POST['point_' . $i]),
  167. 'bonus_id' => isset($_POST['bonus_id_' . $i]) ? intval($_POST['bonus_id_' . $i]) : 0,
  168. 'vouchertemplate_id' => isset($_POST['vouchertemplate_id_' . $i]) ? intval($_POST['vouchertemplate_id_' . $i]) : 0,
  169. );
  170. }
  171. //中奖概率应小于 400%
  172. if($total_marketmanageaward_probability>400){
  173. $this->error(lang('marketmanageaward_probability_error'));
  174. }
  175. $data_marketmanage = array(
  176. 'marketmanage_name' => input('param.marketmanage_name'),
  177. 'marketmanage_detail' => input('param.marketmanage_detail'),
  178. 'marketmanage_begintime' => strtotime(input('param.marketmanage_begintime')),
  179. 'marketmanage_endtime' => strtotime(input('param.marketmanage_endtime')),
  180. 'marketmanage_jointype' => intval(input('param.marketmanage_jointype')),
  181. 'marketmanage_joincount' => intval(input('param.marketmanage_joincount')),
  182. 'marketmanage_point' => intval(input('param.marketmanage_point_type')) == 0 ? 0 : intval(input('param.marketmanage_point')),
  183. 'marketmanage_failed' => input('param.marketmanage_failed'),
  184. );
  185. //编辑营销活动
  186. model('marketmanage')->editMarketmanage(array('marketmanage_id' => $marketmanage_id), $data_marketmanage);
  187. //编辑营销活动奖品记录
  188. foreach ($data_marketmanageaward as $key => $marketmanageaward) {
  189. $condition = array();
  190. $condition[]=array('marketmanageaward_id','=',$marketmanageaward['marketmanageaward_id']);
  191. $condition[]=array('marketmanage_id','=',$marketmanage_id);
  192. Db::name('marketmanageaward')->where($condition)->update($marketmanageaward);
  193. }
  194. $this->log(lang('ds_edit') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
  195. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  196. }
  197. }
  198. //删除活动
  199. public function del()
  200. {
  201. $marketmanage_id = intval(input('param.marketmanage_id'));
  202. if ($marketmanage_id <= 0) {
  203. $this->error(lang('param_error'));
  204. }
  205. $marketmanage_model = model('marketmanage');
  206. $marketmanage_model->delMarketmanage($marketmanage_id);
  207. $this->log(lang('ds_edit') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
  208. ds_json_encode(10000, lang('ds_common_op_succ'));
  209. }
  210. //链接信息
  211. public function link()
  212. {
  213. $condition = array();
  214. $marketmanage_id = intval(input('param.marketmanage_id'));
  215. if ($marketmanage_id <= 0) {
  216. $this->error(lang('param_error'));
  217. }
  218. $condition[] = array('marketmanage_id','=',$marketmanage_id);
  219. $marketmanage_model = model('marketmanage');
  220. $marketmanage = $marketmanage_model->getOneMarketmanage($condition);
  221. View::assign('marketmanage', $marketmanage);
  222. $market_url = '';
  223. //1刮刮卡2大转盘3砸金蛋4生肖翻翻看
  224. switch ($marketmanage['marketmanage_type']) {
  225. case 1:
  226. $market_url = config('ds_config.h5_site_url')."/pages/home/marketmanage/Marketcard?marketmanage_id=".$marketmanage['marketmanage_id'];
  227. break;
  228. case 2:
  229. $market_url = config('ds_config.h5_site_url')."/pages/home/marketmanage/Marketwheel?marketmanage_id=".$marketmanage['marketmanage_id'];
  230. break;
  231. case 3:
  232. $market_url = config('ds_config.h5_site_url')."/pages/home/marketmanage/Marketegg?marketmanage_id=".$marketmanage['marketmanage_id'];
  233. break;
  234. case 4:
  235. $market_url = config('ds_config.h5_site_url')."/pages/home/marketmanage/Marketzodiac?marketmanage_id=".$marketmanage['marketmanage_id'];
  236. break;
  237. default:
  238. break;
  239. }
  240. View::assign('market_url', $market_url);
  241. return View::fetch();
  242. }
  243. //活动参与记录
  244. public function detail() {
  245. $condition = array();
  246. $marketmanage_id = intval(input('param.marketmanage_id'));
  247. if ($marketmanage_id <= 0) {
  248. $this->error(lang('param_error'));
  249. }
  250. $condition[] = array('marketmanage_id','=',$marketmanage_id);
  251. $marketmanage_model = model('marketmanage');
  252. $marketmanagelog_list = $marketmanage_model->getMarketmanageLogList($condition, 10);
  253. View::assign('marketmanagelog_list', $marketmanagelog_list);
  254. View::assign('show_page', $marketmanage_model->page_info->render());
  255. return View::fetch();
  256. }
  257. protected function getAdminItemList() {
  258. $menu_array = array(
  259. array(
  260. 'name' => 'index',
  261. 'text' => lang('ds_manage'),
  262. 'url' => (string)url('Marketmanage/index', ['type' => input('param.type')])
  263. ),
  264. array(
  265. 'name' => 'add',
  266. 'text' => lang('ds_add'),
  267. 'url' => "javascript:dsLayerOpen('" . (string)url('Marketmanage/add', ['type' => input('param.type')]) . "','".lang('ds_add')."')"
  268. ),
  269. );
  270. return $menu_array;
  271. }
  272. }