海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

595 lines
20 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Common\PayType;
  4. use App\Common\ProductStatus;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\AdminSetting;
  7. use App\Models\Agent;
  8. use App\Models\AgentProduct;
  9. use App\Models\AgentSetting;
  10. use App\Models\Coupon;
  11. use App\Models\OrderProductItem;
  12. use App\Models\Product;
  13. use App\Models\ProductSpec;
  14. use App\Models\SystemSetting;
  15. use App\Models\User;
  16. use App\Models\Order;
  17. use App\Service\OpenPlatform;
  18. use EasyWeChat\Factory;
  19. use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
  20. use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
  21. use EasyWeChat\Kernel\Http\StreamResponse;
  22. use GuzzleHttp\Exception\GuzzleException;
  23. use Illuminate\Http\Request;
  24. use Illuminate\Support\Facades\DB;
  25. use App\Common\OrderStatus as Status;
  26. use Illuminate\Support\Facades\Storage;
  27. /**
  28. * 订单
  29. * Class OrderController
  30. * @package App\Http\Controllers\Api
  31. */
  32. class OrderController extends Controller
  33. {
  34. //订单列表
  35. public function index(Request $request)
  36. {
  37. $formData = $request->only(['page', 'status']);
  38. $request->validate([
  39. 'page' => 'regex:/^\d+$/',
  40. 'status' => 'nullable|regex:/^\d+(,\d+)*$/'
  41. ], [
  42. 'page.regex' => '页码错误',
  43. 'status.regex' => '订单状态错误'
  44. ]);
  45. $order_list = Order::where('user_id', $this->user_id);
  46. if (isset($formData['status'])) {
  47. if (preg_match('/^\d+$/', $formData['status'])) {
  48. $order_list = $order_list->where('status', $formData['status']);
  49. } else {
  50. $order_list = $order_list->whereIn('status', explode(',', $formData['status']));
  51. }
  52. }
  53. $order_list = $order_list->select('id', 'agent_product_id', 'product_id', 'title', 'picture', 'price', 'num', 'status', 'timeout', 'created_at')
  54. ->orderBy('id', 'DESC')
  55. ->simplePaginate(15)
  56. ->toArray();
  57. $time = time();
  58. $prefix = Storage::disk('public')->url('');
  59. foreach ($order_list['data'] as &$v) {
  60. //图片加上域名
  61. if (strpos($v['picture'], $prefix) === false) {
  62. $v['picture'] = $prefix . $v['picture'];
  63. }
  64. if (strpos($v['picture'], $prefix) === false) {
  65. $v['picture'] = $prefix . $v['picture'];
  66. }
  67. if (!empty($v['pictures']) && is_array($v['pictures'])) {
  68. $v['pictures'] = array_map(function($item) use ($prefix) {
  69. return strpos($item, $prefix) === false ? $prefix . $item : $item;
  70. }, $v['pictures']);
  71. }
  72. //未付款订单提示剩余付款时间
  73. if ($v['timeout'] !== null) {
  74. $second = strtotime($v['timeout']) - $time;
  75. if ($second > 0) {
  76. $text_arr = [
  77. Status::UNPAID => '付款',
  78. Status::OFFLINE_UNPAID => '线下付款',
  79. Status::PAY_EARNEST => '付尾款',
  80. ];
  81. if (isset($text_arr[$v['status']])) {
  82. $v['status_text'] = '请在' . ceil($second / 60) . "分钟内" . ($text_arr[$v['status']] ?? '付款');
  83. }
  84. } else if ($second < 0 && $v['status'] == Status::PAY_EARNEST) {
  85. $v['status_text'] = '尾款支付已超时';
  86. } /*else { //此部分由定时处理
  87. $timeout_ids[] = $v['id'];
  88. $v['status'] = Status::CANCEL;
  89. $v['status_text'] = '已取消';
  90. //此部分已由定时任务处理
  91. Product::query()->find($v['product_id'])->increment('stock', $v['num']);
  92. }*/
  93. }
  94. }
  95. return $this->success($order_list);
  96. }
  97. //提交订单
  98. public function create(Request $request)
  99. {
  100. $formData = $request->input();
  101. $formData = array_map(fn($v) => trim($v), $formData); //过滤,删除首尾空
  102. //表单验证
  103. $pay_type_values = join(',', array_keys(PayType::array()));
  104. $request->validate([
  105. 'id' => ['required', 'regex:/^\d+$/'],
  106. 'name' => ['required', 'between:2,20'],
  107. 'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'],
  108. 'pay_type' => ['required', 'in:' . $pay_type_values],
  109. 'num' => ['required', 'min:1'],
  110. 'spec_id' => ['required', 'min:1', 'integer'],
  111. 'id_card' => ['regex:/^\d{17}[\dXx]$/'],
  112. ], [
  113. 'id.required' => '未指定产品ID',
  114. 'name.required' => '请输入联系人姓名',
  115. 'mobile.required' => '请输入联系手机号',
  116. 'id.regex' => '产品ID错误',
  117. 'name.between' => '联系人姓名在2~20字符之间',
  118. 'mobile.regex' => '请输入11位手机号',
  119. 'pay_type.required' => '请选择支付方式',
  120. 'pay_type.in' => '不存在此支付方式',
  121. 'num.required' => '请输入购买数量',
  122. 'num.min' => '购买数量输入错误',
  123. 'spec_id.*' => '请选择产品规格',
  124. 'id_card.regex' => '身份证号输入不正确',
  125. ]);
  126. $ap = AgentProduct::query()
  127. ->with(['coupon', 'product.spec', 'agentCloudProduct:id,price'])
  128. ->where('stock', '>=', $formData['num'])
  129. ->where(['id' => $formData['id'], 'status' => ProductStatus::ON_SALE, 'agent_id' => $this->agent_id]) //判断agent_id,防止新入驻小程序的演示产品被下单
  130. ->whereDoesntHave('agentProductItem', function ($query) {
  131. return $query->whereHas('product', function ($query) {
  132. return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE);
  133. });
  134. })
  135. ->first();
  136. if (!$ap || !$ap->product) {
  137. return $this->error('产品已下架或库存不足');
  138. }
  139. if (is_null($ap->product->spec) || !array_filter($ap->product->spec->toArray(), fn($v) => $v['id'] == $formData['spec_id'])) {
  140. return $this->error('你选择的产品规格不存在');
  141. }
  142. $order_info = [];
  143. //0:单品销售;1:组合销售
  144. if ($ap->type == 0) {
  145. //0:旅游线路、1:酒店、2:景区、3:餐厅、4:车队、5:单项 => admin_trans('product.options.publish_type')
  146. switch ($ap->product->type) {
  147. case 0:
  148. if (empty($formData['departure_time']) || !strtotime($formData['departure_time'])) {
  149. return $this->error('请选择出发时间');
  150. }
  151. if (empty($formData['return_time']) || !strtotime($formData['return_time'])) {
  152. return $this->error('请选择回程时间');
  153. }
  154. if (empty($formData['id_card'])) {
  155. return $this->error('请输入身份证号');
  156. }
  157. $order_info['departure_time'] = $formData['departure_time']; //出发时间
  158. $order_info['return_time'] = $formData['return_time']; //回程时间
  159. $order_info['id_card'] = $formData['id_card']; //身份证号
  160. $order_info['sex'] = $formData['sex'] ?? 0; //性别
  161. $order_info['age'] = $formData['age'] ?? 0; //年龄
  162. break;
  163. case 1:
  164. if (empty($formData['check_in_time']) || !strtotime($formData['check_in_time'])) {
  165. return $this->error('请选择入住时间');
  166. }
  167. if (empty($formData['check_out_time']) || !strtotime($formData['check_out_time'])) {
  168. return $this->error('请选择离店时间');
  169. }
  170. if (empty($formData['arrival_time']) || !strtotime($formData['arrival_time'])) {
  171. return $this->error('请选择到店时间');
  172. }
  173. if (empty($formData['id_card'])) {
  174. return $this->error('请输入身份证号');
  175. }
  176. $order_info['check_in_time'] = $formData['departure_time']; //入住时间
  177. $order_info['check_out_time'] = $formData['return_time']; //离店时间
  178. $order_info['arrival_time'] = $formData['arrival_time']; //到店时间
  179. $order_info['id_card'] = $formData['id_card']; //身份证号
  180. $order_info['sex'] = $formData['sex'] ?? 0; //性别
  181. $order_info['age'] = $formData['age'] ?? 0; //年龄
  182. break;
  183. case 2:
  184. if (empty($formData['enter_time']) || !strtotime($formData['enter_time'])) {
  185. return $this->error('请选择入园时间');
  186. }
  187. if (empty($formData['id_card'])) {
  188. return $this->error('请输入身份证号');
  189. }
  190. $order_info['enter_time'] = $formData['enter_time']; //到店时间
  191. $order_info['id_card'] = $formData['id_card']; //身份证号
  192. $order_info['sex'] = $formData['sex'] ?? 0; //性别
  193. $order_info['age'] = $formData['age'] ?? 0; //年龄
  194. break;
  195. }
  196. } else if ($ap->type == 1) {
  197. }
  198. //支付小程序的产品不允许购买
  199. if (AdminSetting::val('payee_appid') == Agent::where('id', $this->agent_id)->value('appid')) {
  200. return $this->error('系统出错了,购买失败~~');
  201. }
  202. $coupon_ids = [];
  203. if ($ap->coupon) {
  204. foreach ($ap->coupon as $v) {
  205. $coupon_ids[] = $v['id'];
  206. }
  207. }
  208. DB::beginTransaction();
  209. try {
  210. $price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap);
  211. //供应商产品表减库存
  212. $product_ids = explode(',', $ap->product_ids);
  213. $affect_row = Product::query()
  214. ->where('stock', '>=', $formData['num']) //乐观锁
  215. ->whereIn('id', $product_ids)
  216. ->decrement('stock', $formData['num']);
  217. if ($affect_row != count($product_ids)) {
  218. throw new \Exception('供应产品库存不足');
  219. }
  220. //产品规格减表减库存
  221. $affect_row = ProductSpec::query()
  222. ->where('stock', '>=', $formData['num']) //乐观锁
  223. ->where('id', $formData['spec_id'])
  224. ->decrement('stock', $formData['num']);
  225. if (!$affect_row) {
  226. throw new \Exception('你选择的产品规格库存不足');
  227. }
  228. //代理商产品表减库存
  229. $affect_row = AgentProduct::query()
  230. ->where('stock', '>=', $formData['num']) //乐观锁
  231. ->where('id', $ap->id)
  232. ->decrement('stock', $formData['num']);
  233. if (!$affect_row) {
  234. throw new \Exception('商户产品库存不足');
  235. }
  236. //未付款时定金/订金的超时时间依然使用默认的订单超时时间,付定金/订金之后才使用定金超时时间
  237. $order_timeout = AgentSetting::val($this->agent_id, 'order_timeout') ?? 60; //默认60分钟
  238. $timeout = date('Y-m-d H:i:s', time() + $order_timeout * 60); //60 * 分钟转为秒
  239. //处理预付金额
  240. if ($formData['pay_type'] == PayType::DEPOSIT_PAY) {
  241. //订金支付
  242. $prepayPrice = $ap->deposit;
  243. $prepayTimeout = $ap->deposit_timeout;
  244. } else if($formData['pay_type'] == PayType::EARNEST_PAY) {
  245. //定金支付
  246. $prepayPrice = $ap->earnest;
  247. $prepayTimeout = $ap->earnest_timeout;
  248. }
  249. // 存入订单表
  250. $order = Order::query()->create([
  251. 'user_id' => $this->user_id,
  252. 'agent_id' => $this->agent_id,
  253. 'order_no' => $this->getOrderNo(),
  254. 'num' => $formData['num'],
  255. 'price' => $price,
  256. 'name' => $formData['name'],
  257. 'mobile' => $formData['mobile'],
  258. 'title' => $ap->title,
  259. 'picture' => $ap->picture,
  260. 'agent_product_id' => $ap->id,
  261. 'product_id' => $ap->product_id,
  262. 'product_ids' => $ap->product->product_ids ?? $ap->product_id,
  263. 'status' => $formData['pay_type'] == PayType::OFFLINE ? Status::OFFLINE_UNPAID : Status::UNPAID,
  264. 'pay_type' => $formData['pay_type'],
  265. 'coupon_id' => join(',', $coupon_ids),
  266. 'guide_id' => $ap->guide_id,
  267. 'guide_price' => $ap->guide_price,
  268. 'timeout' => $timeout,
  269. 'agent_cloud_pid' => $ap->agent_cloud_pid,
  270. 'agent_cloud_price' => $ap->agentCloudProduct->price ?? 0,
  271. 'prepay_price ' => $prepayPrice ?? 0,
  272. 'prepay_timeout' => $prepayTimeout ?? 0,
  273. 'service_persons' => SystemSetting::val('single', 'price'),
  274. 'info' => $order_info,
  275. ]);
  276. //存入订单产品表
  277. $supplier_product_info = Product::whereIn('id', $product_ids)
  278. ->orderBy('id')->get(['type', 'id AS product_id', 'supplier_id', 'price', 'service_persons'])->toArray();
  279. $order_id = $order->id;
  280. $agent_id = $this->agent_id;
  281. $agent_product_id = $ap->id;
  282. foreach ($supplier_product_info as &$v) {
  283. $v['order_id'] = $order_id;
  284. $v['agent_id'] = $agent_id;
  285. $v['agent_product_id'] = $agent_product_id;
  286. $v['num'] = $formData['num'];
  287. if ($v['type'] == 0) { //TODO 此处未处理组合产品
  288. $v['product_spec_id'] = $formData['spec_id'];
  289. }
  290. unset($v['type']);
  291. }
  292. OrderProductItem::insert($supplier_product_info);
  293. DB::commit();
  294. } catch (\Exception $e) {
  295. DB::rollBack();
  296. return $this->error($e->getMessage());
  297. }
  298. if ($formData['pay_type'] == PayType::OFFLINE) { //线下支付
  299. return $this->success(['id' => $order_id], '操作成功,请及时联系客服付款');
  300. } else { //在线支付或定金支付
  301. /*$config = $this->payConfig($order, $price);
  302. if (!empty($config['paySign'])) {
  303. return $this->success($config);
  304. } else {
  305. return $this->error($config['err_code_des'] ?? join(',', $config));
  306. }*/
  307. // 跳转支付专用
  308. return $this->success(['id' => $order->id, 'jump' => true, 'jump_appid' => AdminSetting::val('payee_appid')]);
  309. }
  310. }
  311. //申请退款
  312. public function refund(Request $request)
  313. {
  314. $formData = $request->only(['id', 'desc', 'pictures']);
  315. $request->validate([
  316. 'id' => 'required|integer',
  317. 'desc' => 'required|string',
  318. 'pictures' => 'nullable|array',
  319. ], [
  320. '*.required' => '内容输入不完整',
  321. 'pictures.array' => '图片必须是数组',
  322. ]);
  323. //去掉图片地址前的域名
  324. $prefix = Storage::disk('public')->url('');
  325. foreach ($formData['pictures'] as &$v) {
  326. $v = str_replace($prefix, '', $v);
  327. }
  328. $order = Order::firstWhere(['id' => $formData['id'], 'user_id' => $this->user_id]);
  329. if (!$order) {
  330. return $this->error('订单不存在');
  331. }
  332. //订金/定金/首付款不允许退款,只有付全款才能申请退款
  333. if (!in_array($order->status, [Status::PAID, Status::PAID_RETAINAGE])) {
  334. return $this->error('当前订单状态不允许退款');
  335. }
  336. $order->refund_info = [
  337. 'desc' => strip_tags($formData['desc']),
  338. 'refund_no' => $this->getOrderNo(), //退款单号
  339. 'pictures' => $formData['pictures'] ?? [],
  340. 'old_status' => $order->status,
  341. ];
  342. $order->status = Status::REFUNDING;
  343. $order->save();
  344. return $this->success();
  345. }
  346. //获取应付金额及相关产品信息
  347. public function getPrice(Request $request)
  348. {
  349. $formData = $request->only(['id', 'num', 'pay_type']);
  350. $request->validate([
  351. 'id' => 'required|integer',
  352. 'num' => 'required|integer',
  353. 'pay_type' => 'required|integer',
  354. ], [
  355. '*.required' => '参数缺失',
  356. '*.integer' => '参数类型错误',
  357. ]);
  358. if (!$formData['num'] || $formData['num'] < 1) {
  359. return $this->error('未指定产品数量');
  360. }
  361. $ap = AgentProduct::query()
  362. ->has('product')
  363. ->with('coupon:agent_product_id,type,detail,agent_id,tag,start_at,end_at')
  364. ->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures', 'earnest', 'earnest_timeout', 'deposit', 'deposit_timeout']);
  365. if (!$ap) {
  366. return $this->error('产品信息不存在');
  367. }
  368. $prefix = Storage::disk('public')->url('');
  369. $ap->pictures = array_map(fn($v) => $prefix . $v, $ap->pictures);
  370. //如果是线下支付,显示的价格跟在线全款支付价格一样
  371. if ($formData['pay_type'] == PayType::OFFLINE) {
  372. $formData['pay_type'] = PayType::ONLINE;
  373. }
  374. $ap->final_price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap);
  375. $ap->num = $formData['num'];
  376. return $this->success($ap);
  377. }
  378. //订单支付(在订单列表发起)
  379. public function pay(Request $request)
  380. {
  381. $id = (int)request()->input('id');
  382. //订单信息
  383. $order = Order::query()
  384. ->with('agentProduct')
  385. ->where(['user_id' => $this->user_id, 'agent_id' => $this->agent_id])
  386. ->whereRaw('`timeout` >= NOW()')
  387. ->whereIn('status', [Status::UNPAID, Status::PAY_EARNEST])
  388. ->find($id);
  389. if (!$order) {
  390. return $this->error('订单已支付或已超时');
  391. }
  392. // 跳转支付专用
  393. return $this->success(['id' => $id, 'jump' => true, 'jump_appid' => AdminSetting::val('payee_appid')]);
  394. /*$ap = AgentProduct::with('coupon')->find($order->agent_product_id);
  395. //如果已经付定金或首付款,则仅支付尾款
  396. if ($order->status == Status::PAY_EARNEST) {
  397. $price = $order->price - $order->paid_money;
  398. } else {
  399. $price = $this->calc($order->price, $order->num, $order->pay_type, $ap);
  400. }
  401. $config = $this->payConfig($order, $price);
  402. if (!empty($config['paySign'])) {
  403. return $this->success($config);
  404. } else {
  405. return $this->error($config['err_code_des'] ?? join(',', $config));
  406. }*/
  407. }
  408. //获取支付配置信息
  409. private function payConfig($order, $price)
  410. {
  411. //用户openid
  412. $openid = User::query()->where('id', $this->user_id)->value('openid'); //此处要用where,value()用find有BUG
  413. //代理商信息
  414. $agent = Agent::query()->find($this->agent_id);
  415. $config = config('wechat.payment.default');
  416. $config = array_merge($config, [
  417. 'app_id' => $agent->appid,
  418. 'mch_id' => $agent->mchid,
  419. 'key' => $agent->mchkey,
  420. ]);
  421. $app = Factory::payment($config);
  422. try {
  423. $result = $app->order->unify([
  424. 'body' => mb_strcut($order->title, 0, 127),
  425. 'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付
  426. 'total_fee' => round($price * 100), //支付金额单位为分
  427. 'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  428. 'trade_type' => 'JSAPI',
  429. 'openid' => $openid,
  430. 'profit_sharing' => 'Y', //Y分账,N不分账,默认不分账,Y大写
  431. ]);
  432. } catch (InvalidArgumentException | InvalidConfigException | GuzzleException $e) {
  433. return ['error' => $e->getMessage(), 'file' => basename($e->getFile()), 'line' => $e->getLine()];
  434. }
  435. if (empty($result['prepay_id'])) {
  436. return $result;
  437. }
  438. $jssdk = $app->jssdk;
  439. return $jssdk->bridgeConfig($result['prepay_id'], false) + ['id' => $order->id, 'order_no' => $order->order_no]; // 返回数组
  440. }
  441. //订单详情
  442. public function show()
  443. {
  444. $id = (int)request()->input('id');
  445. $fields = ['id', 'agent_id', 'order_no', 'agent_product_id', 'num', 'price', 'name', 'mobile', 'title', 'picture', 'status',
  446. 'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'verify_code', 'created_at'];
  447. $order = Order::with('agent:id,appid,appsecret')
  448. ->where('user_id', $this->user_id)
  449. ->find($id, $fields);
  450. if (!$order) {
  451. return $this->error('订单不存在');
  452. }
  453. //订单ID和核销码拼接,查询时通过订单ID和核销码来查询,这样核销码不用建索引
  454. $order->verify_code = $order->verify_code ? $order->id . '-' . $order->verify_code : '';
  455. //如果有核销码,生成核销二维码
  456. if ($order->verify_code) {
  457. $app = new OpenPlatform();
  458. $refreshToken = $app->refreshToken($order->agent->appid);
  459. if (!$refreshToken) {
  460. return $this->error('获取refresh_token失败');
  461. }
  462. $app = $app->miniProgram($order->agent->appid, $refreshToken);
  463. //由于参数最多只能32个字符,故通过下面这种方式传参
  464. //pt表示使用普通订单,使用api/verification/verify接口核销;
  465. //hy表示行业产品订单,使用api/verification/industry_verify接口核销
  466. $response = $app->app_code->getUnlimit('pt' . $order->verify_code, ['page' => 'pages/verification/index']);
  467. if ($response instanceof StreamResponse) {
  468. $filename = $response->saveAs(storage_path('app/public/verify_code'), $order->verify_code);
  469. $order->verify_qrcode = Storage::disk('public')->url('verify_code/' . $filename);
  470. }
  471. }
  472. unset($order->agent, $order->agent_id); //必须unset掉$order->agent,否则会造成appsecret泄漏
  473. $order->coupon = Coupon::query()
  474. ->whereIn('id', $order->coupon_id)
  475. ->where(['agent_id' => $this->agent_id, 'agent_product_id' => $order->agent_product_id,])
  476. ->get(['tag']);
  477. return $this->success($order);
  478. }
  479. /**
  480. * 计算最终价格(扣除优惠券之后的价格)
  481. * $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式
  482. * @param float $price
  483. * @param float $num
  484. * @param int $pay_type
  485. * @param AgentProduct $agent_product
  486. * @return float
  487. */
  488. private function calc(float $price, float $num, int $pay_type, AgentProduct $agent_product): float
  489. {
  490. /** 修改需要同步修改sharePay里面的 */
  491. //根据支付方式计算价格
  492. if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
  493. if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) {
  494. return $agent_product->deposit;
  495. } else if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) {
  496. return $agent_product->earnest;
  497. }
  498. }
  499. $total_price = $price * $num;
  500. /*//没有任何优惠券时直接返回最终价
  501. if ($coupon && $coupon->isEmpty()) {
  502. return $total_price;
  503. }
  504. $coupon = $coupon->toArray();
  505. foreach ($coupon as $v) {
  506. // 未判断优惠券有效期
  507. if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减
  508. if ($total_price >= $v['detail']['full']) {
  509. $total_price -= $v['detail']['reduction'];
  510. }
  511. } else if ($v['type'] == 2 && !empty($v['detail']['discount'])) { //打折
  512. $total_price *= $v['detail']['discount'];
  513. }
  514. }*/
  515. return round($total_price, 2);
  516. }
  517. // 生成订单号
  518. private function getOrderNo(): string
  519. {
  520. list($micro, $sec) = explode(' ', microtime());
  521. $micro = str_pad(floor($micro * 1000000), 6, 0, STR_PAD_LEFT);
  522. return date('ymdHis', $sec) . $micro . mt_rand(1000, 9999);
  523. }
  524. }