OrderService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace addons\Agent\backend\services;
  3. use common\enums\OrderStatusEnum;
  4. use common\enums\RefundStatusEnum;
  5. use common\enums\RefundTypeEnum;
  6. use common\enums\StatusEnum;
  7. use common\models\order\Order;
  8. use common\models\order\OrderDetail;
  9. use common\models\order\OrderRefund;
  10. class OrderService extends \services\common\BaseService
  11. {
  12. /**
  13. * @param array $get
  14. *
  15. * @return array
  16. */
  17. public function getOrderDetails(array $get): array
  18. {
  19. if (!isset($get['order_no']) || $get['order_no'] === '') {
  20. return [];
  21. }
  22. $orderId = Order::find()
  23. ->where([
  24. 'order_no' => $get['order_no'],
  25. 'mall_id' => $this->mall_id,
  26. 'status' => StatusEnum::ENABLED,
  27. 'pay_status' => OrderStatusEnum::PAY,
  28. ])
  29. ->andWhere(['<>', 'order_status', OrderStatusEnum::REPEAL])
  30. ->select('id')
  31. ->scalar();
  32. if (empty($orderId)) {
  33. return [];
  34. }
  35. // 排除售后完成(不包含换货)的order_detail_id
  36. $refundOrderDetailIds = OrderRefund::find()
  37. ->where([
  38. 'order_id' => $orderId,
  39. 'status' => StatusEnum::ENABLED,
  40. 'refund_status' => RefundStatusEnum::FINISH,
  41. 'type' => [RefundTypeEnum::MONEY, RefundTypeEnum::MONEY_AND_PRODUCT]
  42. ])
  43. ->select('order_detail_id')
  44. ->column();
  45. $where = [
  46. [
  47. 'order_id' => $orderId,
  48. 'status' => StatusEnum::ENABLED,
  49. ],
  50. ['<>', 'order_status', OrderStatusEnum::REPEAL]
  51. ];
  52. if ($refundOrderDetailIds) {
  53. $where[] = ['not in', 'id', $refundOrderDetailIds];
  54. }
  55. return OrderDetail::lists([
  56. 'where' => $where,
  57. 'select' => 'id, order_id, goods_id, goods_name, pic_url, num'
  58. ]);
  59. }
  60. }