user_id = $user_id; } public function headings(): array { return [ '邀请人ID', '被邀请人ID', '姓名', '电话', '类型', '是否认证', '收益金额', ]; } //设置列格式 public function columnFormats(): array { return [ 'A' => NumberFormat::FORMAT_TEXT, ]; } public function collection() { $data = ReferreAwardHistory::where('user_id', $this->user_id)->distinct('other_user_id')->select('user_id','other_user_id')->get()->toArray(); foreach ($data as $k => $v) { $user = User::withTrashed()->where('id', $v['other_user_id'])->first(); $amount = ReferreAwardHistory::where('user_id', $this->user_id)->where('other_user_id', $v['other_user_id'])->where('is_hooked', 1)->sum('amount'); if (empty($user)) { $data[$k]['name'] = '未知'; //行业 $data[$k]['mobile'] = '未知'; //子行业 $data[$k]['type'] = '未知'; //团契 $data[$k]['is_approved'] = '未知'; }else{ $data[$k]['name'] = $user->name; $data[$k]['mobile'] = $user->mobile; $data[$k]['type'] = $user->type=='single'?'单身':'介绍人'; $data[$k]['is_approved'] = $user->is_approved?'是':'否'; } $data[$k]['amount'] = $amount; } return $data; } }