Lave.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\{Category,Lave as LaveModel};
  5. use liuniu\repositories\LaveRepository;
  6. use liuniu\UtilService;
  7. use think\Request;
  8. class Lave extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function lst(Request $request)
  13. {
  14. $where = UtilService::getMore(
  15. [
  16. ['page',1],
  17. ['limit',10],
  18. ['cid',$this->cid],
  19. ['paid',1],
  20. ['category_id',0],
  21. ],$request
  22. );
  23. $this->success('获取成功',LaveModel::lst($where));
  24. }
  25. public function ify()
  26. {
  27. $this->success('获取成功',Category::getCategoryArray('lave'));
  28. }
  29. public function create(Request $request)
  30. {
  31. $where = UtilService::postMore(
  32. [
  33. ['cid',$this->cid],
  34. ['user_id',$this->auth->getUserinfo()['id']],
  35. ['order_name',''],
  36. ['category_id',0],
  37. ['amount',0],
  38. ['name',''],
  39. ['contact',''],
  40. ['tel',0],
  41. ['address',''],
  42. ['is_open',0],
  43. ['is_ticket',0],
  44. ['pay_type',0],
  45. ['type',0],
  46. ['help_id',0],
  47. ['from','weixin'],
  48. ],$request
  49. );
  50. $where1 = $where;
  51. unset($where1['from']);
  52. $where1['order_id'] = LaveModel::getNewOrderId();
  53. if(cache('lave_'.$where['user_id'])) $this->error('正在处理中');
  54. $order = LaveModel::create($where1);
  55. cache('lave_'.$where['user_id'],'1',10);
  56. if(!$order) $this->error(LaveModel::getErrorInfo());
  57. $orderId = $order['order_id'];
  58. $info = compact('orderId');
  59. if ($orderId) {
  60. $orderInfo = LaveModel::where('order_id', $orderId)->find();
  61. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  62. if ($orderInfo['paid']) $this->error('支付已支付!');
  63. try {
  64. if ($where['from'] == 'routine') {
  65. $jsConfig = LaveRepository::jsPay($this->cid,$orderId); //创建订单jspay
  66. } else if ($where['from'] == 'weixinh5') {
  67. $jsConfig = LaveRepository::h5Pay($this->cid,$orderId);
  68. } else {
  69. $jsConfig = LaveRepository::wxPay($this->cid,$orderId);
  70. }
  71. } catch (\Exception $e) {
  72. return $this->error( $e->getMessage());
  73. }
  74. $info['jsConfig'] = $jsConfig;
  75. return $this->success('订单创建成功',$info);
  76. } else $this->error(LaveModel::getErrorInfo());
  77. }
  78. public function mylst(Request $request)
  79. {
  80. $where = UtilService::getMore(
  81. [
  82. ['page',1],
  83. ['limit',10],
  84. ['cid',$this->cid],
  85. ['user_id',$this->auth->getUserinfo()['id']],
  86. ['paid',-1],
  87. ['category_id',0],
  88. ],$request
  89. );
  90. $this->success('获取成功',LaveModel::lst($where));
  91. }
  92. /**
  93. * 订单支付
  94. * @param Request $request
  95. * @return mixed
  96. */
  97. public function pay(Request $request)
  98. {
  99. list($uni, $paytype, $from) = UtilService::postMore([
  100. ['uni', ''],
  101. ['paytype', '0'],
  102. ['from', 'weixin']
  103. ], $request, true);
  104. if (!$uni) $this->error('参数错误!');
  105. $order = LaveModel::where('cid',$this->cid)->where('order_id',$uni)->find();
  106. if (!$order)
  107. $this->error('订单不存在!');
  108. if ($order['paid'])
  109. $this->error('该订单已支付!');
  110. $order['pay_type'] = $paytype; //重新支付选择支付方式
  111. switch ($order['pay_type']) {
  112. case '0':
  113. try {
  114. if ($from == 'routine') {
  115. $jsConfig = LaveRepository::jsPay($this->cid,$order); //订单列表发起支付
  116. } else if ($from == 'weixinh5') {
  117. $jsConfig = LaveRepository::h5Pay($this->cid,$order);
  118. } else {
  119. $jsConfig = LaveRepository::wxPay($this->cid,$order);
  120. }
  121. } catch (\Exception $e) {
  122. $this->error($e->getMessage());
  123. }
  124. $this->success('获取成功',$jsConfig);
  125. break;
  126. }
  127. return $this->error('支付方式错误');
  128. }
  129. }
  130. ?>