| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use App\Traits\ModelLogChanging;
- class Waybill extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- use SoftDeletes;
- protected $fillable=[
- 'status',
- 'type',
- 'waybill_number',
- 'owner_id',
- 'wms_bill_number',
- 'origination',
- 'destination',
- 'recipient',
- 'recipient_mobile',
- 'charge',
- 'ordering_remark',
- 'logistic_id',
- 'carrier_bill',
- 'origination_city_id',
- 'destination_city_id',
- 'warehouse_weight',
- 'warehouse_weight_unit_id',
- 'carrier_weight',
- 'carrier_weight_unit_id',
- 'carType_id',
- 'car_owner_info',
- 'fee',
- 'pick_up_fee',
- 'other_fee',
- 'collect_fee',
- 'dispatch_remark',
- 'waybill_price_model_id',
- 'warehouse_weight_other',
- 'warehouse_weight_unit_id_other',
- 'carrier_weight_other',
- 'carrier_weight_unit_id_other',
- 'source_bill',
- 'mileage',
- 'amount',
- 'inquire_tel',
- 'amount_unit_id',
- 'other_charge',
- 'other_charge_remark',
- 'deliver_at',
- "district_id",
- "order_id",
- "is_to_pay", //0否 1是
- 'cargo_name',
- 'total_number',
- 'total_weight',
- 'deliveryType_id',
- "merge_owner",//合并货主ID集
- 'order_type',
- 'transport_type',
- 'pay_type',
- 'back_sign_bill',
- 'package_service',
- 'express_face_list',
- 'arrived_org_simple_name',
- 'much_higher_delivery',
- 'station_no',
- 'subjoin_fee',//附加费
- ];
- const ORDER_TYPE_DEFAULT = 2;
- const ORDER_TYPE = [
- 1 => "散客模式",
- 2 => "大客户模式",
- 3 => "同步筛单下单",
- ];
- const PAY_TYPE_DEFAULT = 2;
- const PAY_TYPE = [
- 0 => "发货人付款(现付)(大客户模式不支持寄付)",
- 1 => "收货人付款(到付)",
- 2 => "发货人付款(月结)",
- ];
- const BACK_SIGN_BILL_DEFAULT = 0;
- const BACK_SIGN_BILL = [
- 0 => "无需返单",
- 1 => "签收单原单返回",
- 2 => "电子签收单(签名图需要另外对接查询接口)",
- ];
- public function district()
- { //区
- return $this->belongsTo(Region::class,"district_id","id")->where("type",3);
- }
- public function owner(){
- return $this->hasOne('App\Owner','id','owner_id');
- }
- public function logistic(){
- return $this->hasOne('App\Logistic','id','logistic_id');
- }
- public function originationCity()
- { //始发市
- return $this->hasOne(Region::class,'id','origination_city_id');
- }
- public function destinationCity()
- { //目的市
- return $this->hasOne(Region::class,'id','destination_city_id');
- }
- public function wmsCommodities(){
- return $this->hasMany('App\WMSWaybillOrder','OrderNo','wms_bill_number');
- }
- public function priceModel(){
- return $this->hasOne('App\WaybillPriceModel','id','waybill_price_model_id');
- }
- public function amountUnit(){
- return $this->hasOne('App\Unit','id','amount_unit_id');
- }
- public function warehouseWeightUnit(){
- return $this->hasOne('App\Unit','id','warehouse_weight_unit_id');
- }
- public function carrierWeightUnit(){
- return $this->hasOne('App\Unit','id','carrier_weight_unit_id');
- }
- public function warehouseWeightUnitOther(){
- return $this->hasOne('App\Unit','id','warehouse_weight_unit_id_other');
- }
- public function carrierWeightUnitOther(){
- return $this->hasOne('App\Unit','id','carrier_weight_unit_id_other');
- }
- public function carType(){
- return $this->hasOne('App\CarType','id','carType_id');
- }
- public function waybillAuditLogs(){
- return $this->hasMany('App\WaybillAuditLog','waybill_id','id')->orderByDesc("created_at");
- }
- public function uploadFiles(){
- return $this->hasMany(UploadFile::class,'table_id','id')->where('table_name','waybills');
- }
- public function order()
- { //订单
- return $this->belongsTo(Order::class);
- }
- public function orderByCode()
- { //订单
- return $this->hasOne(Order::class,'code','wms_bill_number');
- }
- public function deliveryType()
- { //订单
- return $this->hasOne(DeliveryType::class,'id','deliveryType_id');
- }
- static public function setWeightByOrderCode($orderCode,$weight){
- if(empty($orderCode))return;
- $waybill=Waybill::query()->where('wms_bill_number',$orderCode)->where('status','!=','已完结')
- ->where('status','!=','无模型')->first();
- if ($waybill){
- $waybill->warehouse_weight_other=$weight;
- $waybill->warehouse_weight_unit_id_other=1;
- $waybill->update();
- }
- }
- /**
- * @return Builder
- */
- public static function filterAuthorities(){
- $ownerQuery = app("OwnerService")->getQuery();
- return (new static)->newQuery()->leftJoin("orders","waybills.order_id","orders.id")
- ->leftJoin("owners","orders.owner_id","owners.id")
- ->selectRaw(<<<column
- owners.name as owner_name,
- orders.consignee_name as order_consignee_name,
- orders.consignee_phone as order_consignee_phone,
- orders.province as order_province,
- orders.city as order_city,
- orders.district as order_district,
- orders.address as order_address
- column
- )
- ->where(function ($query)use($ownerQuery){
- /** @var Builder $query */
- $query->whereIn('waybills.owner_id',$ownerQuery)->
- orWhereIn("orders.owner_id",$ownerQuery);
- });
- }
- public function ownerWayBillFeeDetail(): HasOne
- {
- return $this->hasOne(OwnerWayBillFeeDetail::class);
- }
- public function getDestinationAttribute($value)
- {
- return $this->relations["order"]["address"] ?? $value;
- }
- public function getCarrierNameAttribute()
- {
- return $this->relations["logistic"]["name"] ?? "";
- }
- public function getAmountUnitNameAttribute()
- {
- return $this->relations["amountUnit"]["name"] ?? "件";
- }
- public function getRemoveRelationAttribute()
- {
- $this->unsetRelations();
- $this->offsetUnset("remove_relation");
- }
- }
|