<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\OwnerFeeDetail;
use Faker\Generator as Faker;

$owner = \App\Owner::query()->whereNotNull('customer_id')->first();
if ($owner)$shop = \App\Shop::query()->where("owner_id",$owner->id)->first();
else $shop = null;
$logistic = \App\Logistic::query()->first();
$method = \App\ProcessMethod::query()->first();
$factory->define(OwnerFeeDetail::class, function (Faker $faker)use(&$owner,&$shop,&$logistic,&$method) {
    if (!$owner)$owner = \App\Owner::query()->whereNotNull('customer_id')->first();
    if (!$shop){
        if ($owner)$shop = \App\Shop::query()->where("owner_id",$owner->id)->first();
        else $shop = null;
    }
    if (!$logistic) $logistic = \App\Logistic::query()->first();
    if (!$method)$method = \App\ProcessMethod::query()->first();
    $type = ["发货","收货","增值服务"];
    return [
        "owner_id"          => $owner ? $owner->id : factory(\App\Owner::class),         //货主ID
        "worked_at"         => $faker->date(),//作业时间
        "type"              =>$type[array_rand($type)],//类型
        "shop_id"           =>$shop ? $shop->id : factory(\App\Shop::class),//店铺ID
        "operation_bill"    => \Illuminate\Support\Str::random(10),//发/收/退/提货单号
        "consignee_name"    => $faker->name,   //收件人
        "consignee_phone"   =>$faker->phoneNumber,  //收件人电话
        "commodity_amount"  =>mt_rand(0,100), //商品数量
        "logistic_bill"     =>\Illuminate\Support\Str::random(12),    //快递单号
        "volume"            =>mt_rand(10,2600) / 88,//体积
        "weight"            =>mt_rand(10,2600) / 88,           //重量
        "logistic_id"       =>$logistic ? $logistic->id : factory(\App\Logistic::class),      //物流ID
        "process_method_id" =>$method ? $method->id : factory(\App\ProcessMethod::class),//加工类型ID
        "work_fee"          =>mt_rand(100,10000) / 10,         //作业费
        "logistic_fee"      =>mt_rand(100,10000) / 10,     //物流费
    ];
});
