|
...
|
...
|
@@ -6,7 +6,9 @@ use App\Enums\Common\Code; |
|
|
|
use App\Exceptions\BsideGlobalException;
|
|
|
|
use App\Http\Controllers\Bside\BaseController;
|
|
|
|
use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic;
|
|
|
|
use App\Models\ProjectAssociation\ProjectAssociation;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
|
|
...
|
...
|
@@ -31,9 +33,9 @@ class ProjectAssociationController extends BaseController |
|
|
|
if (empty($project_id)) {
|
|
|
|
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
|
|
|
|
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
|
|
|
|
|
|
|
|
$user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0;
|
|
|
|
$user_id = (int)env('AICC_WECHAT_USER_ID') ?? 0;
|
|
|
|
if (empty($user_id) && $status) {
|
|
|
|
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
...
|
...
|
@@ -44,8 +46,58 @@ class ProjectAssociationController extends BaseController |
|
|
|
$nickname = request()->post('nickname', '');
|
|
|
|
$user_name = request()->post('user_name', '');
|
|
|
|
$image = request()->post('image', '');
|
|
|
|
$data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
|
|
|
|
$data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
|
|
|
|
$this->ProjectAssociationLogic->saveWeChatData($data);
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function check()
|
|
|
|
{
|
|
|
|
$project_id = (int)request()->input('project_id', 0);
|
|
|
|
$status = request()->input('status');
|
|
|
|
if (isset($status)) {
|
|
|
|
$status = (int)$status ? ProjectAssociation::STATUS_NORMAL : ProjectAssociation::STATUS_DISABLED;
|
|
|
|
}
|
|
|
|
$isRes = $this->ProjectAssociationLogic->normal($project_id);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
// 当数据不存在时并开启状态,自动添加一条数据
|
|
|
|
if (is_null($isRes) && (!is_null($status) && $status)) {
|
|
|
|
$isRes = $this->ProjectAssociationLogic->disabled($project_id);
|
|
|
|
if (is_null($isRes)) {
|
|
|
|
$isRes = new ProjectAssociation();
|
|
|
|
}
|
|
|
|
$isRes->project_id = $project_id;
|
|
|
|
$isRes->user_id = (int)env('AICC_WECHAT_USER_ID');
|
|
|
|
$isRes->status = $status;
|
|
|
|
$isRes->save();
|
|
|
|
DB::commit();
|
|
|
|
} // 关闭状态
|
|
|
|
elseif (!is_null($isRes) && (!is_null($status) && empty($status))) {
|
|
|
|
$isRes->status = $status;
|
|
|
|
$isRes->save();
|
|
|
|
DB::commit();
|
|
|
|
return [
|
|
|
|
'code' => Code::SUCCESS,
|
|
|
|
'data' => [],
|
|
|
|
'message' => '关闭AICC绑定成功!',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->response('数据错误,请重试!', Code::SERVER_ERROR);
|
|
|
|
}
|
|
|
|
if (is_null($isRes)) {
|
|
|
|
$this->response('请开启AICC绑定!', Code::USER_ERROR, []);
|
|
|
|
}
|
|
|
|
$url = env('AICC_URL') . env('AICC_WECHAT_FRIEND_API_URL');
|
|
|
|
$result = curlGet($url);
|
|
|
|
$result['info'] = [
|
|
|
|
'friend_id' => $isRes->friend_id ?? 0,
|
|
|
|
'nickname' => $isRes->nickname ?? '',
|
|
|
|
'user_name' => $isRes->user_name ?? '',
|
|
|
|
'image' => $isRes->image ?? '',
|
|
|
|
];
|
|
|
|
$this->response('success', Code::SUCCESS, $result);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|