|
|
@@ -14,6 +14,8 @@ use App\OrderIssue;
|
|
|
use App\Owner;
|
|
|
use App\OwnerFeeDetail;
|
|
|
use App\OwnerFeeDetailLogistic;
|
|
|
+use App\OwnerPriceExpress;
|
|
|
+use App\OwnerReport;
|
|
|
use App\Province;
|
|
|
use App\RejectedBill;
|
|
|
use App\Services\common\BatchUpdateService;
|
|
|
@@ -995,6 +997,76 @@ class OrderService
|
|
|
return Order::query()->create($values);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 订单量丢失补偿逻辑
|
|
|
+ *
|
|
|
+ * @param int $owner
|
|
|
+ * @param array|null $logistics
|
|
|
+ */
|
|
|
+ private function orderQuantityCompensationLogic($owner, $logistics = null)
|
|
|
+ {
|
|
|
+ if (!$logistics)$logistics = app("OwnerPriceExpressService")->getBuildLogistic($owner);
|
|
|
+ $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")."%"]);
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置订单量
|
|
|
+ *
|
|
|
+ * @param int $owner
|
|
|
+ * @param int $logistic
|
|
|
+ */
|
|
|
+ public function setOrderQuantity($owner, $logistic)
|
|
|
+ {
|
|
|
+ $logistics = app("OwnerPriceExpressService")->getBuildLogistic($owner);
|
|
|
+ $date = date("Y-m");
|
|
|
+ if (array_search($logistic,$logistics)===false)$type = "|B|";
|
|
|
+ else $type = "|C|";
|
|
|
+ if (!Cache::has($date.$type.$owner)){
|
|
|
+ //补偿逻辑
|
|
|
+ $this->orderQuantityCompensationLogic($owner,$logistics);
|
|
|
+ }
|
|
|
+ Cache::increment($date.$type.$owner);
|
|
|
+ $key = $date."|D|".$owner;
|
|
|
+ if (!Cache::has($key) || time()-Cache::get($key)>60){
|
|
|
+ //向数据库持久化
|
|
|
+ OwnerReport::query()->where("owner_id",$owner)
|
|
|
+ ->where("counting_month","like",$date."%")
|
|
|
+ ->update(["to_business_quantity"=>Cache::get($date."|B|".$owner),"to_customer_quantity"=>Cache::get($date."|C|".$owner)]);
|
|
|
+ }
|
|
|
+ Cache::put($key,time());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取货主下有效订单量 对C端
|
|
|
+ *
|
|
|
+ * @param int $owner
|
|
|
+ * @param bool $isToB
|
|
|
+ *
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getOrderQuantity($owner, $isToB)
|
|
|
+ {
|
|
|
+ $date = date("Y-m");
|
|
|
+ if ($isToB)$type = "|B|";
|
|
|
+ else $type = "|C|";
|
|
|
+ if (!Cache::has($date.$type.$owner))$this->orderQuantityCompensationLogic($owner);
|
|
|
+ return Cache::get($date.$type.$owner);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成即时账单
|
|
|
*
|
|
|
@@ -1008,9 +1080,7 @@ class OrderService
|
|
|
if (!$order || $order->wms_status != "订单完成")return true;
|
|
|
if (OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first())return true;
|
|
|
|
|
|
- $key = date("Y-m")."_".$order->owner_id;
|
|
|
- if (Cache::has($key))Cache::increment($key);
|
|
|
- else Cache::put($key,1,2678400);
|
|
|
+ $this->setOrderQuantity($order->owner_id,$order->logistic_id);
|
|
|
|
|
|
$order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
|
|
|
|