Pay.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\order\Context;
  4. use app\api\service\User as UserService;
  5. use app\common\enum\OrderType AS OrderTypeEnum;
  6. class Pay extends Controller
  7. {
  8. //准备支付
  9. public function prePay(){
  10. $user = UserService::getCurrentLoginUser(true);
  11. $args = $this->baseValidate([
  12. // "order_type"=>"require" //业务类型
  13. ],[
  14. // "order_type.require"=>"业务类型不能为空"
  15. ]);
  16. $order_type = $args['order_type']??OrderTypeEnum::RCORDER;
  17. $user_id = $user->user_id;
  18. $args = array_merge(["user_id"=>$user_id,"user_mobile"=>$user->mobile],$args);
  19. //dd($args);
  20. $c = new Context($order_type,$args);
  21. $res = $c->prePay();
  22. if(!$res){
  23. return $this->renderError($c->getInstance()->getError());
  24. }
  25. return $this->renderSuccess($res);
  26. }
  27. //重新支付
  28. public function rePay(){
  29. $user = UserService::getCurrentLoginUser(true);
  30. $args = $this->baseValidate([
  31. // "order_type"=>"require" //业务类型
  32. ],[
  33. // "order_type.require"=>"业务类型不能为空"
  34. ]);
  35. $order_type = $args['order_type']??OrderTypeEnum::RCORDER;
  36. $user_id = $user->user_id;
  37. $args = array_merge(["user_id"=>$user_id,"user_mobile"=>$user->mobile],$args);
  38. $c = new Context($order_type,$args);
  39. $res = $c->rePay();
  40. if(!$res){
  41. return $this->renderError($c->getInstance()->getError());
  42. }
  43. return $this->renderSuccess($res);
  44. }
  45. }