Explorar o código

退货导入fixed(没写完被注释)

LD %!s(int64=4) %!d(string=hai) anos
pai
achega
401e24ea96

+ 6 - 0
app/Http/Controllers/TestController.php

@@ -937,6 +937,12 @@ class TestController extends Controller
         event(new SendEmailEvent());
     }
 
+    public function ld2()
+    {
+        /** @var LogisticService $logisticService */
+        $logisticService=app('LogisticService');
+        var_dump($logisticService->get(['name'=>'顺丰'])->first());
+    }
     public function y111()
     {
         $controller = new SendEmailsController();

+ 132 - 0
app/Imports/RejectedImport.php

@@ -9,6 +9,8 @@ use App\Owner;
 use App\Rejected;
 use App\RejectedBill;
 use App\RejectedBillItem;
+use App\Services\LogisticService;
+use App\Services\OwnerService;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Session;
 use Maatwebsite\Excel\Concerns\ToCollection;
@@ -119,6 +121,136 @@ class RejectedImport implements ToCollection, WithHeadingRow
             Session::put('jianshangLastImportedMobile',trim($mobile_sender));
         }
     }
+//    public function collection(Collection $collections)
+//    {
+//        $rejectedBill_index=[];
+//        $errers=[];
+//        foreach ($collections as $i=>$row) {
+//            $logistic_number_return = trim($row['退回单号'] ?? $row['退货单号'] ?? $row['快递单号'] ?? $row['logistic_number_return'] ?? '');
+//            $mobile_sender = trim($row['手机号'] ?? $row['mobile_sender'] ?? '');
+//            $logistic_name = trim($row['快递公司'] ?? $row['logistic_name'] ?? '');
+//            $barcode = trim($row['条码'] ?? $row['barcode'] ?? '');
+//            $amount = trim($row['数量'] ?? $row['amount'] ?? '');
+//            $quality_label_name = trim($row['品质'] ?? $row['quality_label_name'] ?? '正品');
+//            $remark = trim($row['备注'] ?? $row['remark'] ?? '');
+//            $ownerName = trim($row['货主'] ?? $row['owner'] ?? '');
+//            if(!$logistic_number_return){$errers[$i][]='第'.($i+1).'行退回单号不能为空,该行没有录入,请手动编辑';continue;}
+//            if(!$logistic_name){$errers[$i][]='第'.($i+1).'行快递公司不能为空,该行没有录入,请手动编辑';continue;}
+//            if(!$barcode){$errers[$i][]='第'.($i+1).'行条码不能为空,该行没有录入,请手动编辑';continue;}
+//            if(!$amount){$errers[$i][]='第'.($i+1).'行数量不能为空,该行没有录入,请手动编辑';continue;}
+//            if(!$ownerName){$errers[$i][]='第'.($i+1).'行货主不能为空,该行没有录入,请手动编辑';continue;}
+//            /** @var OwnerService $ownerService */
+//            $ownerService=app('OwnerService');
+//            /** @var LogisticService $logisticService */
+//            $logisticService=app('LogisticService');
+//            if(!isset($rejectedBill_index[$logistic_number_return])){
+//                $rejectedBill=RejectedBill::query()->where('logistic_number_return',$logistic_number_return)->get();
+//                if($rejectedBill){$errers[$i][]='第'.($i+1).'行的退货单在导入前已有记录,需要先删除掉再导入或手动添加,该行没有录入';continue;}
+//                $owner_id = $ownerService->get(['name' => $ownerName])->first()['id'];
+//                if($rejectedBill){$errers[$i][]='第'.($i+1).'行的货主不存在,请检查是否输错货主名或未录入系统,该行没有录入,请手动编辑';continue;}
+//                $logistic_id = $logisticService->get(['name' => $logistic_name])->first()['id'];
+//                if($rejectedBill){$errers[$i][]='第'.($i+1).'行的快递不存在,请检查是否输错快递名或未录入系统,该行没有录入,请手动编辑';continue;}
+//                $rejectedBill=new RejectedBill([
+//                    'id_owner'=> $owner_id,
+//                    'mobile_sender'=>$mobile_sender,
+//                    'logistic_number_return'=>$logistic_number_return,
+//                    'id_logistic_return'=>$logistic_id,
+//                    'is_loaded'=>0,
+//                ]);
+//                $rejectedBill_index[$logistic_number_return]=$rejectedBill;
+//            }
+//        }
+//
+//        foreach ($collections as $row)
+//        {
+//            $logistic_number_return = trim($row['退回单号']??$row['退货单号']??$row['快递单号']??$row['logistic_number_return']??'');
+//            $mobile_sender = trim($row['手机号']??$row['mobile_sender']??'');
+//            $logistic_name = trim($row['快递公司']??$row['logistic_name']??'');
+//            $barcode = trim($row['条码']??$row['barcode']??'');
+//            $amount = trim($row['数量']??$row['amount']??'');
+//            $quality_label_name = trim($row['品质']??$row['quality_label_name']??'');
+//            $remark = trim($row['备注']??$row['remark']??'');
+//            $owner=trim($row['货主']??$row['owner']??'');
+//
+////            $lastReturnNumber = Session::get('jianshangLastImportedBill');
+////            if(!$logistic_number_return)$logistic_number_return=$lastReturnNumber;
+////            $lastMobile = Session::get('jianshangLastImportedMobile');
+////            if(!$mobile_sender)$mobile_sender=$lastMobile;
+////            $lastlogistic_name = Session::get('jianshangLastImportedLogisticName');
+////            if(!$logistic_name)$logistic_name=$lastlogistic_name;
+//
+//
+//            $owner=Owner::query()->where('name','like',$owner.'%')->first();
+//            $id_logistic_return=Logistic::query()->where('name','like',"%{$logistic_name}%")->first()['id'];
+//            if(!$id_logistic_return){
+//                $id_logistic_return=Logistic::query()->where('name','like',"%其它%")->first()['id'];
+//            }
+//
+//            $id_quality_label=3;
+//            if(trim($quality_label_name)=='正品'){
+//                $id_quality_label=1;
+//            }elseif(trim($quality_label_name)=='残次'){
+//                $id_quality_label=2;
+//            }
+//            if(!$amount)$amount=1;
+//
+//
+//            $bill=RejectedBill::query()->where('logistic_number_return',trim($logistic_number_return))->first();
+//            if($bill){
+//                $item=RejectedBillItem::query()->where('id_rejected_bill',$bill['id'])
+//                    ->where('barcode_goods',trim($barcode))->where('id_quality_label',$id_quality_label)->first();
+//                if($item){
+//                    $item['amount']+=$amount;
+//                    $item->update();
+//                }else{
+//                    $item=new RejectedBillItem([
+//                        'id_rejected_bill'=>$bill['id'],
+//                        'barcode_goods'=>trim($barcode),
+//                        'amount'=>trim($amount),
+//                        'id_quality_label'=>$id_quality_label,
+//                        'remark'=>$remark,
+//                    ]);
+//                    $item->save();
+//                }
+//                $bill->syncOrderIssue();
+//            }else{
+//                $bill=new RejectedBill([
+//                    'id_owner'=>$owner['id'],
+//                    'mobile_sender'=>$mobile_sender,
+//                    'logistic_number_return'=>$logistic_number_return,
+//                    'id_logistic_return'=>$id_logistic_return,
+//                    'is_loaded'=>0,
+//                ]);
+//                $bill->save();
+//                $bill->joinOrderIssue();
+//                $bill->syncOrderIssue();
+//                $item=RejectedBillItem::query()->where('id_rejected_bill',$bill['id'])
+//                    ->where('barcode_goods',trim($barcode))->where('id_quality_label',$id_quality_label)->first();
+//                if($item){
+//                    $item['amount']+=$amount;
+//                    $item->update();
+//                }else{
+//                    $item=new RejectedBillItem([
+//                        'id_rejected_bill'=>$bill['id'],
+//                        'barcode_goods'=>trim($barcode),
+//                        'amount'=>trim($amount),
+//                        'id_quality_label'=>$id_quality_label,
+//                        'remark'=>$remark,
+//                    ]);
+//                    $item->save();
+//                }
+//            }
+//
+//            $lastBill = Session::get('jianshangLastImportedBill');
+//            if($owner['name']=='笕尚'&&$lastBill&&$lastBill !=trim($logistic_number_return)){
+//                $this->submitToApi($bill);
+//            }
+//            Session::put('jianshangLastImportedLogisticName',trim($logistic_name));
+//            Session::put('jianshangLastImportedBill',trim($logistic_number_return));
+//            Session::put('jianshangLastImportedMobile',trim($mobile_sender));
+//        }
+//    }
+
     private function submitToApi(RejectedBill $bill){
         if(!$bill||$bill->items()->get()->isEmpty())return;
         $havingFail=0;

+ 18 - 13
app/Services/OwnerService.php

@@ -185,19 +185,24 @@ class OwnerService
 
     public function get(array $params, array $withs = null, bool $authority = true, bool $notShowSoftDelete = false, $user = null)
     {
-        /** @var User $user */
-        if ($user==null) {
-            $user = Auth::user();
-        }
-        $query = Owner::query();
-        if ($withs)$query->with($withs);
-        if ($authority){
-            $ids = $user->getPermittingOwnerIdsAttribute();
-            $query->whereIn("id",$ids);
-        }
-        if ($notShowSoftDelete) $query->whereNull('deleted_at');
-        $query = $this->query($query,$params);
-        return $query->get();
+        return Cache::remember(
+            'owner_'.md5(json_encode($params).json_encode($withs).$authority.$notShowSoftDelete.json_encode($user))
+            ,config('cache.expirations.rarelyChange')
+            ,function()use($params,$withs,$authority,$notShowSoftDelete,$user){
+            /** @var User $user */
+            if ($user==null) {
+                $user = Auth::user();
+            }
+            $query = Owner::query();
+            if ($withs)$query->with($withs);
+            if ($authority&&$user){
+                $ids = $user->getPermittingOwnerIdsAttribute();
+                $query->whereIn("id",$ids);
+            }
+            if ($notShowSoftDelete) $query->whereNull('deleted_at');
+            $query = $this->query($query,$params);
+            return $query->get();
+        });
     }
 
     public function paginate(array $params, array $withs = null, bool $authority = true, bool $notShowSoftDelete = false)