123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\admin\controller\lottery;
- use app\common\controller\Backend;
- /**
- * 抽奖记录管理
- *
- * @icon fa fa-list
- */
- class DrawRecord extends Backend
- {
- /**
- * DrawRecord模型对象
- * @var \app\admin\model\lottery\DrawRecord
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\lottery\DrawRecord;
-
- // 获取枚举值列表
- $this->view->assign("triggerTypeList", $this->model->getTriggerTypeList());
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
- $list = $this->model
- ->with(['activity', 'user', 'prize'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
- $row->visible(['id','activity_id','user_id','prize_id','is_win','trigger_type','trigger_amount','draw_time','createtime']);
- $row->visible(['activity', 'user', 'prize']);
-
- // 处理关联数据(belongsTo关系)
- if ($row->getRelation('activity')) {
- $row->getRelation('activity')->visible(['name']);
- }
- if ($row->getRelation('user')) {
- $row->getRelation('user')->visible(['nickname']);
- }
- if ($row->getRelation('prize')) {
- $row->getRelation('prize')->visible(['name', 'type']);
- }
- }
-
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 详情
- */
- public function detail($ids = null)
- {
- $row = $this->model->with(['activity', 'user', 'prize', 'winRecord'])->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
-
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * 导出记录
- */
- public function export()
- {
- // 获取导出参数
- $filter = $this->request->get('filter', '');
- $where = [];
- if ($filter) {
- $where = json_decode($filter, true);
- }
-
- $list = $this->model->with(['activity', 'user', 'prize'])
- ->where($where)
- ->order('createtime', 'desc')
- ->select();
-
- $header = ['ID', '活动名称', '用户昵称', '奖品名称', '是否中奖', '触发类型', '触发金额', '抽奖时间'];
- $data = [];
-
- foreach ($list as $item) {
- $data[] = [
- $item->id,
- $item->activity->name ?? '',
- $item->user->nickname ?? '',
- $item->prize->name ?? '',
- $item->is_win ? '是' : '否',
- $item->trigger_type_text,
- $item->trigger_amount,
- date('Y-m-d H:i:s', $item->draw_time)
- ];
- }
-
- // 这里可以集成Excel导出功能
- $this->success('导出成功', '', $data);
- }
- }
|