优化添加好友底层代码逻辑

This commit is contained in:
wong
2025-06-25 11:40:41 +08:00
parent e91f98ed4b
commit 335ed842b5

View File

@@ -19,7 +19,7 @@ class FriendTaskController extends BaseController
public function getlist($pageIndex, $pageSize, $isInner = false) public function getlist($pageIndex, $pageSize, $isInner = false)
{ {
// 获取授权token // 获取授权token
$authorization = trim($this->request->header('authorization', $this->authorization)); $authorization = $this->authorization;
if (empty($authorization)) { if (empty($authorization)) {
if($isInner){ if($isInner){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']); return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -70,29 +70,29 @@ class FriendTaskController extends BaseController
* 添加好友任务 * 添加好友任务
* @return \think\response\Json * @return \think\response\Json
*/ */
public function addFriendTask() public function addFriendTask($data = [])
{ {
// 获取授权token // 获取授权token
$authorization = trim($this->request->header('authorization', $this->authorization)); $authorization =$this->authorization;
if (empty($authorization)) { if (empty($authorization)) {
return errorJson('缺少授权信息'); return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
} }
try { try {
// 获取请求参数 // 获取请求参数
$phone = $this->request->param('phone', ''); $phone = !empty($data['phone']) ? $data['phone'] : '';
$message = $this->request->param('message', ''); $message = !empty($data['message']) ? $data['message'] : '';
$remark = $this->request->param('remark', ''); $remark = !empty($data['remark']) ? $data['remark'] : '';
$labels = $this->request->param('labels', []); $labels = !empty($data['labels']) ? $data['labels'] : '';
$wechatAccountId = $this->request->param('wechatAccountId', 0); $wechatAccountId = !empty($data['wechatAccountId']) ? $data['wechatAccountId'] : '';
// 参数验证 // 参数验证
if (empty($phone)) { if (empty($phone)) {
return errorJson('手机号不能为空'); return json_encode(['code'=>500,'msg'=>'手机号不能为空']);
} }
if (empty($wechatAccountId)) { if (empty($wechatAccountId)) {
return errorJson('微信号不能为空'); return json_encode(['code'=>500,'msg'=>'微信号不能为空']);
} }
// 构建请求参数 // 构建请求参数
@@ -112,9 +112,9 @@ class FriendTaskController extends BaseController
$result = requestCurl($this->baseUrl . 'api/AddFriendByPhoneTask/add', $params, 'POST', $header, 'json'); $result = requestCurl($this->baseUrl . 'api/AddFriendByPhoneTask/add', $params, 'POST', $header, 'json');
// 处理响应 // 处理响应
return successJson([], '添加好友任务创建成功'); return json_encode(['code'=>200,'msg'=>'添加好友任务创建成功']);
} catch (\Exception $e) { } catch (\Exception $e) {
return errorJson('添加好友任务失败:' . $e->getMessage()); return json_encode(['code'=>500,'msg'=> '添加好友任务失败:' . $e->getMessage()]);
} }
} }