feat(user): 添加用户申请联系功能并优化俱乐部相关操作

- 新增用户申请联系信息功能,包括申请、审核和处理流程
- 优化俱乐部申请、邀请和处理申请的逻辑
- 修复活动不存在时的错误提示
- 优化活动查询条件,支持一次性活动的特殊处理
This commit is contained in:
2025-05-04 17:23:11 +08:00
parent 98eda4e5ff
commit c76019416a
4 changed files with 272 additions and 116 deletions

View File

@@ -2,15 +2,21 @@
namespace addons\shopro\controller\user;
use think\Db;
use think\Exception;
use app\common\library\Sms;
use think\exception\PDOException;
use app\admin\model\zy\link\Apply;
use addons\shopro\controller\Common;
use app\admin\model\zy\link\Message;
use app\admin\model\zy\link\Relation;
use app\admin\model\shopro\ThirdOauth;
use think\exception\ValidateException;
use addons\shopro\service\user\UserAuth;
use app\admin\model\shopro\user\User as UserModel;
use app\admin\model\shopro\user\Coupon as UserCouponModel;
use app\admin\model\shopro\order\Order as OrderModel;
use app\admin\model\shopro\user\Coupon as UserCouponModel;
use app\admin\model\shopro\order\Aftersale as AftersaleModel;
use app\admin\model\zy\link\Message;
use app\admin\model\shopro\ThirdOauth;
class User extends Common
{
@@ -331,4 +337,117 @@ class User extends Common
$this->success('Success', $model);
}
// 申请联系信息
public function apply()
{
$params = $this->request->param();
if (empty($params['content'])) {
return $this->error('申请内容不能为空');
}
Db::startTrans();
try {
$fromUser = auth_user();
$user = UserModel::get($params['user_id'] ?? NULL);
if (empty($user)) {
return $this->error('用户不存在');
}
$apply = (new Apply);
if ($apply::get(['type' => 2, 'user_id' => $fromUser->id, 'target_id' => $user->id, 'status' => 1])) {
return $this->error('申请处理中');
}
$apply->allowField(true)->save([ // 记录申请
'type' => 2,
'user_id' => $fromUser->id,
'target_id' => $user->id,
'content' => $params['content'],
'reason' => $params['reason'] ?? '',
'status' => 1
]);
(new Message())->allowField(true)->save([ // 消息通知
'type' => 2,
'name' => $fromUser->nickname,
'avatar' => $fromUser->avatar,
'from_id' => $fromUser->id,
'user_id' => $user->id,
'content' => json_encode([
'topic' => '申请联系信息',
'申请人' => $fromUser->nickname,
'申请时间' => date('Y-m-d H:i:s'),
'reason' => $params['reason'] ?? '',
'apply_id' => $apply->id
])
]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('已邀请,请等候审核');
}
// 获取申请列表
public function applyList()
{
$params = $this->request->param();
$query = Apply::where('type', 2)->where('target_id', $this->auth->id);
if (isset($params['status'])) {
$query->where('status', $params['status']);
}
$applyList = $query->select();
$this->success('Success', $applyList);
}
// 处理申请
public function handle()
{
$params = $this->request->param();
Db::startTrans();
try {
$apply = Apply::get(['id' => $params['apply_id'], 'user_id' => $this->auth->id, 'status' => 1]);
if (empty($apply)) {
return $this->error('申请记录不存在');
}
if ($params['status'] == 2) { //同意
$relation = Relation::get(['user_id' => $apply['user_id'], 'target_id' => $apply['user_id']]);
if (empty($relation)) {
$relation = new Relation;
}
$relation->allowField(true)->save([
'target_id' => $apply['user_id'],
'user_id' => $apply['target_id'],
'status' => 1,
'content' => $params['content'],
]);
}
$apply->save([
'status' => $params['status'],
'reply' => $params['reply'] ?? ''
]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('Success');
}
// 好友关系
public function relation()
{
$params = $this->request->param();
if (!isset($params['status'])) {
$this->error('缺少参数:status');
}
$relation = Relation::get(['user_id' => $this->auth->id, 'target_id' => $params['user_id']]);
if (empty($relation)) {
$relation = new Relation;
}
$relation->allowField(true)->save([
'target_id' => $params['user_id'],
'user_id' => $this->auth->id,
'status' => $params['status'],
]);
$this->success('Success');
}
}