'充值单号', 'nickname' => '用户昵称', 'order_amount' => '充值金额', 'give_money' => '赠送余额', 'pay_way' => '支付方式', 'pay_time' => '支付时间', 'pay_status' => '订单状态', 'create_time' => '下单时间', ]; } /** * @notes 导出表名 * @return string * @author Tab * @date 2021/9/22 18:20 */ public function setFileName(): string { return '充值记录'; } /** * @notes 设置搜索 * @return \string[][] * @author Tab * @date 2021/8/11 16:09 */ public function setSearch(): array { return [ '=' => ['ro.sn', 'u.mobile', 'ro.pay_way', 'ro.pay_status'], '%like%' => ['u.nickname'] ]; } /** * @notes 附加搜索条件 * @author Tab * @date 2021/8/11 16:11 */ public function attachWhere() { // 用户编号 if(isset($this->params['user_sn']) && !empty($this->params['user_sn'])) { $this->searchWhere[] = ['u.sn', '=', $this->params['user_sn']]; } // 支付时间 if(isset($this->params['type_time']) && $this->params['type_time'] == 1 && isset($this->params['start_time']) && isset($this->params['end_time'])) { $this->searchWhere[] = ['ro.pay_time', 'between', [$this->startTime, $this->endTime]]; } // 下单时间 if(isset($this->params['type_time']) && $this->params['type_time'] == 2 && isset($this->params['start_time']) && isset($this->params['end_time'])) { $this->searchWhere[] = ['ro.create_time', 'between', [$this->startTime, $this->endTime]]; } } /** * @notes 充值记录列表 * @return array * @author Tab * @date 2021/8/11 16:30 */ public function lists(): array { // 附加搜索 $this->attachWhere(); $field = 'ro.sn,ro.order_amount,ro.pay_way,ro.pay_time,ro.pay_status,ro.create_time,ro.award'; $field .= ',u.avatar,u.nickname'; $lists = RechargeOrder::alias('ro') ->leftJoin('user u', 'u.id = ro.user_id') ->field($field) ->where($this->searchWhere) ->order('ro.id', 'desc') ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); foreach($lists as &$item) { $item['avatar'] = FileService::getFileUrl($item['avatar']); $item['give_money'] = $this->giveMoney($item); $item['pay_time'] = empty($item['pay_time']) ? '' : date('Y-m-d H:i:s', $item['pay_time']) ; } return $lists; } /** * @notes 充值记录数量 * @return int * @author Tab * @date 2021/8/11 16:30 */ public function count(): int { // 附加搜索 $this->attachWhere(); $count = RechargeOrder::alias('ro') ->leftJoin('user u', 'u.id = ro.user_id') ->where($this->searchWhere) ->count(); return $count; } /** * @notes 充值赠送金额 * @param $item * @return int|mixed|string * @author Tab * @date 2021/8/11 15:49 */ public function giveMoney($item) { if(!isset($item['award']) || empty($item['award'])) { return 0; } foreach($item['award'] as $subItem) { if(isset($subItem['give_money'])) { return clear_zero($subItem['give_money']); } } return 0; } }