123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Services\OrderService;
- use Elastic\Facades\ES;
- class ComboOrderService extends OrderBase
- {
- public function __construct($userId)
- {
- parent::__construct($userId);
- }
- /**
- * 创建订单 套餐
- *
- * @param $requestData
- * @return mixed
- * @throws \Exception
- */
- public function create($requestData)
- {
- $combo_id = $requestData['id'] ?? '';
- if (empty($combo_id)) {
- return responseMessage(2001, '参数错误!');
- }
- $comboInfo = ES::table('order_combo')->find($combo_id);
- if (empty($comboInfo)) {
- return responseMessage(2002, '该产品可能已删除,请重试!');
- }
- if ($comboInfo['status'] == 2) {
- return responseMessage(2003, '对不起,该产品已下架,不能购买!');
- }
- //
- $preferential_type = 1; // 会员卡
- $totalPrice = $comboInfo['price']; //所有的商品总金额
- $totalPreferentialPrice = 0;
- $order_amount_total = $totalPrice - $totalPreferentialPrice; //实际付款金额
- $order_status = 1; //1 未支付 2 已支付
- $order_no = 'CO' . createNewOrderNo();
- $info = [
- 'user_id' => $this->userId,
- 'order_no' => $order_no,
- 'order_status' => $order_status, //1 未支付
- 'product_amount_total' => $totalPrice, //所有购买商品总价
- 'order_amount_total' => $order_amount_total, //实际付款金额
- 'pay_amount_total' => 0,
- 'preferential_price' => $totalPreferentialPrice, //订单优惠金额(优惠券等)
- 'preferential_type' => $preferential_type, // //优惠类型 1优惠券 2会员卡
- 'pay_channel' => '',
- 'product_ids' => $comboInfo['product_ids'], // 服务商品,便于搜索
- ];
- $isSuccess = ES::table('order_combo')->toRefresh()->insertGetId($info);
- if ($isSuccess) {
- return responseMessage(1001, '订单创建成功!', $order_no);
- } else {
- return responseMessage(2008, '订单创建失败,请重试!');
- }
- }
- public function getOrderInfo($orderNo, $where = []): array
- {
- $find = ES::table('order_combo')->where('order_no', $orderNo);
- if ($where) {
- $find->where($where);
- }
- return $find->first();
- }
- }
|