Level.php 4.0 KB

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