|
@@ -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
|
|
|
@@ -31,9 +33,9 @@ class ProjectAssociationController extends BaseController |
|
@@ -31,9 +33,9 @@ class ProjectAssociationController extends BaseController |
|
31
|
if (empty($project_id)) {
|
33
|
if (empty($project_id)) {
|
|
32
|
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
|
34
|
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
|
|
33
|
}
|
35
|
}
|
|
34
|
- $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
|
36
|
+ $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
|
|
35
|
|
37
|
|
|
36
|
- $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0;
|
38
|
+ $user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0;
|
|
37
|
if (empty($user_id) && $status) {
|
39
|
if (empty($user_id) && $status) {
|
|
38
|
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
|
40
|
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
|
|
39
|
}
|
41
|
}
|
|
@@ -44,8 +46,58 @@ class ProjectAssociationController extends BaseController |
|
@@ -44,8 +46,58 @@ class ProjectAssociationController extends BaseController |
|
44
|
$nickname = request()->post('nickname', '');
|
46
|
$nickname = request()->post('nickname', '');
|
|
45
|
$user_name = request()->post('user_name', '');
|
47
|
$user_name = request()->post('user_name', '');
|
|
46
|
$image = request()->post('image', '');
|
48
|
$image = request()->post('image', '');
|
|
47
|
- $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
|
49
|
+ $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
|
|
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
|
} |