| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace App\Services;
- use App\Http\Params\ProblemParam;
- use App\Models\PaymentLogModel;
- use App\Models\User;
- use App\Models\UserBlacklistModel;
- use App\Models\UserLookModel;
- use App\Models\UserProblemModel;
- use App\Models\VipModel;
- use PHPUnit\Util\Exception;
- use function Symfony\Component\Translation\t;
- class UserService
- {
- /**
- * 问题反馈
- */
- public function problem(ProblemParam $param){
- if(empty($param->content)){
- throw new Exception("请输入问题");
- }
- $ins = array();
- $ins['user_id'] = $param->user_id;
- $ins['content'] = htmlspecialchars($param->content);
- $ins['img_url'] = json_encode($param->img_url);
- $ins['status'] = $param->status;
- UserProblemModel::query()->create($ins);
- return true;
- }
- /**
- * 看过我
- */
- public function looked_me($param){
- $res = UserLookModel::query()
- ->with(['user'=>function($query){
- $query->select('id','sex','is_vip','tencent_im_user_id');
- },'user_info'])
- ->where('look_id',$param['user_id'])
- ->paginate(request('perPage',20));
- return $res;
- }
- /**
- * 购买vip
- */
- public function buy_vip($param){
- if(empty($param['id'])){
- throw new Exception("参数错误");
- }
- if(!$vip_info = VipModel::query()->where('id',$param['id'])->first()){
- throw new Exception("VIP不存在");
- }
- $ins = array();
- $ins['order_no'] = create_order_number();
- $ins['user_id'] = $param['user_id'];
- $ins['price'] = $vip_info['price'];
- $ins['status'] = 0;
- $ins['content'] = json_encode($vip_info);
- $ins['type'] = 1;
- $ins['payment'] = $param['payment'];
- if(!PaymentLogModel::query()->create($ins)){
- throw new Exception("插入订单失败");
- }
- $pay_param = [
- 'out_trade_no' => $ins['order_no'],
- 'body' => '购买VIP',
- 'total_fee' => $ins['price'],
- 'payment' => $ins['payment'],
- ];
- return PayService::pay($pay_param);
- }
- /**
- * 黑名单
- */
- public function black_list(){
- $user = auth('api')->user();
- $res = UserBlacklistModel::query()
- ->leftJoin('users_info','users_blacklist.black_id','=','users_info.user_id')
- ->select(['users_blacklist.id','users_info.user_id','users_info.avatar','users_info.nickname'])
- ->where('users_blacklist.user_id','=',$user->id)
- ->paginate(request('prePage',20));
- return $res;
- }
- /**
- * 移除黑名单
- */
- public function del_black($id){
- if(empty($id)){
- throw new Exception("参数错误");
- }
- $user = auth('api')->user();
- if(!$black = UserBlacklistModel::query()->where(['id'=>$id,'user_id'=>$user->id])->first()){
- throw new Exception("对方不在你的黑名单中");
- }
- $black->delete();
- return true;
- }
- /**
- * 设置隐身和通知开关
- */
- public function online_status($request){
- $user = auth('api')->user();
- if(isset($request->online)){
- $user->online = $request->online;
- $user->save();
- }
- if(isset($request->notice_status)){
- $user->notice_status = $request->notice_status;
- $user->save();
- }
- return ['online'=>$user->online,'notice_status'=>$user->notice_status];
- }
- /**
- * 获取邀请福利信息
- */
- public function invite_info(){
- $user = auth('api')->user();
- //总邀请用户
- $total_user = User::query()->where(['pid'=>$user->id])->count();
- $res['total_user'] = $total_user;
- $res['ycode'] = $user->ycode;
- }
- }
|