leftJoin('user u', 'u.id = ua.user_id') ->order('ua.id', 'desc') ->page($get['page'], $get['limit']) ->field('ua.*,u.nickname') ->select() ->toArray(); return ['count' => $count, 'lists' => $lists]; } public static function add($post) { try{ if (empty($post['user_id']) || empty($post['app_id']) || empty($post['app_secret'])) { throw new \Exception('参数错误'); } $userLevel = UserApi::where(['app_id'=>trim($post['app_id'])])->findOrEmpty(); if(!$userLevel->isEmpty()) { throw new \Exception('APP_ID已被使用,请更换后重试'); } $data = [ 'user_id' => trim($post['user_id']), 'app_id' => trim($post['app_id']), 'app_secret' => trim($post['app_secret']), 'remarks' => trim($post['remarks']), 'status' => 1, ]; UserApi::create($data); User::where('id', $post['user_id'])->save([ 'is_api' => 1 ]); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function edit($post) { try{ $userLevel = UserApi::where([ ['app_id', '=', trim($post['app_id'])], ['id', '<>', $post['id']] ])->findOrEmpty(); if(!$userLevel->isEmpty()) { throw new \think\Exception('名称已被使用,请更换后重试'); } $data = [ 'id' => $post['id'], 'user_id' => trim($post['user_id']), 'app_id' => trim($post['app_id']), 'app_secret' => trim($post['app_secret']), 'remarks' => trim($post['remarks']), ]; UserApi::update($data); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function del($id) { try{ UserApi::where('id', $id)->delete(); return true; }catch(\Exception $e) { self::$error = $e->getMessage(); return false; } } public static function getUserApiList() { $levelArr = UserApi::field('id,name,phone') ->order('id desc') ->select() ->toArray(); return $levelArr; } public static function getUserApi($id){ $detail = UserApi::alias('ua')->leftJoin('user u', 'u.id=ua.user_id')->field('ua.*,u.nickname,u.mobile')->where(['ua.id'=>$id])->findOrEmpty(); if($detail->isEmpty()) { return []; } $detail = $detail->toArray(); return $detail; } }