| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Services;
- use App\Http\Params\ProblemParam;
- use App\Models\PaymentLogModel;
- use App\Models\UserLookModel;
- use App\Models\UserProblemModel;
- use App\Models\VipModel;
- use PHPUnit\Util\Exception;
- 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'] = $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('user_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);
- }
- }
|