|
@@ -6,7 +6,9 @@ use App\Model\BasicType;
|
|
|
use App\Model\Customer;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\FollowUpRecord;
|
|
|
+use App\Model\FollowUpRecordFile;
|
|
|
use App\Model\SalesOrder;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class FollowUpRecordService extends Service
|
|
|
{
|
|
@@ -14,17 +16,45 @@ class FollowUpRecordService extends Service
|
|
|
list($status,$msg) = $this->followUpRecordRule($data,false);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
- $model = new FollowUpRecord();
|
|
|
- $model = $model->where('id',$data['id'])->first();
|
|
|
- $model->data_id = $data['data_id'] ?? 0;
|
|
|
- $model->data_title = $data['data_title'] ?? '';
|
|
|
- $model->type = $data['type'] ?? '';
|
|
|
- $model->basic_type_id = $data['basic_type_id'] ;
|
|
|
- $model->visit_time = $data['visit_time'];
|
|
|
- $model->content = $data['content'];
|
|
|
- $model->is_remind = $data['is_remind'] ?? 0;
|
|
|
- $model->result = $data['result'] ?? '';
|
|
|
- $model->save();
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $model = new FollowUpRecord();
|
|
|
+ $model = $model->where('id',$data['id'])->first();
|
|
|
+ $model->data_id = $data['data_id'] ?? 0;
|
|
|
+ $model->data_title = $data['data_title'] ?? '';
|
|
|
+ $model->type = $data['type'] ?? '';
|
|
|
+ $model->basic_type_id = $data['basic_type_id'] ;
|
|
|
+ $model->visit_time = $data['visit_time'];
|
|
|
+ $model->content = $data['content'];
|
|
|
+ $model->is_remind = $data['is_remind'] ?? 0;
|
|
|
+ $model->result = $data['result'] ?? '';
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ FollowUpRecordFile::where('del_time',0)
|
|
|
+ ->where('follow_up_record_id',$data['id'])
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+
|
|
|
+ if(! empty($data['file'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['file'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'follow_up_record_id' => $data['id'],
|
|
|
+ 'file' => $value['url'],
|
|
|
+ 'name' => $value['name'],
|
|
|
+ 'type' => FollowUpRecordFile::type_one,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ FollowUpRecordFile::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::rollBack();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
@@ -33,17 +63,42 @@ class FollowUpRecordService extends Service
|
|
|
list($status,$msg) = $this->followUpRecordRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
- $model = new FollowUpRecord();
|
|
|
- $model->data_id = $data['data_id'] ?? 0;
|
|
|
- $model->data_title = $data['data_title'] ?? '';
|
|
|
- $model->type = $data['type'] ?? '';
|
|
|
- $model->basic_type_id = $data['basic_type_id'] ;
|
|
|
- $model->visit_time = $data['visit_time'];
|
|
|
- $model->content = $data['content'];
|
|
|
- $model->is_remind = $data['is_remind'] ?? 0;
|
|
|
- $model->crt_id = $user['id'];
|
|
|
- $model->result = $data['result'] ?? '';
|
|
|
- $model->save();
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $model = new FollowUpRecord();
|
|
|
+ $model->data_id = $data['data_id'] ?? 0;
|
|
|
+ $model->data_title = $data['data_title'] ?? '';
|
|
|
+ $model->type = $data['type'] ?? '';
|
|
|
+ $model->basic_type_id = $data['basic_type_id'] ;
|
|
|
+ $model->visit_time = $data['visit_time'];
|
|
|
+ $model->content = $data['content'];
|
|
|
+ $model->is_remind = $data['is_remind'] ?? 0;
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
+ $model->result = $data['result'] ?? '';
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ if(! empty($data['file'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['file'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'follow_up_record_id' => $data['id'],
|
|
|
+ 'file' => $value['url'],
|
|
|
+ 'name' => $value['name'],
|
|
|
+ 'type' => FollowUpRecordFile::type_one,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ FollowUpRecordFile::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::rollBack();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
@@ -51,9 +106,21 @@ class FollowUpRecordService extends Service
|
|
|
public function followUpRecordDel($data){
|
|
|
if($this->isEmpty($data,'id')) return [false,'ID必须!'];
|
|
|
|
|
|
- FollowUpRecord::where('id',$data['id'])->update([
|
|
|
- 'del_time'=>time()
|
|
|
- ]);
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ FollowUpRecord::where('id',$data['id'])->update([
|
|
|
+ 'del_time'=>time()
|
|
|
+ ]);
|
|
|
+ FollowUpRecordFile::where('del_time',0)
|
|
|
+ ->where('follow_up_record_id', $data['id'])
|
|
|
+ ->update(['del_time' => time()]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
|
|
|
return [true,'删除成功'];
|
|
|
}
|
|
@@ -115,6 +182,19 @@ class FollowUpRecordService extends Service
|
|
|
->first();
|
|
|
if(empty($record)) return [false,'跟进记录不存在或已被删除'];
|
|
|
$record = $record->toArray();
|
|
|
+ $record['file'] = [];
|
|
|
+ $sales_info = FollowUpRecordFile::where('del_time',0)
|
|
|
+ ->where('follow_up_record_id',$data['id'])
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($sales_info as $value){
|
|
|
+ if ($value['type'] == FollowUpRecordFile::type_one){
|
|
|
+ $record['file'][] = [
|
|
|
+ 'url' => $value['file'],
|
|
|
+ 'name' => $value['name'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$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']): '';
|