Lave.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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', null, $this->cid));
  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. @file_put_contents("lave.txt", json_encode($where1));
  57. $order = LaveModel::create($where1);
  58. cache('lave_' . $where['user_id'], '1', 10);
  59. if (!$order) $this->error(LaveModel::getErrorInfo());
  60. $orderId = $order['order_id'];
  61. $info = compact('orderId');
  62. if ($orderId) {
  63. $orderInfo = LaveModel::where('order_id', $orderId)->find();
  64. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  65. if ($orderInfo['paid']) $this->error('支付已支付!');
  66. try {
  67. if ($where['from'] == 'routine') {
  68. $jsConfig = LaveRepository::jsPay($this->cid, $orderId); //创建订单jspay
  69. } else if ($where['from'] == 'weixinh5') {
  70. $jsConfig = LaveRepository::h5Pay($this->cid, $orderId);
  71. } else {
  72. $jsConfig = LaveRepository::wxPay($this->cid, $orderId);
  73. }
  74. } catch (\Exception $e) {
  75. return $this->error($e->getMessage());
  76. }
  77. $info['jsConfig'] = $jsConfig;
  78. return $this->success('订单创建成功', $info);
  79. } else $this->error(LaveModel::getErrorInfo());
  80. }
  81. public function mylst(Request $request)
  82. {
  83. $where = UtilService::getMore(
  84. [
  85. ['page', 1],
  86. ['limit', 10],
  87. ['cid', $this->cid],
  88. ['user_id', $this->auth->getUserinfo()['id']],
  89. ['paid', -1],
  90. ['category_id', 0],
  91. ], $request
  92. );
  93. $this->success('获取成功', LaveModel::lst($where));
  94. }
  95. /**
  96. * 订单支付
  97. * @param Request $request
  98. * @return mixed
  99. */
  100. public function pay(Request $request)
  101. {
  102. list($uni, $paytype, $from) = UtilService::postMore([
  103. ['uni', ''],
  104. ['paytype', '0'],
  105. ['from', 'weixin']
  106. ], $request, true);
  107. if (!$uni) $this->error('参数错误!');
  108. $order = LaveModel::where('cid', $this->cid)->where('order_id', $uni)->find();
  109. if (!$order)
  110. $this->error('订单不存在!');
  111. if ($order['paid'])
  112. $this->error('该订单已支付!');
  113. $order['pay_type'] = $paytype; //重新支付选择支付方式
  114. switch ($order['pay_type']) {
  115. case '0':
  116. try {
  117. if ($from == 'routine') {
  118. $jsConfig = LaveRepository::jsPay($this->cid, $order); //订单列表发起支付
  119. } else if ($from == 'weixinh5') {
  120. $jsConfig = LaveRepository::h5Pay($this->cid, $order);
  121. } else {
  122. $jsConfig = LaveRepository::wxPay($this->cid, $order);
  123. }
  124. } catch (\Exception $e) {
  125. $this->error($e->getMessage());
  126. }
  127. $this->success('获取成功', $jsConfig);
  128. break;
  129. }
  130. return $this->error('支付方式错误');
  131. }
  132. }
  133. ?>