|
|
@@ -20,6 +20,9 @@ use App\Order;
|
|
|
use App\OrderPackage;
|
|
|
use App\Owner;
|
|
|
use App\Package;
|
|
|
+use App\Process;
|
|
|
+use App\ProcessDaily;
|
|
|
+use App\ProcessStatistic;
|
|
|
use App\RejectedBillItem;
|
|
|
use App\Services\InventoryCompareService;
|
|
|
use App\Services\LogService;
|
|
|
@@ -29,6 +32,7 @@ use App\Waybill;
|
|
|
use Carbon\Carbon;
|
|
|
use Exception;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -332,14 +336,55 @@ class TestController extends Controller
|
|
|
}
|
|
|
|
|
|
function test1(){
|
|
|
- $post = Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(['row'=>['第一列','第二列'],'list'=>[['第一行','第二行'],['2第一行','2第二行']]],JSON_UNESCAPED_UNICODE)]);
|
|
|
- if ($post->status() == 500){
|
|
|
- throw new Exception($post->header("Msg"));
|
|
|
+ $statistics = ProcessStatistic::query()->whereNull('revenue')->get();
|
|
|
+ $id = array_column($statistics->toArray(),'process_id');
|
|
|
+ $processes = Process::query()->where(function (Builder $query){
|
|
|
+ $query->where('status','待交接')->orWhere('status','交接完成');
|
|
|
+ })->whereIn('process_id',$id)->get();
|
|
|
+ $sign_end = true;
|
|
|
+ foreach ($processes as $process){
|
|
|
+ if (count($process->processDailies)>0){
|
|
|
+ $completed_amount=0;
|
|
|
+ foreach ($process->processDailies as $processDaily){
|
|
|
+ $completed_amount=$completed_amount+($processDaily->output);
|
|
|
+ }
|
|
|
+ $process->completed_amount=$completed_amount;
|
|
|
+ }
|
|
|
+ //统计:
|
|
|
+ $revenue=($process->unit_price)*($process->completed_amount); //收入合计
|
|
|
+ $processDailies=ProcessDaily::with('processDailyParticipants')->where('process_id',$process->id)->where('output','>',0)->get();
|
|
|
+ $duration_days=count($processDailies); //完成天数
|
|
|
+ $duration_man_hours=0; //总工时
|
|
|
+ $total_cost=0; //合计成本
|
|
|
+ foreach ($processDailies as $processDailyOne){
|
|
|
+ foreach ($processDailyOne->processDailyParticipants as $processDailyParticipant){
|
|
|
+ if (!$processDailyParticipant->unit_price && !$processDailyParticipant->hour_price) continue;
|
|
|
+ $duration_man_hours += $processDailyParticipant->hour_count;
|
|
|
+ if ($processDailyParticipant->unit_count){
|
|
|
+ $total_cost += ($processDailyParticipant->unit_count)*($processDailyParticipant->unit_price);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $total_cost += ($processDailyParticipant->hour_count)*($processDailyParticipant->hour_price);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $processStatistic=ProcessStatistic::query()->find($process->id);
|
|
|
+ $processStatistic->revenue=$revenue;
|
|
|
+ $processStatistic->duration_days=$duration_days;
|
|
|
+ $processStatistic->duration_man_hours=$duration_man_hours;
|
|
|
+ if ($sign_end) $processStatistic->ended_at = date('Y-m-d H:i:s');
|
|
|
+ if (!$revenue || !$total_cost){
|
|
|
+ $processStatistic->update();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $gross_profit=$revenue-$total_cost; //毛利润
|
|
|
+ if ($gross_profit!=0)$gross_profit_rate=$gross_profit/$revenue; //毛利率;
|
|
|
+ else $gross_profit_rate=0;
|
|
|
+ $processStatistic->total_cost=$total_cost;
|
|
|
+ $processStatistic->gross_profit=$gross_profit;
|
|
|
+ $processStatistic->gross_profit_rate=$gross_profit_rate;
|
|
|
+ $processStatistic->update();
|
|
|
+ $this->log(__METHOD__,"修改二次加工单统计单_".__FUNCTION__,json_encode($processStatistic),Auth::user()['id']);
|
|
|
}
|
|
|
- return response($post,200, [
|
|
|
- "Content-type"=>"application/octet-stream",
|
|
|
- "Content-Disposition"=>"attachment; filename=订单记录-".date('ymdHis').'.xlsx',
|
|
|
- ]);
|
|
|
}
|
|
|
|
|
|
/*1*/
|