Bläddra i källkod

Merge remote-tracking branch 'origin/master'

gogs 1 år sedan
förälder
incheckning
a599c44780

+ 73 - 0
app/Http/Controllers/Api/ContactsController.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\ContactsService;
+use Illuminate\Http\Request;
+
+class ContactsController extends BaseController
+{
+    public function contactsAdd(Request $request)
+    {
+        $service = new ContactsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->contactsAdd($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function contactsEdit(Request $request)
+    {
+        $service = new ContactsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->contactsEdit($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function contactsDel(Request $request)
+    {
+        $service = new ContactsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->contactsDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function contactsList(Request $request)
+    {
+        $service = new ContactsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->contactsList($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function contactsDetail(Request $request)
+    {
+        $service = new ContactsService();
+        list($status,$data) = $service->contactsDetail($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 34 - 0
app/Http/Controllers/Api/FileUploadController.php

@@ -0,0 +1,34 @@
+<?php
+namespace App\Http\Controllers\Api;
+
+use App\Exports\MyExport;
+use App\Service\FileUploadService;
+use Illuminate\Http\Request;
+
+//文件上传
+class FileUploadController extends BaseController
+{
+    public function uploadFile(Request $request){
+        $service = new FileUploadService();
+        list($status,$data) = $service->uploadFile($request->file('file'));
+
+        if($status){
+            return $this->json_return(200,'上传成功',['url' => $data]);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    //获取文件的位置
+    public function getFile($file_name){
+        $path = storage_path() . "/app/public/upload_files/".$file_name;
+        $ext = '';
+        foreach (FileUploadService::FILE_TYPE as $value){
+            if(file_exists($path. '.' . $value)){
+                $ext = $value;
+            }
+        }
+        if(empty($ext)) return '';
+        return response()->file($path.'.'.$ext);
+    }
+}

+ 116 - 0
app/Http/Controllers/Api/ProductController.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+
+use App\Service\ProductService;
+use Illuminate\Http\Request;
+
+class ProductController extends BaseController
+{
+    public function productCategoryEdit(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productCategoryEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+    
+    public function productCategoryAdd(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productCategoryAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+    
+    public function productCategoryDel(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productCategoryDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function productCategoryList(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productCategoryList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function productEdit(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function productAdd(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->roleAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function productDel(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function productList(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productList($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 13 - 0
app/Model/Contacts.php

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

+ 23 - 0
app/Model/ContactsInfo.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ContactsInfo extends Model
+{
+    protected $table = "contacts_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; // 协同人
+    public static $type = [
+        self::type_one,
+        self::type_two,
+        self::type_three,
+        self::type_four,
+    ];
+}

+ 21 - 0
app/Model/Product.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Product extends Model
+{
+    protected $table = "product"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const State_zero = 0;
+    const State_one = 1;
+    const State_two = 2;
+    public static $state = [
+        self::State_zero => '新增',
+        self::State_one => '上架',
+        self::State_two => '下架',
+    ];
+}

+ 13 - 0
app/Model/ProductCategory.php

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

+ 19 - 0
app/Model/ProductInfo.php

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

+ 13 - 0
app/Model/ProductInventory.php

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

+ 19 - 0
app/Model/ProductRange.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ProductRange extends Model
+{
+    protected $table = "product_range"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const type_one = 1; // 部门
+    const type_two = 2; // 人
+    public static $type = [
+        self::type_one,
+        self::type_two,
+    ];
+}

+ 2 - 2
app/Service/BasicTypeService.php

@@ -38,9 +38,9 @@ class BasicTypeService extends Service
     public function basicTypeList($data){
         $model = BasicType::where('del_time',0)
             ->select('title','id','type')
-            ->orderby('id', 'asc')
-            ->where('type',$data['type']);
+            ->orderby('id', 'asc');
 
+        if(! empty($data['type'])) $model->where('type',$data['type']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
 
         $list = $this->limit($model,'',$data);

+ 322 - 0
app/Service/ContactsService.php

@@ -0,0 +1,322 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\BasicType;
+use App\Model\Contacts;
+use App\Model\ContactsInfo;
+use App\Model\Employee;
+use Illuminate\Support\Facades\DB;
+
+class ContactsService extends Service
+{
+    public function contactsEdit($data,$user){
+        list($status,$msg) = $this->contactsRule($data,false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = Contacts::where('id',$data['id'])->first();
+            $model->img = $data['img'] ?? '';
+            $model->title = $data['title'];
+            $model->mailbox = $data['mailbox'] ?? '';
+            $model->qq = $data['qq'] ?? '';
+            $model->postal_code = $data['postal_code'] ?? '';
+            $model->sex = $data['sex'] ?? '';
+            $model->gregorian_bir = $data['gregorian_bir'] ?? '';
+            $model->lunar_bir = $data['lunar_bir'] ?? '';
+            $model->address1 = $data['address1'] ?? '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->hobby = $data['hobby'] ?? '';
+            $model->mark = $data['mark'] ?? '';
+            $model->importance = $data['importance'] ?? '';
+            $model->intimacy = $data['intimacy'] ?? '';
+            $model->depart = $data['depart'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? '';
+            $model->job = $data['job'] ?? '';
+            $model->decision = $data['decision'] ?? 0;
+            $model->grade = $data['grade'] ?? 0;
+            $model->save();
+
+            $time = time();
+
+            ContactsInfo::where('del_time',0)
+                ->where('contacts_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            if(! empty($data['contacts'])){
+                $insert = [];
+                foreach ($data['contacts'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'contact_type' => $value['id'],
+                        'contact_info' => $value['info'],
+                        'type' => ContactsInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['customers'])){
+                $insert = [];
+                foreach ($data['customers'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_one'])){
+                $insert = [];
+                foreach ($data['employee_one'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_three,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_two'])){
+                $insert = [];
+                foreach ($data['employee_two'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_four,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function contactsAdd($data,$user){
+        list($status,$msg) = $this->contactsRule($data);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new Contacts();
+            $model->img = $data['img'] ?? '';
+            $model->title = $data['title'];
+            $model->mailbox = $data['mailbox'] ?? '';
+            $model->qq = $data['qq'] ?? '';
+            $model->postal_code = $data['postal_code'] ?? '';
+            $model->sex = $data['sex'] ?? '';
+            $model->gregorian_bir = $data['gregorian_bir'] ?? '';
+            $model->lunar_bir = $data['lunar_bir'] ?? '';
+            $model->address1 = $data['address1'] ?? '';
+            $model->address2 = $data['address2'] ?? '';
+            $model->hobby = $data['hobby'] ?? '';
+            $model->crt_id = $user['id'];
+            $model->mark = $data['mark'] ?? '';
+            $model->importance = $data['importance'] ?? '';
+            $model->intimacy = $data['intimacy'] ?? '';
+            $model->depart = $data['depart'] ?? '';
+            $model->depart_id = $data['depart_id'] ?? '';
+            $model->job = $data['job'] ?? '';
+            $model->decision = $data['decision'] ?? 0;
+            $model->grade = $data['grade'] ?? 0;
+            $model->save();
+            $time = time();
+
+            if(! empty($data['contacts'])){
+                $insert = [];
+                foreach ($data['contacts'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'contact_type' => $value['id'],
+                        'contact_info' => $value['info'],
+                        'type' => ContactsInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['customers'])){
+                $insert = [];
+                foreach ($data['customers'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_one'])){
+                $insert = [];
+                foreach ($data['employee_one'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_three,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            if(! empty($data['employee_two'])){
+                $insert = [];
+                foreach ($data['employee_two'] as $value){
+                    $insert[] = [
+                        'contacts_id' => $model->id,
+                        'employee_id' => $value,
+                        'type' => ContactsInfo::type_four,
+                        'crt_time' => $time,
+                    ];
+                }
+                ContactsInfo::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function contactsDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+
+            Contacts::whereIn('id',$data['id'])->update([
+                'del_time'=> time()
+            ]);
+            ContactsInfo::where('del_time',0)
+                ->where('contacts_id',$data['id'])
+                ->update(['del_time' => time()]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function contactsDetail($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        $customer = Contacts::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'联系人不存在或已被删除'];
+        $customer = $customer->toArray();
+        $customer['contacts'] = $customer['customers'] = $customer['employee_one'] = $customer['employee_two'] = [];
+        $array = [
+            $customer['decision'],
+            $customer['grade'],
+        ];
+        $basic_map = BasicType::whereIn('id',$array)
+            ->pluck('title','id')
+            ->toArray();
+        foreach ($customer as $key => $value){
+            $customer[$key]['decision_title'] = $basic_map[$value['decision']] ?? '';
+            $customer[$key]['grade_title'] = $basic_map[$value['grade']] ?? '';
+        }
+
+        $customer_info = ContactsInfo::where('del_time',0)
+            ->where('contacts_id',$customer['id'])
+            ->select('id','contacts_id','contact_type','contact_info','employee_id','type')
+            ->get()->toArray();
+        foreach ($customer_info as $value){
+            if($value['type'] == ContactsInfo::type_one){
+                $customer['contacts'][] = [
+                    'id' => $value['contact_type'],
+                    'info' => $value['contact_info']
+                ];
+            }elseif ($value['type'] == ContactsInfo::type_two){
+                $customer['customers'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == ContactsInfo::type_three){
+                $customer['employee_one'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == ContactsInfo::type_four){
+                $customer['employee_two'][] = [
+                    $value['employee_id']
+                ];
+            }
+        }
+
+        return [true, $customer];
+    }
+
+    public function contactsList($data,$user){
+        $model = Contacts::where('del_time',0)
+            ->select('title','id','img','mailbox','qq','postal_code','sex','gregorian_bir','lunar_bir','hobby','address1','address2','crt_id','crt_time','mark','importance','depart','job','decision','grade')
+            ->orderby('id', 'desc');
+
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list);
+
+        return [true, $list];
+    }
+
+    public function contactsRule($data, $is_add = true){
+        if(empty($data['title'])) return [false,'联系人名不能为空'];
+        if(empty($data['contacts'])) return [false,'联系方式不能为空'];
+        if(empty($data['customers'])) return [false,'关联客户不能为空'];
+        if(empty($data['employee_one'])) return [false,'负责人不能为空'];
+
+        if($is_add){
+
+        }else{
+
+        }
+
+        return [true, $data];
+    }
+
+    public function fillData($data){
+        if(empty($data['data'])) return $data;
+
+        $array = array_unique(array_merge_recursive(array_column($data['data'],'decision'),array_column($data['data'],'grade')));
+        $basic_map = BasicType::whereIn('id',$array)
+            ->pluck('title','id')
+            ->toArray();
+        $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
+            ->pluck('emp_name','id')
+            ->toArray();
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['decision_title'] = $basic_map[$value['decision']] ?? '';
+            $data['data'][$key]['grade_title'] = $basic_map[$value['grade']] ?? '';
+            $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']] ?? '';
+        }
+
+        return $data;
+    }
+}

+ 83 - 11
app/Service/CustomerService.php

@@ -5,6 +5,8 @@ namespace App\Service;
 use App\Model\BasicType;
 use App\Model\Customer;
 use App\Model\CustomerInfo;
+use App\Model\Depart;
+use App\Model\Employee;
 use Illuminate\Support\Facades\DB;
 
 class CustomerService extends Service
@@ -28,7 +30,6 @@ class CustomerService extends Service
             $model->progress_stage = $data['progress_stage'] ?? 0;
             $model->address1 = $data['address1'] ?? '';
             $model->address2 = $data['address2'] ?? '';
-            $model->crt_id = $user['id'];
             $model->mark = $data['mark'] ?? '';
             $model->importance = $data['importance'] ?? '';
             $model->company = $data['company'] ?? '';
@@ -254,12 +255,21 @@ class CustomerService extends Service
     public function customerDel($data){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
-        Customer::whereIn('id',$data['id'])->update([
-            'del_time'=> time()
-        ]);
-        CustomerInfo::where('del_time',0)
-            ->where('customer_id',$data['id'])
-            ->update(['del_time' => time()]);
+        try {
+            DB::beginTransaction();
+
+            Customer::whereIn('id',$data['id'])->update([
+                'del_time'=> time()
+            ]);
+            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,''];
     }
@@ -272,6 +282,7 @@ class CustomerService extends Service
             ->first();
         if(empty($customer)) return [false,'客户不存在或已被删除'];
         $customer = $customer->toArray();
+        $customer['customer_contact'] = $customer['employee_one'] = $customer['employee_two'] = $customer['employee_three'] = $customer['img'] = $customer['file'] =[];
         $array = [
             $customer['customer_intention'],
             $customer['customer_from'],
@@ -286,6 +297,7 @@ class CustomerService extends Service
         $basic_map = BasicType::whereIn('id',$array)
             ->pluck('title','id')
             ->toArray();
+        $depart_title = Depart::where('id',$customer['depart_id'])->select('title')->value();
         foreach ($customer as $key => $value){
             $customer[$key]['customer_intention_title'] = $basic_map[$value['customer_intention']] ?? '';
             $customer[$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
@@ -296,6 +308,40 @@ class CustomerService extends Service
             $customer[$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
             $customer[$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';
             $customer[$key]['customer_grade_title'] = $basic_map[$value['customer_grade']] ?? '';
+            $customer[$key]['depart_title'] = $depart_title ?? '';
+        }
+
+        $customer_info = CustomerInfo::where('del_time',0)
+            ->where('customer_id',$customer['id'])
+            ->select('id','customer_id','contact_type','contact_info','employee_id','file','type')
+            ->get()->toArray();
+        foreach ($customer_info as $value){
+            if($value['type'] == CustomerInfo::type_one){
+                $customer['customer_contact'][] = [
+                    'id' => $value['contact_type'],
+                    'info' => $value['contact_info']
+                ];
+            }elseif ($value['type'] == CustomerInfo::type_two){
+                $customer['employee_one'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == CustomerInfo::type_three){
+                $customer['employee_two'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == CustomerInfo::type_four){
+                $customer['employee_three'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == CustomerInfo::type_five){
+                $customer['img'][] = [
+                    $value['employee_id']
+                ];
+            }elseif ($value['type'] == CustomerInfo::type_six){
+                $customer['file'][] = [
+                    $value['employee_id']
+                ];
+            }
         }
 
         return [true, $customer];
@@ -303,9 +349,9 @@ class CustomerService extends Service
 
     public function customerList($data,$user){
         $model = Customer::where('del_time',0)
-            ->select('title','id','type')
-            ->orderby('id', 'asc')
-            ->where('type',$data['type']);
+            ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','customer_grade')
+            ->orderby('id', 'desc')
+            ->where('model_type',$data['model_type']);
 
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
 
@@ -318,7 +364,7 @@ class CustomerService extends Service
     public function customerRule($data, $is_add = true){
         if(empty($data['model_type'])) return [false,'客户模板类型不能为空'];
         if(! in_array($data['model_type'],Customer::$model_type)) return [false,'客户模板类型错误'];
-        if(empty($data['title'])) return [false,'客户名称错误'];
+        if(empty($data['title'])) return [false,'客户名称不能为空'];
         if($data['model_type'] == Customer::Model_type_one){
             if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
             if(empty($data['customer_type'])) return [false,'客户类别不能为空'];
@@ -351,6 +397,32 @@ class CustomerService extends Service
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
+        $array = array_unique(array_merge_recursive(array_column($data['data'],'customer_intention'),array_column($data['data'],'customer_from'),array_column($data['data'],'customer_type'),array_column($data['data'],'car_type'),array_column($data['data'],'intention_product'),array_column($data['data'],'progress_stage'),array_column($data['data'],'state_type'),array_column($data['data'],'customer_state'),array_column($data['data'],'customer_grade')));
+        $basic_map = BasicType::whereIn('id',$array)
+            ->pluck('title','id')
+            ->toArray();
+        $depart_title = Depart::where('id',array_unique(array_column($data['data'],'depart_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
+            ->pluck('emp_name','id')
+            ->toArray();
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['customer_intention_title'] = $basic_map[$value['customer_intention']] ?? '';
+            $data['data'][$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
+            $data['data'][$key]['customer_type_title'] = $basic_map[$value['customer_type']] ?? '';
+            $data['data'][$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
+            $data['data'][$key]['intention_product_title'] = $basic_map[$value['intention_product']] ?? '';
+            $data['data'][$key]['progress_stage_title'] = $basic_map[$value['progress_stage']] ?? '';
+            $data['data'][$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
+            $data['data'][$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';
+            $data['data'][$key]['customer_grade_title'] = $basic_map[$value['customer_grade']] ?? '';
+            $data['data'][$key]['depart_title'] = $depart_title[$value['depart_id']] ?? '';
+            $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']] ?? '';
+        }
+
         return $data;
     }
 }

+ 43 - 0
app/Service/FileUploadService.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Service;
+
+
+use Illuminate\Support\Facades\Storage;
+
+class FileUploadService extends Service
+{
+    //文件类型
+    const FILE_TYPE = [
+        'txt',
+        'jpg',
+        'png',
+        'gif',
+        'jpeg',
+        'zip',
+        'rar'
+    ];
+
+    public function uploadFile($file){
+        // 获取文件相关信息
+        $ext = $file->getClientOriginalExtension();     // 扩展名
+        $realPath = $file->getRealPath();   //临时文件的绝对路径
+
+        $ext = strtolower($ext);
+        if (! in_array($ext, self::FILE_TYPE)){
+            $str = '文件格式为:';
+            foreach (self::FILE_TYPE as $value){
+                $str.= $value . ' ' ;
+            }
+            return [false,$str];
+        }
+
+        // 上传文件
+        $file_name = date("Y-m-d").time().rand(1000,9999);
+        $filename =  $file_name.'.' . $ext;
+        // 使用我们新建的uploads本地存储空间(目录)
+        Storage::disk('public')->put('upload_files/'.$filename, file_get_contents($realPath));
+
+        return [true, '/api/uploadFiles/'.$file_name];
+    }
+}

+ 426 - 0
app/Service/ProductService.php

@@ -0,0 +1,426 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Employee;
+use App\Model\Product;
+use App\Model\ProductCategory;
+use App\Model\ProductInfo;
+use App\Model\ProductRange;
+use Illuminate\Support\Facades\DB;
+
+class ProductService extends Service
+{
+    public function productCategoryEdit($data,$user){
+        list($status,$msg) = $this->productCategoryRule($data,false);
+        if(!$status) return [$status,$msg];
+
+        $update = $msg['data'][0];
+
+        $model = new ProductCategory();
+        $model->where('id',$data['id'])->update($update);
+
+        return [true,''];
+    }
+
+    public function productCategoryAdd($data,$user){
+        list($status,$msg) = $this->productCategoryRule($data);
+        if(!$status) return [$status,$msg];
+
+        ProductCategory::insert($msg['data']);
+
+        return [true,''];
+    }
+
+    public function productCategoryDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        $bool = Product::where('del_time',0)
+            ->where('product_category_id',$data['id'])
+            ->exists();
+        if($bool) return [false,'产品分类下已添加产品,操作失败'];
+
+        try {
+            DB::beginTransaction();
+
+            ProductCategory::where('id',$data['id'])->update([
+                'del_time' => time()
+            ]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function productCategoryList($data,$user){
+        $model = ProductCategory::where('del_time',0)
+            ->select('title','id','parent_id')
+            ->orderby('id','desc');
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+
+        $list = $model->get()->toArray();
+        if(! empty($list)) {
+            $list = $this->makeTree(0,$list);
+            $list = $this->set_sort_circle($list);
+        }
+
+        return [true, $list];
+    }
+
+    public function productCategoryRule($data, $is_add = true){
+        if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
+
+        $title = array_column($data['data'],'title');
+        $title = array_map(function($val) {
+            return $val !== null ? $val : 0;
+        }, $title);
+        $title_count = array_count_values($title);
+        foreach ($title as $value){
+            if(empty($value)) return [false,'名称不能为空!'];
+            if($title_count[$value] > 1) return [false,'名称不能重复'];
+        }
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['upd_time'] = time();
+
+            if($is_add){
+                $parent_id = 0;
+                if(! empty($value['parent_id'])) {
+                    $bool = Product::where('del_time',0)
+                        ->where('product_category_id',$value['parent_id'])
+                        ->exists();
+                    if($bool) {
+                        $title = ProductCategory::where('id',$value['parent_id'])->select('title')->value();
+                        return [false,'产品分类:'. $title .'下已添加产品,不允许添加子分类'];
+                    }
+                    $parent_id = $value['parent_id'];
+                }
+
+                $data['data'][$key]['parent_id'] = $parent_id;
+                $data['data'][$key]['crt_time'] = time();
+
+                $bool = ProductCategory::where('title',$value['title'])
+                    ->where('del_time',0)
+                    ->exists();
+            }else{
+                if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
+
+                $bool = ProductCategory::where('title',$value['title'])
+                    ->where('id','<>',$data['id'])
+                    ->where('del_time',0)
+                    ->exists();
+            }
+            if($bool) return [false,'分类名称不能重复'];
+        }
+
+        return [true, $data];
+    }
+
+    public function productEdit($data,$user){
+        list($status,$msg) = $this->productRule($data,false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = Product::where('id',$data['id'])->first();
+            $model->product_category_id = $data['product_category_id'] ?? 0;
+            $model->title = $data['title'];
+            $model->code = $data['code'] ?? '';
+            $model->size = $data['size'] ?? '';
+            $model->unit = $data['unit'] ?? '';
+            $model->bar_code = $data['bar_code'] ?? '';
+            $model->retail_price = $data['retail_price'] ?? 0;
+            $model->mark = $data['mark'] ?? '';
+            $model->state = $data['state'] ?? 0;
+            $model->save();
+
+            $time = time();
+
+            ProductInfo::where('del_time',0)
+                ->where('product_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductInfo::insert($insert);
+            }
+
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductInfo::insert($insert);
+            }
+
+            ProductRange::where('del_time',0)
+                ->where('product_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            if(! empty($data['depart'])){
+                $insert = [];
+                foreach ($data['depart'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductRange::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductRange::insert($insert);
+            }
+
+            if(! empty($data['employee'])){
+                $insert = [];
+                foreach ($data['employee'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductRange::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductRange::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function productAdd($data,$user){
+        list($status,$msg) = $this->productRule($data);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new Product();
+            $model->product_category_id = $data['product_category_id'] ?? 0;
+            $model->title = $data['title'];
+            $model->code = $data['code'] ?? '';
+            $model->size = $data['size'] ?? '';
+            $model->unit = $data['unit'] ?? '';
+            $model->bar_code = $data['bar_code'] ?? '';
+            $model->retail_price = $data['retail_price'] ?? 0;
+            $model->mark = $data['mark'] ?? '';
+            $model->state = $data['state'] ?? 0;
+            $model->crt_id = $user['id'];
+            $model->save();
+
+            $time = time();
+
+            if(! empty($data['img'])){
+                $insert = [];
+                foreach ($data['img'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductInfo::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductInfo::insert($insert);
+            }
+
+            if(! empty($data['file'])){
+                $insert = [];
+                foreach ($data['file'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductInfo::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductInfo::insert($insert);
+            }
+
+            if(! empty($data['depart'])){
+                $insert = [];
+                foreach ($data['depart'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductRange::type_one,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductRange::insert($insert);
+            }
+
+            if(! empty($data['employee'])){
+                $insert = [];
+                foreach ($data['employee'] as $value){
+                    $insert[] = [
+                        'product_id' => $model->id,
+                        'file' => $value,
+                        'type' => ProductRange::type_two,
+                        'crt_time' => $time,
+                    ];
+                }
+                ProductRange::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function productDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+            $time = time();
+
+            Product::where('id',$data['id'])->update(['del_time' => $time]);
+
+            ProductInfo::where('del_time',0)
+                ->where('product_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            ProductRange::where('del_time',0)
+                ->where('product_id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true,''];
+    }
+
+    public function productDetail($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        $customer = Product::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'产品不存在或已被删除'];
+        $customer = $customer->toArray();
+        $customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
+
+        $customer_info = ProductInfo::where('del_time',0)
+            ->where('product_id',$customer['id'])
+            ->select('id','product_id','file','type')
+            ->get()->toArray();
+        foreach ($customer_info as $value){
+            if($value['type'] == ProductInfo::type_one){
+                $customer['img'][] = [
+                    $value['file']
+                ];
+            }elseif ($value['type'] == ProductInfo::type_two){
+                $customer['file'][] = [
+                    $value['file']
+                ];
+            }
+        }
+
+        $customer_range = ProductRange::where('del_time',0)
+            ->where('product_id',$customer['id'])
+            ->select('id','product_id','depart_id','type','employee_id')
+            ->get()->toArray();
+        foreach ($customer_range as $value){
+            if($value['type'] == ProductRange::type_one){
+                $customer['depart'][] = [
+                    $value['depart_id']
+                ];
+            }elseif ($value['type'] == ProductRange::type_two){
+                $customer['employee'][] = [
+                    $value['employee_id']
+                ];
+            }
+        }
+
+        return [true, $customer];
+    }
+
+    public function productList($data,$user){
+        $model = Product::where('del_time',0)
+            ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','state','crt_id','crt_time','mark')
+            ->orderby('id', 'desc');
+
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(isset($data['state'])) $model->where('state', $data['state']);
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list);
+
+        return [true, $list];
+    }
+
+    public function productRule($data, $is_add = true){
+        if(empty($data['title'])) return [false,'产品名称不能为空'];
+        if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
+        if(empty($data['code'])) return [false,'产品编码不能为空'];
+        if(! empty($data['retail_price'])){
+            if(! is_numeric($data['retail_price']) || $data['retail_price'] < 0) return [false,'零售价请填写正确'];
+            $formattedNumber = number_format($data['retail_price'], 2, '.', '');
+            if($formattedNumber != $data['retail_price']) return [false,'零售价请不要超过两位小数'];
+        }
+
+        if($is_add){
+            $bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
+                ->where('del_time',0)
+                ->exists();
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
+                ->where('id','<>',$data['id'])
+                ->where('del_time',0)
+                ->exists();
+        }
+        if($bool) return [false,'产品名称或编码不能重复'];
+
+        return [true, $data];
+    }
+
+    public function fillData($data){
+        if(empty($data['data'])) return $data;
+
+        $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
+            ->pluck('emp_name','id')
+            ->toArray();
+        $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
+            ->pluck('title','id')
+            ->toArray();
+
+        foreach ($data['data'] as $key => $value){
+            $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']] ?? '';
+            $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
+            $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
+        }
+
+        return $data;
+    }
+}

+ 26 - 0
routes/api.php

@@ -20,11 +20,17 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 Route::any('login', 'Api\LoginController@login');
 Route::any('test', 'Api\TestController@aa');
 Route::any('getHeaderWord', 'Api\HeaderWordController@getHeaderWord');
+//文件获取
+Route::any('uploadFiles/{file_name}', 'Api\FileUploadController@getFile');
+
 Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('getHeaderSetting', 'Api\HeaderWordController@getHeaderSettings');
     $route->any('HeaderSettingsAdd', 'Api\HeaderWordController@add');
     $route->any('HeaderSettingsDetail', 'Api\HeaderWordController@detail');
 
+    //文件上传统一方法
+    $route->any('uploadFile', 'Api\FileUploadController@uploadFile');
+
     $route->any('menuAdd', 'Api\SysMenuController@add');
     $route->any('menuEdit', 'Api\SysMenuController@edit');
     $route->any('menuDel', 'Api\SysMenuController@del');
@@ -76,4 +82,24 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('customerAdd', 'Api\CustomerController@customerAdd');
     $route->any('customerDel', 'Api\CustomerController@customerDel');
     $route->any('customerDetail', 'Api\CustomerController@customerDetail');
+
+    //联系人
+    $route->any('contactsList', 'Api\ContactsController@contactsList');
+    $route->any('contactsEdit', 'Api\ContactsController@contactsEdit');
+    $route->any('contactsAdd', 'Api\ContactsController@contactsAdd');
+    $route->any('contactsDel', 'Api\ContactsController@contactsDel');
+    $route->any('contactsDetail', 'Api\ContactsController@contactsDetail');
+
+    //产品分类
+    $route->any('productCategoryList', 'Api\ProductController@productCategoryList');
+    $route->any('productCategoryEdit', 'Api\ProductController@productCategoryEdit');
+    $route->any('productCategoryAdd', 'Api\ProductController@productCategoryAdd');
+    $route->any('productCategoryDel', 'Api\ProductController@productCategoryDel');
+
+    //产品名称
+    $route->any('productList', 'Api\ProductController@productList');
+    $route->any('productEdit', 'Api\ProductController@productEdit');
+    $route->any('productAdd', 'Api\ProductController@productAdd');
+    $route->any('productDel', 'Api\ProductController@productDel');
+    $route->any('productDetail', 'Api\ProductController@productDetail');
 });