diff --git a/addons/shopro/controller/user/User.php b/addons/shopro/controller/user/User.php index 96dc098..82561c4 100644 --- a/addons/shopro/controller/user/User.php +++ b/addons/shopro/controller/user/User.php @@ -5,10 +5,13 @@ namespace addons\shopro\controller\user; use think\Db; use think\Exception; use app\common\library\Sms; +use app\admin\model\zy\Club; +use app\admin\model\zy\Menber; 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\Visitor; use app\admin\model\zy\link\Relation; use app\admin\model\shopro\ThirdOauth; use think\exception\ValidateException; @@ -17,8 +20,6 @@ use app\admin\model\shopro\user\User as UserModel; 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\Club; -use app\admin\model\zy\Menber; class User extends Common { @@ -85,9 +86,28 @@ class User extends Common public function profile() { //TODO @ldh: 1.账号被禁用 2.连表查group - $user = auth_user(true); - - $user = UserModel::with(['parent_user', 'third_oauth'])->where('id', $user->id)->find(); + $self = auth_user(true); //自己 + $user_id = $self->id; + $params = $this->request->param(); + if (!empty($params['user_id'])) { + $user_id = $params['user_id']; + $relation = Relation::where('user_id', $self->id)->where('target_id', $user_id)->find(); + $content = json_decode($relation->content ?? '', true); + $visitor = Visitor::where('type', 2)->where('obj_id', $user_id)->where('user_id', $self->id)->find(); + if (empty($visitor)) { + $visitor = new Visitor; + } + $visitor->allowField(true)->save([ + 'type' => 2, + 'obj_id' => $user_id, + 'user_id' => $self->id, + 'nickname' => $self['nickname'], + 'avatar' => $self['avatar'], + 'gender' => $self['gender'], + 'times' => empty($visitor->times) ? 1 : $visitor->times + 1 + ]); + } + $user = UserModel::with(['parent_user', 'third_oauth'])->where('id', $user_id)->find(); $user->hidden(['password', 'salt', 'createtime', 'updatetime', 'deletetime', 'remember_token', 'login_fail', 'login_ip', 'login_time']); $user = $user->toArray(); @@ -95,6 +115,12 @@ class User extends Common $user['club_list'] = Menber::alias('m')->join([Club::$tableName => 'c'], 'c.id=m.club_id')->field('m.*,c.name')->where('user_id', $user['id'])->where('role', '>', 0)->select(); $user['club_num'] = count($user['club_list']); $user['card_num'] = 0; + if (isset($content)) { + if (empty($content['phone'])) $user['mobile'] = ''; //手机查看权限 + if (empty($content['wechat'])) $user['wechat'] = ''; //微信查看权限 + if (empty($content['qq'])) $user['qq'] = ''; //qq查看权限 + $user['content'] = $content; //权限 + } $this->success('个人详情', $user); } @@ -317,6 +343,44 @@ class User extends Common $this->success('注销成功'); } + // 发送用户消息 + public function sendMsg() + { + $params = $this->request->param(); + if ($params['user_id'] == $this->auth->id) { + $this->error('不能发送给自己'); + } + $user = auth_user(); + $target = UserModel::get($params['user_id']); + if (empty($target)) { + $this->error('用户不存在'); + } + + Db::startTrans(); + try { + $result = (new Message())->allowField(true)->save([ + 'type' => 2, + 'name' => $user['nickname'], + 'avatar' => $user['avatar'], + 'from_id' => $user['id'], + 'target_id' => $params['user_id'], + 'content' => json_encode([ + 'topic' => '好友消息', + 'time' => date('Y-m-d H:i:s'), + 'content' => $params['content'] + ]), + 'status' => 0 + ]); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error('操作失败'); + } + $this->success('Success'); + } // 分类消息 public function msgGroup() @@ -331,7 +395,7 @@ class User extends Common } $query1->group('from_id')->order('update_time', 'desc'); $query2->group('from_id')->order('update_time', 'desc'); - $num = $query2->where('status', 0)->column('count(*) as num','from_id');// ->column('count(*) as num', 'gender'); + $num = $query2->where('status', 0)->column('count(*) as num', 'from_id'); // ->column('count(*) as num', 'gender'); // dd($num); $res = $query1->paginate($params['pageSize'] ?? 10); $list = $res->items(); diff --git a/addons/shopro/controller/zy/Sys.php b/addons/shopro/controller/zy/Sys.php index aa66f42..67495bf 100644 --- a/addons/shopro/controller/zy/Sys.php +++ b/addons/shopro/controller/zy/Sys.php @@ -73,45 +73,6 @@ class Sys extends Base $this->success('Success'); } - // 发送用户消息 - public function sendMsg() - { - $params = $this->request->param(); - if ($params['user_id'] == $this->auth->id) { - $this->error('不能发送给自己'); - } - $user = auth_user(); - $target = User::get($params['user_id']); - if (empty($target)) { - $this->error('用户不存在'); - } - - Db::startTrans(); - try { - $result = (new Message())->allowField(true)->save([ - 'type' => 2, - 'name' => $user['nickname'], - 'avatar' => $user['avatar'], - 'from_id' => $user['id'], - 'target_id' => $params['user_id'], - 'content' => json_encode([ - 'topic' => '好友消息', - 'time' => date('Y-m-d H:i:s'), - 'content' => $params['content'] - ]), - 'status' => 0 - ]); - Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result === false) { - $this->error('操作失败'); - } - $this->success('Success'); - } - public function visitor() { $params = $this->request->param();