Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 51 |
| RejectedBill | |
0.00% |
0 / 1 |
|
0.00% |
0 / 18 |
702.00 | |
0.00% |
0 / 51 |
| owner | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| logistic | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| items | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| rejectedBillItems | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| logisticName | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 2 |
|||
| makeCheckedNumbers | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 8 |
|||
| delete | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| update | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| save | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| restore | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getOwnerNameAttribute | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getLogisticNameAttribute | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getIsLoadedStrAttribute | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| getCreatedAtShortAttribute | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
|||
| getGoodsAmountAttribute | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 4 |
|||
| getOperatorNameAttribute | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| getIsLoadedNullAttribute | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 2 |
|||
| changeIsLoaded_ifItemsAllLoaded | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| <?php | |
| namespace App; | |
| use App\Http\Controllers\LogisticNumberFeatureController; | |
| use Carbon\Carbon; | |
| use Illuminate\Database\Eloquent\Collection; | |
| use Illuminate\Database\Eloquent\Model; | |
| use Illuminate\Database\Eloquent\SoftDeletes; | |
| use Overtrue\LaravelPinyin\Facades\Pinyin; | |
| /** | |
| * @method static find(array|string|null $param) | |
| */ | |
| class RejectedBill extends Model | |
| { | |
| use SoftDeletes; | |
| protected $fillable=['id_owner','order_number','sender','mobile_sender', | |
| 'logistic_number','logistic_number_return','id_logistic_return', | |
| 'is_loaded','fee_collected','remark','id_operator','is_checked' | |
| ,'is_finished','checked_numbers','remark']; | |
| protected $appends = ['owner_name','logistic_name','created_at_short' | |
| ,'is_loaded_str','goods_amount','is_loaded_null','operator_name']; | |
| function owner(){ | |
| return $this->hasOne('App\Owner','id','id_owner'); | |
| } | |
| function logistic(){ | |
| return $this->hasOne('App\Logistic','id','id_logistic_return'); | |
| } | |
| function items(){ | |
| return $this->hasMany('App\RejectedBillItem','id_rejected_bill','id'); | |
| } | |
| function rejectedBillItems(){ | |
| return $this->items(); | |
| } | |
| function logisticName(){ | |
| $logistic=$this->hasOne('App\Logistic','id','id_logistic_return')->first(); | |
| return $logistic?$logistic['name']:''; | |
| } | |
| function makeCheckedNumbers(){ | |
| $owner = $this->owner()->first(); | |
| if(!$owner)return ''; | |
| $pinyinOwnerName=Pinyin::convert($owner->name); | |
| $pinyinArr=array_map(function($pinyin){ | |
| return $pinyin[0]; | |
| },$pinyinOwnerName); | |
| $initials=implode("", $pinyinArr); | |
| $this['checked_numbers']=$initials.Carbon::now()->format('Ymd').$owner->getIncreasedCheckingCount(); | |
| return $this['checked_numbers']; | |
| } | |
| function delete() | |
| { | |
| $items=$this->items(); | |
| $items->delete(); | |
| return parent::delete(); | |
| } | |
| function update(array $attributes = [], array $options = []) | |
| { | |
| (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']); | |
| return parent::update($attributes, $options); | |
| } | |
| function save(array $options = []) | |
| { | |
| (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']); | |
| return parent::save($options); | |
| } | |
| function restore() | |
| { | |
| $items=$this->items(); | |
| $items->restore(); | |
| return parent::restore(); | |
| } | |
| public function getOwnerNameAttribute(){ | |
| $id_owner=$this['id_owner']??0; | |
| $owner=Owner::find($id_owner); | |
| return $this['owner_name']=$owner['name']; | |
| } | |
| public function getLogisticNameAttribute(){ | |
| $id_logistic=$this['id_logistic_return']??0; | |
| $logistic=Logistic::find($id_logistic); | |
| return $this['logistic_name']=$logistic['name']; | |
| } | |
| public function getIsLoadedStrAttribute(){ | |
| return $this['is_loaded']?'是':'否'; | |
| } | |
| public function getCreatedAtShortAttribute(){ | |
| return $this['created_at']?$this['created_at_short']=$this['created_at']->format('m-d H:i:s'):''; | |
| } | |
| public function getGoodsAmountAttribute(){ | |
| $amount=0; | |
| $this->items()->get()->each(function (RejectedBillItem $item)use(&$amount){ | |
| $amount+=$item['amount']; | |
| }); | |
| return $amount; | |
| } | |
| public function getOperatorNameAttribute(){ | |
| if(!$this['id_operator']){return '';} | |
| $user=User::find($this['id_operator']); | |
| return $user['name']; | |
| } | |
| public function getIsLoadedNullAttribute(){ | |
| if($this['is_loaded']===null) return 'null'; | |
| return $this['is_loaded']; | |
| } | |
| public function changeIsLoaded_ifItemsAllLoaded(){ | |
| $allItemsAreLoaded=true; | |
| $this->items->each(function (RejectedBillItem $item)use(&$allItemsAreLoaded){ | |
| if($item['is_loaded']=='未入库'){ | |
| $allItemsAreLoaded=false; | |
| return false; | |
| } | |
| }); | |
| if($allItemsAreLoaded){ | |
| $this['is_loaded']=true; | |
| }else{ | |
| $this['is_loaded']=false; | |
| } | |
| $this->update(); | |
| return $this['is_loaded']; | |
| } | |
| } |