cqpCow 1 year ago
parent
commit
af9fcbbd67

+ 6 - 0
app/Model/Customer.php

@@ -10,4 +10,10 @@ class Customer extends Model
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+    const Model_type_one = 1; // 基础模板
+    const Model_type_two = 2; // T9二手车客户模板
+    public static $model_type = [
+        self::Model_type_one,
+        self::Model_type_two
+    ];
 }

+ 27 - 0
app/Model/CustomerInfo.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerInfo extends Model
+{
+    protected $table = "customer_info"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 1; // 客户联系方式
+    const type_two = 2; // 销售sa/负责 人员
+    const type_three = 3; // 协同人
+    const type_four = 4; // 联系人
+    const type_five = 5; // 图片
+    const type_six = 6; // 文件
+    public static $type = [
+        self::type_one,
+        self::type_two,
+        self::type_three,
+        self::type_four,
+        self::type_five,
+        self::type_six,
+    ];
+}

+ 295 - 4
app/Service/CustomerService.php

@@ -2,7 +2,10 @@
 
 namespace App\Service;
 
+use App\Model\BasicType;
 use App\Model\Customer;
+use App\Model\CustomerInfo;
+use Illuminate\Support\Facades\DB;
 
 class CustomerService extends Service
 {
@@ -10,6 +13,121 @@ class CustomerService extends Service
         list($status,$msg) = $this->customerRule($data,false);
         if(!$status) return [$status,$msg];
 
+        try {
+            DB::beginTransaction();
+
+            $model = Customer::where('id',$data['id'])->first();
+            $model->title = $data['title'];
+            $model->model_type = $data['model_type'];
+            $model->customer_intention = $data['customer_intention'] ?? 0;
+            $model->customer_from = $data['customer_from'] ?? 0;
+            $model->customer_type = $data['customer_type'] ?? 0;
+            $model->car_type = $data['car_type'] ?? 0;
+            $model->consulting_product = $data['consulting_product'] ?? '';
+            $model->intention_product = $data['intention_product'] ?? 0;
+            $model->progress_stage = $data['progress_stage'] ?? 0;
+            $model->address1 = $data['address1'] ?? '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->crt_id = $user['id'];
+            $model->mark = $data['mark'] ?? '';
+            $model->importance = $data['importance'] ?? '';
+            $model->company = $data['company'] ?? '';
+            $model->company_short_name = $data['company_short_name'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? 0;
+            $model->state_type = $data['state_type'] ?? 0;
+            $model->customer_state = $data['customer_state'] ?? 0;
+            $model->customer_grade = $data['customer_grade'] ?? 0;
+            $model->save();
+            $time = time();
+
+            CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            if(! empty($data['customer_contact'])){
+                $insert = [];
+                foreach ($data['customer_contact'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'contact_type' => $value['id'],
+                        'contact_info' => $value['info'],
+                        'type' => CustomerInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_one'])){
+                $insert = [];
+                foreach ($data['employee_one'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_two'])){
+                $insert = [];
+                foreach ($data['employee_two'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_three,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_three'])){
+                $insert = [];
+                foreach ($data['employee_three'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_four,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value,
+                        'type' => CustomerInfo::type_five,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value,
+                        'type' => CustomerInfo::type_six,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
 
         return [true,''];
     }
@@ -18,6 +136,118 @@ class CustomerService extends Service
         list($status,$msg) = $this->customerRule($data);
         if(!$status) return [$status,$msg];
 
+        try {
+            DB::beginTransaction();
+
+            $model = new Customer();
+            $model->title = $data['title'];
+            $model->model_type = $data['model_type'];
+            $model->customer_intention = $data['customer_intention'] ?? 0;
+            $model->customer_from = $data['customer_from'] ?? 0;
+            $model->customer_type = $data['customer_type'] ?? 0;
+            $model->car_type = $data['car_type'] ?? 0;
+            $model->consulting_product = $data['consulting_product'] ?? '';
+            $model->intention_product = $data['intention_product'] ?? 0;
+            $model->progress_stage = $data['progress_stage'] ?? 0;
+            $model->address1 = $data['address1'] ?? '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->crt_id = $user['id'];
+            $model->mark = $data['mark'] ?? '';
+            $model->importance = $data['importance'] ?? '';
+            $model->company = $data['company'] ?? '';
+            $model->company_short_name = $data['company_short_name'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? 0;
+            $model->state_type = $data['state_type'] ?? 0;
+            $model->customer_state = $data['customer_state'] ?? 0;
+            $model->customer_grade = $data['customer_grade'] ?? 0;
+            $model->save();
+            $time = time();
+
+            if(! empty($data['customer_contact'])){
+                $insert = [];
+                foreach ($data['customer_contact'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'contact_type' => $value['id'],
+                        'contact_info' => $value['info'],
+                        'type' => CustomerInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_one'])){
+                $insert = [];
+                foreach ($data['employee_one'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_two'])){
+                $insert = [];
+                foreach ($data['employee_two'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_three,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_three'])){
+                $insert = [];
+                foreach ($data['employee_three'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => CustomerInfo::type_four,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value,
+                        'type' => CustomerInfo::type_five,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value,
+                        'type' => CustomerInfo::type_six,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
         return [true,''];
     }
 
@@ -25,8 +255,11 @@ class CustomerService extends Service
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
         Customer::whereIn('id',$data['id'])->update([
-            'del_time'=>time()
+            'del_time'=> time()
         ]);
+        CustomerInfo::where('del_time',0)
+            ->where('customer_id',$data['id'])
+            ->update(['del_time' => time()]);
 
         return [true,''];
     }
@@ -34,10 +267,41 @@ class CustomerService extends Service
     public function customerDetail($data){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
-        return [true,''];
+        $customer = Customer::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'客户不存在或已被删除'];
+        $customer = $customer->toArray();
+        $array = [
+            $customer['customer_intention'],
+            $customer['customer_from'],
+            $customer['customer_type'],
+            $customer['car_type'],
+            $customer['intention_product'],
+            $customer['progress_stage'],
+            $customer['state_type'],
+            $customer['customer_state'],
+            $customer['customer_grade'],
+        ];
+        $basic_map = BasicType::whereIn('id',$array)
+            ->pluck('title','id')
+            ->toArray();
+        foreach ($customer as $key => $value){
+            $customer[$key]['customer_intention_title'] = $basic_map[$value['customer_intention']] ?? '';
+            $customer[$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
+            $customer[$key]['customer_type_title'] = $basic_map[$value['customer_type']] ?? '';
+            $customer[$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
+            $customer[$key]['intention_product_title'] = $basic_map[$value['intention_product']] ?? '';
+            $customer[$key]['progress_stage_title'] = $basic_map[$value['progress_stage']] ?? '';
+            $customer[$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
+            $customer[$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';
+            $customer[$key]['customer_grade_title'] = $basic_map[$value['customer_grade']] ?? '';
+        }
+
+        return [true, $customer];
     }
 
-    public function customerList($data){
+    public function customerList($data,$user){
         $model = Customer::where('del_time',0)
             ->select('title','id','type')
             ->orderby('id', 'asc')
@@ -52,7 +316,34 @@ class CustomerService extends Service
     }
 
     public function customerRule($data, $is_add = true){
-        if($this->isEmpty($data,'type')) return [false,'客户模板类型不能为空'];
+        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($data['model_type'] == Customer::Model_type_one){
+            if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
+            if(empty($data['customer_type'])) return [false,'客户类别不能为空'];
+            if(empty($data['consulting_product'])) return [false,'咨询产品不能为空'];
+            if(empty($data['progress_stage'])) return [false,'进展阶段不能为空'];
+            if(empty($data['employee_one'])) return [false,'销售SA不能为空'];
+        }else{
+            if(empty($data['car_type'])) return [false,'车型不能为空'];
+            if(empty($data['customer_contact'])) return [false,'客户联系方式不能为空'];
+        }
+
+        if($is_add){
+            $bool = Customer::where('del_time',0)
+                ->where('title',$data['title'])
+                ->where('model_type',$data['model_type'])
+                ->exists();
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = Customer::where('del_time',0)
+                ->where('id','<>',$data['id'])
+                ->where('title',$data['title'])
+                ->where('model_type',$data['model_type'])
+                ->exists();
+        }
+        if($bool) return [false,'客户名称不能重复'];
 
         return [true, $data];
     }

+ 1 - 0
app/Service/HeaderWord/HeaderWordHookService.php

@@ -39,6 +39,7 @@ class HeaderWordHookService extends Service
 
         return [true,$list];
     }
+
     public function getHeaderSettings($data){
         if($this->isEmpty($data,'menu_id')) return [false,'菜单ID不能为空!'];
         $type = 1;

+ 35 - 0
config/header/1.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    1 => [
+      'order_no' => '内部订单编号',
+      'out_order_no' => '销售订单号',
+      'out_order_no_time' => '销售订单时间',
+      'customer_no' => '客户编码',
+      'customer_name' => '客户名称',
+      'table_header_mark' => '表头备注',
+      'product_no' => '产品编码',
+      'product_title' => '产品名称',
+      'product_size' => '规格型号',
+      'product_unit' => '计量单位',
+      'order_quantity' => '计量单位',
+      'product_quantity_on_hand' => '现存量',
+      'technology_material'=> '工艺/材质',
+      'technology_name'=> '工艺名称',
+      'wood_name'=> '木皮名称',
+      'process_mark'=> '加工备注',
+      'table_body_mark'=> '表体备注',
+      'out_crt_man'=> '制单人',
+      'out_checker_man'=> '审核人',
+      'out_checker_time'=> '审核日期',
+      'crt_time'=> '引入时间',
+      'box_num'=> '已包装数量',
+      'production_quantity' => '已生产数量',
+      'finished_num' => '已完工数量',
+    ],
+];

+ 1 - 0
routes/api.php

@@ -21,6 +21,7 @@ Route::any('login', 'Api\LoginController@login');
 Route::any('test', 'Api\TestController@aa');
 Route::any('getHeaderWord', 'Api\HeaderWordController@getHeaderWord');
 Route::group(['middleware'=> ['checkLogin']],function ($route){
+    $route->any('getHeaderSetting', 'Api\HeaderWordController@getHeaderSettings');
     $route->any('HeaderSettingsAdd', 'Api\HeaderWordController@add');
     $route->any('HeaderSettingsDetail', 'Api\HeaderWordController@detail');