cqpCow 1 gadu atpakaļ
vecāks
revīzija
82f2b7545c

+ 13 - 0
app/Http/Controllers/Api/FollowUpRecordController.php

@@ -58,4 +58,17 @@ class FollowUpRecordController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function followUpRecordDetail(Request $request)
+    {
+        $service = new FollowUpRecordService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->followUpRecordDetail($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 26 - 1
app/Service/FollowUpRecordService.php

@@ -4,7 +4,9 @@ namespace App\Service;
 
 use App\Model\BasicType;
 use App\Model\Customer;
+use App\Model\Employee;
 use App\Model\FollowUpRecord;
+use App\Model\SalesOrder;
 
 class FollowUpRecordService extends Service
 {
@@ -14,6 +16,7 @@ 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->basic_type_id = $data['basic_type_id'] ;
         $model->visit_time = $data['visit_time'];
@@ -29,6 +32,7 @@ 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->basic_type_id = $data['basic_type_id'] ;
         $model->visit_time = $data['visit_time'];
@@ -52,12 +56,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')
+            ->select('customer_id','basic_type_id','visit_time','id','content','is_remind','crt_time','crt_id','sales_order_id')
             ->orderBy('id','desc');
 
         if(! empty($data['customer_id'])) $model->where('customer_id',$data['customer_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']);
 
         $list = $this->limit($model,'',$data);
         $list = $this->organizationData($list);
@@ -75,10 +80,12 @@ class FollowUpRecordService extends Service
         $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;
     }
@@ -88,6 +95,7 @@ class FollowUpRecordService extends Service
         if($this->isEmpty($data,'basic_type_id')) return [false,'跟进方式不能为空'];
         if($this->isEmpty($data,'visit_time')) return [false,'拜访时间不能为空'];
         if($this->isEmpty($data,'content')) return [false,'跟进内容不能为空'];
+        if($this->isEmpty($data,'sales_order_id')) return [false,'请选择合同'];
 
         if(! $is_add){
             if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
@@ -96,4 +104,21 @@ class FollowUpRecordService extends Service
 
         return [true,''];
     }
+
+    public function followUpRecordDetail($data){
+        if($this->isEmpty($data,'id')) return [false,'ID必须!'];
+
+        $record = FollowUpRecord::where('del_time',0)
+            ->where('id',$data['id'])
+            ->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']): '';
+
+        return [true, $record];
+    }
 }

+ 1 - 0
routes/api.php

@@ -78,6 +78,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('followUpRecordList', 'Api\FollowUpRecordController@followUpRecordList');
     $route->any('followUpRecordEdit', 'Api\FollowUpRecordController@followUpRecordEdit');
     $route->any('followUpRecordAdd', 'Api\FollowUpRecordController@followUpRecordAdd');
+    $route->any('followUpRecordDetail', 'Api\FollowUpRecordController@followUpRecordDetail');
     $route->any('followUpRecordDel', 'Api\FollowUpRecordController@followUpRecordDel');
 
     //客户