Lave.php 4.5 KB

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