Quellcode durchsuchen

合同 施工单 加部门和人员范围

cqpCow vor 1 Jahr
Ursprung
Commit
03bac70db0

+ 7 - 0
app/Http/Middleware/CheckLogin.php

@@ -39,6 +39,13 @@ class CheckLogin
         list($depart, $is_main) = EmployeeService::getLoginDepart($result);
         $data['rule_depart'] = $depart;
         $data['is_main'] = $is_main;
+        $depart_b = [];
+        if(is_array($depart)){
+            foreach ($depart as $value){
+                $depart_b[] = $value['depart_id'];
+            }
+        }
+        $data['depart_has'] = $depart_b;
 
         //写入user信息
         $request->userData = $data;

+ 23 - 0
app/Model/Construction.php

@@ -2,6 +2,7 @@
 
 namespace App\Model;
 
+use App\Scopes\DepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
 class Construction extends Model
@@ -21,4 +22,26 @@ class Construction extends Model
         self::Model_type_one => 'WO0.',
         self::Model_type_two => 'T9SH.',
     ];
+
+    public static $user = [];
+    public static $is_search = false;
+
+    public function __construct(array $attributes = [])
+    {
+        if(! empty($attributes['userData'])) {
+            self::$user = $attributes['userData'];
+            self::$is_search = true;
+        }
+        parent::__construct($attributes);
+    }
+
+    protected static function boot(){
+        parent::boot();
+        if(self::$is_search){
+            $depart = self::$user['depart_has'] ?? [];
+            $is_main = self::$user['is_main'] ?? 0;
+            $user_id = self::$user['id'] ?? 0;
+            static::addGlobalScope(new DepartmentScope($depart,$is_main,$user_id));
+        }
+    }
 }

+ 23 - 0
app/Model/SalesOrder.php

@@ -2,10 +2,12 @@
 
 namespace App\Model;
 
+use App\Scopes\DepartmentScope;
 use Illuminate\Database\Eloquent\Model;
 
 class SalesOrder extends Model
 {
+    protected $fillable = ['userData'];
     protected $table = "sales_order"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
@@ -24,4 +26,25 @@ class SalesOrder extends Model
         self::Model_type_two => 'T9SO.',
         self::Model_type_three => 'T9XS.'
     ];
+    public static $user = [];
+    public static $is_search = false;
+
+    public function __construct(array $attributes = [])
+    {
+        if(! empty($attributes['userData'])) {
+            self::$user = $attributes['userData'];
+            self::$is_search = true;
+        }
+        parent::__construct($attributes);
+    }
+
+    protected static function boot(){
+        parent::boot();
+        if(self::$is_search){
+            $depart = self::$user['depart_has'] ?? [];
+            $is_main = self::$user['is_main'] ?? 0;
+            $user_id = self::$user['id'] ?? 0;
+            static::addGlobalScope(new DepartmentScope($depart,$is_main,$user_id));
+        }
+    }
 }

+ 33 - 0
app/Scopes/DepartmentScope.php

@@ -0,0 +1,33 @@
+<?php
+namespace App\Scopes;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Scope;
+
+class DepartmentScope implements Scope
+{
+    public $depart_id = [];
+    public $is_main = 0;
+    public $user_id = 0;
+
+    public function __construct($depart_id = [], $is_main = 0, $user_id = 0)
+    {
+        if(! is_array($depart_id)) $depart_id = [$depart_id];
+        $this->depart_id = $depart_id;
+        $this->is_main = $is_main;
+        $this->user_id = $user_id;
+    }
+
+    public function apply(Builder $builder, Model $model)
+    {
+        if(! $this->is_main) {
+            $depart_id = $this->depart_id;
+            $user_id = $this->user_id;
+            $builder->where(function ($query) use ($depart_id,$user_id){
+                $query->whereIn('depart_id', $depart_id)
+                    ->orWhere('crt_id', $user_id);
+            });
+        }
+    }
+}

+ 11 - 10
app/Service/ConstructionService.php

@@ -8,15 +8,12 @@ use App\Model\ConstructionInfo;
 use App\Model\ConstructionProductInfo;
 use App\Model\Customer;
 use App\Model\Employee;
-use App\Model\SalesOrder;
-use App\Model\SalesOrderInfo;
-use App\Model\SalesOrderProductInfo;
 use Illuminate\Support\Facades\DB;
 
 class ConstructionService extends Service
 {
     public function constructionEdit($data,$user){
-        list($status,$msg) = $this->constructionRule($data,false);
+        list($status,$msg) = $this->constructionRule($data, $user, false);
         if(!$status) return [$status,$msg];
 
         try {
@@ -38,6 +35,7 @@ class ConstructionService extends Service
             $model->address1 = $data['address1'] ?? '';
             $model->address2 = $data['address2'] ?? '';
             $model->introduction = $data['introduction'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? 0;
             $model->save();
             $time = time();
 
@@ -59,7 +57,7 @@ class ConstructionService extends Service
                         'crt_time' => $time,
                     ];
                 }
-                SalesOrderInfo::insert($insert);
+                ConstructionInfo::insert($insert);
             }
 
             if(! empty($data['employee_one'])){
@@ -100,13 +98,13 @@ class ConstructionService extends Service
     }
 
     public function constructionAdd($data,$user){
-        list($status,$msg) = $this->constructionRule($data);
+        list($status,$msg) = $this->constructionRule($data,$user);
         if(!$status) return [$status,$msg];
 
         try {
             DB::beginTransaction();
 
-            $model = new SalesOrder();
+            $model = new Construction();
             $model->model_type = $data['model_type'];
             $model->order_number = $data['order_number'];
             $model->title = $data['title'] ?? '';
@@ -123,6 +121,7 @@ class ConstructionService extends Service
             $model->address2 = $data['address2'] ?? '';
             $model->introduction = $data['introduction'] ?? '';
             $model->crt_id = $user['id'];
+            $model->depart_id = $data['depart_id'] ?? 0;
             $model->save();
             $time = time();
 
@@ -137,7 +136,7 @@ class ConstructionService extends Service
                         'crt_time' => $time,
                     ];
                 }
-                SalesOrderInfo::insert($insert);
+                ConstructionInfo::insert($insert);
             }
 
             if(! empty($data['employee_one'])){
@@ -271,7 +270,8 @@ class ConstructionService extends Service
     }
 
     public function constructionList($data,$user){
-        $model = Construction::where('del_time',0)
+        $model = new Construction(['userData' => $user]);
+        $model = $model->where('del_time',0)
             ->select('title','id','model_type','order_number','customer_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction')
             ->orderby('id', 'desc')
             ->where('model_type',$data['model_type']);
@@ -284,7 +284,7 @@ class ConstructionService extends Service
         return [true, $list];
     }
 
-    public function constructionRule(&$data, $is_add = true){
+    public function constructionRule(&$data, $user, $is_add = true){
         if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
         if(! in_array($data['model_type'],Construction::$model_type)) return [false,'工单模板类型错误'];
         if(empty($data['order_number'])) return [false,'工单编号不能为空'];
@@ -311,6 +311,7 @@ class ConstructionService extends Service
         }else{
             if(empty($data['address1']) || empty($data['address2'])) return [false,'地址不能为空'];
         }
+        if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
 
         if($is_add){
             $bool = Construction::where('del_time',0)->where('order_number',$data['order_number'])->exists();

+ 2 - 1
app/Service/EmployeeService.php

@@ -41,7 +41,7 @@ class EmployeeService extends Service
             $model->is_admin = $data['is_admin'];
             if($model->is_admin == 1){
                 $model->account = $data['number'];
-                if($data['password'] !== '********'){
+                if($data['password'] !== '******'){
                     $model->password   = Hash::make($data['password']);
                 }
             }
@@ -831,6 +831,7 @@ class EmployeeService extends Service
             ->where('a.employee_id',$employee_id)
             ->where('b.is_use',Depart::IS_UES)
             ->select('a.depart_id','b.is_main')
+            ->orderBy('a.depart_id','asc')
             ->get()->toArray();
         if(! empty($depart)){
             foreach ($depart as $value){

+ 20 - 5
app/Service/SalesOrderService.php

@@ -5,6 +5,7 @@ namespace App\Service;
 use App\Model\BasicType;
 use App\Model\Customer;
 use App\Model\Employee;
+use App\Model\Product;
 use App\Model\SalesOrder;
 use App\Model\SalesOrderInfo;
 use App\Model\SalesOrderProductInfo;
@@ -13,7 +14,7 @@ use Illuminate\Support\Facades\DB;
 class SalesOrderService extends Service
 {
     public function salesOrderEdit($data,$user){
-        list($status,$msg) = $this->salesOrderRule($data,false);
+        list($status,$msg) = $this->salesOrderRule($data, $user, false);
         if(!$status) return [$status,$msg];
 
         try {
@@ -50,6 +51,7 @@ class SalesOrderService extends Service
             $model->color = $data['color'] ?? '';
             $model->original_set = $data['original_set'] ?? '';
             $model->processing = $data['processing'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? 0;
             $model->save();
             $time = time();
 
@@ -124,7 +126,7 @@ class SalesOrderService extends Service
     }
 
     public function salesOrderAdd($data,$user){
-        list($status,$msg) = $this->salesOrderRule($data);
+        list($status,$msg) = $this->salesOrderRule($data,$user);
         if(!$status) return [$status,$msg];
 
         try {
@@ -161,6 +163,7 @@ class SalesOrderService extends Service
             $model->color = $data['color'] ?? '';
             $model->original_set = $data['original_set'] ?? '';
             $model->processing = $data['processing'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? 0;
             $model->crt_id = $user['id'];
             $model->save();
             $time = time();
@@ -311,12 +314,23 @@ class SalesOrderService extends Service
             ->where('sales_order_id',$sales['id'])
             ->select('id','sales_order_id','product_id','mark','price','number')
             ->get()->toArray();
+        $pro = Product::whereIn('id',array_column($sales_p_info,'product_id'))
+            ->select('bar_code','code','cost','depart_price','size','title','id')
+            ->get()->toArray();
+        $pro = array_column($pro,null,'id');
         foreach ($sales_p_info as $value){
+            $p = $pro[$value['product_id']] ?? [];
             $sales['product'][] = [
                 'product_id' => $value['product_id'],
                 'mark' => $value['mark'],
                 'retail_price' => $value['price'],
                 'number' => $value['number'],
+                'bar_code' => $p['bar_code'] ?? '',
+                'code' => $p['code'] ?? '',
+                'cost' => $p['cost'] ?? 0,
+                'depart_price' => $p['depart_price'] ?? 0,
+                'size' => $p['size'] ?? '',
+                'title' => $p['title'] ?? '',
             ];
         }
         $sales['crt_name'] = $emp_map[$sales['crt_id']] ?? '';
@@ -326,7 +340,8 @@ class SalesOrderService extends Service
     }
 
     public function salesOrderList($data,$user){
-        $model = SalesOrder::where('del_time',0)
+        $model = new SalesOrder(['userData' => $user]);
+        $model = $model->where('del_time',0)
             ->select('title','id','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');
 
@@ -352,7 +367,7 @@ class SalesOrderService extends Service
         return [true, $list];
     }
 
-    public function salesOrderRule(&$data, $is_add = true){
+    public function salesOrderRule(&$data, $user, $is_add = true){
         if(empty($data['model_type'])) return [false,'订单模板类型不能为空'];
         if(! in_array($data['model_type'],SalesOrder::$model_type)) return [false,'订单模板类型错误'];
         if(empty($data['order_number'])) return [false,'合同编号不能为空'];
@@ -376,7 +391,6 @@ class SalesOrderService extends Service
         if(empty($data['contract_fee'])) return [false,'合同金额不能为空'];
         $res = $this->checkNumber($data['contract_fee']);
         if(! $res) return [false, '合同金额请输入不超过两位小数并且大于0的数值'];
-
         if(! empty($data['rate'])){
             $res = $this->checkNumber($data['rate']);
             if(! $res) return [false, '整单扣除率请输入不超过两位小数并且大于0的数值'];
@@ -389,6 +403,7 @@ class SalesOrderService extends Service
             $res = $this->checkNumber($data['discount_fee']);
             if(! $res) return [false, '优惠金额请输入不超过两位小数并且大于0的数值'];
         }
+        if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
 
         if($data['model_type'] == SalesOrder::Model_type_one){
             if(empty($data['order_type'])) return [false,'订单类型不能为空'];

+ 10 - 3
app/Service/Service.php

@@ -305,8 +305,8 @@ class Service
         $formattedDate1 = $dateTime1->format('Y-m-d');
 
         $return = [];
-        $return[] = $formattedDate;
-        $return[] = $formattedDate1;
+        $return[] = strtotime($formattedDate);
+        $return[] = strtotime($formattedDate1);
 
         return $return;
     }
@@ -325,7 +325,7 @@ class Service
         // 将日期时间格式化为特定格式
         $formattedDate = $dateTime->format('Y-m-d H:i');
 
-        return $formattedDate;
+        return strtotime($formattedDate);
     }
 
     /**
@@ -346,4 +346,11 @@ class Service
 
         return true;
     }
+
+    public function getDepart($user){
+        if(empty($user)) return 0;
+        if(! empty($user['is_main'])) return 0;
+        $depart = array_shift($user['depart_has']);
+        return $depart;
+    }
 }

+ 3 - 2
app/Service/SysMenuService.php

@@ -135,8 +135,9 @@ class SysMenuService extends Service
                 ->select('title','icon','uri','parent_id','sort','crt_time','id')
                 ->orderBy('sort','desc');
             if($user['id'] != Employee::SPECIAL_ADMIN){
-                $role = EmployeeService::getPersonRole($user['id']);
-                $menu = EmployeeService::getMenuByRole($role,$user['id']);
+                $emp = new EmployeeService();
+                $role = $emp->getPersonRole($user['id']);
+                $menu = $emp->getMenuByRole($role,$user['id']);
                 $list->whereIn('id',array_column($menu,'menu_id'));
             }
             $list = $list->get()->toArray();