UserService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Services;
  3. use App\Http\Params\ProblemParam;
  4. use App\Models\PaymentLogModel;
  5. use App\Models\User;
  6. use App\Models\UserBlacklistModel;
  7. use App\Models\UserLookModel;
  8. use App\Models\UserProblemModel;
  9. use App\Models\VipModel;
  10. use PHPUnit\Util\Exception;
  11. use function Symfony\Component\Translation\t;
  12. class UserService
  13. {
  14. /**
  15. * 问题反馈
  16. */
  17. public function problem(ProblemParam $param){
  18. if(empty($param->content)){
  19. throw new Exception("请输入问题");
  20. }
  21. $ins = array();
  22. $ins['user_id'] = $param->user_id;
  23. $ins['content'] = htmlspecialchars($param->content);
  24. $ins['img_url'] = json_encode($param->img_url);
  25. $ins['status'] = $param->status;
  26. UserProblemModel::query()->create($ins);
  27. return true;
  28. }
  29. /**
  30. * 看过我
  31. */
  32. public function looked_me($param){
  33. $res = UserLookModel::query()
  34. ->with(['user'=>function($query){
  35. $query->select('id','sex','is_vip','tencent_im_user_id');
  36. },'user_info'])
  37. ->where('look_id',$param['user_id'])
  38. ->paginate(request('perPage',20));
  39. return $res;
  40. }
  41. /**
  42. * 购买vip
  43. */
  44. public function buy_vip($param){
  45. if(empty($param['id'])){
  46. throw new Exception("参数错误");
  47. }
  48. if(!$vip_info = VipModel::query()->where('id',$param['id'])->first()){
  49. throw new Exception("VIP不存在");
  50. }
  51. $ins = array();
  52. $ins['order_no'] = create_order_number();
  53. $ins['user_id'] = $param['user_id'];
  54. $ins['price'] = $vip_info['price'];
  55. $ins['status'] = 0;
  56. $ins['content'] = json_encode($vip_info);
  57. $ins['type'] = 1;
  58. $ins['payment'] = $param['payment'];
  59. if(!PaymentLogModel::query()->create($ins)){
  60. throw new Exception("插入订单失败");
  61. }
  62. $pay_param = [
  63. 'out_trade_no' => $ins['order_no'],
  64. 'body' => '购买VIP',
  65. 'total_fee' => $ins['price'],
  66. 'payment' => $ins['payment'],
  67. ];
  68. return PayService::pay($pay_param);
  69. }
  70. /**
  71. * 黑名单
  72. */
  73. public function black_list(){
  74. $user = auth('api')->user();
  75. $res = UserBlacklistModel::query()
  76. ->leftJoin('users_info','users_blacklist.black_id','=','users_info.user_id')
  77. ->select(['users_blacklist.id','users_info.user_id','users_info.avatar','users_info.nickname'])
  78. ->where('users_blacklist.user_id','=',$user->id)
  79. ->paginate(request('prePage',20));
  80. return $res;
  81. }
  82. /**
  83. * 移除黑名单
  84. */
  85. public function del_black($id){
  86. if(empty($id)){
  87. throw new Exception("参数错误");
  88. }
  89. $user = auth('api')->user();
  90. if(!$black = UserBlacklistModel::query()->where(['id'=>$id,'user_id'=>$user->id])->first()){
  91. throw new Exception("对方不在你的黑名单中");
  92. }
  93. $black->delete();
  94. return true;
  95. }
  96. /**
  97. * 设置隐身和通知开关
  98. */
  99. public function online_status($request){
  100. $user = auth('api')->user();
  101. if(isset($request->online)){
  102. $user->online = $request->online;
  103. $user->save();
  104. }
  105. if(isset($request->notice_status)){
  106. $user->notice_status = $request->notice_status;
  107. $user->save();
  108. }
  109. return ['online'=>$user->online,'notice_status'=>$user->notice_status];
  110. }
  111. /**
  112. * 获取邀请福利信息
  113. */
  114. public function invite_info(){
  115. $user = auth('api')->user();
  116. //总邀请用户
  117. $total_user = User::query()->where(['pid'=>$user->id])->count();
  118. $res['total_user'] = $total_user;
  119. $res['ycode'] = $user->ycode;
  120. }
  121. }