|
|
@@ -1100,25 +1100,27 @@ class OrderService
|
|
|
*
|
|
|
* @param int $owner
|
|
|
* @param array|null $logistics
|
|
|
+ * @param string|null $month
|
|
|
*/
|
|
|
- private function orderQuantityCompensationLogic($owner, $logistics = null)
|
|
|
+ private function orderQuantityCompensationLogic(int $owner, ?array $logistics = null, ?string $month = null)
|
|
|
{
|
|
|
if (!$logistics) $logistics = app("OwnerPriceExpressService")->getBuildLogistic($owner);
|
|
|
+ if (!$month)$month = date("Y-m");
|
|
|
$query = DB::raw(<<<sql
|
|
|
SELECT COUNT(1) count,logistic_id FROM orders WHERE wms_status = '订单完成'
|
|
|
AND owner_id = ?
|
|
|
AND wms_edittime like ? GROUP BY logistic_id
|
|
|
sql
|
|
|
);
|
|
|
- $statistics = DB::select($query, [$owner, date("Y-m") . "%"]);
|
|
|
+ $statistics = DB::select($query, [$owner, $month . "%"]);
|
|
|
$toB = 0;
|
|
|
$toC = 0;
|
|
|
foreach ($statistics as $statistic) {
|
|
|
if (array_search($statistic->logistic_id, $logistics) === false) $toB += $statistic->count;
|
|
|
else $toC += $statistic->count;
|
|
|
}
|
|
|
- Cache::put(date("Y-m") . "|B|" . $owner, $toB, 2764800);
|
|
|
- Cache::put(date("Y-m") . "|C|" . $owner, $toC, 2764800);
|
|
|
+ Cache::put($month . "|B|" . $owner, $toB, 2764800);
|
|
|
+ Cache::put($month . "|C|" . $owner, $toC, 2764800);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1126,17 +1128,18 @@ sql
|
|
|
*
|
|
|
* @param int|null $owner
|
|
|
* @param int|null $logistic
|
|
|
+ * @param string|null $month
|
|
|
*/
|
|
|
- public function setOrderQuantity(?int $owner, ?int $logistic)
|
|
|
+ public function setOrderQuantity(?int $owner, ?int $logistic, ?string $month = null)
|
|
|
{
|
|
|
if (!$owner || !$logistic) return;
|
|
|
$logistics = app("OwnerPriceExpressService")->getBuildLogistic($owner);
|
|
|
- $date = date("Y-m");
|
|
|
+ $date = $month ?: date("Y-m");
|
|
|
if (array_search($logistic, $logistics) === false) $type = "|B|";
|
|
|
else $type = "|C|";
|
|
|
if (!Cache::has($date . $type . $owner)) {
|
|
|
//补偿逻辑
|
|
|
- $this->orderQuantityCompensationLogic($owner, $logistics);
|
|
|
+ $this->orderQuantityCompensationLogic($owner, $logistics, $month);
|
|
|
}
|
|
|
Cache::increment($date . $type . $owner);
|
|
|
$key = $date . "|D|" . $owner;
|
|
|
@@ -1154,12 +1157,13 @@ sql
|
|
|
*
|
|
|
* @param int $owner
|
|
|
* @param bool $isToB
|
|
|
+ * @param string|null $month
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function getOrderQuantity(int $owner, bool $isToB = false): int
|
|
|
+ public function getOrderQuantity(int $owner, bool $isToB = false, ?string $month = null): int
|
|
|
{
|
|
|
- $date = date("Y-m");
|
|
|
+ $date = $month ?: date("Y-m");
|
|
|
if ($isToB) $type = "|B|";
|
|
|
else $type = "|C|";
|
|
|
if (!Cache::has($date . $type . $owner)) $this->orderQuantityCompensationLogic($owner);
|
|
|
@@ -1170,10 +1174,11 @@ sql
|
|
|
* 获取物流费用信息
|
|
|
*
|
|
|
* @param Order|\stdClass $order
|
|
|
+ * @param string $month
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getLogisticFeeInfo(Order $order): array
|
|
|
+ public function getLogisticFeeInfo(Order $order,string $month): array
|
|
|
{
|
|
|
//预定义返回参数
|
|
|
$default = function () {
|
|
|
@@ -1192,12 +1197,12 @@ sql
|
|
|
$unit = app("UnitService")->getUnit();
|
|
|
$city = app("CityService")->getCity($order->city);
|
|
|
$isBunched = $order->logistic->is_bunched == 'Y';
|
|
|
- $exe = function ($type, $ownerId, $logisticId, $amount, $weight) use ($province, $unit, $city) {
|
|
|
+ $exe = function ($type, $ownerId, $logisticId, $amount, $weight) use ($province, $unit, $city, $month) {
|
|
|
switch ($type) {
|
|
|
case "快递":
|
|
|
/** @var OwnerPriceExpressService $service */
|
|
|
$service = app("OwnerPriceExpressService");
|
|
|
- return $service->matching($weight, $ownerId, $logisticId, $province->id);
|
|
|
+ return $service->matching($weight, $ownerId, $logisticId, $province->id, $month);
|
|
|
default:
|
|
|
/** @var OwnerPriceLogisticService $service */
|
|
|
$service = app("OwnerPriceLogisticService");
|
|
|
@@ -1279,19 +1284,21 @@ sql
|
|
|
if (Cache::has("owner_fee_details:orders_" . $order->id)) return true;
|
|
|
//加载所需数据
|
|
|
$order->loadMissing(["logistic", "shop", "packages.commodities.commodity", "batch"]);
|
|
|
+ $workedAt = $order->wms_edittime ?: $order->updated_at;
|
|
|
//获取运输费
|
|
|
- $logisticInfo = $this->getLogisticFeeInfo($order);
|
|
|
+ $month = substr($workedAt,0,7);
|
|
|
+ $logisticInfo = $this->getLogisticFeeInfo($order,$month);
|
|
|
|
|
|
//获取作业费
|
|
|
/** @var OwnerPriceOperationService $service */
|
|
|
$service = app("OwnerPriceOperationService");
|
|
|
$GLOBALS["FEE_INFO"] = [];
|
|
|
- list($id, $money, $workTaxFee) = $service->matching($order, Feature::MAPPING["order"], $order->owner_id);
|
|
|
+ list($id, $money, $workTaxFee) = $service->matching($month, $order, Feature::MAPPING["order"], $order->owner_id);
|
|
|
|
|
|
//数据组装
|
|
|
$detail = OwnerFeeDetail::query()->create([
|
|
|
"owner_id" => $order->owner_id,
|
|
|
- "worked_at" => $order->wms_edittime ?: $order->updated_at,
|
|
|
+ "worked_at" => $workedAt,
|
|
|
"type" => "发货",
|
|
|
"shop_id" => $order->shop_id,
|
|
|
"operation_bill" => $order->code,
|
|
|
@@ -1328,7 +1335,7 @@ sql
|
|
|
//后续处理
|
|
|
foreach ($logisticInfo["items"] as &$item) $item["owner_fee_detail_id"] = $detail->id;
|
|
|
if (count($logisticInfo["items"]) > 1) OwnerFeeDetailLogistic::query()->insert($logisticInfo["items"]);
|
|
|
- $this->setOrderQuantity($order->owner_id, $order->logistic_id);
|
|
|
+ $this->setOrderQuantity($order->owner_id, $order->logistic_id, $month);
|
|
|
Cache::put("owner_fee_details:orders_" . $order->id, 1, 86400);
|
|
|
return true;
|
|
|
}
|
|
|
@@ -1425,7 +1432,7 @@ sql
|
|
|
$order->loadMissing(["logistic", "shop", "packages.commodities.commodity", "batch"]);
|
|
|
if (!$order->packages->count() || !$order->owner) return false;
|
|
|
//获取运输费
|
|
|
- $logisticInfo = $this->getLogisticFeeInfo($order);
|
|
|
+ $logisticInfo = $this->getLogisticFeeInfo($order,substr($feeBill->worked_at,0,7));
|
|
|
if (!$logisticInfo["logisticFee"] || !$logisticInfo["fee_info"]) return false;
|
|
|
//获取作业费
|
|
|
$GLOBALS["FEE_INFO"] = [];
|