Pay.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\BaseController;
  4. use app\mobile\logic\PayLogic;
  5. use app\model\CommonModel;
  6. use think\exception\ValidateException;
  7. use think\facade\Validate;
  8. //支付相关
  9. class Pay extends BaseController
  10. {
  11. //微信支付预下单
  12. public function getPrepayId()
  13. {
  14. $param = $this->request->only(['type', 'list', 'addr_id'], 'post');
  15. $val = Validate::rule([
  16. 'type|购买类型' => 'require|number|in:' . CommonModel::$pay_type_service . ',' . CommonModel::$pay_type_shopping_good,
  17. 'list|购买列表' => 'require|array|max:100',
  18. 'addr_id|收货地址' => 'require|number|gt:0'
  19. ]);
  20. if (!$val->check($param)) throw new ValidateException($val->getError());
  21. $val2 = Validate::rule([
  22. 'id' => 'require|number|gt:0',
  23. 'num|购买数量' => 'require|number|max:99999999',
  24. ]);
  25. foreach ($param['list'] as $list) {
  26. if (!$val2->check($list)) throw new ValidateException($val2->getError());
  27. }
  28. return PayLogic::getPrepayId($param);
  29. }
  30. //微信支付成功后的异步通知及订单处理
  31. public function Notify()
  32. {
  33. return PayLogic::Notify();
  34. }
  35. //检查支付结果
  36. public function checkPayResult()
  37. {
  38. $param = $this->request->only(['pay_code'],'post');
  39. $val = Validate::rule(['pay_code|支付编码'=>'require|length:18']);
  40. if(!$val->check($param)) throw new ValidateException($val->getError());
  41. return PayLogic::checkPayResult($param['pay_code']);
  42. }
  43. }