cqpCow hai 1 ano
pai
achega
4441f3cc45
Modificáronse 2 ficheiros con 13 adicións e 18 borrados
  1. 4 0
      app/Model/FollowUpRecord.php
  2. 9 18
      app/Service/FollowUpRecordService.php

+ 4 - 0
app/Model/FollowUpRecord.php

@@ -10,4 +10,8 @@ class FollowUpRecord extends Model
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+    public static $type = [
+        'customer' => '客户跟进记录',
+        'sales_order' => '合同跟进记录',
+    ];
 }

+ 9 - 18
app/Service/FollowUpRecordService.php

@@ -16,8 +16,8 @@ class FollowUpRecordService extends Service
 
         $model = new FollowUpRecord();
         $model = $model->where('id',$data['id'])->first();
-        $model->sales_order_id = $data['sales_order_id'] ?? 0;
-        $model->customer_id = $data['customer_id'];
+        $model->data_id = $data['data_id'] ?? 0;
+        $model->type = $data['type'] ?? '';
         $model->basic_type_id = $data['basic_type_id'] ;
         $model->visit_time = $data['visit_time'];
         $model->content = $data['content'];
@@ -33,8 +33,8 @@ class FollowUpRecordService extends Service
         if(!$status) return [$status,$msg];
 
         $model = new FollowUpRecord();
-        $model->sales_order_id = $data['sales_order_id'] ?? 0;
-        $model->customer_id = $data['customer_id'];
+        $model->data_id = $data['data_id'] ?? 0;
+        $model->type = $data['type'] ?? '';
         $model->basic_type_id = $data['basic_type_id'] ;
         $model->visit_time = $data['visit_time'];
         $model->content = $data['content'];
@@ -58,13 +58,13 @@ class FollowUpRecordService extends Service
 
     public function followUpRecordList($data,$user){
         $model = FollowUpRecord::where('del_time',0)
-            ->select('customer_id','basic_type_id','visit_time','id','content','is_remind','crt_time','crt_id','sales_order_id','result')
+            ->select('data_id','basic_type_id','visit_time','id','content','is_remind','crt_time','crt_id','type','result')
             ->orderBy('id','desc');
 
-        if(! empty($data['customer_id'])) $model->where('customer_id',$data['customer_id']);
+        if(! empty($data['data_id'])) $model->where('data_id',$data['data_id']);
         if(! empty($data['basic_type_id'])) $model->where('basic_type_id', $data['basic_type_id']);
         if(! empty($data['crt_id'])) $model->where('crt_id',$data['crt_id']);
-        if(! empty($data['sales_order_id'])) $model->where('sales_order_id',$data['sales_order_id']);
+        if(! empty($data['type'])) $model->where('type',$data['type']);
 
         $list = $this->limit($model,'',$data);
         $list = $this->organizationData($list);
@@ -75,25 +75,18 @@ class FollowUpRecordService extends Service
     public function organizationData($data) {
         if (empty($data['data'])) return $data;
 
-        $customer = Customer::whereIn('id',array_unique(array_column($data['data'],'customer_id')))
-            ->pluck('title','id')
-            ->toArray();
-
         $basic_type = BasicType::whereIn('id',array_unique(array_column($data['data'],'basic_type_id')))
             ->pluck('title','id')
             ->toArray();
-        $sales = SalesOrder::whereIn('id',array_unique(array_column($data['data'],'sales_order_id')))->pluck('order_number','id')->toArray();
-
         foreach ($data['data'] as $key => $value){
-            $data['data'][$key]['customer_name'] = $customer[$value['customer_id']] ?? '';
             $data['data'][$key]['basic_type_name'] = $basic_type[$value['basic_type_id']] ?? '';
-            $data['data'][$key]['sales_order_number'] = $sales[$value['sales_order_id']] ?? '';
         }
         return $data;
     }
 
     public function followUpRecordRule(&$data,$is_add = true){
-        if($this->isEmpty($data,'customer_id')) return [false,'客户不能为空'];
+        if($this->isEmpty($data,'data_id')) return [false,'数据id不能为空'];
+        if(empty($data['type']) || ! isset(FollowUpRecord::$type[$data['type']])) return [false,'跟进类型不能为空'];
         if($this->isEmpty($data,'basic_type_id')) return [false,'跟进方式不能为空'];
         if($this->isEmpty($data,'visit_time')) return [false,'拜访时间不能为空'];
         if($this->isEmpty($data,'content')) return [false,'跟进内容不能为空'];
@@ -114,8 +107,6 @@ class FollowUpRecordService extends Service
             ->first();
         if(empty($record)) return [false,'跟进记录不存在或已被删除'];
         $record = $record->toArray();
-        $sales = SalesOrder::where('id',$record['sales_order_id'])->value('order_number');
-        $record['sales_order_number'] = $sales;
         $emp_map = Employee::where('id',$record['crt_id'])->value('emp_name');
         $record['crt_name'] = $emp_map;
         $record['crt_time'] = $record['crt_time'] ? date("Y-m-d H:i:s",$record['crt_time']): '';