Lave.php 4.6 KB

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