Marketmanage.php 14 KB

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