Level.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ['pay_price',0],
  26. ['from','weixin'],
  27. ],$request
  28. );
  29. $where1 = $where;
  30. unset($where1['from']);
  31. $where1['order_id'] = OrderLevel::getNewOrderId();
  32. $where1['createtime'] = time();
  33. $order = OrderLevel::order_create($where1);
  34. if(!$order) $this->error(OrderLevel::getErrorInfo());
  35. $orderId = $order['order_id'];
  36. $info = compact('orderId');
  37. if ($orderId) {
  38. $orderInfo = OrderLevel::where('order_id', $orderId)->find();
  39. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  40. if ($orderInfo['paid']) $this->error('支付已支付!');
  41. try {
  42. if ($where['from'] == 'routine') {
  43. $jsConfig = LevelRepository::jsPay($this->cid,$orderId); //创建订单jspay
  44. } else if ($where['from'] == 'weixinh5') {
  45. $jsConfig = LevelRepository::h5Pay($this->cid,$orderId);
  46. } else {
  47. $jsConfig = LevelRepository::wxPay($this->cid,$orderId);
  48. }
  49. } catch (\Exception $e) {
  50. return $this->error( $e->getMessage());
  51. }
  52. $info['jsConfig'] = $jsConfig;
  53. return $this->success('订单创建成功',$info);
  54. } else $this->error(OrderLevel::getErrorInfo());
  55. }
  56. public function mylst(Request $request)
  57. {
  58. $where = UtilService::getMore(
  59. [
  60. ['page',1],
  61. ['limit',10],
  62. ['cid',$this->cid],
  63. ['user_id',$this->auth->getUserinfo()['id']],
  64. ['paid',-1],
  65. ],$request
  66. );
  67. $this->success('获取成功',OrderLevel::lst($where));
  68. }
  69. /**
  70. * 订单支付
  71. * @param Request $request
  72. * @return mixed
  73. */
  74. public function pay(Request $request)
  75. {
  76. list($uni, $paytype, $from) = UtilService::postMore([
  77. ['uni', ''],
  78. ['paytype', '0'],
  79. ['from', 'weixin']
  80. ], $request, true);
  81. if (!$uni) $this->error('参数错误!');
  82. $order = LevelRepository::where('cid',$this->cid)->where('order_id',$uni)->find();
  83. if (!$order)
  84. $this->error('订单不存在!');
  85. if ($order['paid'])
  86. $this->error('该订单已支付!');
  87. $order['pay_type'] = $paytype; //重新支付选择支付方式
  88. switch ($order['pay_type']) {
  89. case '0':
  90. try {
  91. if ($from == 'routine') {
  92. $jsConfig = LevelRepository::jsPay($this->cid,$order); //订单列表发起支付
  93. } else if ($from == 'weixinh5') {
  94. $jsConfig = LevelRepository::h5Pay($this->cid,$order);
  95. } else {
  96. $jsConfig = LevelRepository::wxPay($this->cid,$order);
  97. }
  98. } catch (\Exception $e) {
  99. $this->error($e->getMessage());
  100. }
  101. $this->success('获取成功',$jsConfig);
  102. break;
  103. }
  104. return $this->error('支付方式错误');
  105. }
  106. }