| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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(['users'=>function($query){
- $query->select('id','sex','is_vip','tencent_im_user_id');
- },'users_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;
- if(!$order_id = PaymentLogModel::query()->insertGetId($ins)){
- throw new Exception("插入订单失败");
- }
- return true;
- }
- }
|