'优惠券ID', 'sn' => '优惠券编号', 'name' => '优惠券名称', 'discount_content' => '优惠券内容', 'get_method' => '推广方式', 'use_time_text' => '用卷时间', 'send_total_text' => '发放总量', 'receive_number' => '已领取', 'surplus_number' => '剩余', 'use_number' => '已使用', 'status_text' => '优惠券状态', 'create_time' => '创建时间' ]; } /** * @notes 设置导出文件名 * @return string * @author 张无忌 * @date 2021/7/31 16:28 */ public function setFileName(): string { return '优惠券列表'; } /** * @notes 优惠券搜索条件 * @return array * @author 张无忌 * @date 2021/7/29 18:07 */ public function setSearch(): array { return [ '=' => ['status', 'get_type'], '%like%' => ['name'], "between_time" => 'create_time' ]; } /** * @notes 优惠券扩展统计 * @return mixed * @author 张无忌 * @date 2021/7/29 18:07 */ public function extend() { $searchwhere = $this->searchWhere; foreach ($searchwhere as $key => $value) { if ($value[0] == 'status') { unset($searchwhere[$key]); } } $searchwhere = array_values($searchwhere); $model = new Coupon(); $detail['all'] = $model->where($searchwhere)->count(); $detail['not'] = $model->where($searchwhere) ->where(['status' => CouponEnum::COUPON_STATUS_NOT])->count(); $detail['conduct'] = $model->where($searchwhere) ->where(['status' => CouponEnum::COUPON_STATUS_CONDUCT])->count(); $detail['end'] = $model->where($searchwhere) ->where(['status' => CouponEnum::COUPON_STATUS_END])->count(); return $detail; } /** * @notes 获取优惠券列表 * @return array * @throws @\think\db\exception\DataNotFoundException * @throws @\think\db\exception\DbException * @throws @\think\db\exception\ModelNotFoundException * @author 张无忌 * @date 2021/7/29 18:07 */ public function lists(): array { $lists = (new Coupon())->withoutField('update_time,delete_time') ->where($this->searchWhere) ->append([ 'discount_content', 'use_time_type', 'use_time_text', 'status_text', 'use_number', 'receive_number', 'surplus_number', 'send_total_text' ]) ->limit($this->limitOffset, $this->limitLength) ->order('id desc') ->select() ->toArray(); foreach ($lists as &$item) { $item['get_method'] = CouponEnum::getTypeDesc($item['get_type']); unset($item['condition_type']); unset($item['condition_money']); unset($item['send_total_type']); unset($item['send_total']); unset($item['use_time_type']); unset($item['use_time_start']); unset($item['use_time_end']); unset($item['use_time']); unset($item['get_num_type']); unset($item['get_num']); unset($item['use_goods_type']); unset($item['use_goods_ids']); } return $lists; } /** * @notes 获取优惠券数量统计 * @return int * @author 张无忌 * @date 2021/7/29 18:07 */ public function count(): int { return (new Coupon())->where($this->searchWhere)->count(); } }