Ver Fonte

客户&人员

cqp há 11 meses atrás
pai
commit
fc35691210

+ 74 - 0
app/Http/Controllers/Api/CustomerController.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\CustomerService;
+use Illuminate\Http\Request;
+
+class CustomerController extends BaseController
+{
+    public function customerAdd(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerAdd($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerEdit(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerEdit($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerDel(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerList(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerList($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerDetail(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerDetail($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 26 - 0
app/Http/Controllers/Api/EmployeeController.php

@@ -8,6 +8,32 @@ use Illuminate\Http\Request;
 
 class EmployeeController extends BaseController
 {
+    public function employeeEditImg(Request $request)
+    {
+        $service = new EmployeeService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->employeeEditImg($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function getEmployeeImg(Request $request)
+    {
+        $service = new EmployeeService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->getEmployeeImg($user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function employeeEditOther(Request $request)
     {
         $service = new EmployeeService();

+ 4 - 0
app/Http/Middleware/CheckLogin.php

@@ -56,6 +56,10 @@ class CheckLogin
         //该接口是否需要个人部门所有的权限区分
         $request->merge(['is_authority' => $is_authority, 'menu_authority_id' => $menu_id]);
 
+        //某些接口需要传输菜单ID
+        $menu = $query['menu_option'] ?? [];
+        if(isset($menu[$url])) $request->merge(['menu_id' => $menu[$url]]);
+
         //写入user信息
         $request->userData = $data;
 

+ 17 - 0
app/Model/Customer.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Model;
+
+class Customer extends UseScopeBaseModel
+{
+    protected $table = "customer"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    public static $prefix = "kh";
+
+    public static $user = [];
+    public static $search = [];
+    public static $limitKey = "";
+    const range_function = '';
+}

+ 34 - 0
app/Model/CustomerInfo.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerInfo extends Model
+{
+    protected $table = "customer_info"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 1; // 客户联系方式
+    const type_two = 2; // 负责人
+    const type_three = 3; // 协同人
+    const type_four = 4; // 联系人
+    const type_five = 5; // 图片
+    const type_six = 6; // 文件
+    const type_nine = 9; //前负责人
+    public static $type = [
+        self::type_one,
+        self::type_two,
+        self::type_three,
+        self::type_four,
+        self::type_five,
+        self::type_six,
+    ];
+
+    public static $man2 = [
+        self::type_two,
+        self::type_three,
+        self::type_nine,
+    ];
+}

+ 14 - 0
app/Model/EmployeeFile.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class EmployeeFile extends Model
+{
+    protected $table = "employee_file"; //指定表
+    const CREATED_AT = null;
+    const UPDATED_AT = null;
+    protected $dateFormat = 'U';
+
+}

+ 17 - 0
app/Model/FollowUpRecord.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class FollowUpRecord extends Model
+{
+    protected $table = "follow_up_record"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 'customer';
+    public static $type = [
+        self::type_one => '客户跟进记录',
+    ];
+}

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

+ 472 - 0
app/Service/CustomerService.php

@@ -0,0 +1,472 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\BasicType;
+use App\Model\Customer;
+use App\Model\CustomerInfo;
+use App\Model\Depart;
+use App\Model\Employee;
+use App\Model\FollowUpRecord;
+use App\Model\Product;
+use App\Model\SeeRange;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 客户管理相关
+ */
+class CustomerService extends Service
+{
+    /**
+     * 客户编辑
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function customerEdit($data,$user){
+        list($status,$msg) = $this->customerRule($data,$user, false);
+        if(!$status) return [$status,$msg];
+
+        $params = $this->getDataFile($data);
+        (new OperationLogService())->setOperationList($params,$user,2);
+
+        try {
+            DB::beginTransaction();
+
+            $model = Customer::where('id',$data['id'])->first();
+            $model->title = $data['title'] ?? "";
+            $model->relationship_level = $data['relationship_level'] ?? 0;
+            $model->is_company = $data['is_company'] ?? 0;
+            $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->mark = $data['mark'] ?? '';
+            $model->intention = $data['intention'] ?? '';
+            $model->customer_type = $data['customer_type'] ?? '';
+            $model->save();
+            $time = time();
+
+            $old = CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
+            CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->where('type','<>',CustomerInfo::type_two)
+                ->update(['del_time' => $time]);
+
+            if(! empty($data['customer_contact'])){
+                $insert = [];
+                foreach ($data['customer_contact'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'contact_type' => $value['type'],
+                        'contact_info' => $value['info'],
+                        'type' => CustomerInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            $new = [];
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value['url'],
+                        'type' => CustomerInfo::type_five,
+                        'name' => $value['name'],
+                        'crt_time' => $time,
+                    ];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value['url'],
+                        'type' => CustomerInfo::type_six,
+                        'name' => $value['name'],
+                        'crt_time' => $time,
+                    ];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
+    }
+
+    /**
+     * 客户新增
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function customerAdd($data,$user){
+        list($status,$msg) = $this->customerRule($data, $user);
+        if(! $status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new Customer();
+            $model->order_number = (new OrderNoService())->createOrderNumber(Customer::$prefix);
+            $model->title = $data['title'] ?? "";
+            $model->relationship_level = $data['relationship_level'] ?? 0;
+            $model->is_company = $data['is_company'] ?? 0;
+            $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->mark = $data['mark'] ?? '';
+            $model->intention = $data['intention'] ?? '';
+            $model->customer_type = $data['customer_type'] ?? '';
+            $model->crt_id = $user['id'];
+            $model->save();
+            $time = time();
+
+            if(! empty($data['customer_contact'])){
+                $insert = [];
+                foreach ($data['customer_contact'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'contact_type' => $value['type'],
+                        'contact_info' => $value['info'],
+                        'type' => CustomerInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            $new = [];
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value['url'],
+                        'type' => CustomerInfo::type_five,
+                        'name' => $value['name'],
+                        'crt_time' => $time,
+                    ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
+                }
+                CustomerInfo::insert($insert);
+            }
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'customer_id' => $model->id,
+                        'file' => $value['url'],
+                        'type' => CustomerInfo::type_six,
+                        'name' => $value['name'],
+                        'crt_time' => $time,
+                    ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
+                }
+                CustomerInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        (new OperationLogService())->setOperationList($data,$user);
+
+        return [true, ['file' => ['new' => $new]]];
+    }
+
+    /**
+     * 客户删除
+     * @param $data
+     * @return array
+     */
+    public function customerDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        if($data['id'] < 0) return [false, '系统数据,操作失败!'];
+        try {
+            DB::beginTransaction();
+
+            Customer::where('id',$data['id'])->update([
+                'del_time'=> time()
+            ]);
+            $old = CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
+
+            CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->update(['del_time' => time()]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ['file' => ['old' => $old]]];
+    }
+
+    /**
+     * 客户详情
+     * @param $data
+     * @return array
+     */
+    public function customerDetail($data,$user){
+        if($this->isEmpty($data,'id')) return [false,'请选择客户'];
+
+        $customer = Customer::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'客户不存在或已被删除'];
+        $customer = $customer->toArray();
+
+        //地址
+        $address_map = config('address');
+        $address_str = [];
+        if(! empty($customer['address1'])) {
+            $tmp = json_decode($customer['address1'],true);
+            $this->findLabelsByValue($address_map,$tmp,$address_str);
+            $customer['address1'] = $tmp;
+            $tmp = implode(' ',$address_str);
+            $tmp .= ' ' . $customer['address2'];
+            $address = $tmp;
+        }else{
+            $address = $customer['address2'];
+        }
+        $customer['address'] = $address;
+        $customer['customer_contact'] = $customer['img'] = $customer['file'] = [];
+
+        //详情
+        $customer_info = CustomerInfo::where('del_time',0)
+            ->where('customer_id',$customer['id'])
+            ->select('id','customer_id','contact_type','contact_info','data_id','file','type','name')
+            ->get()->toArray();
+        $emp_id = [];
+        $emp_id[] = $customer['crt_id'];
+
+        $emp_map = Employee::whereIn('id',array_unique($emp_id))
+            ->pluck('emp_name','id')
+            ->toArray();
+
+        $fileUploadService = new FileUploadService();
+        foreach ($customer_info as $value){
+            if($value['type'] == CustomerInfo::type_one){
+                $tmp = [
+                    'id' => $value['contact_type'],
+                    'type' => $value['contact_type'],
+                    'info' => $value['contact_info']
+                ];
+                $customer['customer_contact'][] = $tmp;
+            }elseif ($value['type'] == CustomerInfo::type_five){
+                $tmp = [
+                    'url' => $value['file'],
+                    'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
+                ];
+                $customer['img'][] = $tmp;
+            }elseif ($value['type'] == CustomerInfo::type_six){
+                $tmp = [
+                    'url' => $value['file'],
+                    'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
+                ];
+                $customer['file'][] = $tmp;
+            }
+        }
+        $customer['crt_name'] = $emp_map[$customer['crt_id']] ?? '';
+        $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+
+        return [true, $customer];
+    }
+
+    /**
+     * 客户列表
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function customerList($data,$user){
+        $model = Customer::Clear($user,$data);
+        $model = $model->where('del_time',0)
+            ->select('title','id','order_number','intention','customer_type','address1','address2','crt_id','crt_time','mark','relationship_level','is_company')
+            ->orderby('id', 'desc');
+
+        if(! empty($data['id'])) $model->where('id', $data['id']);
+        if(isset($data['relationship_level'])) $model->where('relationship_level', $data['relationship_level']);
+        if(isset($data['is_company'])) $model->where('is_company', $data['is_company']);
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['time_type'])) {
+            if($data['time_type'] == 1) {
+                $start = strtotime('today');
+                $end = strtotime('tomorrow') - 1;
+            }elseif ($data['time_type'] == 2){
+                $start = strtotime('this week',strtotime('today'));
+                $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
+            }
+            if(! empty($start) && ! empty($end)) {
+                $model->where('crt_time','>=',$start);
+                $model->where('crt_time','<=',$end);
+            }
+        }
+        if(! empty($data['mark'])) $model->where('mark','LIKE', '%'.$data['mark'].'%');
+        if(! empty($data['intention'])) $model->where('intention',$data['intention']);
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
+            $model->where('crt_time','>=',$return[0]);
+            $model->where('crt_time','<=',$return[1]);
+        }
+        if(! empty($data['contact_info'])){
+            $customer_info = CustomerInfo::where('del_time',0)
+                ->where("type",CustomerInfo::type_one)
+                ->where('contact_info','LIKE', '%'.$data['contact_info'].'%')
+                ->select('customer_id')
+                ->get()->toArray();
+            $model->whereIn('id',array_column($customer_info,'customer_id'));
+        }
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$data);
+
+        return [true, $list];
+    }
+
+    /**
+     * 客户参数规则
+     * @param $data
+     * @param $is_add
+     * @return array
+     */
+    public function customerRule(&$data, $user, $is_add = true){
+        if(empty($data['title'])) return [false,'客户名称不能为空'];
+
+        if($is_add){
+            $data['order_number'] = (new OrderNoService())->createOrderNumber(Customer::$prefix);
+            $bool = Customer::where('del_time',0)
+                ->where('title',$data['title'])
+                ->exists();
+            if(! empty($data['customer_contact'])) {
+                $search = [];
+                foreach ($data['customer_contact'] as $value){
+                    $search[] = $value['info'];
+                }
+                $boolean = CustomerInfo::from('customer_info as a')
+                    ->join('customer as b','b.id','a.customer_id')
+                    ->where('a.del_time',0)
+                    ->where('b.del_time',0)
+                    ->whereIn('a.contact_info', $search)
+                    ->exists();
+                if($boolean) return [false,'客户联系内容已存在'];
+            }
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = Customer::where('del_time',0)
+                ->where('id','<>',$data['id'])
+                ->where('title',$data['title'])
+                ->exists();
+
+            if(! empty($data['customer_contact'])) {
+                $search = [];
+                foreach ($data['customer_contact'] as $value){
+                    $search[] = $value['info'];
+                }
+                $boolean = CustomerInfo::from('customer_info as a')
+                    ->join('customer as b','b.id','a.customer_id')
+                    ->where('b.id','<>',$data['id'])
+                    ->where('a.del_time',0)
+                    ->where('b.del_time',0)
+                    ->whereIn('a.contact_info', $search)
+                    ->exists();
+                if($boolean) return [false,'客户联系内容已存在'];
+            }
+        }
+        if($bool) return [false,'客户名称不能重复'];
+
+        return [true, ''];
+    }
+
+    /**
+     * 拼接数据
+     * @param $data
+     * @return array
+     */
+    public function fillData($data,$ergs){
+        if(empty($data['data'])) return $data;
+
+        $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
+            ->pluck('emp_name','id')
+            ->toArray();
+
+        //跟进记录
+        $record_array = (new FollowUpRecordService())->getVisitDataOfTime(array_column($data['data'],'id'), FollowUpRecord::type_one);
+
+        $customer_info = CustomerInfo::where('del_time',0)
+            ->whereIn('customer_id',array_column($data['data'],'id'))
+            ->whereIn('type',[CustomerInfo::type_one])
+            ->select('type','contact_type','contact_info','customer_id','data_id')
+            ->get()->toArray();
+
+        //客户的联系方式
+        $customer_info_map = [];
+        foreach ($customer_info as $value){
+            $customer_info_map[$value['customer_id']][] = $value;
+        }
+
+        $address_map = config('address');
+        foreach ($data['data'] as $key => $value){
+            $address_str = [];
+            if(! empty($value['address1'])) {
+                $tmp = json_decode($value['address1'],true);
+                $this->findLabelsByValue($address_map,$tmp,$address_str);
+                $tmp = implode(' ',$address_str);
+                $tmp .= ' ' . $value['address2'];
+                $address = $tmp;
+            }else{
+                $address = $value['address2'];
+            }
+            $data['data'][$key]['address'] = $address;
+            $data['data'][$key]['is_company_title'] = $value['customer_intention'] ? '是' : '否';
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $record_tmp = $record_array[$value['id']] ?? "";
+            $data['data'][$key]['has_record'] = $record_tmp ? "查看" : "无记录";
+            $data['data'][$key]['follow_record'] = $record_array[$value['id']] ?? "";
+            $customer_tmp = $customer_info_map[$value['id']] ?? [];
+            $data['data'][$key]['customer_detail'] = $customer_tmp;
+        }
+
+        return $data;
+    }
+}

+ 53 - 7
app/Service/EmployeeService.php

@@ -2,26 +2,20 @@
 
 namespace App\Service;
 
-use App\Model\BasicType;
 use App\Model\Depart;
 use App\Model\Employee;
 use App\Model\EmployeeDepartPermission;
+use App\Model\EmployeeFile;
 use App\Model\EmployeeManagerDepart;
 use App\Model\EmployeeMenuPermission;
 use App\Model\EmployeeRole;
 use App\Model\EmployeeTeamPermission;
-use App\Model\ProductInventory;
-use App\Model\ProductInventorySet;
 use App\Model\Role;
 use App\Model\RoleMenu;
 use App\Model\RoleMenuButton;
-use App\Model\Storehouse;
-use App\Model\Supplier;
 use App\Model\SysMenu;
 use App\Model\SysMenuButton;
 use App\Model\Team;
-use App\Model\WxEmployeeOfficial;
-use App\Service\Weixin\WeixinService;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Hash;
 use Mockery\Exception;
@@ -32,6 +26,58 @@ use Mockery\Exception;
  */
 class EmployeeService extends Service
 {
+    public function employeeEditImg($data, $user){
+        $time = time();
+        try {
+            DB::beginTransaction();
+
+            $old = EmployeeFile::where('del_time',0)
+                ->where('employee_id',$user['id'])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
+            EmployeeFile::where('del_time',0)
+                ->where('employee_id',$user['id'])
+                ->update(['del_time' => $time]);
+
+            $new = [];
+            $insert = [];
+            if(! empty($data['img_url'])){
+                $insert[] = [
+                    'employee_id' => $user['id'],
+                    'file' => $data['img_url'],
+                    'crt_time' => $time,
+                ];
+                EmployeeFile::insert($insert);
+                $new[] = $data['img_url'];
+            }
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
+    }
+
+    public function getEmployeeImg($user){
+        $file = EmployeeFile::where('del_time',0)
+            ->where('employee_id',$user['id'])
+            ->select('file')
+            ->get()->toArray();
+        $file = array_column($file,'file');
+        $file = $file[0] ?? "";
+        $img_str = "";
+        $timpstamp = 86400;
+        if(! empty($file)){
+            $fileUploadService = new FileUploadService();
+            $img_str = $fileUploadService->getFileShow($file, $timpstamp);
+        }
+
+        return [true, ['img_url' => $img_str]];
+    }
+
     public function employeeEditOther($data,$user){
         list($status,$msg) = $this->employeeOtherRule($data,$user);
         if(!$status) return [$status,$msg];

+ 10 - 22
app/Service/FileUploadService.php

@@ -21,8 +21,9 @@ class FileUploadService extends Service
     ];
     const tmp_dir = 'kq';
     const string = '/image/';
-    const string2 = 'qy|';
-    const string3 = 'qy/';
+    const string_1 = '/api/uploadFiles/';
+    const string2 = 'qyadmin|';
+    const string3 = 'qyadmin/';
 
     public function uploadFileForKq($file){
         if(empty($file)) return [false, '请上传文件'];
@@ -72,7 +73,7 @@ class FileUploadService extends Service
         $dir = self::tmp_dir . '/' . $date . '/' . $filename;
         Storage::disk('public')->put($dir, file_get_contents($realPath));
 
-        return [true, self::string . self::string2 . $filename];
+        return [true, self::string_1 . self::string2 . $filename];
     }
 
     //获取文件的位置oss
@@ -80,20 +81,13 @@ class FileUploadService extends Service
         $path = "";
         if(empty($file_name)) return $path;
 
-        $document = self::string3;
-        if(strpos($file_name, FileUploadService::string . FileUploadService::string2) !== false){
-            $file_name = str_replace(FileUploadService::string . FileUploadService::string2,'', $file_name);
+        if(strpos($file_name, FileUploadService::string_1 . FileUploadService::string2) !== false){
+            $file_name = str_replace(FileUploadService::string_1 . FileUploadService::string2,'', $file_name);
             $timestamp = substr($file_name, 0, 8); // 截取前八位数字
             $date = \DateTime::createFromFormat('Ymd', $timestamp);
             $date = $date->format('Y-m-d');
-            $savePath = $document . $date . '/' . $file_name;
+            $savePath = self::string3 . $date . '/' . $file_name;
             list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
-        }else{
-            if(strpos($file_name, FileUploadService::string) !== false){
-                $file_name = str_replace(FileUploadService::string ,'', $file_name);
-                $savePath = $document . 'old/upload_files/' . $file_name;
-                list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
-            }
         }
 
         return $path;
@@ -126,7 +120,7 @@ class FileUploadService extends Service
     public function createOssUpload($file){
         if(! is_array($file) && empty($file)) return;
         foreach ($file as $filename){
-            $filename = str_replace(FileUploadService::string.FileUploadService::string2,'', $filename);
+            $filename = str_replace(FileUploadService::string_1.FileUploadService::string2,'', $filename);
             $timestamp = substr($filename, 0, 8); // 截取前八位数字
             $date = \DateTime::createFromFormat('Ymd', $timestamp);
             $date = $date->format('Y-m-d');
@@ -142,8 +136,8 @@ class FileUploadService extends Service
         if(! is_array($file) && empty($file)) return;
 
         foreach ($file as $filename){
-            if(strpos($filename, FileUploadService::string.FileUploadService::string2) !== false){
-                $filename = str_replace(FileUploadService::string.FileUploadService::string2,'',$filename);
+            if(strpos($filename, FileUploadService::string_1.FileUploadService::string2) !== false){
+                $filename = str_replace(FileUploadService::string_1.FileUploadService::string2,'',$filename);
                 $timestamp = substr($filename, 0, 8); // 截取前八位数字
                 $date = \DateTime::createFromFormat('Ymd', $timestamp);
                 $date = $date->format('Y-m-d');
@@ -151,12 +145,6 @@ class FileUploadService extends Service
 
                 list($status,$msg) = (new OssService())->deleteFile($delPath);
 //                if(! $status) return [false , $msg];
-            }else{
-                if(strpos($filename, FileUploadService::string) !== false){
-                    $filename = str_replace(FileUploadService::string,'',$filename);
-                    $delPath = self::string3 . 'old/upload_files/' . $filename;
-                    list($status,$msg) = (new OssService())->deleteFile($delPath);
-                }
             }
         }
     }

+ 223 - 0
app/Service/FollowUpRecordService.php

@@ -0,0 +1,223 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Customer;
+use App\Model\FollowUpRecord;
+use App\Model\FollowUpRecordFile;
+use Illuminate\Support\Facades\DB;
+
+class FollowUpRecordService extends Service
+{
+    public function followUpRecordEdit($data,$user){return [true, ''];
+        list($status,$msg) = $this->followUpRecordRule($data,false);
+        if(!$status) return [$status,$msg];
+
+        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::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function followUpRecordAdd($data,$user){
+        list($status,$msg) = $this->followUpRecordRule($data);
+        if(!$status) return [$status,$msg];
+
+        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();
+
+            $new = [];
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'follow_up_record_id' => $model->id,
+                        'file' => $value['url'],
+                        'name' => $value['name'],
+                        'type' => FollowUpRecordFile::type_one,
+                        'crt_time' => $time,
+                    ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
+                }
+                FollowUpRecordFile::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ['file' => ['new' => $new]]];
+    }
+
+    public function followUpRecordDel($data){return [true, ''];
+        if($this->isEmpty($data,'id')) return [false,'ID必须!'];
+
+        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,'删除成功'];
+    }
+
+    public function followUpRecordList($data,$user){
+        $model = FollowUpRecord::where('del_time',0)
+            ->select('data_id','data_title','basic_type_id','visit_time','id','content','is_remind','crt_time','crt_id','type','result')
+            ->orderBy('id','desc');
+
+        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['type'])) $model->where('type',$data['type']);
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->organizationData($list);
+
+        return [true, $list];
+    }
+
+    public function organizationData($data) {
+        if (empty($data['data'])) return $data;
+
+        $basic_type = BasicType::whereIn('id',array_unique(array_column($data['data'],'basic_type_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $follow_up_record_id = FollowUpRecordFile::where('del_time',0)
+            ->where('type',FollowUpRecordFile::type_one)
+            ->whereIn('follow_up_record_id',array_column($data['data'],'id'))
+            ->where('file','<>','')
+            ->select('follow_up_record_id')
+            ->get()->toArray();
+        $follow_up_record_id = array_unique(array_column($follow_up_record_id,'follow_up_record_id'));
+        foreach ($data['data'] as $key => $value){
+            $has_image = 0;
+            if(in_array($value['id'], $follow_up_record_id)) $has_image = 1;
+            $data['data'][$key]['has_image'] = $has_image;
+            $data['data'][$key]['basic_type_name'] = $basic_type[$value['basic_type_id']] ?? '';
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d H:i:s",$value['crt_time']): '';
+        }
+        return $data;
+    }
+
+    public function followUpRecordRule(&$data,$is_add = true){
+        if($this->isEmpty($data,'data_id')) return [false,'数据id不能为空'];
+        if(empty($data['type']) || ! isset(FollowUpRecord::$type[$data['type']])) return [false,'跟进类型不能为空或跟进类型不存在'];
+        if($data['type'] == FollowUpRecord::type_one){
+            $data['data_title'] = Customer::where('id',$data['data_id'])->value('title');
+        }
+        if($this->isEmpty($data,'visit_time')) return [false,'拜访时间不能为空'];
+        if($this->isEmpty($data,'content')) return [false,'跟进内容不能为空'];
+
+        if(! $is_add){
+            if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
+        }
+        $data['visit_time'] = $this->changeDateToDateMin($data['visit_time']);
+
+        return [true,''];
+    }
+
+    public function followUpRecordDetail($data){
+        if($this->isEmpty($data,'id')) return [false,'ID必须!'];
+
+        $record = [];
+        $sales_info = FollowUpRecordFile::where('del_time',0)
+            ->where('follow_up_record_id',$data['id'])
+            ->get()->toArray();
+        $fileUploadService = new FileUploadService();
+        foreach ($sales_info as $value){
+            if ($value['type'] == FollowUpRecordFile::type_one){
+                $record[] = [
+                    'url' => $value['file'],
+                    'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
+                ];
+            }
+        }
+
+        return [true, $record];
+    }
+
+    public function getVisitDataOfTime($data_id = [], $type = 0){
+        if(empty($data_id) || empty($type)) return [];
+
+        $record = FollowUpRecord::where('del_time',0)
+            ->where('type',$type)
+            ->whereIn('data_id',$data_id)
+            ->select('data_id',DB::raw('max(visit_time) as visit_time'))
+            ->groupBy('data_id')
+            ->pluck('visit_time','data_id')->toArray();
+        $record_array = [];
+        if(! empty($record)){
+            $now = time();
+            foreach ($record as $key => $value){
+                $record_array[$key] = $this->showTimeAgo($value, $now);
+            }
+        }
+
+        return $record_array;
+    }
+}

+ 12 - 4
app/Service/KqService.php

@@ -81,25 +81,33 @@ class KqService extends Service
             $total = $total_key[$v['number']];
             $total['kq_day']++;
 
-            $total['kq_time'] += floatval(sprintf('%.2f',($v['max_crt_time'] - $v['min_crt_time'])/3600));
+            $kq_time = bcdiv($v['max_crt_time'] - $v['min_crt_time'], 3600,2);
+            $kq_time = bcadd($kq_time, $total['kq_time'],2);
+            $total['kq_time'] = $kq_time;
 
             $begin_time = strtotime($v['date'].' '.$work_start_time);
             if($begin_time < $v['min_crt_time']){
                 $total['later_day']++;
-                $total['later_time'] += floatval(sprintf('%.2f',($v['min_crt_time'] - $begin_time)/3600));;
+                $later_time = bcdiv($v['min_crt_time'] - $begin_time, 3600,2);
+                $later_time = bcadd($later_time, $total['later_time'],2);
+                $total['later_time'] = $later_time;
             }
 
             $end_time = strtotime($v['date'].' '.$work_end_time);
             if($end_time > $v['max_crt_time']){
                 $total['early_day']++;
-                $total['early_time'] += floatval(sprintf('%.2f',($end_time - $v['max_crt_time'])/3600));
+                $early_time = bcdiv($end_time - $v['max_crt_time'], 3600,2);
+                $early_time = bcadd($early_time, $total['early_time'],2);
+                $total['early_time'] = $early_time;
             }
 
             $overtime = strtotime($v['date'].' '.$work_end_time)+$overtime*3600;
 
             if($overtime < $v['max_crt_time']){
                 $total['overtime_day']++;
-                $total['overtime_time'] += floatval(sprintf('%.2f',($overtime - $v['max_crt_time']+$overtime_hour*3600)/3600));
+                $overtime_time = bcdiv($overtime - $v['max_crt_time'], 3600,2);
+                $overtime_time = bcadd($overtime_time, $total['overtime_time'],2);
+                $total['overtime_time'] = $overtime_time;
             }
 
             $total_key[$v['number']] = $total;

+ 1 - 17
app/Service/OperationLogService.php

@@ -193,11 +193,8 @@ class OperationLogService extends Service
         return [true, $list_final];
     }
 
-    public function setOperationList($data, $user, $type = 1, $menu_id = 18)
+    public function setOperationList($data, $user, $type = 1, $menu_id = 0)
     {
-
-        file_put_contents('log.txt', date('Y-m-d H:i:s') . json_encode($data) . PHP_EOL, 8);
-
         //获取oa参数
         $key = 'menu_id'; // 要匹配的键
 //        $value = $menu_id; // 要匹配的值
@@ -228,16 +225,6 @@ class OperationLogService extends Service
                 $key_data[$v['key']] = $v['title'];
             }
             $menu_id = $data['menu_id'];
-//            $param = isset($data['order_number']) ? ['order_number' => $data['order_number']] : ['id' => $data['id']];
-//            $request = request();
-//            foreach ($param as $k => $v) {
-//                $request->$k = $v;
-//            }
-//            $newUser = new Employee();
-//            $newUser = $newUser->fill($user);
-//            $request->userData = $newUser;
-//            $all = $request->all();
-//            if (!isset($all['order_number'])) $request->merge($param);
 
             //创建request副本对象 没有参数让检索出来的数据为空数组
             $result_one['id'] = $data['id'] ?? -1;
@@ -251,7 +238,6 @@ class OperationLogService extends Service
                 $currentRequest->files->all(),
                 []
             );
-            file_put_contents('log.txt', date('Y-m-d H:i:s') . "入参:".json_encode($request->all()) . PHP_EOL, 8);
             $detail = $this->oaGetData($menu_id, $request);
 
             $log = new OperationLog();
@@ -282,7 +268,6 @@ class OperationLogService extends Service
                         $v = strtotime($v);
                     }
                     if($v != $detail[$k]){
-
                         $bind_data_detail[] = [
                             'log_id' => $id,
                             'parent_id' => 0,
@@ -298,7 +283,6 @@ class OperationLogService extends Service
             return [true, ''];
         } catch (\Exception $e) {
             DB::rollBack();
-            file_put_contents('log.txt', date('Y-m-d H:i:s') . $e->getCode() . $e->getLine() . $e->getMessage() . PHP_EOL, 8);
             return [false, $e->getLine() . $e->getMessage()];
         }
     }

+ 15 - 0
app/Service/OrderNoService.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Service;
+
+class OrderNoService extends Service
+{
+    public static function createOrderNumber($prefix = "") {
+        // 获取当前时间的微秒级时间戳
+        list($micro, $seconds) = explode(' ', microtime());
+        // 从微秒部分截取全部6位作为唯一标识符
+        $microSuffix = substr($micro, 2, 6);
+
+        return $prefix . date('YmdHis', $seconds) . $microSuffix;
+    }
+}

+ 4 - 0
config/morequery.php

@@ -5,5 +5,9 @@ return [
         "api/kqList" => 10,
         "api/kqCollect" => 11,
     ],
+    "menu_option" => [
+        "api/customerAdd" => 0,
+        "api/customerEdit" => 0,
+    ],
 ];
 

+ 10 - 0
routes/api.php

@@ -54,10 +54,20 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('employeeEditOther', 'Api\EmployeeController@employeeEditOther');
     $route->any('employeeDel', 'Api\EmployeeController@employeeDel');
     $route->any('employeeList', 'Api\EmployeeController@employeeList');
+    $route->any('employeeEditImg', 'Api\EmployeeController@employeeEditImg')->middleware('OssFileDeal');
+    $route->any('getEmployeeImg', 'Api\EmployeeController@getEmployeeImg');
 
     $route->any('kqList', 'Api\KqController@kqList');
     $route->any('kqCollect', 'Api\KqController@kqCollect');
 
+    //客户
+    $route->any('customerList', 'Api\CustomerController@customerList');
+    $route->any('customerEdit', 'Api\CustomerController@customerEdit')->middleware('OssFileDeal');
+    $route->any('customerAdd', 'Api\CustomerController@customerAdd')->middleware('OssFileDeal');
+    $route->any('customerDel', 'Api\CustomerController@customerDel')->middleware('OssFileDeal');
+    $route->any('customerDetail', 'Api\CustomerController@customerDetail');
+    $route->any('customerGrabbing', 'Api\CustomerController@customerGrabbing');
+
     //获取考勤的图片
     $route->get('/kq/image/{filename}', function ($filename) {
         $last_dir = explode('_',$filename)[0];