Lave.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\WechatPlan;
  4. use app\common\controller\Api;
  5. use app\common\model\{Category, Lave as LaveModel};
  6. use liuniu\repositories\LaveRepository;
  7. use liuniu\UtilService;
  8. use think\Request;
  9. class Lave extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. public function lst(Request $request)
  14. {
  15. $where = UtilService::getMore(
  16. [
  17. ['page', 1],
  18. ['limit', 10],
  19. ['cid', $this->cid],
  20. ['paid', 1],
  21. ['category_id', 0],
  22. ['order', ''],
  23. ['key', ''],
  24. ], $request
  25. );
  26. $this->success('获取成功', LaveModel::lst($where));
  27. }
  28. public function ify()
  29. {
  30. $this->success('获取成功', Category::getCategoryArray('lave', null, $this->cid));
  31. }
  32. public function create(Request $request)
  33. {
  34. $where = UtilService::postMore(
  35. [
  36. ['cid', $this->cid],
  37. ['user_id', $this->auth->getUserinfo()['id']],
  38. ['order_name', ''],
  39. ['category_id', 0],
  40. ['amount', 0],
  41. ['name', ''],
  42. ['contact', ''],
  43. ['tel', 0],
  44. ['address', ''],
  45. ['is_open', '0'],
  46. ['is_ticket', '0'],
  47. ['pay_type', '0'],
  48. ['type', '0'],
  49. ['help_id', 0],
  50. ['from', 'weixin'],
  51. ], $request
  52. );
  53. $where1 = $where;
  54. unset($where1['from']);
  55. $where1['order_id'] = LaveModel::getNewOrderId();
  56. if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
  57. @file_put_contents("lave.txt", json_encode($where1));
  58. $order = LaveModel::create($where1);
  59. cache('lave_' . $where['user_id'], '1', 10);
  60. if (!$order) $this->error(LaveModel::getErrorInfo());
  61. $orderId = $order['order_id'];
  62. $info = compact('orderId');
  63. if ($orderId) {
  64. $orderInfo = LaveModel::where('order_id', $orderId)->find();
  65. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  66. if ($orderInfo['paid']) $this->error('支付已支付!');
  67. try {
  68. if ($where['from'] == 'routine') {
  69. $jsConfig = LaveRepository::jsPay($this->cid, $orderId); //创建订单jspay
  70. } else if ($where['from'] == 'weixinh5') {
  71. $jsConfig = LaveRepository::h5Pay($this->cid, $orderId);
  72. } else {
  73. $jsConfig = LaveRepository::wxPay($this->cid, $orderId);
  74. }
  75. } catch (\Exception $e) {
  76. return $this->error($e->getMessage());
  77. }
  78. $info['jsConfig'] = $jsConfig;
  79. return $this->success('订单创建成功', $info);
  80. } else $this->error(LaveModel::getErrorInfo());
  81. }
  82. public function mylst(Request $request)
  83. {
  84. $where = UtilService::getMore(
  85. [
  86. ['page', 1],
  87. ['limit', 10],
  88. ['cid', $this->cid],
  89. ['user_id', $this->auth->getUserinfo()['id']],
  90. ['paid', -1],
  91. ['category_id', 0],
  92. ], $request
  93. );
  94. $this->success('获取成功', LaveModel::lst($where));
  95. }
  96. /**
  97. * 订单支付
  98. * @param Request $request
  99. * @return mixed
  100. */
  101. public function pay(Request $request)
  102. {
  103. list($uni, $paytype, $from) = UtilService::postMore([
  104. ['uni', ''],
  105. ['paytype', '0'],
  106. ['from', 'weixin']
  107. ], $request, true);
  108. if (!$uni) $this->error('参数错误!');
  109. $order = LaveModel::where('cid', $this->cid)->where('order_id', $uni)->find();
  110. if (!$order)
  111. $this->error('订单不存在!');
  112. if ($order['paid'])
  113. $this->error('该订单已支付!');
  114. $order['pay_type'] = $paytype; //重新支付选择支付方式
  115. switch ($order['pay_type']) {
  116. case '0':
  117. try {
  118. if ($from == 'routine') {
  119. $jsConfig = LaveRepository::jsPay($this->cid, $order); //订单列表发起支付
  120. } else if ($from == 'weixinh5') {
  121. $jsConfig = LaveRepository::h5Pay($this->cid, $order);
  122. } else {
  123. $jsConfig = LaveRepository::wxPay($this->cid, $order);
  124. }
  125. } catch (\Exception $e) {
  126. $this->error($e->getMessage());
  127. }
  128. $this->success('获取成功', $jsConfig);
  129. break;
  130. }
  131. return $this->error('支付方式错误');
  132. }
  133. // 支付中签约
  134. public function createSign(Request $request)
  135. {
  136. var_dump(123);die();
  137. $where = UtilService::postMore(
  138. [
  139. ['cid', $this->cid],
  140. ['user_id', $this->auth->getUserinfo()['id']],
  141. ['order_name', ''],
  142. ['category_id', 0],
  143. ['amount', 0],
  144. ['name', ''],
  145. ['contact', ''],
  146. ['tel', 0],
  147. ['address', ''],
  148. ['is_open', '0'],
  149. ['is_ticket', '0'],
  150. ['pay_type', '0'],
  151. ['type', '0'],
  152. ['help_id', 0],
  153. ['from', 'weixin'],
  154. ], $request
  155. );
  156. $where1 = $where;
  157. unset($where1['from']);
  158. $where1['order_id'] = LaveModel::getNewOrderId();
  159. if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
  160. @file_put_contents("lave.txt", json_encode($where1));
  161. $order = LaveModel::create($where1);
  162. cache('lave_' . $where['user_id'], '1', 10);
  163. if (!$order) $this->error(LaveModel::getErrorInfo());
  164. $orderId = $order['order_id'];
  165. $info = compact('orderId');
  166. $order['plan_id'] = WechatPlan::where('price', $where['amount'])->value('plan_id');
  167. if ($orderId) {
  168. $orderInfo = LaveModel::where('order_id', $orderId)->find();
  169. if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
  170. if ($orderInfo['paid']) $this->error('支付已支付!');
  171. try {
  172. if ($where['from'] == 'routine') {
  173. $jsConfig = LaveRepository::jsPaySign($this->cid, $orderId); //创建订单jspay
  174. } else if ($where['from'] == 'weixinh5') {
  175. $jsConfig = LaveRepository::h5PaySign($this->cid, $orderId);
  176. } else {
  177. $jsConfig = LaveRepository::wxPaySign($this->cid, $orderId);
  178. }
  179. } catch (\Exception $e) {
  180. return $this->error($e->getMessage());
  181. }
  182. $info['jsConfig'] = $jsConfig;
  183. return $this->success('订单创建成功', $info);
  184. } else $this->error(LaveModel::getErrorInfo());
  185. }
  186. /**
  187. * 签约订单支付
  188. * @param Request $request
  189. * @return mixed
  190. */
  191. public function paySign(Request $request)
  192. {
  193. var_dump(456);die();
  194. list($uni, $paytype, $from) = UtilService::postMore([
  195. ['uni', ''],
  196. ['paytype', '0'],
  197. ['from', 'weixin']
  198. ], $request, true);
  199. if (!$uni) $this->error('参数错误!');
  200. $order = LaveModel::where('cid', $this->cid)->where('order_id', $uni)->find();
  201. if (!$order)
  202. $this->error('订单不存在!');
  203. if ($order['paid'])
  204. $this->error('该订单已支付!');
  205. $order['pay_type'] = $paytype; //重新支付选择支付方式
  206. switch ($order['pay_type']) {
  207. case '0':
  208. try {
  209. if ($from == 'routine') {
  210. $jsConfig = LaveRepository::jsPaySign($this->cid, $order); //订单列表发起支付
  211. } else if ($from == 'weixinh5') {
  212. $jsConfig = LaveRepository::h5PaySign($this->cid, $order);
  213. } else {
  214. $jsConfig = LaveRepository::wxPaySign($this->cid, $order);
  215. }
  216. } catch (\Exception $e) {
  217. $this->error($e->getMessage());
  218. }
  219. $this->success('获取成功', $jsConfig);
  220. break;
  221. }
  222. return $this->error('支付方式错误');
  223. }
  224. }
  225. ?>