data["active_test"] = "active"; } public function method(Request $request, $method) { return call_user_func([$this, $method], $request); } public function lightUp() { app("CacheShelfService")->lightUp('HAIB1-02-02','3','2'); } public function lightOff() { $params = [ "areaCode" => "1004", 'locCode' => "HAIB1-02-02", 'PTLAction' => 0, ]; $response = Http::post(config('api.haiq.storage.light'), $params); return json_decode($response->body()); } public function test() { ini_set('max_execution_time',-1); $rule = OwnerPriceOperation::query()->with("items")->find(205); $owner = 3;$discountIndex = 0; $pivot = new \stdClass(); $pivot->owner_price_operation_id = 205; $pivot->owner_id = 3; $pivot->discount_date = "2021-08-01"; $pivot->target_value = 0; 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"]); //获取单位映射集 $exe = function ($mapping,$object,$detail)use($rule,$units,$owner,$discountIndex){ $money = app("OwnerPriceOperationService")->matchItem($rule,$mapping,$object,$units,$owner,[$discountIndex=>true]); $rate = $rule->taxRate ?: (Owner::query()->with("taxRate")->find($owner)->taxRate ?? null); if ($money>0)$detail->update(["work_fee"=>$money,"work_tax_fee"=>$rate ? ($money*($rate->value/100)) : null]); else dd($money); }; 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); }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); } DB::commit(); dd("OK"); }catch (\Exception $e){ DB::rollBack(); //处理失败回退标记 DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"), [$pivot->discount_date,$pivot->target_value,$rule->id,$owner]); dd($e); } } }