Browse Source

现存量

cqpCow 1 year ago
parent
commit
dc5b1885fb

+ 52 - 0
app/Model/ReturnExchangeOrder.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Model;
+
+use App\Scopes\DepartmentScope;
+use Illuminate\Database\Eloquent\Model;
+
+class ReturnExchangeOrder extends Model
+{
+    protected $fillable = ['userData'];
+    protected $table = "return_exchange_order"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const Model_type_one = 1; // 退货单
+    const Model_type_two = 2; // 换货单
+    public static $model_type = [
+        self::Model_type_one,
+        self::Model_type_two,
+    ];
+
+    const State_zero = 0;//未确认
+    const State_one = 1;//已确认
+    public static $state = [
+        self::State_zero => '未确认',
+        self::State_one => '已确认',
+    ];
+
+    public static $prefix = [
+        self::Model_type_one => 'TH',
+        self::Model_type_two => 'HH',
+    ];
+    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){
+            static::addGlobalScope(new DepartmentScope(self::$user));
+        }
+    }
+}

+ 13 - 0
app/Model/ReturnExchangeOrderProductInfo.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ReturnExchangeOrderProductInfo extends Model
+{
+    protected $table = "return_exchange_order_product_info"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+}

+ 19 - 0
app/Model/ReturnExchangeOrderRange.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ReturnExchangeOrderRange extends Model
+{
+    protected $table = "return_exchange_order_range"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 1; // 部门
+    const type_two = 2; // 人
+    public static $type = [
+        self::type_one,
+        self::type_two,
+    ];
+}

+ 15 - 2
app/Service/CustomerService.php

@@ -35,6 +35,7 @@ class CustomerService extends Service
             $model->company = $data['company'] ?? '';
             $model->company_short_name = $data['company_short_name'] ?? '';
             $model->depart_id = $data['depart_id'] ?? 0;
+            $model->top_depart_id = $data['top_depart_id'] ?? 0;
             $model->state_type = $data['state_type'] ?? 0;
             $model->customer_state = $data['customer_state'] ?? 0;
             $model->customer_grade = $data['customer_grade'] ?? 0;
@@ -160,6 +161,7 @@ class CustomerService extends Service
             $model->company = $data['company'] ?? '';
             $model->company_short_name = $data['company_short_name'] ?? '';
             $model->depart_id = $data['depart_id'] ?? 0;
+            $model->top_depart_id = $data['top_depart_id'] ?? 0;
             $model->state_type = $data['state_type'] ?? 0;
             $model->customer_state = $data['customer_state'] ?? 0;
             $model->customer_grade = $data['customer_grade'] ?? 0;
@@ -384,9 +386,19 @@ class CustomerService extends Service
 
     public function customerList($data,$user){
         $model = Customer::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')
+            ->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')
             ->orderby('id', 'desc');
 
+        //getALL传入后无视设置范围
+        if(empty($data['getAll']) && $user['id'] != Employee::SPECIAL_ADMIN) {
+            $user_id = $user['id'];
+            $customer_id = CustomerInfo::where('del_time',0)
+                ->where(function ($query) use($user_id) {
+                    $query->where('employee_id',$user_id);
+                })->select('customer_id')->get()
+                ->toArray();
+            $model->whereIn('id',array_unique(array_column($customer_id,'customer_id')));
+        }
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['time_type'])) {
             if($data['time_type'] == 1) {
@@ -409,10 +421,11 @@ class CustomerService extends Service
         return [true, $list];
     }
 
-    public function customerRule($data, $is_add = true){
+    public function customerRule(&$data, $is_add = true){
         if(empty($data['model_type'])) return [false,'客户模板类型不能为空'];
         if(! in_array($data['model_type'],Customer::$model_type)) return [false,'客户模板类型错误'];
         if(empty($data['title'])) return [false,'客户名称不能为空'];
+        if(! empty($data['depart_id'])) $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
         if($data['model_type'] == Customer::Model_type_one){
             if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
             if(empty($data['customer_type'])) return [false,'客户类别不能为空'];