Level.php 4.0 KB

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