| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 18 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 51
RejectedBill | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 18 | 702.00 | 0.00% covered (danger) | 0.00% | 0 / 51
owner | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
logistic | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
items | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
rejectedBillItems | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
logisticName | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 2
makeCheckedNumbers | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 8
delete | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 3
update | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2
save | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2
restore | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 3
getOwnerNameAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 3
getLogisticNameAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 3
getIsLoadedStrAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 1
getCreatedAtShortAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 1
getGoodsAmountAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 4
getOperatorNameAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 3
getIsLoadedNullAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 2
changeIsLoaded_ifItemsAllLoaded | 0.00% covered (danger) | 0.00% | 0 / 1 | 12.00 | 0.00% covered (danger) | 0.00% | 0 / 10

1 | <?php
2 |
3 | namespace App;
4 |
5 | use App\Http\Controllers\LogisticNumberFeatureController;
6 | use Carbon\Carbon;
7 | use Illuminate\Database\Eloquent\Collection;
8 | use Illuminate\Database\Eloquent\Model;
9 | use Illuminate\Database\Eloquent\SoftDeletes;
10 | use Overtrue\LaravelPinyin\Facades\Pinyin;
11 |
12 | /**
13 | * @method static find(array|string|null $param)
14 | */
15 | class RejectedBill extends Model
16 | {
17 | use SoftDeletes;
18 | protected $fillable=['id_owner','order_number','sender','mobile_sender',
19 | 'logistic_number','logistic_number_return','id_logistic_return',
20 | 'is_loaded','fee_collected','remark','id_operator','is_checked'
21 | ,'is_finished','checked_numbers','remark'];
22 |
23 | protected $appends = ['owner_name','logistic_name','created_at_short'
24 | ,'is_loaded_str','goods_amount','is_loaded_null','operator_name'];
25 | function owner(){
26 | return $this->hasOne('App\Owner','id','id_owner');
27 | }
28 | function logistic(){
29 | return $this->hasOne('App\Logistic','id','id_logistic_return');
30 | }
31 | function items(){
32 | return $this->hasMany('App\RejectedBillItem','id_rejected_bill','id');
33 | }
34 | function rejectedBillItems(){
35 | return $this->items();
36 | }
37 | function logisticName(){
38 | $logistic=$this->hasOne('App\Logistic','id','id_logistic_return')->first();
39 | return $logistic?$logistic['name']:'';
40 | }
41 | function makeCheckedNumbers(){
42 | $owner = $this->owner()->first();
43 | if(!$owner)return '';
44 | $pinyinOwnerName=Pinyin::convert($owner->name);
45 | $pinyinArr=array_map(function($pinyin){
46 | return $pinyin[0];
47 | },$pinyinOwnerName);
48 | $initials=implode("", $pinyinArr);
49 | $this['checked_numbers']=$initials.Carbon::now()->format('Ymd').$owner->getIncreasedCheckingCount();
50 | return $this['checked_numbers'];
51 | }
52 |
53 | function delete()
54 | {
55 | $items=$this->items();
56 | $items->delete();
57 | return parent::delete();
58 | }
59 | function update(array $attributes = [], array $options = [])
60 | {
61 | (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']);
62 | return parent::update($attributes, $options);
63 | }
64 | function save(array $options = [])
65 | {
66 | (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']);
67 | return parent::save($options);
68 | }
69 | function restore()
70 | {
71 | $items=$this->items();
72 | $items->restore();
73 | return parent::restore();
74 | }
75 |
76 | public function getOwnerNameAttribute(){
77 | $id_owner=$this['id_owner']??0;
78 | $owner=Owner::find($id_owner);
79 | return $this['owner_name']=$owner['name'];
80 | }
81 | public function getLogisticNameAttribute(){
82 | $id_logistic=$this['id_logistic_return']??0;
83 | $logistic=Logistic::find($id_logistic);
84 | return $this['logistic_name']=$logistic['name'];
85 | }
86 | public function getIsLoadedStrAttribute(){
87 | return $this['is_loaded']?'是':'否';
88 | }
89 | public function getCreatedAtShortAttribute(){
90 | return $this['created_at']?$this['created_at_short']=$this['created_at']->format('m-d H:i:s'):'';
91 | }
92 | public function getGoodsAmountAttribute(){
93 | $amount=0;
94 | $this->items()->get()->each(function (RejectedBillItem $item)use(&$amount){
95 | $amount+=$item['amount'];
96 | });
97 | return $amount;
98 | }
99 | public function getOperatorNameAttribute(){
100 | if(!$this['id_operator']){return '';}
101 | $user=User::find($this['id_operator']);
102 | return $user['name'];
103 | }
104 | public function getIsLoadedNullAttribute(){
105 | if($this['is_loaded']===null) return 'null';
106 | return $this['is_loaded'];
107 | }
108 | public function changeIsLoaded_ifItemsAllLoaded(){
109 | $allItemsAreLoaded=true;
110 | $this->items->each(function (RejectedBillItem $item)use(&$allItemsAreLoaded){
111 | if($item['is_loaded']=='未入库'){
112 | $allItemsAreLoaded=false;
113 | return false;
114 | }
115 | });
116 | if($allItemsAreLoaded){
117 | $this['is_loaded']=true;
118 | }else{
119 | $this['is_loaded']=false;
120 | }
121 | $this->update();
122 | return $this['is_loaded'];
123 | }
124 | }