Activity.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. namespace app\admin\controller\lottery;
  3. use app\common\controller\Backend;
  4. use app\common\Enum\ActivityEnum;
  5. use think\Db;
  6. use think\exception\ValidateException;
  7. use think\exception\PDOException;
  8. use Exception;
  9. /**
  10. * 抽奖活动管理
  11. *
  12. * @icon fa fa-gift
  13. */
  14. class Activity extends Backend
  15. {
  16. /**
  17. * Activity模型对象
  18. * @var \app\admin\model\lottery\Activity
  19. */
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\admin\model\lottery\Activity;
  25. // 获取枚举值列表
  26. $this->view->assign("typeList", ActivityEnum::getActivityTypeMap());
  27. $this->assignconfig("typeList", json_encode(ActivityEnum::getActivityTypeMap()));
  28. $this->view->assign("statusList", ActivityEnum::getActivityStatusMap());
  29. $this->assignconfig("statusList", json_encode(ActivityEnum::getActivityStatusMap()));
  30. $this->view->assign("lotteryTypeList", ActivityEnum::getLotteryTypeMap());
  31. $this->assignconfig("lotteryTypeList", json_encode(ActivityEnum::getLotteryTypeMap()));
  32. $this->view->assign("userLimitTypeList", ActivityEnum::getUserLimitTypeMap());
  33. $this->assignconfig("userLimitTypeList", json_encode(ActivityEnum::getUserLimitTypeMap()));
  34. $this->view->assign("guideStyleList", ActivityEnum::getGuideStyleMap());
  35. $this->assignconfig("guideStyleList", json_encode(ActivityEnum::getGuideStyleMap()));
  36. $this->view->assign("conditionTypeList", ActivityEnum::getConditionTypeMap());
  37. $this->assignconfig("conditionTypeList", json_encode(ActivityEnum::getConditionTypeMap()));
  38. // 奖品类型配置
  39. $this->view->assign("prizeTypeList", ActivityEnum::getPrizeTypeMap());
  40. $this->assignconfig("prizeTypeList", json_encode(ActivityEnum::getPrizeTypeMap()));
  41. // 奖品默认图片配置
  42. $this->assignconfig("prizeDefaultImages", json_encode(ActivityEnum::getPrizeDefaultImageMap()));
  43. $config = config('site');
  44. $lottery_guide = $config['lottery_guide'] ?? '';
  45. $prize_losing_lottery = $config['prize_losing_lottery'] ?? '';
  46. $this->view->assign("prize_losing_lottery", $prize_losing_lottery);
  47. $this->view->assign("lottery_guide", $lottery_guide);
  48. }
  49. /**
  50. * 查看
  51. */
  52. public function index()
  53. {
  54. //当前是否为关联查询
  55. $this->relationSearch = true;
  56. //设置过滤方法
  57. $this->request->filter(['strip_tags', 'trim']);
  58. if ($this->request->isAjax()) {
  59. //如果发送的来源是Selectpage,则转发到Selectpage
  60. if ($this->request->request('keyField')) {
  61. return $this->selectpage();
  62. }
  63. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  64. $list = $this->model
  65. ->with(['prize'])
  66. ->where($where)
  67. ->order($sort, $order)
  68. ->paginate($limit);
  69. foreach ($list as $row) {
  70. $row->visible(['id','name','description','cover_image','type','status','start_time','end_time','lottery_type','total_draw_count','total_people_count','total_win_count']);
  71. $row->visible(['prize']);
  72. $row->getRelation('prize')->visible(['name','type','total_stock','remain_stock']);
  73. }
  74. $result = array("total" => $list->total(), "rows" => $list->items());
  75. return json($result);
  76. }
  77. return $this->view->fetch();
  78. }
  79. /**
  80. * 添加
  81. */
  82. public function add()
  83. {
  84. if ($this->request->isPost()) {
  85. $params = $this->request->post("row/a");
  86. if ($params) {
  87. $params = $this->preExcludeFields($params);
  88. // 获取奖品和条件数据
  89. $prizesData = $this->request->post("prizes/a", []);
  90. $conditionData = $this->request->post("condition/a", []);
  91. $taskTypes = isset($params['task_type']) ? $params['task_type'] : [];
  92. // 处理活动基础数据
  93. $activityData = $this->processActivityData($params);
  94. // 验证奖品数据
  95. $this->validatePrizesData($prizesData);
  96. // 验证条件数据
  97. $this->validateConditionData($conditionData, $taskTypes);
  98. $result = false;
  99. Db::startTrans();
  100. try {
  101. // 保存活动主表数据
  102. //是否采用模型验证
  103. if ($this->modelValidate) {
  104. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  105. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  106. $this->model->validateFailException(true)->validate($validate);
  107. }
  108. $result = $this->model->allowField(true)->save($activityData);
  109. if ($result) {
  110. $activityId = $this->model->id;
  111. // 保存奖品数据
  112. $this->savePrizesData($activityId, $prizesData);
  113. // 保存参与条件数据
  114. $this->saveConditionData($activityId, $conditionData, $taskTypes);
  115. }
  116. Db::commit();
  117. } catch (ValidateException $e) {
  118. Db::rollback();
  119. $this->error($e->getMessage());
  120. } catch (PDOException $e) {
  121. Db::rollback();
  122. $this->error($e->getMessage());
  123. } catch (Exception $e) {
  124. Db::rollback();
  125. $this->error($e->getMessage());
  126. }
  127. if ($result !== false) {
  128. $this->success();
  129. } else {
  130. $this->error(__('No rows were inserted'));
  131. }
  132. }
  133. $this->error(__('Parameter %s can not be empty', ''));
  134. }
  135. return $this->view->fetch();
  136. }
  137. /**
  138. * 处理活动基础数据
  139. */
  140. private function processActivityData($params)
  141. {
  142. // 处理时间字段
  143. if (isset($params['start_time']) && $params['start_time']) {
  144. $params['start_time'] = strtotime($params['start_time']);
  145. }
  146. if (isset($params['end_time']) && $params['end_time']) {
  147. $params['end_time'] = strtotime($params['end_time']);
  148. }
  149. if (isset($params['lottery_time']) && $params['lottery_time']) {
  150. $params['lottery_time'] = strtotime($params['lottery_time']);
  151. }
  152. // 处理JSON字段
  153. if (isset($params['user_limit_value']) && $params['user_limit_value']) {
  154. $params['user_limit_value'] = json_encode($params['user_limit_value']);
  155. }
  156. // 处理渠道字段(如果存在的话)
  157. if (isset($params['channels']) && is_array($params['channels'])) {
  158. $params['channels'] = json_encode($params['channels']);
  159. }
  160. // 处理兑奖期限设置
  161. if (isset($params['redeem_expire_type'])) {
  162. $params['redeem_expire_type'] = intval($params['redeem_expire_type']);
  163. if ($params['redeem_expire_type'] == ActivityEnum::REDEEM_EXPIRE_FIXED) {
  164. $params['redeem_expire_days'] = isset($params['redeem_expire_days']) ? intval($params['redeem_expire_days']) : 7;
  165. } else {
  166. $params['redeem_expire_days'] = null;
  167. }
  168. }
  169. // 字段名映射 - 将前端字段名映射到实际数据表字段名
  170. if (isset($params['title'])) {
  171. $params['name'] = $params['title']; // 活动标题映射到name字段
  172. unset($params['title']);
  173. }
  174. if (isset($params['lottery_people'])) {
  175. $params['lottery_people_num'] = $params['lottery_people']; // 开奖人数字段名映射
  176. unset($params['lottery_people']);
  177. }
  178. if (isset($params['per_person_limit'])) {
  179. $params['person_limit_num'] = $params['per_person_limit']; // 单人限制次数字段名映射
  180. unset($params['per_person_limit']);
  181. }
  182. // 移除不属于活动表的字段
  183. unset($params['task_type']);
  184. // 设置默认值
  185. $params['type'] = ActivityEnum::ACTIVITY_TYPE_CONSUMPTION_LOTTERY; // 消费抽奖
  186. // 初始化统计字段
  187. if (!isset($params['total_draw_count'])) {
  188. $params['total_draw_count'] = 0;
  189. }
  190. if (!isset($params['total_people_count'])) {
  191. $params['total_people_count'] = 0;
  192. }
  193. if (!isset($params['total_win_count'])) {
  194. $params['total_win_count'] = 0;
  195. }
  196. return $params;
  197. }
  198. /**
  199. * 验证奖品数据
  200. */
  201. private function validatePrizesData($prizesData)
  202. {
  203. if (empty($prizesData) || count($prizesData) < 8) {
  204. throw new Exception('奖品数量不足,必须配置8个奖品(包含未中奖项)');
  205. }
  206. $totalRate = 0;
  207. foreach ($prizesData as $prize) {
  208. if (!isset($prize['name']) || !isset($prize['type']) || !isset($prize['rate'])) {
  209. throw new Exception('奖品配置不完整');
  210. }
  211. $totalRate += floatval($prize['rate']);
  212. // 验证特定类型奖品的必需字段
  213. switch (intval($prize['type'])) {
  214. case 5: // 优惠券
  215. if (empty($prize['coupon_id'])) {
  216. throw new Exception('优惠券奖品必须选择优惠券');
  217. }
  218. break;
  219. case 8: // 商城奖品
  220. if (empty($prize['goods_id'])) {
  221. throw new Exception('商城奖品必须选择商品');
  222. }
  223. break;
  224. }
  225. }
  226. if (abs($totalRate - 100) > 0.01) {
  227. throw new Exception('奖品总概率必须等于100%,当前为' . $totalRate . '%');
  228. }
  229. }
  230. /**
  231. * 验证条件数据
  232. */
  233. private function validateConditionData($conditionData, $taskTypes)
  234. {
  235. if (empty($taskTypes)) {
  236. throw new Exception('请至少选择一种任务类型');
  237. }
  238. foreach ($taskTypes as $taskType) {
  239. $type = intval($taskType);
  240. switch ($type) {
  241. case 1: // 购买指定商品
  242. if (!isset($conditionData[$type]) || empty($conditionData[$type]['goods_ids'])) {
  243. throw new Exception('购买指定商品任务必须選擇商品');
  244. }
  245. break;
  246. case 2: // 单笔订单消费满额
  247. case 3: // 单次充值满额
  248. case 4: // 活动期间累计消费满额
  249. if (!isset($conditionData[$type]) || empty($conditionData[$type]['condition_value'])) {
  250. throw new Exception('消费/充值任务必须设置金额');
  251. }
  252. if (floatval($conditionData[$type]['condition_value']) <= 0) {
  253. throw new Exception('消费/充值任务金额必须大于0');
  254. }
  255. break;
  256. }
  257. }
  258. }
  259. /**
  260. * 保存奖品数据
  261. */
  262. private function savePrizesData($activityId, $prizesData)
  263. {
  264. $prizeModel = new \app\admin\model\lottery\Prize;
  265. foreach ($prizesData as $index => $prize) {
  266. $prizeData = [
  267. 'activity_id' => $activityId,
  268. 'name' => $prize['name'],
  269. 'type' => intval($prize['type']),
  270. 'image' => isset($prize['image']) ? $prize['image'] : '',
  271. 'probability' => floatval($prize['rate']),
  272. 'total_stock' => isset($prize['quantity']) ? intval($prize['quantity']) : 0,
  273. 'remain_stock' => isset($prize['quantity']) ? intval($prize['quantity']) : 0,
  274. 'sort_order' => $index,
  275. 'status' => 1,
  276. 'createtime' => time()
  277. ];
  278. // 根据奖品类型设置特定字段
  279. switch (intval($prize['type'])) {
  280. case ActivityEnum::PRIZE_TYPE_POINTS: // 积分 - 使用amount字段存储积分数量
  281. $prizeData['amount'] = isset($prize['points']) ? intval($prize['points']) : 0;
  282. $prizeData['description'] = '积分奖品';
  283. break;
  284. case ActivityEnum::PRIZE_TYPE_BALANCE: // 余额 - 使用amount字段存储余额金额
  285. $prizeData['amount'] = isset($prize['balance']) ? floatval($prize['balance']) : 0;
  286. $prizeData['description'] = '余额奖品';
  287. break;
  288. case ActivityEnum::PRIZE_TYPE_COUPON: // 优惠券
  289. $prizeData['coupon_id'] = isset($prize['coupon_id']) ? intval($prize['coupon_id']) : 0;
  290. $prizeData['description'] = '优惠券奖品';
  291. break;
  292. case ActivityEnum::PRIZE_TYPE_REDPACK: // 红包 - 使用amount字段存储红包金额
  293. $prizeData['amount'] = isset($prize['redpack_amount']) ? floatval($prize['redpack_amount']) : 0;
  294. $prizeData['description'] = '红包奖品';
  295. break;
  296. case ActivityEnum::PRIZE_TYPE_CODE: // 兑换码
  297. if (isset($prize['manual_codes']) && !empty($prize['manual_codes'])) {
  298. $codes = array_filter(array_map('trim', explode("\n", $prize['manual_codes'])));
  299. $prizeData['exchange_codes'] = json_encode($codes);
  300. $prizeData['used_codes'] = json_encode([]); // 初始化已使用列表
  301. $prizeData['total_stock'] = count($codes);
  302. $prizeData['remain_stock'] = count($codes);
  303. }
  304. $prizeData['description'] = '兑换码奖品';
  305. break;
  306. case ActivityEnum::PRIZE_TYPE_SHOP_GOODS: // 商城奖品
  307. $prizeData['goods_id'] = isset($prize['goods_id']) ? intval($prize['goods_id']) : 0;
  308. $prizeData['goods_sku_id'] = isset($prize['goods_sku_id']) ? intval($prize['goods_sku_id']) : null;
  309. $prizeData['description'] = '商城奖品';
  310. break;
  311. case ActivityEnum::PRIZE_TYPE_GOODS: // 实物奖品
  312. $prizeData['description'] = isset($prize['description']) ? $prize['description'] : '实物奖品';
  313. break;
  314. case ActivityEnum::PRIZE_TYPE_NO_PRIZE: // 未中奖
  315. default:
  316. $prizeData['description'] = '未中奖';
  317. break;
  318. }
  319. $prizeModel->create($prizeData);
  320. }
  321. }
  322. /**
  323. * 保存参与条件数据
  324. */
  325. private function saveConditionData($activityId, $conditionData, $taskTypes)
  326. {
  327. $conditionModel = new \app\admin\model\lottery\Condition;
  328. foreach ($taskTypes as $taskType) {
  329. $type = intval($taskType);
  330. $condition = isset($conditionData[$type]) ? $conditionData[$type] : [];
  331. $conditionRecord = [
  332. 'activity_id' => $activityId,
  333. 'type' => $type,
  334. 'reward_times' => 1,
  335. 'is_repeatable' => 0,
  336. 'status' => $conditionModel::STATUS_ENABLED,
  337. 'createtime' => time()
  338. ];
  339. switch ($type) {
  340. case ActivityEnum::CONDITION_TYPE_BUY_GOODS: // 购买指定商品
  341. $goodsIds = isset($condition['goods_ids']) ? $condition['goods_ids'] : '[]';
  342. if (is_string($goodsIds)) {
  343. $goodsIds = json_decode($goodsIds, true) ?: [];
  344. }
  345. $conditionRecord['goods_ids'] = json_encode($goodsIds);
  346. $conditionRecord['goods_rule'] = isset($condition['goods_rule']) ? intval($condition['goods_rule']) : $conditionModel::GOODS_RULE_INCLUDE;
  347. break;
  348. case ActivityEnum::CONDITION_TYPE_ORDER_AMOUNT: // 单笔订单消费满额
  349. case ActivityEnum::CONDITION_TYPE_RECHARGE_AMOUNT: // 单次充值满额
  350. case ActivityEnum::CONDITION_TYPE_TOTAL_AMOUNT: // 活动期间累计消费满额
  351. $conditionRecord['condition_value'] = isset($condition['condition_value']) ? floatval($condition['condition_value']) : 0;
  352. if ($type == ActivityEnum::CONDITION_TYPE_TOTAL_AMOUNT) {
  353. $conditionRecord['is_repeatable'] = 0; // 累计消费不可重复
  354. } else {
  355. $conditionRecord['is_repeatable'] = 1; // 其他类型可重复
  356. }
  357. break;
  358. }
  359. $conditionModel->create($conditionRecord);
  360. }
  361. }
  362. /**
  363. * 编辑
  364. */
  365. public function edit($ids = null)
  366. {
  367. $row = $this->model->get($ids);
  368. if (!$row) {
  369. $this->error(__('No Results were found'));
  370. }
  371. $adminIds = $this->getDataLimitAdminIds();
  372. if (is_array($adminIds)) {
  373. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  374. $this->error(__('You have no permission'));
  375. }
  376. }
  377. if ($this->request->isPost()) {
  378. $params = $this->request->post("row/a");
  379. if ($params) {
  380. $params = $this->preExcludeFields($params);
  381. // 获取奖品和条件数据
  382. $prizesData = $this->request->post("prizes/a", []);
  383. $conditionData = $this->request->post("condition/a", []);
  384. $taskTypes = isset($params['task_type']) ? $params['task_type'] : [];
  385. // 处理活动基础数据
  386. $activityData = $this->processActivityData($params);
  387. // 验证奖品数据
  388. $this->validatePrizesData($prizesData);
  389. // 验证条件数据
  390. $this->validateConditionData($conditionData, $taskTypes);
  391. $result = false;
  392. Db::startTrans();
  393. try {
  394. // 更新活动主表数据
  395. //是否采用模型验证
  396. if ($this->modelValidate) {
  397. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  398. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  399. $row->validateFailException(true)->validate($validate);
  400. }
  401. $result = $row->allowField(true)->save($activityData);
  402. if ($result !== false) {
  403. $activityId = $ids;
  404. // 删除原有奖品数据
  405. Db::name('shop_lottery_prize')->where('activity_id', $activityId)->delete();
  406. // 删除原有条件数据
  407. Db::name('shop_lottery_condition')->where('activity_id', $activityId)->delete();
  408. // 保存新的奖品数据
  409. $this->savePrizesData($activityId, $prizesData);
  410. // 保存新的参与条件数据
  411. $this->saveConditionData($activityId, $conditionData, $taskTypes);
  412. }
  413. Db::commit();
  414. } catch (ValidateException $e) {
  415. Db::rollback();
  416. $this->error($e->getMessage());
  417. } catch (PDOException $e) {
  418. Db::rollback();
  419. $this->error($e->getMessage());
  420. } catch (Exception $e) {
  421. Db::rollback();
  422. $this->error($e->getMessage());
  423. }
  424. if ($result !== false) {
  425. $this->success();
  426. } else {
  427. $this->error(__('No rows were updated'));
  428. }
  429. }
  430. $this->error(__('Parameter %s can not be empty', ''));
  431. }
  432. // 处理时间显示
  433. if ($row->start_time) {
  434. $row->start_time = date('Y-m-d H:i:s', $row->start_time);
  435. }
  436. if ($row->end_time) {
  437. $row->end_time = date('Y-m-d H:i:s', $row->end_time);
  438. }
  439. if ($row->lottery_time) {
  440. $row->lottery_time = date('Y-m-d H:i:s', $row->lottery_time);
  441. }
  442. // 处理JSON字段
  443. if ($row->user_limit_value) {
  444. $row->user_limit_value = json_decode($row->user_limit_value, true);
  445. }
  446. // 处理渠道字段
  447. if ($row->channels) {
  448. $row->channels = json_decode($row->channels, true);
  449. }
  450. // 字段名映射 - 将数据表字段名映射回前端字段名
  451. if (isset($row->name)) {
  452. $row->title = $row->name; // 将name映射回title供前端使用
  453. }
  454. if (isset($row->lottery_people_num)) {
  455. $row->lottery_people = $row->lottery_people_num; // 映射回前端字段名
  456. }
  457. if (isset($row->person_limit_num)) {
  458. $row->per_person_limit = $row->person_limit_num; // 映射回前端字段名
  459. }
  460. // 获取奖品数据
  461. $prizes = Db::name('shop_lottery_prize')
  462. ->where('activity_id', $ids)
  463. ->order('sort_order', 'asc')
  464. ->select();
  465. // 处理奖品数据的字段映射
  466. foreach ($prizes as &$prize) {
  467. // 将数据表字段映射回前端字段
  468. $prize['quantity'] = $prize['total_stock']; // 前端使用quantity字段
  469. $prize['rate'] = $prize['probability']; // 前端使用rate字段
  470. // 根据奖品类型设置特定字段
  471. switch (intval($prize['type'])) {
  472. case ActivityEnum::PRIZE_TYPE_POINTS:
  473. $prize['points'] = $prize['amount'] ?? 0;
  474. break;
  475. case ActivityEnum::PRIZE_TYPE_BALANCE:
  476. $prize['balance'] = $prize['amount'] ?? 0;
  477. break;
  478. case ActivityEnum::PRIZE_TYPE_REDPACK:
  479. $prize['redpack_amount'] = $prize['amount'] ?? 0;
  480. break;
  481. case ActivityEnum::PRIZE_TYPE_CODE:
  482. if (!empty($prize['exchange_codes'])) {
  483. $codes = json_decode($prize['exchange_codes'], true) ?: [];
  484. $prize['manual_codes'] = implode("\n", $codes);
  485. }
  486. break;
  487. }
  488. }
  489. // 获取条件数据
  490. $conditions = Db::name('shop_lottery_condition')
  491. ->where('activity_id', $ids)
  492. ->select();
  493. // 处理条件数据的字段映射
  494. $taskTypes = [];
  495. $conditionsData = [];
  496. foreach ($conditions as $condition) {
  497. $taskTypes[] = $condition['type'];
  498. $conditionsData[$condition['type']] = $condition;
  499. // 处理商品IDs JSON
  500. if (!empty($condition['goods_ids'])) {
  501. $conditionsData[$condition['type']]['goods_ids_array'] = json_decode($condition['goods_ids'], true) ?: [];
  502. }
  503. }
  504. $this->view->assign("row", $row);
  505. $this->view->assign("prizes", $prizes);
  506. $this->view->assign("conditions", $conditions);
  507. $this->view->assign("conditionsData", $conditionsData);
  508. $this->view->assign("taskTypes", $taskTypes);
  509. return $this->view->fetch();
  510. }
  511. /**
  512. * 奖品管理
  513. */
  514. public function prize($ids = null)
  515. {
  516. $activity = $this->model->get($ids);
  517. if (!$activity) {
  518. $this->error(__('No Results were found'));
  519. }
  520. $this->view->assign("activity", $activity);
  521. return $this->view->fetch();
  522. }
  523. /**
  524. * 参与条件管理
  525. */
  526. public function condition($ids = null)
  527. {
  528. $activity = $this->model->get($ids);
  529. if (!$activity) {
  530. $this->error(__('No Results were found'));
  531. }
  532. $this->view->assign("activity", $activity);
  533. return $this->view->fetch();
  534. }
  535. /**
  536. * 抽奖记录
  537. */
  538. public function records($ids = null)
  539. {
  540. $activity = $this->model->get($ids);
  541. if (!$activity) {
  542. $this->error(__('No Results were found'));
  543. }
  544. $this->view->assign("activity", $activity);
  545. return $this->view->fetch();
  546. }
  547. /**
  548. * 统计数据
  549. */
  550. public function statistics($ids = null)
  551. {
  552. $activity = $this->model->get($ids);
  553. if (!$activity) {
  554. $this->error(__('No Results were found'));
  555. }
  556. // 获取统计数据
  557. $statisticsModel = new \app\admin\model\lottery\Statistics;
  558. $statistics = $statisticsModel->where('activity_id', $ids)->order('stat_date', 'desc')->paginate(15);
  559. $this->view->assign("activity", $activity);
  560. $this->view->assign("statistics", $statistics);
  561. return $this->view->fetch();
  562. }
  563. }