Delivery.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model\order;
  13. use app\store\model\OrderAddress as OrderAddressModel;
  14. use app\common\model\order\Delivery as DeliveryModel;
  15. use app\common\service\Express as ExpressService;
  16. /**
  17. * 订单发货单模型
  18. * Class Delivery
  19. * @package app\store\model\order
  20. */
  21. class Delivery extends DeliveryModel
  22. {
  23. /**
  24. * 获取发货记录
  25. * @param array $param
  26. * @return \think\Paginator
  27. */
  28. public function getList(array $param): \think\Paginator
  29. {
  30. // 检索查询条件
  31. $filter = $this->getQueryFilter($param);
  32. return $this
  33. ->with(['orderData' => ['user', 'address'], 'goods.goods.image', 'express'])
  34. ->alias('delivery')
  35. ->field($this->getAliasFields('delivery', ['eorder_html']))
  36. ->join('order', 'order.order_id = delivery.order_id')
  37. ->where($filter)
  38. ->order(['delivery.create_time' => 'desc', 'delivery.' . $this->getPk() => 'asc'])
  39. ->paginate(10);
  40. }
  41. /**
  42. * 设置检索查询条件
  43. * @param array $param
  44. * @return array
  45. */
  46. private function getQueryFilter(array $param): array
  47. {
  48. // 默认参数
  49. $params = $this->setQueryDefaultValue($param, [
  50. 'searchType' => '', // 关键词类型 (10订单号)
  51. 'searchValue' => '', // 关键词内容
  52. 'betweenTime' => [], // 起止时间
  53. ]);
  54. // 检索查询条件
  55. $filter = [];
  56. // 关键词
  57. if (!empty($params['searchValue'])) {
  58. $searchWhere = [
  59. 10 => ['order.order_no', 'like', "%{$params['searchValue']}%"]
  60. ];
  61. array_key_exists($params['searchType'], $searchWhere) && $filter[] = $searchWhere[$params['searchType']];
  62. }
  63. // 起止时间
  64. if (!empty($params['betweenTime'])) {
  65. $times = between_time($params['betweenTime']);
  66. $filter[] = ['delivery.create_time', '>=', $times['start_time']];
  67. $filter[] = ['delivery.create_time', '<', $times['end_time'] + 86400];
  68. }
  69. return $filter;
  70. }
  71. /**
  72. * 查询指定发货单的物流跟踪信息
  73. * @param int $deliveryId
  74. * @return array
  75. * @throws \cores\exception\BaseException
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function getExpressTraces(int $deliveryId): array
  81. {
  82. // 发货单详情
  83. $detail = self::detail($deliveryId, ['express']);
  84. empty($detail) && throwError('未找到指定的发货单');
  85. // 订单收货地址
  86. $address = OrderAddressModel::detail(['order_id' => $detail['order_id']]);
  87. // 整理物流跟踪信息
  88. $Express = new ExpressService;
  89. return empty($detail['express']) ? []
  90. : $Express->traces($detail['express'], $detail['express_no'], $address, self::$storeId);
  91. }
  92. }