cqpCow před 1 rokem
rodič
revize
d6afc48e9a

+ 17 - 0
app/Model/FollowUpRecordFile.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class FollowUpRecordFile extends Model
+{
+    protected $table = "follow_up_record_file"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 1; // 图片
+    public static $type = [
+        self::type_one,
+    ];
+}

+ 105 - 25
app/Service/FollowUpRecordService.php

@@ -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']): '';

+ 17 - 0
app/Service/Service.php

@@ -349,6 +349,23 @@ class Service
         return strtotime($formattedDate);
     }
 
+    //前端传来的时间 转为时间戳
+    //精确到日
+    function changeDateToDate($time){
+        if(empty($time)) return '';
+
+        // 创建一个 DateTime 对象并设置时区为 UTC
+        $dateTime = new \DateTime($time, new \DateTimeZone('UTC'));
+
+        // 将时区设置为 PRC
+        $dateTime->setTimezone(new \DateTimeZone('Asia/Shanghai'));
+
+        // 将日期时间格式化为特定格式
+        $formattedDate = $dateTime->format('Y-m-d 00:00:00');
+
+        return strtotime($formattedDate);
+    }
+
     /**
      * 用于用户行为操作日志记录
      * @param $insert