正在显示
4 个修改的文件
包含
79 行增加
和
2 行删除
| @@ -79,7 +79,7 @@ class PushAiccData extends Command | @@ -79,7 +79,7 @@ class PushAiccData extends Command | ||
| 79 | $data['friend_id'] = $isExists->friend_id; | 79 | $data['friend_id'] = $isExists->friend_id; |
| 80 | $data['user_id'] = $isExists->user_id; | 80 | $data['user_id'] = $isExists->user_id; |
| 81 | 81 | ||
| 82 | - $url = env('AICC_URL'); | 82 | + $url = env('AICC_URL') . env('AICC_PUSH_API_URL'); |
| 83 | $msg = http_post($url, json_encode(compact('data'))); | 83 | $msg = http_post($url, json_encode(compact('data'))); |
| 84 | $status_code = 0; | 84 | $status_code = 0; |
| 85 | if ($msg) { | 85 | if ($msg) { |
| @@ -105,7 +105,7 @@ class PushAiccData extends Command | @@ -105,7 +105,7 @@ class PushAiccData extends Command | ||
| 105 | 105 | ||
| 106 | public function post_data($data) | 106 | public function post_data($data) |
| 107 | { | 107 | { |
| 108 | - $url = env('AICC_URL'); | 108 | + $url = env('AICC_URL') . env('AICC_PUSH_API_URL'); |
| 109 | $msg = http_post($url, json_encode(compact('data'))); | 109 | $msg = http_post($url, json_encode(compact('data'))); |
| 110 | print_r($msg); | 110 | print_r($msg); |
| 111 | } | 111 | } |
| @@ -6,7 +6,9 @@ use App\Enums\Common\Code; | @@ -6,7 +6,9 @@ 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; | 8 | use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic; |
| 9 | +use App\Models\ProjectAssociation\ProjectAssociation; | ||
| 9 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 11 | +use Illuminate\Support\Facades\DB; | ||
| 10 | use Psr\Container\ContainerExceptionInterface; | 12 | use Psr\Container\ContainerExceptionInterface; |
| 11 | use Psr\Container\NotFoundExceptionInterface; | 13 | use Psr\Container\NotFoundExceptionInterface; |
| 12 | 14 | ||
| @@ -48,4 +50,54 @@ class ProjectAssociationController extends BaseController | @@ -48,4 +50,54 @@ class ProjectAssociationController extends BaseController | ||
| 48 | $this->ProjectAssociationLogic->saveWeChatData($data); | 50 | $this->ProjectAssociationLogic->saveWeChatData($data); |
| 49 | $this->response('success'); | 51 | $this->response('success'); |
| 50 | } | 52 | } |
| 53 | + | ||
| 54 | + public function check() | ||
| 55 | + { | ||
| 56 | + $project_id = (int)request()->input('project_id', 0); | ||
| 57 | + $status = request()->input('status'); | ||
| 58 | + if (isset($status)) { | ||
| 59 | + $status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED; | ||
| 60 | + } | ||
| 61 | + $isRes = $this->ProjectAssociationLogic->normal($project_id); | ||
| 62 | + DB::beginTransaction(); | ||
| 63 | + try { | ||
| 64 | + // 当数据不存在时并开启状态,自动添加一条数据 | ||
| 65 | + if (is_null($isRes) && (!is_null($status) && $status)) { | ||
| 66 | + $isRes = $this->ProjectAssociationLogic->disabled($project_id); | ||
| 67 | + if (is_null($isRes)) { | ||
| 68 | + $isRes = new ProjectAssociation(); | ||
| 69 | + } | ||
| 70 | + $isRes->project_id = $project_id; | ||
| 71 | + $isRes->user_id = (int)env('AICC_WECHAT_USER_ID'); | ||
| 72 | + $isRes->status = $status; | ||
| 73 | + $isRes->save(); | ||
| 74 | + DB::commit(); | ||
| 75 | + } // 关闭状态 | ||
| 76 | + elseif (!is_null($isRes) && (!is_null($status) && empty($status))) { | ||
| 77 | + $isRes->status = $status; | ||
| 78 | + $isRes->save(); | ||
| 79 | + DB::commit(); | ||
| 80 | + return [ | ||
| 81 | + 'code' => Code::SUCCESS, | ||
| 82 | + 'data' => [], | ||
| 83 | + 'message' => '关闭AICC绑定成功!', | ||
| 84 | + ]; | ||
| 85 | + } | ||
| 86 | + } catch (\Exception $exception) { | ||
| 87 | + DB::rollBack(); | ||
| 88 | + $this->response('数据错误,请重试!', Code::SERVER_ERROR); | ||
| 89 | + } | ||
| 90 | + if (is_null($isRes)) { | ||
| 91 | + $this->response('请开启AICC绑定!', Code::USER_ERROR, []); | ||
| 92 | + } | ||
| 93 | + $url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL'); | ||
| 94 | + $result = curlGet($url); | ||
| 95 | + $result['info'] = [ | ||
| 96 | + 'friend_id' => $isRes->friend_id ?? 0, | ||
| 97 | + 'nickname' => $isRes->nickname ?? '', | ||
| 98 | + 'user_name' => $isRes->user_name ?? '', | ||
| 99 | + 'image' => $isRes->image ?? '', | ||
| 100 | + ]; | ||
| 101 | + $this->response('success', Code::SUCCESS, $result); | ||
| 102 | + } | ||
| 51 | } | 103 | } |
| @@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\ProjectAssociation; | @@ -5,6 +5,8 @@ namespace App\Http\Logic\Aside\ProjectAssociation; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Logic\Logic; | 6 | use App\Http\Logic\Logic; |
| 7 | use App\Models\ProjectAssociation\ProjectAssociation; | 7 | use App\Models\ProjectAssociation\ProjectAssociation; |
| 8 | +use Illuminate\Database\Eloquent\Builder; | ||
| 9 | +use Illuminate\Database\Eloquent\Model; | ||
| 8 | use Illuminate\Support\Facades\DB; | 10 | use Illuminate\Support\Facades\DB; |
| 9 | 11 | ||
| 10 | class ProjectAssociationLogic extends Logic | 12 | class ProjectAssociationLogic extends Logic |
| @@ -24,4 +26,25 @@ class ProjectAssociationLogic extends Logic | @@ -24,4 +26,25 @@ class ProjectAssociationLogic extends Logic | ||
| 24 | } | 26 | } |
| 25 | return $status; | 27 | return $status; |
| 26 | } | 28 | } |
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * status - 正常 | ||
| 32 | + * @param $project_id | ||
| 33 | + * @return ProjectAssociation|Builder|Model|object|null | ||
| 34 | + */ | ||
| 35 | + public function normal($project_id) | ||
| 36 | + { | ||
| 37 | + return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_NORMAL)->first(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * status - 禁用 | ||
| 43 | + * @param $project_id | ||
| 44 | + * @return ProjectAssociation|Builder|Model|object|null | ||
| 45 | + */ | ||
| 46 | + public function disabled($project_id) | ||
| 47 | + { | ||
| 48 | + return ProjectAssociation::query()->whereProjectId($project_id)->whereStatus(ProjectAssociation::STATUS_DISABLED)->first(); | ||
| 49 | + } | ||
| 27 | } | 50 | } |
| @@ -73,6 +73,8 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -73,6 +73,8 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 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('/wechat', [ProjectAssociationController::class, 'saveWeChatData'])->name('admin.aicc.wechat'); |
| 76 | + // OA后台开启关闭AICC用户绑定 | ||
| 77 | + Route::get('/check', [ProjectAssociationController::class, 'check'])->name('admin.aicc.check'); | ||
| 76 | }); | 78 | }); |
| 77 | //特殊模块权限设置 | 79 | //特殊模块权限设置 |
| 78 | Route::prefix('special')->group(function () { | 80 | Route::prefix('special')->group(function () { |
-
请 注册 或 登录 后发表评论