<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OperateStockLog extends BaseModel
{
    use HasFactory;
    protected $table = 'operate_stock_logs';
    const TYPE_ADMIN = 0;
    const TYPE_H5 = 1;
    const TYPE_MP = 2;
    const TYPE_AGENT = 3;

    const OPERATE_TYPE_IN = 0;
    const OPERATE_TYPE_OUT = 1;

    const OPERATE_STATUS_APPLY = 0; //未审核
    const OPERATE_STATUS_PASS = 1; //审核通过
    const OPERATE_STATUS_REJECT = 2; //拒绝

    const GOODS_TYPE_FOOD = 1;
    const GOODS_TYPE_GOODS = 0;

    public static function addLog($admin,$param){
        //增加库存记录
        $log = [
            'food_id' => $param['id'],
            'name' => $param['name'],
            'user_id'=>$admin->id??$admin['id'],
            'operate_name'=>$admin->name??$admin['name'],
            'operate_mobile'=>isset($admin->mobile) ? $admin->mobile:$admin['mobile'],
            'type' => $param['type'],
            'operate_type' => $param['operate_type']??self::OPERATE_TYPE_IN,
            'before_num' => $param['stock']??0,
            'num' => $param['num']??0,
            'after_num' => $param['after_num']??0,
            'remark'=>$param['remark']??null,
            'status' => $param['status']??self::OPERATE_STATUS_PASS,
            'contract_id'=>$param['contract']??null,
            'images' => $param['images']??json_encode([]),
            'goods_type' => $param['goods_type']??self::GOODS_TYPE_GOODS,
            'sku_id' => $param['sku_id']??null,
            'order_id' => $param['order_id']??null,
        ];
        $res = self::create($log);
    }
}
