<?php namespace App\Models; use App\Exceptions\InvalidRequestException; use Dcat\Admin\Traits\HasDateTimeFormatter; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; class Increasid extends Model { use HasDateTimeFormatter; protected $table = 'increasid'; protected $primaryKey = 'id'; public $timestamps = false; static $increas_type=[ "1"=>"PI", "2"=>"CI", "3"=>"PL", ]; static $TYPE_ORDER = 1;//订单 static $INCREAS_TYPE_PI = 1; static $INCREAS_TYPE_CI = 2; static $INCREAS_TYPE_PL = 3; public static function getSn($increasType,$type=1){ $isExists = self::where("type",self::$TYPE_ORDER)->where("increas_type",$increasType) ->where("year",date("Y")) ->where("month",date("m")) ->where("day",date("d")) ->orderBy("id","DESC") ->first(); $data=[]; $data["type"] = intval($type); $data["increas_type"] = intval($increasType); $data["year"] = (int)date("Y"); $data["month"] = (int)date("m"); $data["day"] = (int)date("d"); $data["num"] = $isExists ? ($isExists->num+1) : 1; $bk = self::insert($data); if(!$bk){ return ""; } return sprintf("%sSEMOUR%s%s%s-%s",Arr::get(self::$increas_type,$increasType,""),$data["month"],$data["day"],$data["year"],str_pad($data["num"],4,"0",STR_PAD_LEFT)); } }