['store_id','user_ship','is_disable'], '%like%' => ['account','mobile'], '%pipe_like%' => ['nickname'=>'nickname|real_name'], ]; } /** * @notes 获取用户列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 乔峰 * @date 2022/9/22 15:50 */ public function lists(): array { $field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time,purchase_funds,user_ship, label_id,integral,now_money,total_recharge_amount,vip_time,store_id"; $lists = User::where($this->searchWhere) ->with(['user_ship','user_label']) ->limit($this->limitOffset, $this->limitLength) ->field($field) ->order('id desc') ->select() ->each(function($data){ $data['sex_text'] = $data->sex_text; })->toArray(); foreach ($lists as &$item) { $item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']); $item['user_address'] = UserAddress::where([ 'uid'=>$item['id'],'is_default'=>YesNoEnum::YES ])->value('detail'); if($item['vip_name']== null){ $item['vip_name'] = '普通会员'; } if($item['vip_time']!= null){ $item['vip_time'] = date('Y-m-d H:i:s', $item['vip_time']); } if($item['label_name']== null){ $item['label_name'] = '无'; } $item['store_name']=''; if($item['store_id']>0){ $item['store_name'] = SystemStore::where('id',$item['store_id'])->value('name'); } $item['return_money'] = VipFlow:: where(['user_id'=>$item['id'],'status'=>0]) ->sum('number')??0; $address = UserAddress::where('uid',$item['id'])->find(); $item['city'] = ''; $item['area'] = ''; $item['street'] = ''; $item['village'] = ''; $item['brigade'] = ''; if($address){ if($address['city']){ $item['city'] = \think\facade\Db::name('geo_city')->where('city_code',$address['city'])->value('city_name')??''; } if($address['area']){ $item['area'] = \think\facade\Db::name('geo_area')->where('area_code',$address['area'])->value('area_name')??''; } if($address['street']){ $item['street'] = \think\facade\Db::name('geo_street')->where('street_code',$address['street'])->value('street_name')??''; } if($address['village']){ $item['village'] = \think\facade\Db::name('geo_village')->where('village_code',$address['village'])->value('village_name')??''; } if($address['brigade']){ $item['brigade'] = $address['brigade'] ? $address['brigade'].'队':''; } } $item['format_address'] = $item['city'].'/'.$item['area'].'/'.$item['street'].'/'.$item['village'].'/'. $item['brigade']; } return $lists; } /** * @notes 获取数量 * @return int * @author 乔峰 * @date 2022/9/22 15:51 */ public function count(): int { return User::where($this->searchWhere)->count(); } /** * @notes 导出文件名 * @return string * @author 乔峰 * @date 2022/11/24 16:17 */ public function setFileName(): string { return '用户列表'; } /** * @notes 导出字段 * @return string[] * @author 乔峰 * @date 2022/11/24 16:17 */ public function setExcelFields(): array { return [ 'nickname' => '用户昵称', 'real_name' => '真实姓名', 'account' => '账号', 'mobile' => '手机号码', 'now_money' => '用户余额', 'integral' => '礼品券', 'vip_name' => '会员类型', 'store_name' => '门店', 'total_recharge_amount' => '累计消费', 'purchase_funds' => '采购款', 'format_address'=>'地址', 'vip_time'=>'开通时间' ]; } }