yuang 4 лет назад
Родитель
Сommit
9c74d7ef62
1 измененных файлов с 125 добавлено и 78 удалено
  1. 125 78
      app/RejectedBill.php

+ 125 - 78
app/RejectedBill.php

@@ -15,7 +15,9 @@ use Overtrue\LaravelPinyin\Facades\Pinyin;
 
 /**
  * @method static find(array|string|null $param)
- */use App\Traits\ModelTimeFormat;
+ */
+
+use App\Traits\ModelTimeFormat;
 
 use App\Traits\ModelLogChanging;
 
@@ -26,7 +28,7 @@ class RejectedBill extends Model
     use ModelTimeFormat;
     use SoftDeletes;
 
-    protected $fillable=[
+    protected $fillable = [
         'id_owner',
         'order_number',
         'delivery_status',//收货状态
@@ -46,30 +48,38 @@ class RejectedBill extends Model
         'common_02'
     ];
 
-    static public $enums=[
-        'delivery_status'=>[
-            ''=>0,
-            '未收货'=>1,
-            '已收货'=>2,
+    static public $enums = [
+        'delivery_status' => [
+            '' => 0,
+            '未收货' => 1,
+            '已收货' => 2,
         ],
     ];
+
     function __construct(array $attributes = [])
     {
         foreach (self::$enums as &$enum) {
-            $enum=$enum+array_flip($enum);
+            $enum = $enum + array_flip($enum);
         }
         parent::__construct($attributes);
     }
 
     public function getDeliveryStatusAttribute($value)
     {
-        if(!$value)return '';
-        return self::$enums['delivery_status'][$value]??'';
+        switch ($value) {
+            case 1:
+                return '未收货';
+            case 2:
+                return '已收货';
+            default:
+                return '';
+        }
     }
+
     public function setDeliveryStatusAttribute($value)
     {
-        if(!$value)return 0;
-        $this->attributes['delivery_status']=self::$enums['delivery_status'][$value];
+        if (!$value) return 0;
+        $this->attributes['delivery_status'] = self::$enums['delivery_status'][$value];
     }
 
     /*
@@ -88,121 +98,158 @@ class RejectedBill extends Model
      *  checked_numbers             审核编号
      */
 
-    protected $appends = ['owner_name','logistic_name'
-        ,'is_loaded_str','goods_amount','is_loaded_null','operator_name'];
-    function owner(){
-        return $this->hasOne('App\Owner','id','id_owner');
+    protected $appends = ['owner_name', 'logistic_name'
+        , '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 logistic()
+    {
+        return $this->hasOne('App\Logistic', 'id', 'id_logistic_return');
     }
-    function items(){
-        return $this->hasMany('App\RejectedBillItem','id_rejected_bill','id');
+
+    function items()
+    {
+        return $this->hasMany('App\RejectedBillItem', 'id_rejected_bill', 'id');
     }
-    function user(){
-        return $this->hasOne('App\User','id','id_operator');
+
+    function user()
+    {
+        return $this->hasOne('App\User', 'id', 'id_operator');
     }
-    function rejectedBillItems(){
+
+    function rejectedBillItems()
+    {
         return $this->items();
     }
-    function wmsReflectReceive(){
-        return $this->belongsTo('App\WMSReflectReceive','id','id_rejected_bill');
+
+    function wmsReflectReceive()
+    {
+        return $this->belongsTo('App\WMSReflectReceive', 'id', 'id_rejected_bill');
     }
 
     function orderIssue()
     {
-        return $this->hasOneThrough(OrderIssue::class,OrderIssueRejectedBill::class,'logistic_number_return','id','logistic_number_return','order_issue_id');
+        return $this->hasOneThrough(OrderIssue::class, OrderIssueRejectedBill::class, 'logistic_number_return', 'id', 'logistic_number_return', 'order_issue_id');
     }
 
-    function orderIssueRejectedBill(){
-        return $this->hasOne(OrderIssueRejectedBill::class,'logistic_number_return','logistic_number_return')->whereNotNull('order_issue_id');
+    function orderIssueRejectedBill()
+    {
+        return $this->hasOne(OrderIssueRejectedBill::class, 'logistic_number_return', 'logistic_number_return')->whereNotNull('order_issue_id');
     }
+
     function record(): BelongsTo
     {
-        return $this->belongsTo(ReceiveRecord::class,"logistic_number_return","logistic_number");
+        return $this->belongsTo(ReceiveRecord::class, "logistic_number_return", "logistic_number");
     }
 
 
-    function setIsLoaded_toWaitConfirm(){
-        if(config('api.jianshang_rejecteds_log_switch'))Controller::logS(__METHOD__,__FUNCTION__,"将待推单修改为待确认! 退单号:".$this['logistic_number_return'],Auth::user()['id']);
-        $bill=RejectedBill::find($this['id']);
-        $bill['is_loaded']=4;
+    function setIsLoaded_toWaitConfirm()
+    {
+        if (config('api.jianshang_rejecteds_log_switch')) Controller::logS(__METHOD__, __FUNCTION__, "将待推单修改为待确认! 退单号:" . $this['logistic_number_return'], Auth::user()['id']);
+        $bill = RejectedBill::find($this['id']);
+        $bill['is_loaded'] = 4;
         $bill->save();
     }
-    function logisticName(){
-        $logistic=$this->hasOne('App\Logistic','id','id_logistic_return')->first();
-        return $logistic?$logistic['name']:'';
+
+    function logisticName()
+    {
+        $logistic = $this->hasOne('App\Logistic', 'id', 'id_logistic_return')->first();
+        return $logistic ? $logistic['name'] : '';
     }
-    function makeCheckedNumbers(){
+
+    function makeCheckedNumbers()
+    {
         $owner = $this->owner()->first();
-        if(!$owner)return '';
-        $pinyinOwnerName=Pinyin::convert($owner->name);
-        $pinyinArr=array_map(function($pinyin){
+        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();
+        }, $pinyinOwnerName);
+        $initials = implode("", $pinyinArr);
+        $this['checked_numbers'] = $initials . Carbon::now()->format('Ymd') . $owner->getIncreasedCheckingCount();
         return $this['checked_numbers'];
     }
 
 
-
     function update(array $attributes = [], array $options = [])
     {
-        (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']);
+        (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'], $this['id_logistic_return']);
         return parent::update($attributes, $options);
     }
+
     function save(array $options = [])
     {
-        if($this['logistic_number_return'])(new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'],$this['id_logistic_return']);
+        if ($this['logistic_number_return']) (new LogisticNumberFeatureController())->createFeatures($this['logistic_number_return'], $this['id_logistic_return']);
         return parent::save($options);
     }
 
 
-    public function getOwnerNameAttribute(){
-        return $this->owner['name']??'';
+    public function getOwnerNameAttribute()
+    {
+        return $this->owner['name'] ?? '';
     }
-    public function getLogisticNameAttribute(){
-        return $this->logistic['name']??'';
+
+    public function getLogisticNameAttribute()
+    {
+        return $this->logistic['name'] ?? '';
     }
-    public function getIsLoadedStrAttribute(){
-        $val=$this['is_loaded']===null?'null':$this['is_loaded'];
-        $val=$val===0?'0':$val;
-        switch ($val){
-            case 'null':return '无需入库';
-            case '0':return '否';
-            case 1:return '是';
-            case 2:return '待推单';
-            case 3:return '上传异常';
+
+    public function getIsLoadedStrAttribute()
+    {
+        $val = $this['is_loaded'] === null ? 'null' : $this['is_loaded'];
+        $val = $val === 0 ? '0' : $val;
+        switch ($val) {
+            case 'null':
+                return '无需入库';
+            case '0':
+                return '否';
+            case 1:
+                return '是';
+            case 2:
+                return '待推单';
+            case 3:
+                return '上传异常';
         }
         return '';
     }
-    public function getGoodsAmountAttribute(){
-        $amount=0;
-        $this->items->each(function (RejectedBillItem $item)use(&$amount){
-            $amount+=$item['amount'];
+
+    public function getGoodsAmountAttribute()
+    {
+        $amount = 0;
+        $this->items->each(function (RejectedBillItem $item) use (&$amount) {
+            $amount += $item['amount'];
         });
         return $amount;
     }
-    public function getOperatorNameAttribute(){
+
+    public function getOperatorNameAttribute()
+    {
         return $this['user'] ? $this['user']['name'] : null;
     }
-    public function getIsLoadedNullAttribute(){
-        if($this['is_loaded']===null) return 'null';
+
+    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;
+
+    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']=1;
-        }else{
-            $this['is_loaded']=0;
+        if ($allItemsAreLoaded) {
+            $this['is_loaded'] = 1;
+        } else {
+            $this['is_loaded'] = 0;
         }
         $this->update();
         return $this['is_loaded'];
@@ -212,9 +259,9 @@ class RejectedBill extends Model
     {
         /** @var OrderIssue $orderIssue */
         $order_issue_rejected_bill = OrderIssueRejectedBill::query()->select('logistic_number_return')
-            ->where('logistic_number_return',$this->logistic_number_return)->first();
-        if ($order_issue_rejected_bill){
-            OrderIssueRejectedBill::query()->where('logistic_number_return',$this->logistic_number_return)->delete();
+            ->where('logistic_number_return', $this->logistic_number_return)->first();
+        if ($order_issue_rejected_bill) {
+            OrderIssueRejectedBill::query()->where('logistic_number_return', $this->logistic_number_return)->delete();
             SyncOrderRejectingStatusJob::dispatch($this);
         }
         return parent::delete();