'int', 'platform_id' => 'int', 'language_id' => 'int', 'site_id' => 'int', 'country_id' => 'int', 'province_id' => 'int', 'city_id' => 'int', 'from' => 'string', 'area' => 'string', 'phone' => 'string', 'name' => 'string', 'email' => 'string', 'wechat' => 'string', 'qq' => 'string', 'desc' => 'string', 'sort' => 'int', 'is_open' => 'int', 'create_time' => 'int', 'update_time' => 'int' ]; /** * 查看列表数据 * @param int $page 分页页码 * @param int $pageSize 分页类目数量 * @param array $field 需要输入的字段,默认为全部输出,筛选表字段 * @param array $vague 需要进行模糊查询的字段,如: a like %a% * @param array $focus 精确搜索条件,如a=1,b=2这种精确等于某个值的 * @param array $order 排序字段,如:['id'=>'desc','sort'=>'desc'] * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getIndexList(int $page,int $pageSize,array $field = [], array $vague = [],array $focus = [],array $order = []):array { $fields = array_keys($this->schema); $collection = $this->field($field)->where(function ($query) use ($fields,$focus) { //精准查询 if (!empty($focus)) { foreach ($focus as $key => $item) { if (in_array($key,$fields)) { $query->where($key,$item); } } } })->where(function($query) use ($fields,$vague) { //模糊查询 if (!empty($vague)) { $query->whereOr('phone','like',"%".$vague['keyword']."%"); $query->whereOr('name','like',"%".$vague['keyword']."%"); $query->whereOr('wechat','like',"%".$vague['keyword']."%"); $query->whereOr('qq','like',"%".$vague['keyword']."%"); $query->whereOr('email','like',"%".$vague['keyword']."%"); } })->order($order); //判断是否需要分页 if (0 == $page || 0 == $pageSize) { //不需要分页 return $collection->select()->toArray(); } else { //需要分布 $totalNum = $collection->count(); $data = $collection->page($page)->limit($pageSize)->select()->toArray();; return ['count'=>$totalNum,'data'=>$data]; } } /** * 通过ID获取数据 * @param $ids * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getExportData($ids): array { $result = $this->whereIn($this->pk,$ids['ids'])->order('create_time','desc')->select()->toArray(); foreach ($result as &$item){ $item['platform_id'] = $this->getPlatformName($item['platform_id']); $item['language_id'] = $item['site_id'] = $this->getLanguageName($item['site_id']); $item['country_id'] = '中国'; $item['province_id'] = $this->getAreaNameById($item['province_id']); $item['city_id'] = $this->getAreaNameById($item['city_id']); $item['is_open'] = $item['is_open'] == 0 ? '同意同类厂家查看,以便获得更多产品代理机会' : '同意意向厂家查看'; unset($item['area']); unset($item['qq']); unset($item['sort']); unset($item['update_time']); unset($item['email']); } return $result; } }