fileName = '卡券记录' . date('YmdHis') . '.xlsx'; $this->user = $user; if (!empty($serchDatas)) { foreach ($serchDatas as $key => $data) { if ($key == 'start') { $data = $data . ' 00:00:01'; } if ($key == 'end') { $data = $data . ' 23:59:59'; } if ($data) { $this->$key = $data; } } } } public function headings(): array { return ['ID', '网点名称', '平安券编号', '优惠政策', '核销金额', '状态', '处理结果', '核销时间']; } /** * @inheritDoc */ public function query() { return Coupon::where('user_id', $this->user->id) ->when($this->outlet, function ($q) { $q->whereHas('outlet', function ($q) { $q->whereHas('info', function ($q) { $q->where('nickname', 'like', "%{$this->outlet}%"); }); }); }) ->when($this->redemptionCode, function ($q) { $q->where('redemptionCode', $this->redemptionCode); }) ->when($this->thirdPartyGoodsId, function ($q) { $q->where('thirdPartyGoodsId', $this->thirdPartyGoodsId); }) ->when(is_numeric($this->status), function ($query) { if ($this->status == 4) { $query->where('is_profit', 1); } else { $query->where('status', $this->status); } }) ->when($this->start && $this->end, function ($query) { $query->whereBetween('created_at', [$this->start, $this->end]); }) ->when($this->start, function ($query) { $query->where('created_at', '>', $this->start); }) ->when($this->end, function ($query) { $query->where('created_at', '<', $this->end); }) ->whereIn('status', [2, 3]) ->orderBy('created_at', 'desc'); } public function map($info): array { $data = [ $info->id, $info->outlet ? $info->outlet->nickname : 'Id:' . $info->outletId, ' ' . $info->redemptionCode, ' ' . $info->couponName, $info->price, $info->status_text, $info->remark, $info->created_at, ]; return $data; } }