Marketmanage.php 15 KB

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