UserService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Services;
  3. use App\Http\Params\ProblemParam;
  4. use App\Models\PaymentLogModel;
  5. use App\Models\UserLookModel;
  6. use App\Models\UserProblemModel;
  7. use App\Models\VipModel;
  8. use PHPUnit\Util\Exception;
  9. class UserService
  10. {
  11. /**
  12. * 问题反馈
  13. */
  14. public function problem(ProblemParam $param){
  15. if(empty($param->content)){
  16. throw new Exception("请输入问题");
  17. }
  18. $ins = array();
  19. $ins['user_id'] = $param->user_id;
  20. $ins['content'] = htmlspecialchars($param->content);
  21. $ins['img_url'] = $param->img_url;
  22. $ins['status'] = $param->status;
  23. UserProblemModel::query()->create($ins);
  24. return true;
  25. }
  26. /**
  27. * 看过我
  28. */
  29. public function looked_me($param){
  30. $res = UserLookModel::query()
  31. ->with(['users'=>function($query){
  32. $query->select('id','sex','is_vip','tencent_im_user_id');
  33. },'users_info'])
  34. ->where('user_id',$param['user_id'])
  35. ->paginate(request('perPage',20));
  36. return $res;
  37. }
  38. /**
  39. * 购买vip
  40. */
  41. public function buy_vip($param){
  42. if(empty($param['id'])){
  43. throw new Exception("参数错误");
  44. }
  45. if(!$vip_info = VipModel::query()->where('id',$param['id'])->first()){
  46. throw new Exception("VIP不存在");
  47. }
  48. $ins = array();
  49. $ins['order_no'] = create_order_number();
  50. $ins['user_id'] = $param['user_id'];
  51. $ins['price'] = $vip_info['price'];
  52. $ins['status'] = 0;
  53. $ins['content'] = json_encode($vip_info);
  54. $ins['type'] = 1;
  55. if(!$order_id = PaymentLogModel::query()->insertGetId($ins)){
  56. throw new Exception("插入订单失败");
  57. }
  58. return true;
  59. }
  60. }