正在显示
5 个修改的文件
包含
170 行增加
和
121 行删除
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Controllers\Bside\ProjectAssociation; | 3 | +namespace App\Http\Controllers\Aside\ProjectAssociation; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Exceptions\BsideGlobalException; | 6 | use App\Exceptions\BsideGlobalException; |
| 7 | use App\Http\Controllers\Bside\BaseController; | 7 | use App\Http\Controllers\Bside\BaseController; |
| 8 | -use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic; | ||
| 9 | use App\Models\ProjectAssociation\ProjectAssociation; | 8 | use App\Models\ProjectAssociation\ProjectAssociation; |
| 10 | -use Illuminate\Http\Request; | ||
| 11 | -use Illuminate\Support\Facades\DB; | ||
| 12 | -use Psr\Container\ContainerExceptionInterface; | ||
| 13 | -use Psr\Container\NotFoundExceptionInterface; | 9 | +use App\Services\Aside\ProjectAssociation\ProjectAssociationServices; |
| 14 | 10 | ||
| 15 | class ProjectAssociationController extends BaseController | 11 | class ProjectAssociationController extends BaseController |
| 16 | { | 12 | { |
| 17 | - private $ProjectAssociationLogic; | ||
| 18 | - | ||
| 19 | - public function __construct(Request $request) | ||
| 20 | - { | ||
| 21 | - $this->ProjectAssociationLogic = new ProjectAssociationLogic(); | ||
| 22 | - parent::__construct($request); | ||
| 23 | - } | ||
| 24 | 13 | ||
| 25 | /** | 14 | /** |
| 26 | * V6与AICC数据关联 | 15 | * V6与AICC数据关联 |
| 27 | * @return void | 16 | * @return void |
| 28 | * @throws BsideGlobalException | 17 | * @throws BsideGlobalException |
| 29 | */ | 18 | */ |
| 30 | - public function saveWeChatData() | 19 | + public function save() |
| 31 | { | 20 | { |
| 32 | $project_id = (int)request()->post('project_id', 0); | 21 | $project_id = (int)request()->post('project_id', 0); |
| 33 | if (empty($project_id)) { | 22 | if (empty($project_id)) { |
| 34 | - $this->fail('请选择项目!', Code::USER_PARAMS_ERROE); | 23 | + $this->response('请选择项目!', Code::USER_PARAMS_ERROE); |
| 35 | } | 24 | } |
| 36 | $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用 | 25 | $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用 |
| 37 | 26 | ||
| 38 | $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0; | 27 | $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0; |
| 39 | if (empty($user_id) && $status) { | 28 | if (empty($user_id) && $status) { |
| 40 | - $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE); | 29 | + $this->response('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE); |
| 41 | } | 30 | } |
| 42 | $friend_id = (int)request()->post('friend_id', 0); | 31 | $friend_id = (int)request()->post('friend_id', 0); |
| 43 | if (empty($friend_id) && $status) { | 32 | if (empty($friend_id) && $status) { |
| 44 | - $this->fail('请选择要绑定的AICC用户列表!', Code::USER_PARAMS_ERROE); | 33 | + $this->response('请选择要绑定的AICC用户列表!', Code::USER_PARAMS_ERROE); |
| 45 | } | 34 | } |
| 35 | + $app = (int)request()->post('app', ProjectAssociation::ENTERPRISE_WECHAT); | ||
| 36 | + $app = ProjectAssociation::getApplicationID($app); | ||
| 46 | $nickname = request()->post('nickname', ''); | 37 | $nickname = request()->post('nickname', ''); |
| 47 | $user_name = request()->post('user_name', ''); | 38 | $user_name = request()->post('user_name', ''); |
| 48 | $image = request()->post('image', ''); | 39 | $image = request()->post('image', ''); |
| 49 | - $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image'); | ||
| 50 | - $this->ProjectAssociationLogic->saveWeChatData($data); | 40 | + $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image', 'app'); |
| 41 | + ProjectAssociationServices::getInstance()->save($data); | ||
| 51 | $this->response('绑定成功'); | 42 | $this->response('绑定成功'); |
| 52 | } | 43 | } |
| 53 | 44 | ||
| @@ -58,27 +49,34 @@ class ProjectAssociationController extends BaseController | @@ -58,27 +49,34 @@ class ProjectAssociationController extends BaseController | ||
| 58 | public function check() | 49 | public function check() |
| 59 | { | 50 | { |
| 60 | $project_id = (int)request()->input('project_id', 0); | 51 | $project_id = (int)request()->input('project_id', 0); |
| 61 | - $status = request()->input('status'); | 52 | + if (empty($project_id)) { |
| 53 | + $this->response('请输入项目信息!', Code::SERVER_ERROR); | ||
| 54 | + } | ||
| 55 | + // 项目绑定状态 | ||
| 56 | + $app = (int)request()->input('type', ProjectAssociation::ENTERPRISE_WECHAT); | ||
| 57 | + $app = ProjectAssociation::getApplicationID($app); | ||
| 58 | + $status = request()->input('status'); | ||
| 62 | // 重载redis缓存 | 59 | // 重载redis缓存 |
| 63 | $cache = request()->input('cache'); | 60 | $cache = request()->input('cache'); |
| 64 | if (isset($status)) { | 61 | if (isset($status)) { |
| 65 | $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED; | 62 | $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED; |
| 66 | } | 63 | } |
| 67 | - $isRes = $this->ProjectAssociationLogic->normal($project_id); | 64 | + $isRes = ProjectAssociationServices::getInstance()->normal($project_id, $app); |
| 68 | // 当数据不存在时并开启状态,自动添加一条数据 | 65 | // 当数据不存在时并开启状态,自动添加一条数据 |
| 69 | if (is_null($isRes) && (!is_null($status) && $status)) { | 66 | if (is_null($isRes) && (!is_null($status) && $status)) { |
| 70 | - $isRes = $this->ProjectAssociationLogic->saveProject($project_id, $status); | ||
| 71 | - if (is_null($isRes)) { | 67 | + $value = ProjectAssociationServices::getInstance()->saveProject($project_id, $status, $app); |
| 68 | + if (empty($value['bool'])) { | ||
| 72 | // 保存数据失败 | 69 | // 保存数据失败 |
| 73 | $this->response('绑定AICC数据失败!', Code::SERVER_ERROR); | 70 | $this->response('绑定AICC数据失败!', Code::SERVER_ERROR); |
| 74 | } | 71 | } |
| 72 | + $isRes = $value['isRes']; | ||
| 75 | } // 关闭状态 | 73 | } // 关闭状态 |
| 76 | elseif (!is_null($isRes) && (!is_null($status) && empty($status))) { | 74 | elseif (!is_null($isRes) && (!is_null($status) && empty($status))) { |
| 77 | - $bool = $this->ProjectAssociationLogic->closedState($isRes, $status); | 75 | + $bool = ProjectAssociationServices::getInstance()->closedState($isRes, $status); |
| 78 | if ($bool) { | 76 | if ($bool) { |
| 79 | // 关闭aicc绑定成功 | 77 | // 关闭aicc绑定成功 |
| 80 | $this->response('关闭aicc绑定 - 成功!'); | 78 | $this->response('关闭aicc绑定 - 成功!'); |
| 81 | - }else{ | 79 | + } else { |
| 82 | // 关闭aicc绑定失败 | 80 | // 关闭aicc绑定失败 |
| 83 | $this->response('关闭aicc绑定 - 失败!'); | 81 | $this->response('关闭aicc绑定 - 失败!'); |
| 84 | } | 82 | } |
| @@ -88,7 +86,7 @@ class ProjectAssociationController extends BaseController | @@ -88,7 +86,7 @@ class ProjectAssociationController extends BaseController | ||
| 88 | $this->response('success', Code::SERVER_ERROR); | 86 | $this->response('success', Code::SERVER_ERROR); |
| 89 | } | 87 | } |
| 90 | $cache = isset($cache); | 88 | $cache = isset($cache); |
| 91 | - $result = $this->ProjectAssociationLogic->getAiccWechatLists($isRes, $cache); | 89 | + $result = ProjectAssociationServices::getInstance()->getAiccWechatLists($isRes, $app, $cache); |
| 92 | $this->response('success', Code::SUCCESS, $result); | 90 | $this->response('success', Code::SUCCESS, $result); |
| 93 | } | 91 | } |
| 94 | } | 92 | } |
| @@ -5,6 +5,7 @@ namespace App\Models\ProjectAssociation; | @@ -5,6 +5,7 @@ namespace App\Models\ProjectAssociation; | ||
| 5 | use Illuminate\Database\Eloquent\Builder; | 5 | use Illuminate\Database\Eloquent\Builder; |
| 6 | use Illuminate\Database\Eloquent\Model; | 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | 7 | ||
| 8 | + | ||
| 8 | /** | 9 | /** |
| 9 | * App\Models\ProjectAssociation\ProjectAssociation | 10 | * App\Models\ProjectAssociation\ProjectAssociation |
| 10 | * | 11 | * |
| @@ -17,11 +18,13 @@ use Illuminate\Database\Eloquent\Model; | @@ -17,11 +18,13 @@ use Illuminate\Database\Eloquent\Model; | ||
| 17 | * @property string|null $image AICC朋友头像 | 18 | * @property string|null $image AICC朋友头像 |
| 18 | * @property int|null $status 1 - 正常, 0 - 禁用 | 19 | * @property int|null $status 1 - 正常, 0 - 禁用 |
| 19 | * @property int|null $m_status 统计当月是否生成数据 | 20 | * @property int|null $m_status 统计当月是否生成数据 |
| 21 | + * @property int|null $binding_app 1 - 企业微信 2 - 个人微信 | ||
| 20 | * @property \Illuminate\Support\Carbon|null $created_at | 22 | * @property \Illuminate\Support\Carbon|null $created_at |
| 21 | * @property \Illuminate\Support\Carbon|null $updated_at | 23 | * @property \Illuminate\Support\Carbon|null $updated_at |
| 22 | * @method Builder|ProjectAssociation newModelQuery() | 24 | * @method Builder|ProjectAssociation newModelQuery() |
| 23 | * @method Builder|ProjectAssociation newQuery() | 25 | * @method Builder|ProjectAssociation newQuery() |
| 24 | * @method static Builder|ProjectAssociation query() | 26 | * @method static Builder|ProjectAssociation query() |
| 27 | + * @method Builder|ProjectAssociation whereBindingApp($value) | ||
| 25 | * @method Builder|ProjectAssociation whereCreatedAt($value) | 28 | * @method Builder|ProjectAssociation whereCreatedAt($value) |
| 26 | * @method Builder|ProjectAssociation whereFriendId($value) | 29 | * @method Builder|ProjectAssociation whereFriendId($value) |
| 27 | * @method Builder|ProjectAssociation whereId($value) | 30 | * @method Builder|ProjectAssociation whereId($value) |
| @@ -46,60 +49,30 @@ class ProjectAssociation extends Model | @@ -46,60 +49,30 @@ class ProjectAssociation extends Model | ||
| 46 | /** @var int 数据状态 - 禁用 */ | 49 | /** @var int 数据状态 - 禁用 */ |
| 47 | const STATUS_DISABLED = 0; | 50 | const STATUS_DISABLED = 0; |
| 48 | 51 | ||
| 49 | - /** | ||
| 50 | - * 保存|修改数据 | ||
| 51 | - * @param array $data | ||
| 52 | - * @return bool | ||
| 53 | - */ | ||
| 54 | - public function saveData(array $data): bool | ||
| 55 | - { | ||
| 56 | - # V6项目ID | ||
| 57 | - $project_id = (int)$data['project_id'] ?? 0; | ||
| 58 | - $isRes = self::query()->where('project_id', $project_id)->first(); | ||
| 59 | - if (!$isRes) { | ||
| 60 | - $isRes = new self(); | ||
| 61 | - $isRes->project_id = $project_id; | ||
| 62 | - } | ||
| 63 | - # AICC朋友ID | ||
| 64 | - $isRes->friend_id = $data['friend_id'] ?? 0; | ||
| 65 | - # AICC朋友昵称 | ||
| 66 | - $isRes->nickname = $data['nickname'] ?? 0; | ||
| 67 | - # AICC用户ID | ||
| 68 | - $isRes->user_id = $data['user_id'] ?? 0; | ||
| 69 | - # AICC用户姓名 | ||
| 70 | - $isRes->user_name = $data['user_name'] ?? ''; | ||
| 71 | - # AICC朋友头像 | ||
| 72 | - $isRes->image = $data['image'] ?? ''; | ||
| 73 | - return $isRes->save(); | ||
| 74 | - } | 52 | + /** @var int 企业微信 */ |
| 53 | + const ENTERPRISE_WECHAT = 1; | ||
| 75 | 54 | ||
| 76 | - /** | ||
| 77 | - * 检查项目是否存在 | ||
| 78 | - * @param $project_id | ||
| 79 | - * @return Builder|Model|object|null | ||
| 80 | - */ | ||
| 81 | - public function check($project_id) | 55 | + /** @var int 个人微信 */ |
| 56 | + const PERSONAL_WECHAT = 2; | ||
| 57 | + | ||
| 58 | + public static function getApplicationApiUrl($app) | ||
| 82 | { | 59 | { |
| 83 | - return self::query()->where('project_id', $project_id)->first(); | 60 | + return [ |
| 61 | + 1 => env('AICC_ENTERPRISE_WECHAT_FRIEND_API_URL'), | ||
| 62 | + 2 => env('AICC_WECHAT_FRIEND_API_URL'), | ||
| 63 | + ][$app]; | ||
| 84 | } | 64 | } |
| 85 | 65 | ||
| 86 | /** | 66 | /** |
| 87 | - * @param int $page | ||
| 88 | - * @param int $perPage | ||
| 89 | - * @return array | 67 | + * 返回绑定的APP应用类型 |
| 68 | + * @param $app | ||
| 69 | + * @return int | ||
| 90 | */ | 70 | */ |
| 91 | - public function allData(int $page = 1, int $perPage = 15) | 71 | + public static function getApplicationID($app) |
| 92 | { | 72 | { |
| 93 | - $status = 1; # 1 - 正常, 0 - 禁用 | ||
| 94 | - $lists = self::query()->where('status', $status) | ||
| 95 | - ->where('project_id', '!=', 0) | ||
| 96 | - ->where('friend_id', '!=', 0) | ||
| 97 | - ->where('user_id', '!=', 0) | ||
| 98 | - ->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page); | ||
| 99 | - $items = $lists->Items(); | ||
| 100 | - $totalPage = $lists->lastPage(); | ||
| 101 | - $total = $lists->total(); | ||
| 102 | - $currentPage = $lists->currentPage(); | ||
| 103 | - return compact('total', 'items', 'totalPage', 'currentPage'); | 73 | + return [ |
| 74 | + 1 => self::ENTERPRISE_WECHAT, | ||
| 75 | + 2 => self::PERSONAL_WECHAT, | ||
| 76 | + ][$app] ?? self::ENTERPRISE_WECHAT; | ||
| 104 | } | 77 | } |
| 105 | } | 78 | } |
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Logic\Aside\ProjectAssociation; | 3 | +namespace App\Services\Aside\ProjectAssociation; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | -use App\Http\Logic\Logic; | 6 | +use App\Exceptions\BsideGlobalException; |
| 7 | use App\Models\ProjectAssociation\ProjectAssociation; | 7 | use App\Models\ProjectAssociation\ProjectAssociation; |
| 8 | +use App\Services\BaseService; | ||
| 8 | use Illuminate\Database\Eloquent\Builder; | 9 | use Illuminate\Database\Eloquent\Builder; |
| 9 | use Illuminate\Database\Eloquent\Model; | 10 | use Illuminate\Database\Eloquent\Model; |
| 10 | use Illuminate\Support\Facades\DB; | 11 | use Illuminate\Support\Facades\DB; |
| 11 | 12 | ||
| 12 | -class ProjectAssociationLogic extends Logic | 13 | +class ProjectAssociationServices extends BaseService |
| 13 | { | 14 | { |
| 14 | - public function saveWeChatData($data) | 15 | + /** |
| 16 | + * 保存aicc与项目关系数据 | ||
| 17 | + * @param array $data | ||
| 18 | + * @return bool | ||
| 19 | + * @throws BsideGlobalException | ||
| 20 | + */ | ||
| 21 | + public function save(array $data) | ||
| 15 | { | 22 | { |
| 16 | - $wx = new ProjectAssociation(); | 23 | + $bool = false; |
| 17 | DB::beginTransaction(); | 24 | DB::beginTransaction(); |
| 18 | try { | 25 | try { |
| 19 | - $status = $wx->saveData($data); | 26 | + # V6项目ID |
| 27 | + $project_id = (int)$data['project_id'] ?? 0; | ||
| 28 | + $isRes = ProjectAssociation::query()->where('project_id', $project_id)->first(); | ||
| 29 | + if (!$isRes) { | ||
| 30 | + $isRes = new ProjectAssociation(); | ||
| 31 | + $isRes->project_id = $project_id; | ||
| 32 | + } | ||
| 33 | + # AICC朋友ID | ||
| 34 | + $isRes->friend_id = $data['friend_id'] ?? 0; | ||
| 35 | + # AICC朋友昵称 | ||
| 36 | + $isRes->nickname = $data['nickname'] ?? 0; | ||
| 37 | + # AICC用户ID | ||
| 38 | + $isRes->user_id = $data['user_id'] ?? 0; | ||
| 39 | + # AICC用户姓名 | ||
| 40 | + $isRes->user_name = $data['user_name'] ?? ''; | ||
| 41 | + # AICC朋友头像 | ||
| 42 | + $isRes->image = $data['image'] ?? ''; | ||
| 43 | + $isRes->binding_app = $data['app'] ?? 1; | ||
| 44 | + $bool = $isRes->save(); | ||
| 20 | DB::commit(); | 45 | DB::commit(); |
| 21 | } catch (\Exception $e) { | 46 | } catch (\Exception $e) { |
| 22 | DB::rollBack(); | 47 | DB::rollBack(); |
| 23 | $e->getMessage(); | 48 | $e->getMessage(); |
| 24 | - errorLog('V6与AICC关联失败', $wx, $e); | 49 | + errorLog('V6与AICC关联失败', $data, $e); |
| 25 | $this->fail('请检查操作是否正确!', Code::SERVER_MYSQL_ERROR); | 50 | $this->fail('请检查操作是否正确!', Code::SERVER_MYSQL_ERROR); |
| 26 | } | 51 | } |
| 27 | - return $status; | 52 | + return $bool; |
| 28 | } | 53 | } |
| 29 | 54 | ||
| 30 | /** | 55 | /** |
| 31 | * status - 正常 | 56 | * status - 正常 |
| 32 | * @param $project_id | 57 | * @param $project_id |
| 58 | + * @param $app | ||
| 33 | * @return ProjectAssociation|Builder|Model|object|null | 59 | * @return ProjectAssociation|Builder|Model|object|null |
| 34 | */ | 60 | */ |
| 35 | - public function normal($project_id) | 61 | + public function normal($project_id, $app) |
| 36 | { | 62 | { |
| 37 | - return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_NORMAL)->first(); | 63 | + return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_NORMAL)->whereBindingApp($app)->first(); |
| 38 | } | 64 | } |
| 39 | 65 | ||
| 40 | - | ||
| 41 | /** | 66 | /** |
| 42 | * status - 禁用 | 67 | * status - 禁用 |
| 43 | * @param $project_id | 68 | * @param $project_id |
| @@ -50,11 +75,12 @@ class ProjectAssociationLogic extends Logic | @@ -50,11 +75,12 @@ class ProjectAssociationLogic extends Logic | ||
| 50 | 75 | ||
| 51 | /** | 76 | /** |
| 52 | * 初始化数据/修改数据 | 77 | * 初始化数据/修改数据 |
| 53 | - * @param int $project_id | ||
| 54 | - * @param int $status | ||
| 55 | - * @return Builder|Model|object|ProjectAssociation|null | 78 | + * @param $project_id |
| 79 | + * @param $status | ||
| 80 | + * @param $app | ||
| 81 | + * @return array | ||
| 56 | */ | 82 | */ |
| 57 | - public function saveProject($project_id, $status) | 83 | + public function saveProject($project_id, $status, $app) |
| 58 | { | 84 | { |
| 59 | $bool = false; | 85 | $bool = false; |
| 60 | DB::beginTransaction(); | 86 | DB::beginTransaction(); |
| @@ -62,32 +88,58 @@ class ProjectAssociationLogic extends Logic | @@ -62,32 +88,58 @@ class ProjectAssociationLogic extends Logic | ||
| 62 | if (is_null($isRes)) { | 88 | if (is_null($isRes)) { |
| 63 | $isRes = new ProjectAssociation(); | 89 | $isRes = new ProjectAssociation(); |
| 64 | } | 90 | } |
| 65 | - $isRes->project_id = $project_id; | ||
| 66 | - $isRes->user_id = (int)env('AICC_WECHAT_USER_ID'); | ||
| 67 | - $isRes->status = $status; | 91 | + $isRes->project_id = $project_id; |
| 92 | + $isRes->user_id = (int)env('AICC_WECHAT_USER_ID'); | ||
| 93 | + $isRes->status = $status; | ||
| 94 | + $isRes->binding_app = $app; | ||
| 95 | + try { | ||
| 96 | + $bool = $isRes->save(); | ||
| 97 | + DB::commit(); | ||
| 98 | + } catch (\Exception $exception) { | ||
| 99 | + DB::rollBack(); | ||
| 100 | + } | ||
| 101 | + return compact('bool', 'isRes'); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * 关闭状态 | ||
| 107 | + * @param ProjectAssociation $res | ||
| 108 | + * @param int $status 1 - 正常, 0 - 禁用 | ||
| 109 | + * @return bool | ||
| 110 | + */ | ||
| 111 | + public function closedState($res, $status) | ||
| 112 | + { | ||
| 113 | + DB::beginTransaction(); | ||
| 114 | + $bool = false; | ||
| 68 | try { | 115 | try { |
| 69 | - $isRes->save(); | 116 | + $res->status = $status; |
| 117 | + $bool = $res->save(); | ||
| 70 | DB::commit(); | 118 | DB::commit(); |
| 71 | } catch (\Exception $exception) { | 119 | } catch (\Exception $exception) { |
| 72 | DB::rollBack(); | 120 | DB::rollBack(); |
| 73 | } | 121 | } |
| 74 | - return $isRes; | 122 | + return $bool; |
| 75 | } | 123 | } |
| 76 | 124 | ||
| 77 | /** | 125 | /** |
| 78 | * 获取AICC微信列表数据 | 126 | * 获取AICC微信列表数据 |
| 79 | * @param ProjectAssociation $res | 127 | * @param ProjectAssociation $res |
| 80 | - * @param bool $cache | 128 | + * @param int $type 绑定app应用类型 |
| 129 | + * @param bool $cache 是否缓存 | ||
| 81 | * @return mixed | 130 | * @return mixed |
| 82 | */ | 131 | */ |
| 83 | - public function getAiccWechatLists($res, $cache = false) | 132 | + public function getAiccWechatLists($res, $type = ProjectAssociation::PERSONAL_WECHAT, $cache = false) |
| 84 | { | 133 | { |
| 85 | - $redis_key = 'aicc_friend_lists_' . (int)env('AICC_WECHAT_USER_ID'); | 134 | + $redis_key = 'aicc_friend_lists_' . $type . '_' . (int)env('AICC_WECHAT_USER_ID'); |
| 86 | $result = $cache ? false : redis_get($redis_key); | 135 | $result = $cache ? false : redis_get($redis_key); |
| 87 | if (empty($result)) { | 136 | if (empty($result)) { |
| 88 | - $url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL'); | 137 | + $apiUrl = ProjectAssociation::getApplicationApiUrl($type); |
| 138 | + $url = env('AICC_URL') . $apiUrl; | ||
| 89 | $result = curlGet($url); | 139 | $result = curlGet($url); |
| 90 | - redis_set($redis_key, json_encode($result), 60); | 140 | + if ($result['data']) { |
| 141 | + redis_set($redis_key, json_encode($result), 60); | ||
| 142 | + } | ||
| 91 | } else { | 143 | } else { |
| 92 | $result = json_decode($result, true); | 144 | $result = json_decode($result, true); |
| 93 | } | 145 | } |
| @@ -99,24 +151,4 @@ class ProjectAssociationLogic extends Logic | @@ -99,24 +151,4 @@ class ProjectAssociationLogic extends Logic | ||
| 99 | ]; | 151 | ]; |
| 100 | return $result; | 152 | return $result; |
| 101 | } | 153 | } |
| 102 | - | ||
| 103 | - /** | ||
| 104 | - * 关闭状态 | ||
| 105 | - * @param ProjectAssociation $res | ||
| 106 | - * @param int $status 1 - 正常, 0 - 禁用 | ||
| 107 | - * @return bool | ||
| 108 | - */ | ||
| 109 | - public function closedState($res, $status) | ||
| 110 | - { | ||
| 111 | - DB::beginTransaction(); | ||
| 112 | - $bool = false; | ||
| 113 | - try { | ||
| 114 | - $res->status = $status; | ||
| 115 | - $bool = $res->save(); | ||
| 116 | - DB::commit(); | ||
| 117 | - } catch (\Exception $exception) { | ||
| 118 | - DB::rollBack(); | ||
| 119 | - } | ||
| 120 | - return $bool; | ||
| 121 | - } | ||
| 122 | } | 154 | } |
| @@ -8,10 +8,56 @@ namespace App\Services; | @@ -8,10 +8,56 @@ namespace App\Services; | ||
| 8 | 8 | ||
| 9 | use App\Enums\Common\Code; | 9 | use App\Enums\Common\Code; |
| 10 | use App\Exceptions\BsideGlobalException; | 10 | use App\Exceptions\BsideGlobalException; |
| 11 | +use Mockery; | ||
| 11 | 12 | ||
| 12 | class BaseService | 13 | class BaseService |
| 13 | { | 14 | { |
| 14 | /** | 15 | /** |
| 16 | + * 单例模式 | ||
| 17 | + * 特点:三私,两静,一公 | ||
| 18 | + * 三私:三个私有方法,(静态变量、构造函数、克隆函数) | ||
| 19 | + * 两静:两个静态方法,(一个静态变量,一个静态方法) | ||
| 20 | + * 一公:单例模式的出口 | ||
| 21 | + * | ||
| 22 | + * 优点: | ||
| 23 | + * 1、在内存里只有一个实例,减少了内存的开销,尤其是频繁的创建和销毁实例(比如管理学院首页页面缓存)。 | ||
| 24 | + * 2、避免对资源的多重占用(比如写文件操作)。 | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | + protected static $instance; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @return static | ||
| 31 | + */ | ||
| 32 | + public static function getInstance() | ||
| 33 | + { | ||
| 34 | + if ((static::$instance[static::class] ?? null) instanceof static) { | ||
| 35 | + return static::$instance[static::class]; | ||
| 36 | + } | ||
| 37 | + return static::$instance[static::class] = new static(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * @return Mockery\Mock | ||
| 42 | + */ | ||
| 43 | + public static function mockInstance() | ||
| 44 | + { | ||
| 45 | + return static::$instance[static::class] = Mockery::mock(static::class) | ||
| 46 | + ->makePartial() | ||
| 47 | + ->shouldAllowMockingProtectedMethods(); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private function __construct() | ||
| 51 | + { | ||
| 52 | + | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + private function __clone() | ||
| 56 | + { | ||
| 57 | + // TODO: Implement __clone() method. | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 15 | * @notes: 手动抛出异常 | 61 | * @notes: 手动抛出异常 |
| 16 | * @param string $msg | 62 | * @param string $msg |
| 17 | * @param string $code | 63 | * @param string $code |
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | use App\Http\Controllers\Aside; | 6 | use App\Http\Controllers\Aside; |
| 7 | -use App\Http\Controllers\Bside\ProjectAssociation\ProjectAssociationController; | 7 | +use App\Http\Controllers\Aside\ProjectAssociation\ProjectAssociationController; |
| 8 | use Illuminate\Support\Facades\Route; | 8 | use Illuminate\Support\Facades\Route; |
| 9 | 9 | ||
| 10 | 10 | ||
| @@ -72,7 +72,7 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -72,7 +72,7 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 72 | //发送记录 | 72 | //发送记录 |
| 73 | Route::any('/log', [Aside\Ai\AiLogController::class, 'lists'])->name('admin.lists'); | 73 | Route::any('/log', [Aside\Ai\AiLogController::class, 'lists'])->name('admin.lists'); |
| 74 | // 绑定AICC微信应用 | 74 | // 绑定AICC微信应用 |
| 75 | - Route::post('/wechat', [ProjectAssociationController::class, 'saveWeChatData'])->name('admin.aicc.wechat'); | 75 | + Route::post('/binding/save', [ProjectAssociationController::class, 'save'])->name('admin.binding.save'); |
| 76 | // OA后台开启关闭AICC用户绑定 | 76 | // OA后台开启关闭AICC用户绑定 |
| 77 | Route::post('/check', [ProjectAssociationController::class, 'check'])->name('admin.aicc.check'); | 77 | Route::post('/check', [ProjectAssociationController::class, 'check'])->name('admin.aicc.check'); |
| 78 | }); | 78 | }); |
-
请 注册 或 登录 后发表评论