Level.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\OrderLevel;
  5. use app\common\model\UserGroup;
  6. use liuniu\repositories\LevelRepository;
  7. use liuniu\UtilService;
  8. use think\Request;
  9. class Level extends Api
  10. {
  11. protected $noNeedRight = ['*'];
  12. public function ify()
  13. {
  14. $this->success('获取成功',UserGroup::where('cid',$this->cid)->where('status','normal')->where("pay_price",'>',0)->select());
  15. }
  16. public function create(Request $request)
  17. {
  18. $where = UtilService::postMore(
  19. [
  20. ['cid',$this->cid],
  21. ['user_id',$this->auth->getUserinfo()['id']],
  22. ['level_id',0],
  23. ['body',''],
  24. ['pay_type',0],
  25. ['name',''],
  26. ['pay_price',0],
  27. ['from','weixin'],
  28. ],$request
  29. );
  30. $order = OrderLevel::order_create($where);
  31. if(!$order) $this->error(OrderLevel::getErrorInfo());
  32. $orderId = $order['order_id'];
  33. $info = compact('orderId');
  34. if ($orderId) {
  35. $orderInfo = OrderLevel::where('order_id', $orderId)->find();
  36. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  37. if ($orderInfo['paid']) $this->error('支付已支付!');
  38. try {
  39. if ($where['from'] == 'routine') {
  40. $jsConfig = LevelRepository::jsPay($orderId); //创建订单jspay
  41. } else if ($where['from'] == 'weixinh5') {
  42. $jsConfig = LevelRepository::h5Pay($orderId);
  43. } else {
  44. $jsConfig = LevelRepository::wxPay($orderId);
  45. }
  46. } catch (\Exception $e) {
  47. return $this->error( $e->getMessage());
  48. }
  49. $info['jsConfig'] = $jsConfig;
  50. return $this->success('订单创建成功');
  51. } else $this->error(OrderLevel::getErrorInfo());
  52. }
  53. public function mylst(Request $request)
  54. {
  55. $where = UtilService::getMore(
  56. [
  57. ['page',1],
  58. ['limit',10],
  59. ['cid',$this->cid],
  60. ['user_id',$this->auth->getUserinfo()['id']],
  61. ['paid',-1],
  62. ],$request
  63. );
  64. $this->success('获取成功',OrderLevel::lst($where));
  65. }
  66. /**
  67. * 订单支付
  68. * @param Request $request
  69. * @return mixed
  70. */
  71. public function pay(Request $request)
  72. {
  73. list($uni, $paytype, $from) = UtilService::postMore([
  74. ['uni', ''],
  75. ['paytype', '0'],
  76. ['from', 'weixin']
  77. ], $request, true);
  78. if (!$uni) $this->error('参数错误!');
  79. $order = OrderLevel::where('cid',$this->cid)->where('order_id',$uni)->find();
  80. if (!$order)
  81. $this->error('订单不存在!');
  82. if ($order['paid'])
  83. $this->error('该订单已支付!');
  84. $order['pay_type'] = $paytype; //重新支付选择支付方式
  85. switch ($order['pay_type']) {
  86. case '0':
  87. try {
  88. if ($from == 'routine') {
  89. $jsConfig = OrderLevel::jsPay($order); //订单列表发起支付
  90. } else if ($from == 'weixinh5') {
  91. $jsConfig = OrderLevel::h5Pay($order);
  92. } else {
  93. $jsConfig = OrderLevel::wxPay($order);
  94. }
  95. } catch (\Exception $e) {
  96. $this->error($e->getMessage());
  97. }
  98. $this->success('获取成功',$jsConfig);
  99. break;
  100. }
  101. return $this->error('支付方式错误');
  102. }
  103. }