Lave.php 4.6 KB

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