'用户编号', 'nickname' => '用户昵称', 'level_name' => '用户等级', 'mobile' => '手机号码', 'user_money' => '钱包金额', 'total_order_amount' => '消费金额', 'login_time' => '最近登录时间', 'create_time' => '注册时间', ]; } /** * @notes 设置搜索 * @return \string[][] * @author Tab * @date 2021/9/22 17:48 */ public function setSearch(): array { return [ '%like%' => ['sn', 'nickname'] ]; } /** * @notes 附加搜索 * @author Tab * @date 2021/9/22 18:15 */ public function attachSearch() { $this->searchWhere[] = ['inviter_id', '=', $this->params['user_id']]; } /** * @notes 列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Tab * @date 2021/9/14 10:08 */ public function lists(): array { $this->attachSearch(); $field = [ 'sn', 'nickname', 'avatar', 'level', 'mobile', 'user_money', 'total_order_amount', 'login_time', 'create_time', ]; $lists = User::field($field) ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); foreach($lists as &$item) { $item['level_name'] = UserLevel::getLevelName($item['level']); } return $lists; } /** * @notes 记录数 * @return int * @author Tab * @date 2021/9/14 10:07 */ public function count(): int { $this->attachSearch(); $field = [ 'sn', 'nickname', 'avatar', 'level', 'mobile', 'user_money', 'total_order_amount', 'login_time', 'create_time', ]; $count = User::field($field) ->where($this->searchWhere) ->count(); return $count; } }