OrderController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-30
  6. * Time: 下午10:58
  7. */
  8. namespace App\Http\Controllers\Api\V1;
  9. use App\Models\Nurse;
  10. use App\Models\Order;
  11. use App\Models\OrderNurse;
  12. use App\Models\OrderPack;
  13. use App\Models\OrderPatient;
  14. use App\Models\OrderVaccine;
  15. use App\Models\Patient;
  16. use App\Models\Payment;
  17. use App\Models\ServicePack;
  18. use App\Models\TimePeriod;
  19. use App\Models\User;
  20. use App\Models\UserCoupon;
  21. use App\Models\Vaccine;
  22. use EasyWeChat\Factory;
  23. use DB;
  24. class OrderController extends AuthController
  25. {
  26. public function consultPlaceOrder()
  27. {
  28. $req = request()->post();
  29. $this->validate(request(), [
  30. 'payment_type' => 'required|in:1,2',
  31. 'product_type' => 'required|in:1,2',
  32. 'docter_id' => 'required|integer',
  33. 'patient_id' => 'required|integer',
  34. 'total_amount' => 'required|integer',
  35. 'user_coupon_id' => 'integer',
  36. 'phone' => 'required_if:product_type,1',
  37. 'phone_minutes' => 'required_if:product_type,1|integer',
  38. 'symptoms' => 'required_if:product_type,2|max:2000',
  39. 'medical_imgs' => 'required_if:product_type,2|json|max:3000',
  40. 'pay_password|支付密码' => 'integer',
  41. ]);
  42. $user = $this->user;
  43. if (!empty($req['pay_password'])) {
  44. if (empty($user['pay_password'])) {
  45. return out(null, 60010, '未设置支付密码');
  46. }
  47. if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
  48. return out(null, 10001, '密码错误');
  49. }
  50. }
  51. $discount_amount = 0;
  52. if (!empty($req['user_coupon_id'])) {
  53. //计算优惠金额
  54. $discount_amount = UserCoupon::getDiscountAmount($req['user_coupon_id'], $user['id'], $req['total_amount'], $req['product_type']);
  55. }
  56. $payment_amount = $req['total_amount'] - $discount_amount;
  57. $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
  58. if ($req['payment_type'] == 2) {
  59. if ($user['balance'] < $payment_amount) {
  60. return out(null, 601, '余额不足');
  61. }
  62. }
  63. if ($req['payment_type'] == 2 && $payment_amount > 0 && empty($req['pay_password'])) {
  64. return out(null, 10011, '请输入支付密码');
  65. }
  66. $order_status = $payment_status = 1;
  67. $payment_time = 0;
  68. if ($payment_amount == 0 || $req['payment_type'] == 2) {
  69. $order_status = $payment_status = 2;
  70. $payment_time = time();
  71. }
  72. $config = null;
  73. DB::beginTransaction();
  74. try {
  75. //保存订单数据
  76. $order = Order::create([
  77. 'user_id' => $user['id'],
  78. 'payment_type' => $req['payment_type'],
  79. 'product_type' => $req['product_type'],
  80. 'docter_id' => $req['docter_id'],
  81. 'total_amount' => $req['total_amount'],
  82. 'payment_amount' => $payment_amount,
  83. 'discount_amount' => $discount_amount,
  84. 'patient_id' => $req['patient_id'],
  85. 'order_status' => $order_status,
  86. 'payment_status' => $payment_status,
  87. 'payment_time' => $payment_time,
  88. ]);
  89. $order_sn = build_sn($order['id']);
  90. Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
  91. //保存订单患者信息
  92. $addPatient = Patient::select(['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'info', 'card_type', 'card_number', 'card_img_url', 'card_back_img_url', 'email', 'phone as patient_phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'])->where('id', $req['patient_id'])->first()->getOriginal();
  93. $addPatient['order_id'] = $order['id'];
  94. $addPatient['patient_id'] = $req['patient_id'];
  95. if ($req['product_type'] == 1) {
  96. $addPatient['phone'] = $req['phone'];
  97. $addPatient['phone_minutes'] = $req['phone_minutes'];
  98. }
  99. elseif ($req['product_type'] == 2) {
  100. $addPatient['symptoms'] = $req['symptoms'];
  101. $addPatient['medical_imgs'] = $req['medical_imgs'];
  102. }
  103. OrderPatient::create($addPatient);
  104. //判断是微信支付
  105. if ($req['payment_type'] == 1) {
  106. //生成支付交易单
  107. if ($payment_amount > 0) {
  108. $trade_sn = build_sn($order['id'], 3, 'T');
  109. $payBody = '超级宝妈-'.config('config.product_type_map')[$req['product_type']];
  110. Payment::create([
  111. 'user_id' => $user['id'],
  112. 'order_id' => $order['id'],
  113. 'trade_sn' => $trade_sn,
  114. 'amount' => $payment_amount,
  115. 'remark' => $payBody,
  116. ]);
  117. //请求支付
  118. $payment = Factory::payment(config('config.wechat_pay'));
  119. $result = $payment->order->unify([
  120. 'body' => $payBody,
  121. 'out_trade_no' => $trade_sn,
  122. 'total_fee' => $payment_amount,
  123. 'trade_type' => 'JSAPI',
  124. 'openid' => $user['openid'],
  125. ]);
  126. if (empty($result['prepay_id'])) {
  127. $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
  128. return out(null, 702, $errorMsg);
  129. }
  130. $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
  131. }
  132. }
  133. //判断是余额支付
  134. elseif ($req['payment_type'] == 2) {
  135. if ($payment_amount > 0) {
  136. //改变用户余额
  137. $change_amount = 0 - $payment_amount;
  138. User::changeBalance($user['id'], $change_amount, 1, $order['id'], '咨询订单消费');
  139. Order::payCompletedHandle($order['id']);
  140. }
  141. }
  142. DB::commit();
  143. } catch (\Exception $e) {
  144. DB::rollBack();
  145. return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
  146. }
  147. return out($config);
  148. }
  149. public function appointPlaceOrder()
  150. {
  151. $req = request()->post();
  152. $this->validate(request(), [
  153. 'payment_type' => 'required|in:1,2',
  154. 'product_type' => 'required|in:3,4,5',
  155. 'patient_id' => 'required|integer',
  156. 'organization_id' => 'required|integer',
  157. 'schedule_date' => 'required|date',
  158. 'time_period_id' => 'required|integer',
  159. 'total_amount' => 'required|integer',
  160. 'user_coupon_id' => 'integer',
  161. 'docter_id' => 'required_if:product_type,3|integer',
  162. 'vaccine_id' => 'required_if:product_type,4|integer',
  163. 'nurse_ids' => 'required_if:product_type,5|json',
  164. 'pay_password|支付密码' => 'required_if:payment_type,2|integer',
  165. ]);
  166. $user = $this->user;
  167. if (!empty($req['pay_password'])) {
  168. if (empty($user['pay_password'])) {
  169. return out(null, 60010, '未设置支付密码');
  170. }
  171. if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
  172. return out(null, 10001, '密码错误');
  173. }
  174. }
  175. $product_type = $req['product_type'];
  176. if ($req['product_type'] == 4) {
  177. $vaccine = Vaccine::select(['type'])->where('id', $req['vaccine_id'])->first();
  178. if ($vaccine['type'] == 2) {
  179. if (empty($req['total_amount'])) {
  180. return out(null, 10001, '总价不能为0');
  181. }
  182. }
  183. }
  184. $discount_amount = 0;
  185. if (!empty($req['user_coupon_id'])) {
  186. //计算优惠金额
  187. $discount_amount = UserCoupon::getDiscountAmount($req['user_coupon_id'], $user['id'], $req['total_amount'], $product_type);
  188. }
  189. $payment_amount = $req['total_amount'] - $discount_amount;
  190. $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
  191. if ($req['payment_type'] == 2) {
  192. if ($user['balance'] < $payment_amount) {
  193. return out(null, 601, '余额不足');
  194. }
  195. }
  196. $order_status = $payment_status = 1;
  197. $payment_time = 0;
  198. if ($payment_amount == 0 || $req['payment_type'] == 2) {
  199. $order_status = 3;
  200. $payment_status = 2;
  201. $payment_time = time();
  202. }
  203. $config = null;
  204. DB::beginTransaction();
  205. try {
  206. //保存订单数据
  207. $order = Order::create([
  208. 'user_id' => $user['id'],
  209. 'docter_id' => $req['docter_id'] ?? 0,
  210. 'patient_id' => $req['patient_id'],
  211. 'organization_id' => $req['organization_id'],
  212. 'payment_type' => $req['payment_type'],
  213. 'product_type' => $product_type,
  214. 'order_status' => $order_status,
  215. 'payment_status' => $payment_status,
  216. 'total_amount' => $req['total_amount'],
  217. 'payment_amount' => $payment_amount,
  218. 'discount_amount' => $discount_amount,
  219. 'payment_time' => $payment_time,
  220. ]);
  221. $order_sn = build_sn($order['id']);
  222. Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
  223. //保存订单患者信息
  224. $addPatient = Patient::select(['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'info', 'card_type', 'card_number', 'card_img_url', 'card_back_img_url', 'email', 'phone as patient_phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'])->where('id', $req['patient_id'])->first()->getOriginal();
  225. $addPatient['order_id'] = $order['id'];
  226. $addPatient['patient_id'] = $req['patient_id'];
  227. $addPatient['organization_id'] = $req['organization_id'];
  228. $addPatient['time_period_id'] = $req['time_period_id'];
  229. $timePeriod = TimePeriod::where('id', $req['time_period_id'])->first();
  230. $addPatient['appoint_start_time'] = strtotime($req['schedule_date'].' '.$timePeriod['start_time_period'].':00');
  231. $addPatient['appoint_end_time'] = strtotime($req['schedule_date'].' '.$timePeriod['end_time_period'].':00');
  232. $orderPatient = OrderPatient::create($addPatient);
  233. //保存订单疫苗信息
  234. if ($req['product_type'] == 4) {
  235. $addVaccine = Vaccine::select(['id as vaccine_id', 'type as vaccine_type', 'price as vaccine_price', 'name as vaccine_name', 'remark as vaccine_remark', 'supplier as vaccine_supplier'])->where('id', $req['vaccine_id'])->first()->getOriginal();
  236. $addVaccine['order_id'] = $order['id'];
  237. $addVaccine['order_patient_id'] = $orderPatient['id'];
  238. OrderVaccine::create($addVaccine);
  239. }
  240. //保存儿保订单信息
  241. if ($req['product_type'] == 5) {
  242. $nurse_ids = json_decode($req['nurse_ids'], true);
  243. foreach ($nurse_ids as $k => $v) {
  244. $addNurse = Nurse::select(['id as nurse_id', 'price as nurse_price', 'name as nurse_name', 'remark as nurse_remark'])->where('id', $v)->first()->getOriginal();
  245. $addNurse['order_id'] = $order['id'];
  246. $addNurse['order_patient_id'] = $orderPatient['id'];
  247. OrderNurse::create($addNurse);
  248. }
  249. }
  250. //判断是微信支付
  251. if ($req['payment_type'] == 1) {
  252. //生成支付交易单
  253. if ($payment_amount > 0) {
  254. $trade_sn = build_sn($order['id'], 3, 'T');
  255. $payBody = '超级宝妈-'.config('config.product_type_map')[$product_type];
  256. Payment::create([
  257. 'user_id' => $user['id'],
  258. 'order_id' => $order['id'],
  259. 'trade_sn' => $trade_sn,
  260. 'amount' => $payment_amount,
  261. 'remark' => $payBody,
  262. ]);
  263. //请求支付
  264. $payment = Factory::payment(config('config.wechat_pay'));
  265. $result = $payment->order->unify([
  266. 'body' => $payBody,
  267. 'out_trade_no' => $trade_sn,
  268. 'total_fee' => $payment_amount,
  269. 'trade_type' => 'JSAPI',
  270. 'openid' => $user['openid'],
  271. ]);
  272. if (empty($result['prepay_id'])) {
  273. $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
  274. return out(null, 702, $errorMsg);
  275. }
  276. $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
  277. }
  278. }
  279. //判断是余额支付
  280. elseif ($req['payment_type'] == 2) {
  281. if ($payment_amount > 0) {
  282. //改变用户余额
  283. $change_amount = 0 - $payment_amount;
  284. User::changeBalance($user['id'], $change_amount, 1, $order['id'], '预约订单消费');
  285. Order::payCompletedHandle($order['id']);
  286. }
  287. }
  288. DB::commit();
  289. } catch (\Exception $e) {
  290. DB::rollBack();
  291. return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
  292. }
  293. return out($config);
  294. }
  295. public function packPlaceOrder()
  296. {
  297. $req = request()->post();
  298. $this->validate(request(), [
  299. 'payment_type' => 'required|in:1,2',
  300. 'patient_id' => 'required|integer',
  301. 'total_amount' => 'required|integer',
  302. 'user_coupon_id' => 'integer',
  303. 'service_pack_id' => 'required|integer',
  304. 'is_security' => 'required|in:0,1',
  305. 'guardian_name' => 'required|max:50',
  306. 'relationship_type' => 'required|integer',
  307. 'pay_password|支付密码' => 'required_if:payment_type,2|integer',
  308. ]);
  309. $user = $this->user;
  310. if (!empty($req['pay_password'])) {
  311. if (empty($user['pay_password'])) {
  312. return out(null, 60010, '未设置支付密码');
  313. }
  314. if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
  315. return out(null, 10001, '密码错误');
  316. }
  317. }
  318. $discount_amount = 0;
  319. if (!empty($req['user_coupon_id'])) {
  320. //计算优惠金额
  321. $discount_amount = UserCoupon::getDiscountAmount($req['user_coupon_id'], $user['id'], $req['total_amount'], 6);
  322. }
  323. $addPatient = Patient::select(['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'info', 'card_type', 'card_number', 'card_img_url', 'card_back_img_url', 'email', 'phone as patient_phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'])->where('id', $req['patient_id'])->first()->getOriginal();
  324. if (empty($addPatient['card_img_url'])) {
  325. return out(null, 70011, '该患者未上传身份证');
  326. }
  327. $payment_amount = $req['total_amount'] - $discount_amount;
  328. $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
  329. if ($req['payment_type'] == 2) {
  330. if ($user['balance'] < $payment_amount) {
  331. return out(null, 601, '余额不足');
  332. }
  333. }
  334. $order_status = $payment_status = 1;
  335. $payment_time = 0;
  336. if ($payment_amount == 0 || $req['payment_type'] == 2) {
  337. $order_status = 3;
  338. $payment_status = 2;
  339. $payment_time = time();
  340. }
  341. $config = null;
  342. DB::beginTransaction();
  343. try {
  344. //保存订单数据
  345. $order = Order::create([
  346. 'user_id' => $user['id'],
  347. 'patient_id' => $req['patient_id'],
  348. 'payment_type' => $req['payment_type'],
  349. 'product_type' => 6,
  350. 'total_amount' => $req['total_amount'],
  351. 'payment_amount' => $payment_amount,
  352. 'discount_amount' => $discount_amount,
  353. 'order_status' => $order_status,
  354. 'payment_status' => $payment_status,
  355. 'payment_time' => $payment_time,
  356. ]);
  357. $order_sn = build_sn($order['id']);
  358. Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
  359. //保存订单患者信息
  360. $addPatient['order_id'] = $order['id'];
  361. $addPatient['patient_id'] = $req['patient_id'];
  362. OrderPatient::create($addPatient);
  363. //保存订单服务包表
  364. $addPack = ServicePack::select(['id as service_pack_id', 'name as pack_name', 'intro as pack_intro', 'price as pack_price', 'insurance_policy', 'insurance_img_url', 'team_id', 'phone_minutes', 'chat_num', 'appoint_num', 'vaccine_limit_amount', 'nurses_limit_amount', 'effective_days'])->where('id', $req['service_pack_id'])->first()->getOriginal();
  365. $addPack['order_id'] = $order['id'];
  366. $addPack['is_security'] = $req['is_security'];
  367. $addPack['guardian_name'] = $req['guardian_name'];
  368. $addPack['relationship_type'] = $req['relationship_type'];
  369. $addPack['start_time'] = time();
  370. $addPack['end_time'] = time() + $addPack['effective_days']*24*3600;
  371. OrderPack::create($addPack);
  372. //判断是微信支付
  373. if ($req['payment_type'] == 1) {
  374. //生成支付交易单
  375. if ($payment_amount > 0) {
  376. $trade_sn = build_sn($order['id'], 3, 'T');
  377. $payBody = '超级宝妈-'.config('config.product_type_map')[6];
  378. Payment::create([
  379. 'user_id' => $user['id'],
  380. 'order_id' => $order['id'],
  381. 'trade_sn' => $trade_sn,
  382. 'amount' => $payment_amount,
  383. 'remark' => $payBody,
  384. ]);
  385. //请求支付
  386. $payment = Factory::payment(config('config.wechat_pay'));
  387. $result = $payment->order->unify([
  388. 'body' => $payBody,
  389. 'out_trade_no' => $trade_sn,
  390. 'total_fee' => $payment_amount,
  391. 'trade_type' => 'JSAPI',
  392. 'openid' => $user['openid'],
  393. ]);
  394. if (empty($result['prepay_id'])) {
  395. $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
  396. return out(null, 702, $errorMsg);
  397. }
  398. $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
  399. }
  400. }
  401. //判断是余额支付
  402. elseif ($req['payment_type'] == 2) {
  403. if ($payment_amount > 0) {
  404. //改变用户余额
  405. $change_amount = 0 - $payment_amount;
  406. User::changeBalance($user['id'], $change_amount, 1, $order['id'], '购买服务包');
  407. Order::payCompletedHandle($order['id']);
  408. }
  409. }
  410. DB::commit();
  411. } catch (\Exception $e) {
  412. DB::rollBack();
  413. return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
  414. }
  415. return out($config);
  416. }
  417. public function orderList()
  418. {
  419. $req = request()->post();
  420. $this->validate(request(), [
  421. 'list_type' => 'required|in:0,1,2',
  422. 'product_type' => 'integer',
  423. 'order_status' => 'integer',
  424. 'time_sort' => 'in:0,1',
  425. 'is_pack_expire' => 'in:0,1,2',
  426. ]);
  427. $user = $this->user;
  428. $builder = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack', 'orderNurse', 'orderVaccine', 'organization.docter', 'suggest'])->where('user_id', $user['id']);
  429. if (!empty($req['product_type'])) {
  430. $builder->where('product_type', $req['product_type']);
  431. }
  432. else {
  433. if (!empty($req['list_type'])) {
  434. if ($req['list_type'] == 1) {
  435. $builder->whereIn('product_type', [1,2]);
  436. }
  437. elseif ($req['list_type'] == 2) {
  438. $builder->whereIn('product_type', [3,4,5]);
  439. }
  440. }
  441. else {
  442. $builder->where('product_type', '<', 7);
  443. }
  444. }
  445. if (!empty($req['order_status'])) {
  446. $builder->where('order_status', $req['order_status']);
  447. }
  448. if (!empty($req['is_pack_expire'])) {
  449. $tmpBuilder = OrderPack::join('orders as o', 'o.id', '=', 'order_packs.order_id')->where('o.user_id', $user['id']);
  450. if ($req['is_pack_expire'] == 1) {
  451. $tmpBuilder->where('order_packs.end_time', '<', time());
  452. }
  453. else {
  454. $tmpBuilder->where('order_packs.end_time', '>=', time());
  455. }
  456. $order_ids = $tmpBuilder->pluck('o.id')->toArray();
  457. $builder->whereIn('id', $order_ids);
  458. }
  459. if (!empty($req['time_sort'])) {
  460. $builder->orderBy('id', 'desc');
  461. }
  462. else {
  463. $builder->orderBy('id', 'asc');
  464. }
  465. $data = $builder->paginate();
  466. return out($data);
  467. }
  468. public function orderDetail()
  469. {
  470. $req = request()->post();
  471. $this->validate(request(), [
  472. 'order_id' => 'required|integer'
  473. ]);
  474. $user = $this->user;
  475. $data = Order::with(['docter.office', 'docter.qualification', 'orderPatient', 'orderPack.team.docter', 'orderNurse', 'orderVaccine', 'organization.docter', 'suggest'])->where('id', $req['order_id'])->where('user_id', $user['id'])->first();
  476. return out($data);
  477. }
  478. public function topup()
  479. {
  480. $req = request()->post();
  481. $this->validate(request(), [
  482. 'amount' => 'required|integer',
  483. ]);
  484. $user = $this->user;
  485. DB::beginTransaction();
  486. try {
  487. //保存订单数据
  488. $order = Order::create([
  489. 'user_id' => $user['id'],
  490. 'product_type' => 7,
  491. 'total_amount' => $req['amount'],
  492. 'payment_amount' => $req['amount'],
  493. ]);
  494. $order_sn = build_sn($order['id']);
  495. Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
  496. //生成支付交易单
  497. $trade_sn = build_sn($order['id'], 3, 'T');
  498. $payBody = '超级宝妈-'.config('config.product_type_map')[7];
  499. Payment::create([
  500. 'user_id' => $user['id'],
  501. 'order_id' => $order['id'],
  502. 'trade_sn' => $trade_sn,
  503. 'amount' => $req['amount'],
  504. 'remark' => $payBody,
  505. ]);
  506. //请求支付
  507. $payment = Factory::payment(config('config.wechat_pay'));
  508. $result = $payment->order->unify([
  509. 'body' => $payBody,
  510. 'out_trade_no' => $trade_sn,
  511. 'total_fee' => $req['amount'],
  512. 'trade_type' => 'JSAPI',
  513. 'openid' => $user['openid'],
  514. ]);
  515. if (empty($result['prepay_id'])) {
  516. $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
  517. return out(null, 702, $errorMsg);
  518. }
  519. $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
  520. DB::commit();
  521. } catch (\Exception $e) {
  522. DB::rollBack();
  523. return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
  524. }
  525. return out($config);
  526. }
  527. }