cqpCow 1 năm trước cách đây
mục cha
commit
b869b566ac

+ 1 - 18
app/Model/BasicType.php

@@ -2,12 +2,8 @@
 
 namespace App\Model;
 
-use App\Scopes\TopDepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class BasicType extends Model
+class BasicType extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "basic_type"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -39,17 +35,4 @@ class BasicType extends Model
         22 => '产品价格',
         23 => '安装地点',
     ];
-
-    public static $user = [];
-    public static $search = [];
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new TopDepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 19
app/Model/Construction.php

@@ -2,12 +2,8 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class Construction extends Model
+class Construction extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "construction"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -30,19 +26,5 @@ class Construction extends Model
         self::STATE_ZERO => '未确认',
         self::STATE_ONE => '已确认',
     ];
-
-    public static $user = [];
-    public static $search = [];
     const range_function = 'constructionRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 18
app/Model/Customer.php

@@ -2,13 +2,8 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class Customer extends Model
+class Customer extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData','search'];
-    protected $guarded = [];
     protected $table = "customer"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -24,16 +19,4 @@ class Customer extends Model
     public static $search = [];
     public static $limitKey = "customerPondState";
     const range_function = 'customerRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'];
-            self::$user['range_function'] = self::range_function;
-            //进入公海池 去掉限制
-            if(! empty(self::$search['pond_state']))  static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 20
app/Model/InOutRecord.php

@@ -2,29 +2,10 @@
 
 namespace App\Model;
 
-use App\Scopes\ProductInventoryScope;
-use Illuminate\Database\Eloquent\Model;
-
-class InOutRecord extends Model
+class InOutRecord extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "in_out_record"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
-    const range_function = '';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            self::$user['range_function'] = self::range_function;
-            static::addGlobalScope(new ProductInventoryScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 0 - 15
app/Model/InvoiceOrder.php

@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
 
 class InvoiceOrder extends Model
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "invoice_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -21,18 +19,5 @@ class InvoiceOrder extends Model
         1 => '已确认',
     ];
 
-    public static $user = [];
-    public static $search = [];
     const range_function = 'invoiceRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            self::$user['range_function'] = self::range_function;
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 19
app/Model/Product.php

@@ -2,13 +2,8 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class Product extends Model
+class Product extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "product"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -22,18 +17,5 @@ class Product extends Model
         self::State_two => '下架',
     ];
 
-    public static $user = [];
-    public static $search = [];
     const range_function = 'productRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 20
app/Model/ProductActivity.php

@@ -2,30 +2,11 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class ProductActivity extends Model
+class ProductActivity extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "product_activity"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
     const range_function = '';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 15
app/Model/ProductCategory.php

@@ -5,24 +5,10 @@ namespace App\Model;
 use App\Scopes\TopDepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
-class ProductCategory extends Model
+class ProductCategory extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "product_category"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new TopDepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 20
app/Model/ProductInventory.php

@@ -2,29 +2,10 @@
 
 namespace App\Model;
 
-use App\Scopes\ProductInventoryScope;
-use Illuminate\Database\Eloquent\Model;
-
-class ProductInventory extends Model
+class ProductInventory extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "product_inventory"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = null;
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
-    const range_function = '';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            self::$user['range_function'] = self::range_function;
-            static::addGlobalScope(new ProductInventoryScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 15
app/Model/ProductInventorySet.php

@@ -5,26 +5,12 @@ namespace App\Model;
 use App\Scopes\TopDepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
-class ProductInventorySet extends Model
+class ProductInventorySet extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "depart_set"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
     const type_one = 1;//校验锁定
     const type_two = 2;//不校验锁定
-
-    public static $user = [];
-    public static $search = [];
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'];
-            static::addGlobalScope(new TopDepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 16
app/Model/PurchaseOrder.php

@@ -5,10 +5,8 @@ namespace App\Model;
 use App\Scopes\DepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
-class PurchaseOrder extends Model
+class PurchaseOrder extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "purchase_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -31,18 +29,5 @@ class PurchaseOrder extends Model
         self::Order_type_three => '采购施工(安装费)'
     ];
 
-    public static $user = [];
-    public static $search = [];
     const range_function = 'purchaseRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'] ?? [];
-            self::$user['range_function'] = self::range_function;
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 16
app/Model/ReturnExchangeOrder.php

@@ -5,10 +5,8 @@ namespace App\Model;
 use App\Scopes\DepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
-class ReturnExchangeOrder extends Model
+class ReturnExchangeOrder extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "return_exchange_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -42,18 +40,5 @@ class ReturnExchangeOrder extends Model
         self::Model_type_one => 'TH',
         self::Model_type_two => 'HH',
     ];
-    public static $user = [];
-    public static $search = [];
     const range_function = 'returnExchangeOrderRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 14
app/Model/Role.php

@@ -10,25 +10,12 @@ use Illuminate\Database\Eloquent\Model;
  * Class Unit
  * @package App\Models
  */
-class Role extends Model
+class Role extends UseScopeBaseModel
 {
-    protected $guarded = [];
     protected $table = "role"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
     public static $user = [];
     public static $search = [];
-    const range_function = '';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 2 - 20
app/Model/SalesOrder.php

@@ -2,17 +2,13 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class SalesOrder extends Model
+class SalesOrder extends UseScopeBaseModel
 {
-//    protected $fillable = [];
-    protected $guarded = [];
     protected $table = "sales_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+    const range_function = 'salesOrderRange';
     const Order_type_one = 1;//安装件
     const Order_type_two = 2;//快递件
     public static $order_type = [
@@ -58,18 +54,4 @@ class SalesOrder extends Model
         self::Model_type_two => 'T9SO.',
         self::Model_type_three => 'T9XS.'
     ];
-    public static $user = [];
-    public static $search = [];
-    const range_function = 'salesOrderRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 20
app/Model/SportsBag.php

@@ -2,30 +2,11 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class SportsBag extends Model
+class SportsBag extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "sports_bag"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
     const range_function = 'sportsBagRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 24
app/Model/Storehouse.php

@@ -2,33 +2,10 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-/**
- * 仓库
- * Class Unit
- * @package App\Models
- */
-class Storehouse extends Model
+class Storehouse extends UseScopeBaseModel
 {
-//    protected $fillable = ['userData'];
-    protected $guarded = [];
     protected $table = "storehouse"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-
-    public static $user = [];
-    public static $search = [];
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$search = $attributes['search'];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 1 - 19
app/Model/Supplier.php

@@ -2,31 +2,13 @@
 
 namespace App\Model;
 
-use App\Scopes\DepartmentScope;
-use Illuminate\Database\Eloquent\Model;
-
-class Supplier extends Model
+class Supplier extends UseScopeBaseModel
 {
-//    protected $fillable = [];
-    protected $guarded = [];
     protected $table = "supplier"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
     const is_main = 1;//是否总供应商
 
-    public static $user = [];
-    public static $search = [];
     const range_function = 'supplierRange';
-
-    public function __construct(array $attributes = [])
-    {
-        if(! empty($attributes['userData'])) {
-            self::$user = $attributes['userData'];
-            self::$user['range_function'] = self::range_function;
-            self::$search = $attributes['search'] ?? [];
-            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
-        }
-        parent::__construct($attributes);
-    }
 }

+ 159 - 0
app/Model/UseScopeBaseModel.php

@@ -0,0 +1,159 @@
+<?php
+
+namespace App\Model;
+
+use App\Scopes\TopDepartmentScope;
+use App\Service\RangeService;
+use Illuminate\Database\Eloquent\Model;
+
+class UseScopeBaseModel extends Model
+{
+    //可见范围
+    const range_function = '';
+
+    public function __construct(array $attributes = [])
+    {
+        parent::__construct($attributes);
+    }
+
+    //顶级部门过滤
+    public function scopeTopClear($query, $user, $search)
+    {
+        //是否所有部门
+        $is_all_depart = $user['is_all_depart'] ?? 0;
+        //权限范围内的部门
+        $depart_range = $user['depart_range'] ?? [];
+
+        //顶级部门
+        $search_depart_id = $search['top_depart_id'] ?? 0;
+        if(empty($search_depart_id)){
+            //默认进来 自身顶级公司
+            $top_depart_id = $user['depart_top'][0] ?? [];
+            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
+        }else{
+            //查询 顶级公司
+            $top_depart_id = $search_depart_id;
+        }
+
+        if($is_all_depart){
+            //所有部门
+            if(empty($search_depart_id)){
+                //全部
+                $query->whereIn('top_depart_id', $depart_range);
+            }else{
+                //查看某个分社
+                $query->where('top_depart_id', $top_depart_id);
+            }
+        }else{
+            //某个分社全部
+            $query->where('top_depart_id', $top_depart_id);
+        }
+
+        return $query;
+    }
+
+    //部门和顶级部门(公司)过滤
+    public function scopeClear($query, $user, $search)
+    {
+        //是否所有部门
+        $is_all_depart = $user['is_all_depart'] ?? 0;
+        //权限范围内的部门
+        $depart_range = $user['depart_range'] ?? [];
+        //我可见的
+        $is_see = $search['is_see'] ?? 0;
+
+        //可见范围方法
+        $model = $query->getModel(); // 获取模型的实例
+        $range_function = $model::range_function ?? ""; // 访问静态属性
+        $is_function_range = $this->hasMethod(new RangeService(),$range_function);
+
+        //顶级部门
+        $search_depart_id = $search['top_depart_id'] ?? 0; //顶级公司
+        if(empty($search_depart_id)){
+            //默认进来 自身顶级公司
+            $top_depart_id = $user['depart_top'][0] ?? [];
+            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
+        }else{
+            //查询 顶级公司
+            $top_depart_id = $search_depart_id;
+        }
+
+        $id = [];
+        //可见范围 以及单据里面填写人员
+        if($is_function_range) $id = RangeService::$range_function($user,$search);
+
+        if($is_all_depart){
+            //所有部门
+            if(empty($search_depart_id)){
+                if(! $is_see){
+                    //全部
+                    $query->whereIn('depart_id', $depart_range);
+                }else{
+                    //可见
+                    $query->whereIn('id', $id);
+                }
+            }else{
+                if(! $is_see){
+                    //查看某个分社
+                    $query->where('top_depart_id', $top_depart_id);
+                }else{
+                    //查看某个分社可见
+                    $query->whereIn('id', $id);
+                }
+            }
+        }else{
+            //分社
+            if(! $is_see){
+                //某个分社全部
+                $query->where('top_depart_id', $top_depart_id)
+                    ->whereIn('depart_id', $depart_range)
+                    ->orWhereIn('id', $id);
+            }else{
+                //某个分社可见
+                $query->whereIn('id', $id);
+            }
+        }
+    }
+
+    function hasMethod($class, $methodName)
+    {
+        $reflection = new \ReflectionClass($class);
+        return $reflection->hasMethod($methodName);
+    }
+
+    //顶级部门过滤 取别名a
+    public function scopeATopClear($query, $user, $search)
+    {
+        //是否所有部门
+        $is_all_depart = $user['is_all_depart'] ?? 0;
+        //权限范围内的部门
+        $depart_range = $user['depart_range'] ?? [];
+
+        //顶级部门
+        $search_depart_id = $search['top_depart_id'] ?? 0;
+        if(empty($search_depart_id)){
+            //默认进来 自身顶级公司
+            $top_depart_id = $user['depart_top'][0] ?? [];
+            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
+        }else{
+            //查询 顶级公司
+            $top_depart_id = $search_depart_id;
+        }
+
+        if($is_all_depart){
+            //所有部门
+            if(empty($search_depart_id)){
+                //全部
+                $query->whereIn('a.top_depart_id', $depart_range);
+            }else{
+                //查看某个分社
+                $query->where('a.top_depart_id', $top_depart_id);
+            }
+        }else{
+            //某个分社全部
+            $query->where('a.top_depart_id', $top_depart_id);
+        }
+
+        return $query;
+    }
+}

+ 1 - 1
app/Service/BasicTypeService.php

@@ -58,7 +58,7 @@ class BasicTypeService extends Service
      * @return array
      */
     public function basicTypeList($data, $user){
-        $model = new BasicType(['userData' => $user, 'search' => $data]);
+        $model = BasicType::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','type')
             ->orderby('id', 'asc');

+ 1 - 1
app/Service/ConstructionService.php

@@ -362,7 +362,7 @@ class ConstructionService extends Service
      * @return array
      */
     public function constructionList($data,$user){
-        $model = new Construction(['userData' => $user, 'search' => $data]);
+        $model = Construction::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/CustomerService.php

@@ -436,7 +436,7 @@ class CustomerService extends Service
      * @return array
      */
     public function customerList($data,$user){
-        $model = new Customer(['userData' => $user,'search'=> $data]);
+        $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','customer_grade','pond_state','top_depart_id')
             ->orderby('id', 'desc');

+ 5 - 1
app/Service/EmployeeService.php

@@ -374,6 +374,10 @@ class EmployeeService extends Service
             'del_time' => time()
         ]);
 
+        RoleMenu::where('role_id',$data['id'])->update([
+            'del_time' => time()
+        ]);
+
         return [true,'删除成功'];
     }
 
@@ -383,7 +387,7 @@ class EmployeeService extends Service
      * @return array
      */
     public function roleList($data,$user){
-        $model = new Role(['userData' => $user, 'search' => $data]);
+        $model = Role::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','crt_time','id','upd_time')
             ->orderBy('id','desc');

+ 1 - 1
app/Service/InvoiceOrderService.php

@@ -216,7 +216,7 @@ class InvoiceOrderService extends Service
      * @return array
      */
     public function getList($data,$user){
-        $model = new InvoiceOrder(['userData' => $user, 'search' => $data]);
+        $model = InvoiceOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','order_number','sales_order_id','depart_id','send','send_time','take','take_address','take_phone','logistics_company','logistics_number','crt_id','mark','state','crt_time','storehouse_id')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/ProductActivityService.php

@@ -164,7 +164,7 @@ class ProductActivityService extends Service
     }
 
     public function productList($data,$user){
-        $model = new ProductActivity(['userData' => $user, 'search' => $data]);
+        $model = ProductActivity::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','title','crt_id','mark','start_time','end_time','crt_time')
             ->orderby('id', 'desc');

+ 4 - 8
app/Service/ProductInventoryService.php

@@ -179,7 +179,7 @@ class ProductInventoryService extends Service
 
     //现存量
     public function productInventoryList($data,$user){
-        $model = new ProductInventory(['userData' => $user, 'search' => $data]);
+        $model = ProductInventory::ATopClear($user,$data);
         $model = $model->from('product_inventory as a')
             ->join('product as b','b.id','a.product_id')
             ->select('a.product_id','a.id','a.number','b.title','b.code','b.product_category_id','b.unit','b.bar_code','a.crt_time','a.storehouse_id')
@@ -240,7 +240,7 @@ class ProductInventoryService extends Service
     public function productInventoryStockList($data,$user){
         if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false,'时间必须选择'];
 
-        $model = new InOutRecord(['userData' => $user, 'search' => $data]);
+        $model = InOutRecord::ATopClear($user,$data);
         $model = $model->from('in_out_record as a')
             ->where('a.del_time',0)
             ->join('product as b','b.id','a.product_id')
@@ -281,8 +281,7 @@ class ProductInventoryService extends Service
     public function fillData($data,$time_arr){
         if (empty($data)) return $data;
 
-        $start_data = InOutRecord::withoutGlobalScopes()
-            ->whereIn('product_id',array_unique(array_column($data,'product_id')))
+        $start_data = InOutRecord::whereIn('product_id',array_unique(array_column($data,'product_id')))
             ->where('crt_time','<',$time_arr[0])
             ->where('del_time',0)
             ->select('product_id','number',DB::raw('sum(number) as number'),'top_depart_id')
@@ -354,14 +353,11 @@ class ProductInventoryService extends Service
 
     //系统设置列表
     public function productInventorySetList($data, $user){
-        $model = new ProductInventorySet(['userData' => $user, 'search' => $data]);
-
+        $model = ProductInventorySet::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','top_depart_id','param_one','param_two')
             ->orderby('id', 'desc');
-
         $list = $model->get()->toArray();
-
         $map = Depart::whereIn('id',array_column($list,'top_depart_id'))->pluck('title','id')->toArray();
         foreach ($list as $key => $value){
             $list[$key]['top_depart_title'] = $map[$value['top_depart_id']] ?? "";

+ 2 - 2
app/Service/ProductService.php

@@ -87,7 +87,7 @@ class ProductService extends Service
      * @return array
      */
     public function productCategoryList($data,$user){
-        $model = new ProductCategory(['userData' => $user, 'search' => $data]);
+        $model = ProductCategory::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','parent_id')
             ->orderby('id','desc');
@@ -469,7 +469,7 @@ class ProductService extends Service
      * @return array
      */
     public function productList($data,$user){
-        $model = new Product(['userData' => $user, 'search' => $data]);
+        $model = Product::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/PurchaseOrderService.php

@@ -276,7 +276,7 @@ class PurchaseOrderService extends Service
      * @return array
      */
     public function getList($data,$user){
-        $model = new PurchaseOrder(['userData' => $user, 'search' => $data]);
+        $model = PurchaseOrder::Clear($user,$data);
         $model = $model->where('del_time',0)->select('order_number','id','depart_id','top_depart_id','mark','crt_time','state','crt_id','order_type','sales_order_id','supplier','purchase_id','purchase_total','discount_fee','other_fee','total','storehouse_id')
             ->orderby('id', 'desc');
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');

+ 1 - 1
app/Service/ReturnExchangeOrderService.php

@@ -245,7 +245,7 @@ class ReturnExchangeOrderService extends Service
     }
 
     public function getList($data,$user){
-        $model = new ReturnExchangeOrder(['userData' => $user,'search' => $data]);
+        $model = ReturnExchangeOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','order_number','data_id','difference_amount','state','crt_time','crt_id','mark','model_type','storehouse_id','type')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/SalesOrderService.php

@@ -483,7 +483,7 @@ class SalesOrderService extends Service
      * @return array
      */
     public function salesOrderList($data,$user){
-        $model = new SalesOrder(['userData' => $user, 'search' => $data]);
+        $model = SalesOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','deal_type','customer_id','sign_time','contract_state','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','expire_time','other_fee','discount_fee','contract_fee','contract_type','pay_way','send_state','logistics_company','logistics_number','car_type','year','mileage','color','original_set','processing','state')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/SportsBagService.php

@@ -168,7 +168,7 @@ class SportsBagService extends Service
     }
 
     public function getList($data,$user){
-        $model = new SportsBag(['userData' => $user,'search' => $data]);
+        $model = SportsBag::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','title','number','start_time','end_time','crt_time','crt_id','mark','total_amount')
             ->orderby('id', 'desc');

+ 1 - 1
app/Service/StorehouseService.php

@@ -80,7 +80,7 @@ class StorehouseService extends Service
     }
 
     public function storehouseList($data, $user){
-        $model = new Storehouse(['userData' => $user, 'search' => $data]);
+        $model = Storehouse::TopClear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','title')
             ->orderBy('id','asc');

+ 1 - 1
app/Service/SupplierService.php

@@ -138,7 +138,7 @@ class SupplierService extends Service
      * @return array
      */
     public function customerList($data,$user){
-        $model = new Supplier(['userData' => $user,'search'=> $data]);
+        $model = Supplier::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','title','address1','address2','mobile','crt_id','crt_time','is_main','mark')
             ->orderby('id', 'asc');