ComboOrderService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Services\OrderService;
  3. use Elastic\Facades\ES;
  4. class ComboOrderService extends OrderBase
  5. {
  6. public function __construct($userId)
  7. {
  8. parent::__construct($userId);
  9. }
  10. /**
  11. * 创建订单 套餐
  12. *
  13. * @param $requestData
  14. * @return mixed
  15. * @throws \Exception
  16. */
  17. public function create($requestData)
  18. {
  19. $combo_id = $requestData['id'] ?? '';
  20. if (empty($combo_id)) {
  21. return responseMessage(2001, '参数错误!');
  22. }
  23. $comboInfo = ES::table('order_combo')->find($combo_id);
  24. if (empty($comboInfo)) {
  25. return responseMessage(2002, '该产品可能已删除,请重试!');
  26. }
  27. if ($comboInfo['status'] == 2) {
  28. return responseMessage(2003, '对不起,该产品已下架,不能购买!');
  29. }
  30. //
  31. $preferential_type = 1; // 会员卡
  32. $totalPrice = $comboInfo['price']; //所有的商品总金额
  33. $totalPreferentialPrice = 0;
  34. $order_amount_total = $totalPrice - $totalPreferentialPrice; //实际付款金额
  35. $order_status = 1; //1 未支付 2 已支付
  36. $order_no = 'CO' . createNewOrderNo();
  37. $info = [
  38. 'user_id' => $this->userId,
  39. 'order_no' => $order_no,
  40. 'order_status' => $order_status, //1 未支付
  41. 'product_amount_total' => $totalPrice, //所有购买商品总价
  42. 'order_amount_total' => $order_amount_total, //实际付款金额
  43. 'pay_amount_total' => 0,
  44. 'preferential_price' => $totalPreferentialPrice, //订单优惠金额(优惠券等)
  45. 'preferential_type' => $preferential_type, // //优惠类型 1优惠券 2会员卡
  46. 'pay_channel' => '',
  47. 'product_ids' => $comboInfo['product_ids'], // 服务商品,便于搜索
  48. ];
  49. $isSuccess = ES::table('order_combo')->toRefresh()->insertGetId($info);
  50. if ($isSuccess) {
  51. return responseMessage(1001, '订单创建成功!', $order_no);
  52. } else {
  53. return responseMessage(2008, '订单创建失败,请重试!');
  54. }
  55. }
  56. public function getOrderInfo($orderNo, $where = []): array
  57. {
  58. $find = ES::table('order_combo')->where('order_no', $orderNo);
  59. if ($where) {
  60. $find->where($where);
  61. }
  62. return $find->first();
  63. }
  64. }