|
@@ -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];
|
|
|
+ }
|
|
|
}
|