<?php
namespace app\model;
use think\Model;
class Cost extends Model{
protected $type = [
'time'=>'timestamp:Y-m-d'
];
public function sourceData(){
return $this->morphTo(['type','class'],[
'buy' => Buy::class,
'bre' => Bre::class,
'sell' => Sell::class,
'sre' => Sre::class,
'vend' => Vend::class,
'barter' => Barter::class,
'vre' => Vre::class,
'swap' => Swap::class,
'entry' => Entry::class,
'extry' => Extry::class
]);
}
public function ietData(){
return $this->hasOne(Iet::class,'id','iet')->field(['id','name']);
}
public function getMoneyAttr($val,$data){
return floatval($val);
}
public function getSettleAttr($val,$data){
return floatval($val);
}
public function getExtensionAttr($val,$data){
$source=[];
$source['type']=['buy'=>'采购单','bre'=>'采购退货单','sell'=>'销售单','sre'=>'销售退货单','vend'=>'零售单','vre'=>'零售退货单','barter'=>'积分兑换单','swap'=>'调拨单','entry'=>'其它入库单','extry'=>'其它出库单'][$data['type']];
$source['state']=[0=>'未结算',1=>'部分结算',2=>'已结算'][$data['state']];
return $source;
}
}