|
|
@@ -4,12 +4,14 @@ namespace App\Services;
|
|
|
|
|
|
use App\Components\ErrorPush;
|
|
|
use App\Feature;
|
|
|
+use App\Jobs\ExecutePostBillHandler;
|
|
|
use App\Jobs\HandlePastBill;
|
|
|
-use App\Owner;
|
|
|
+use App\Order;
|
|
|
use App\OwnerFeeDetail;
|
|
|
use App\OwnerPriceOperation;
|
|
|
use App\OwnerPriceOperationItem;
|
|
|
use App\Services\common\QueryService;
|
|
|
+use App\Store;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
@@ -242,8 +244,9 @@ class OwnerPriceOperationService
|
|
|
* @param Model|\stdClass $rule
|
|
|
* @param integer $owner
|
|
|
* @param bool|array $result
|
|
|
+ * @param string $month
|
|
|
*/
|
|
|
- public function handleDiscount(Model $rule, int $owner, $result)
|
|
|
+ public function handleDiscount(Model $rule, int $owner, $result, string $month)
|
|
|
{
|
|
|
if (!$result)return;
|
|
|
$sign = false;
|
|
|
@@ -258,15 +261,15 @@ class OwnerPriceOperationService
|
|
|
$pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner){
|
|
|
return DB::selectOne(DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = ? AND owner_id = ? for update"),[$rule->id,$owner]);
|
|
|
},1000);
|
|
|
- if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=date("Y-m") || $pivot->target_value < $targetValue)){
|
|
|
+ if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=$month || $pivot->target_value < $targetValue)){
|
|
|
//未被标记过处理时间或处理时间不为本月,或上次处理值过期,处理历史即时账单
|
|
|
$sign = true;
|
|
|
}
|
|
|
if ($sign){
|
|
|
//先标记成功 这将在后续推进历史单处理流程,防止程序在此堵塞
|
|
|
DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"),
|
|
|
- [date("Y-m-d"),$targetValue,$rule->id,$owner]);
|
|
|
- $pivot->discount_date = date("Y-m-d");
|
|
|
+ [$month."-01",$targetValue,$rule->id,$owner]);
|
|
|
+ $pivot->discount_date = $month."-01";
|
|
|
$pivot->target_value = $targetValue;
|
|
|
Cache::put($key,$pivot,1000);
|
|
|
}
|
|
|
@@ -276,7 +279,7 @@ class OwnerPriceOperationService
|
|
|
$this->push(__METHOD__."->".__LINE__,"即时账单满减处理失败",$exception->getMessage()." 参数".json_encode(array($rule, $owner, $result)));
|
|
|
}
|
|
|
//进入历史单处理
|
|
|
- if ($pivot && $sign)dispatch(new HandlePastBill(array($rule,$owner,$discountIndex,$pivot)));
|
|
|
+ if ($pivot && $sign)dispatch(new HandlePastBill(array($rule,$owner,$discountIndex,$pivot,$month)));
|
|
|
}
|
|
|
|
|
|
/** 参数顺序: 数量 匹配对象 列映射 货主ID 单位ID 类型 SKU .
|
|
|
@@ -344,7 +347,7 @@ class OwnerPriceOperationService
|
|
|
if ($rule->strategy == '特征' && !app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject))continue;
|
|
|
//获取满减信息并处理满减
|
|
|
$result = $this->getDiscount($rule->discount_count,$total); //满减信息
|
|
|
- $this->handleDiscount($rule,$ownerId,$result);
|
|
|
+ $this->handleDiscount($rule,$ownerId,$result,$month);
|
|
|
|
|
|
$taxRate = app("OwnerService")->getTaxRateFee($rule, $ownerId);//获取税率
|
|
|
|
|
|
@@ -655,12 +658,12 @@ class OwnerPriceOperationService
|
|
|
* @param int $owner
|
|
|
* @param int $discountIndex
|
|
|
* @param \stdClass|object $pivot
|
|
|
+ * @param string $month
|
|
|
*/
|
|
|
- public function handlePastBill($rule, int $owner, int $discountIndex, $pivot)
|
|
|
+ public function handlePastBill($rule, int $owner, int $discountIndex, $pivot, $month)
|
|
|
{
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
- $month = date("Y-m");
|
|
|
$day = date("t",strtotime($month));
|
|
|
$query = OwnerFeeDetail::query()->where("owner_id",$owner)->whereBetween("worked_at",[$month."-01",$month."-".$day]);
|
|
|
$units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"],true); //获取单位映射集
|
|
|
@@ -694,12 +697,13 @@ class OwnerPriceOperationService
|
|
|
};
|
|
|
if ($rule->operation_type=='入库'){
|
|
|
foreach ($query->with(["store.storeItems.commodity","store.warehouse"])
|
|
|
- ->where("outer_table_name",'stores')->get() as $detail)
|
|
|
- $exe(Feature::MAPPING["store"],$detail->store,$detail);
|
|
|
+ ->where("outer_table_name",'stores')->get()->chunk(50) as $coll){
|
|
|
+ dispatch(new ExecutePostBillHandler($exe,$coll,Store::class));
|
|
|
+ }
|
|
|
}else{
|
|
|
foreach ($query->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
|
|
|
- ->where("outer_table_name",'orders')->get() as $detail)
|
|
|
- $exe(Feature::MAPPING["order"],$detail->order,$detail);
|
|
|
+ ->where("outer_table_name",'orders')->get()->chunk(50) as $coll)
|
|
|
+ dispatch(new ExecutePostBillHandler($exe,$coll,Order::class));
|
|
|
}
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|