cqpCow пре 1 година
родитељ
комит
b3b309d2d3

+ 5 - 2
app/Model/Construction.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class Construction extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = ['userData'];
+    protected $guarded = [];
     protected $table = "construction"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -32,12 +33,14 @@ class Construction extends Model
     ];
 
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -46,7 +49,7 @@ class Construction extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 6 - 3
app/Model/Customer.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class Customer extends Model
 {
-    protected $fillable = ['userData','search'];
+//    protected $fillable = ['userData','search'];
+    protected $guarded = [];
     protected $table = "customer"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -20,6 +21,7 @@ class Customer extends Model
     ];
 
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
     public static $is_pond_state = true;
     public static $limitKey = "customerPondState";
@@ -27,8 +29,9 @@ class Customer extends Model
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'];
             self::$is_search = true;
-            if(! empty($attributes['search']['pond_state'])) self::$is_pond_state = false;
+            if(! empty(self::$search['pond_state'])) self::$is_pond_state = false;
         }
         parent::__construct($attributes);
     }
@@ -36,7 +39,7 @@ class Customer extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search && self::$is_pond_state){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 5 - 2
app/Model/InvoiceOrder.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class InvoiceOrder extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = ['userData'];
+    protected $guarded = [];
     protected $table = "invoice_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -21,12 +22,14 @@ class InvoiceOrder extends Model
     ];
 
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -35,7 +38,7 @@ class InvoiceOrder extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 5 - 2
app/Model/Product.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class Product extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = ['userData'];
+    protected $guarded = [];
     protected $table = "product"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -22,12 +23,14 @@ class Product extends Model
     ];
 
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -36,7 +39,7 @@ class Product extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
         }
     }
 }

+ 5 - 2
app/Model/PurchaseOrder.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class PurchaseOrder extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = ['userData'];
+    protected $guarded = [];
     protected $table = "purchase_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -31,12 +32,14 @@ class PurchaseOrder extends Model
     ];
 
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -45,7 +48,7 @@ class PurchaseOrder extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 5 - 2
app/Model/ReturnExchangeOrder.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class ReturnExchangeOrder extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = ['userData'];
+    protected $guarded = [];
     protected $table = "return_exchange_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -36,12 +37,14 @@ class ReturnExchangeOrder extends Model
         self::Model_type_two => 'HH',
     ];
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -50,7 +53,7 @@ class ReturnExchangeOrder extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 5 - 2
app/Model/SalesOrder.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class SalesOrder extends Model
 {
-    protected $fillable = ['userData'];
+//    protected $fillable = [];
+    protected $guarded = [];
     protected $table = "sales_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -58,12 +59,14 @@ class SalesOrder extends Model
         self::Model_type_three => 'T9XS.'
     ];
     public static $user = [];
+    public static $search = [];
     public static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -72,7 +75,7 @@ class SalesOrder extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 5 - 2
app/Model/Storehouse.php

@@ -12,19 +12,22 @@ use Illuminate\Database\Eloquent\Model;
  */
 class Storehouse extends Model
 {
-    protected $fillable = ['userData'];
+//    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 static $is_search = false;
 
     public function __construct(array $attributes = [])
     {
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
+            self::$search = $attributes['search'];
             self::$is_search = true;
         }
         parent::__construct($attributes);
@@ -33,7 +36,7 @@ class Storehouse extends Model
     protected static function boot(){
         parent::boot();
         if(self::$is_search){
-            static::addGlobalScope(new DepartmentScope(self::$user));
+            static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
         }
     }
 }

+ 12 - 12
app/Scopes/DepartmentScope.php

@@ -1,7 +1,6 @@
 <?php
 namespace App\Scopes;
 
-use App\Model\Employee;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Scope;
@@ -9,24 +8,25 @@ use Illuminate\Database\Eloquent\Scope;
 class DepartmentScope implements Scope
 {
     public $user = [];
+    public $search = [];
 
-    public function __construct($user = [])
+    public function __construct($user = [], $search = [])
     {
         $this->user = $user;
+        $this->search = $search;
     }
 
     public function apply(Builder $builder, Model $model)
     {
-        if($this->user['id'] != Employee::SPECIAL_ADMIN) {
-            $depart_id = $this->user['depart_range'];
-            $user_id = $this->user['id'];
-            $builder->orwhere(function ($query) use ($depart_id,$user_id){
-                $query->where(function ($query_sub) use ($depart_id,$user_id){
-                    $query_sub->whereIn('depart_id', $depart_id)
-                        ->orWhereIn('top_depart_id',$depart_id)
-                        ->orWhere('crt_id', $user_id);
-                });
-            });
+        if(empty($this->search['top_depart_id'])){
+            //默认进来 只显示自己公司下的 自己权限范围下的部门数据
+            $top_depart_id = $this->user['depart_top'][0] ?? [];
+            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
+        }else{
+            //查询给的公司下的 自己权限范围下的部门数据
+            $top_depart_id = $this->search['top_depart_id'];
         }
+        $builder->where('top_depart_id', $top_depart_id)
+            ->whereIn('depart_id', $this->user['depart_range']);
     }
 }

+ 5 - 3
app/Service/ConstructionService.php

@@ -347,12 +347,12 @@ class ConstructionService extends Service
      * @return array
      */
     public function constructionList($data,$user){
-        $model = new Construction(['userData' => $user]);
+        $model = new Construction(['userData' => $user, 'search' => $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');
 
-        if($user['id'] != Employee::SPECIAL_ADMIN){
+        if($user['id'] != Employee::SPECIAL_ADMIN && empty($data['top_depart_id'])){
             //单据中选择的签订负责协同人
             $construction_id = ConstructionInfo::where('del_time',0)
                 ->where('employee_id',$user['id'])
@@ -360,7 +360,9 @@ class ConstructionService extends Service
                 ->get()->toArray();
             $construction_id = array_unique(array_column($construction_id,'construction_id'));
             //可见范围
-            $model->whereIn('id', $construction_id);
+            $model->when(! empty($sales_order_id), function ($query) use ($construction_id) {
+                return $query->orWhereIn('id', $construction_id);
+            });
         }
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);

+ 2 - 7
app/Service/EmployeeService.php

@@ -1113,15 +1113,12 @@ class EmployeeService extends Service
     public static function getLoginDepart($employee_id){
         if(empty($employee_id)) return [];
 
-        //admin账号
-        if($employee_id == Employee::SPECIAL_ADMIN) return [];
-
         //自己绑定的部门 启用的部门
         $depart = EmployeeDepartPermission::from('employee_depart_permission as a')
             ->join('depart as b','b.id','a.depart_id')
             ->where('a.employee_id',$employee_id)
             ->where('b.is_use',Depart::IS_UES)
-            ->select('a.depart_id','b.is_main','b.parent_id')
+            ->select('a.depart_id','b.is_main','b.parent_id','b.basic_type_id')
             ->orderBy('b.parent_id','asc')
             ->orderBy('b.is_main','desc')
             ->orderBy('a.depart_id','asc')
@@ -1161,7 +1158,6 @@ class EmployeeService extends Service
                     if($value['is_main']) {//是总公司
                         //所有部门都有
                         $rule = array_column($list,'id');
-                        $rule[] = 0;
                     }else{//不是总公司
                         //自己以及子部门
                         $depart_id = array_merge(self::getAllIds($list,$map[$value['depart_id']]),[$map[$value['depart_id']]]);
@@ -1173,7 +1169,6 @@ class EmployeeService extends Service
                         if(! empty($depart_map[$top_tmp]['is_main'])){
                             //顶级公司是总公司 所有部门都有
                             $rule = array_column($list,'id');
-                            $rule[] = 0;
                         }else{
                             //顶级公司是分公司 分公司所有部门
                             $depart_id = array_merge(self::getAllIds($list,$top_tmp),[$top_tmp]);
@@ -1186,7 +1181,7 @@ class EmployeeService extends Service
             }
         }
 
-        return [$depart, $top, $map, array_unique($rule), $is_all_depart];
+        return [$depart, array_values($top), $map, array_unique($rule), $is_all_depart];
     }
 
     //判断是否总公司

+ 1 - 1
app/Service/InvoiceOrderService.php

@@ -210,7 +210,7 @@ class InvoiceOrderService extends Service
      * @return array
      */
     public function getList($data,$user){
-        $model = new InvoiceOrder(['userData' => $user]);
+        $model = new InvoiceOrder(['userData' => $user, 'search' => $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');

+ 7 - 3
app/Service/ProductService.php

@@ -536,13 +536,13 @@ class ProductService extends Service
      * @return array
      */
     public function productList($data,$user){
-        $model = new Product(['userData' => $user]);
+        $model = new Product(['userData' => $user, 'search' => $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');
 
         //getALL传入后无视设置范围
-        if(empty($data['getAll']) && $user['id'] != Employee::SPECIAL_ADMIN) {
+        if($user['id'] != Employee::SPECIAL_ADMIN ) {
             $user_id = $user['id'];
             $depart_id = $user['depart_range'];
             $product_id = ProductRange::where('del_time',0)
@@ -551,7 +551,11 @@ class ProductService extends Service
                         ->orWhereIn('depart_id', $depart_id);
                 })->select('product_id')->get()
                 ->toArray();
-            $model->whereIn('id',array_unique(array_column($product_id,'product_id')));
+            $product_id = array_unique(array_column($product_id,'product_id'));
+            //可见范围
+            $model->when(! empty($sales_order_id), function ($query) use ($product_id) {
+                return $query->orWhereIn('id', $product_id);
+            });
         }
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(isset($data['state'])) $model->where('state', $data['state']);

+ 1 - 1
app/Service/PurchaseOrderService.php

@@ -211,7 +211,7 @@ class PurchaseOrderService extends Service
      * @return array
      */
     public function getList($data,$user){
-        $model = new PurchaseOrder(['userData' => $user]);
+        $model = new PurchaseOrder(['userData' => $user, 'search' => $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','rate','discount_fee','other_fee','total','is_purchase_to_main','storehouse_id')
             ->orderby('id', 'desc');
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');

+ 13 - 12
app/Service/SalesOrderService.php

@@ -430,12 +430,12 @@ class SalesOrderService extends Service
      * @return array
      */
     public function salesOrderList($data,$user){
-        $model = new SalesOrder(['userData' => $user]);
+        $model = new SalesOrder(['userData' => $user, 'search' => $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');
 
-        if($user['id'] != Employee::SPECIAL_ADMIN){
+        if($user['id'] != Employee::SPECIAL_ADMIN && empty($data['top_depart_id'])){
             //单据中选择的签订负责协同人
             $sales_order_id = SalesOrderInfo::where('del_time',0)
                 ->where('employee_id',$user['id'])
@@ -453,8 +453,11 @@ class SalesOrderService extends Service
                 ->toArray();
             $sales_order_id = array_unique(array_merge_recursive($sales_order_id,array_column($sales_order_id2,'sales_order_id')));
             //可见范围
-            $model->whereIn('id', $sales_order_id);
+            $model->when(! empty($sales_order_id), function ($query) use ($sales_order_id) {
+                return $query->orWhereIn('id', $sales_order_id);
+            });
         }
+
         if(! empty($data['sales_order_type'])) $model->where('sales_order_type',$data['sales_order_type']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
@@ -529,18 +532,16 @@ class SalesOrderService extends Service
         $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
 
         if($data['model_type'] == SalesOrder::Model_type_one){
-            if(empty($data['order_type'])) return [false,'订单类型不能为空'];
-            if(empty($data['construction_time'])) return [false,'施工日期不能为空'];
-            $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
-            if(empty($data['handover_time'])) return [false,'交车日期不能为空'];
-            $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
-            if(empty($data['deal_type'])) return [false,'成交类型不能为空'];
+//            if(empty($data['order_type'])) return [false,'订单类型不能为空'];
+            if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
+            if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
+//            if(empty($data['deal_type'])) return [false,'成交类型不能为空'];
         }elseif($data['model_type'] == SalesOrder::Model_type_two){
             if(empty($data['title'])) return [false,'合同名称不能为空'];
         }else{
-            if(empty($data['car_type'])) return [false,'车型不能为空'];
-            if(empty($data['year'])) return [false,'年份不能为空'];
-            if(empty($data['mileage'])) return [false,'表显里程不能为空'];
+//            if(empty($data['car_type'])) return [false,'车型不能为空'];
+//            if(empty($data['year'])) return [false,'年份不能为空'];
+//            if(empty($data['mileage'])) return [false,'表显里程不能为空'];
         }
 
         if($is_add){

+ 1 - 1
app/Service/StorehouseService.php

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