完善客户表单设计

This commit is contained in:
lilong@dgg.net 2021-03-22 19:00:48 +08:00
parent 9f8d86c87e
commit 9556e036f2
16 changed files with 585 additions and 0 deletions

View File

@ -0,0 +1,90 @@
<?php
namespace App\Http\Controllers\Crm;
use App\Http\Controllers\Controller;
use App\Models\CustomerField;
use App\Models\Customer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
class AssignmentController extends Controller
{
/**
* 待分配库列表
* @param Request $request
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\JsonResponse
*/
public function assignment(Request $request)
{
if ($request->ajax()){
$res = Customer::query()
->where('status','=',1)
->orderByDesc()
->paginate($request->get('limit', 30));
return $this->success('ok',$res->items(),$res->total());
}
return View::make('crm.assignment.index');
}
public function create()
{
$fields = CustomerField::query()
->where('visiable',1)
->orderBy('sort','asc')
->get();
return View::make('crm.assignment.create',compact('fields'));
}
public function store(ProjectRequest $request)
{
$user = Auth::user();
$data = $request->all(['company_name','name','phone']);
$dataInfo = [];
$fields = ProjectDesign::where('visiable',1)->get();
foreach ($fields as $d){
$items = [
'project_design_id' => $d->id,
'data' => $request->get($d->field_key),
];
if ($d->field_type=='checkbox'){
if (!empty($items['data'])){
$items['data'] = implode(',',$items['data']);
}else{
$items['data'] = null;
}
}
array_push($dataInfo,$items);
}
DB::beginTransaction();
try{
$project_id = DB::table('project')->insertGetId([
'company_name' => $data['company_name'],
'name' => $data['name'],
'phone' => $data['phone'],
'created_user_id' => $user->id,
'owner_user_id' => 0,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
foreach ($dataInfo as $d){
DB::table('project_design_value')->insert([
'project_id' => $project_id,
'project_design_id' => $d['project_design_id'],
'data' => $d['data'],
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
DB::commit();
return Response::json(['code'=>0,'msg'=>'添加成功']);
}catch (\Exception $exception){
DB::rollBack();
Log::info('添加项目异常:'.$exception->getMessage());
return Response::json(['code'=>1,'msg'=>'添加失败']);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers\Crm;
use App\Http\Controllers\Controller;
use App\Models\Customer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
class CustomerController extends Controller
{
}

View File

@ -0,0 +1,90 @@
<?php
namespace App\Http\Controllers\Crm;
use App\Http\Controllers\Controller;
use App\Models\CustomerField;
use App\Models\CustomerFieldValue;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\View;
class CustomerFieldController extends Controller
{
public function index(Request $request)
{
if ($request->ajax()){
$res = CustomerField::query()
->orderBy('sort','asc')
->paginate($request->get('limit', 30));
return $this->success('ok',$res->items(),$res->total());
}
return View::make('crm.customer_field.index');
}
public function create()
{
return View::make('crm.customer_field.create');
}
public function store(Request $request)
{
$data = $request->all(['field_label','field_key','field_type','field_option','field_value','field_tips','sort','visiable']);
//验证field_key是否重复
$has_exist = CustomerField::where('field_key',$data['field_key'])->count();
if ($has_exist){
return $this->error('字段Key'.$data['field_key'].'已存在');
}
try{
CustomerField::create($data);
return $this->success();
}catch (\Exception $exception){
Log::error('添加客户字段异常:'.$exception->getMessage());
return $this->error();
}
}
public function edit($id)
{
$model = CustomerField::findOrFail($id);
return View::make('crm.customer_field.create',compact('model'));
}
public function update(Request $request,$id)
{
$model = CustomerField::findOrFail($id);
$data = $request->all(['field_label','field_key','field_type','field_option','field_value','field_tips','sort','visiable','required']);
//验证field_key是否重复
$has_exist = CustomerField::where('field_key',$data['field_key'])->where('id','!=',$id)->count();
if ($has_exist){
return $this->error('字段Key'.$data['field_key'].'已存在');
}
try{
$model->update($data);
return $this->success();
}catch (\Exception $exception){
Log::error('更新客户字段异常:'.$exception->getMessage());
return $this->error();
}
}
public function destroy(Request $request)
{
$ids = $request->get('ids',[]);
//删除
DB::beginTransaction();
try{
CustomerField::query()->whereIn('id',$ids)->delete();
CustomerFieldValue::query()->whereIn('customer_field_id',$ids)->delete();
DB::commit();
return $this->success();
}catch (\Exception $exception){
DB::rollBack();
Log::error('删除客户字段异常:'.$exception->getMessage());
return $this->error();
}
}
}

13
app/Models/Customer.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $table = 'customer';
protected $guarded = ['id'];
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
class CustomerField extends Model
{
protected $table = 'customer_field';
protected $guarded = ['id'];
protected $appends = ['field_type_name'];
public function getFieldTypeNameAttribute($value)
{
return Arr::get(config('freeswitch.field_type'),$this->field_type,'-');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CustomerFieldValue extends Model
{
protected $table = 'customer_field_value';
protected $guarded = ['id'];
}

View File

@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Customer extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uuid')->comment('客户编号,唯一');
$table->string('name')->nullable()->comment('客户名称');
$table->string('contact_name')->nullable()->comment('联系人');
$table->string('contact_phone')->nullable()->comment('联系电话');
$table->unsignedBigInteger('created_user_id')->default(0)->comment('创建人ID');
$table->string('created_user_nickname')->nullable()->comment('创建人姓名');
$table->unsignedBigInteger('node_id')->nullable()->comment('当前节点ID');
$table->string('node_name')->nullable()->comment('当前节点名称');
$table->unsignedBigInteger('follow_user_id')->default(0)->comment('最近跟进人ID');
$table->string('follow_user_nickname')->nullable()->comment('最近跟进人姓名');
$table->timestamp('next_follow_time')->nullable()->comment('下次跟进时间');
$table->unsignedBigInteger('owner_user_id')->default(0)->comment('当前所属用户ID');
$table->string('owner_user_nickname')->default(0)->comment('当前所属用户名称');
$table->unsignedBigInteger('owner_department_id')->default(0)->comment('当前所属用户部门ID');
$table->tinyInteger('status')->default(1)->comment('资源所在库1待分配库录入库2经理库3个人库4部门库5公海库');
$table->text('remark')->nullable()->comment('客户跟进备注');
$table->dateTime('remove_time')->nullable()->comment('剔除到公海库的时间');
$table->tinyInteger('is_end')->default(0)->comment('是否成单0未成单1成单');
$table->timestamp('end_time')->nullable()->comment('成单时间');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer');
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CustomerField extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_field', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('field_label')->comment('字段名称');
$table->string('field_key')->comment('字段标识');
$table->string('field_type')->default('input')->comment('字段类型');
$table->string('field_option')->nullable()->comment('字段配置项');
$table->string('field_value')->nullable()->comment('字段默认值');
$table->string('field_tips')->nullable()->default(null)->comment('提示信息');
$table->tinyInteger('sort')->default(10)->comment('排序');
$table->tinyInteger('visiable')->default(1)->comment('可见性1显示2隐藏。默认1');
$table->tinyInteger('required')->default(1)->comment('是否必填1是2否。默认2');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer_field');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CustomerFieldValue extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_field_value', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('customer_id')->comment('客户ID');
$table->unsignedBigInteger('customer_field_id')->comment('客户字段ID');
$table->string('data')->nullable()->comment('项目对应表单字段的值');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer_field_value');
}
}

View File

@ -124,6 +124,14 @@ class MenuTableSeeder extends Seeder
'type' => 1,
'permission_name' => 'crm.node',
],
[
'name' => '客户配置',
'route' => 'crm.customer_field',
'url' => null,
'icon' => 'layui-icon-set-fill',
'type' => 1,
'permission_name' => 'crm.customer_field',
],
]
],
];

View File

@ -145,6 +145,15 @@ class UserTableSeeder extends Seeder
['name' => 'crm.node.destroy', 'display_name' => '删除'],
]
],
[
'name' => 'crm.customer_field',
'display_name' => '客户配置',
'child' => [
['name' => 'crm.customer_field.create', 'display_name' => '添加'],
['name' => 'crm.customer_field.edit', 'display_name' => '编辑'],
['name' => 'crm.customer_field.destroy', 'display_name' => '删除'],
]
],
],
],
];

View File

@ -0,0 +1,69 @@
{{csrf_field()}}
<div class="layui-form-item">
<label for="" class="layui-form-label">字段名称</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="field_label" lay-verify="required" value="{{$model->field_label??old('field_label')}}" placeholder="如:姓名">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">字段Key</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="field_key" lay-verify="required" value="{{$model->field_key??old('field_key')}}" placeholder="name">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">字段类型</label>
<div class="layui-input-block">
<select name="field_type" lay-verify="required">
<option value=""></option>
@foreach(config('freeswitch.field_type') as $k => $v)
<option value="{{$k}}" @if(isset($model)&&$model->field_type==$k) selected @endif >{{$v}}</option>
@endforeach
</select>
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">默认值</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="field_value" value="{{$model->field_value??''}}" placeholder="可为空">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">字段选项</label>
<div class="layui-input-inline">
<textarea name="field_option" class="layui-textarea">{{$model->field_option??''}}</textarea>
</div>
<div class="layui-word-aux layui-form-mid">例:<br/>1:<br/>2:<br/>3:保密</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">排序</label>
<div class="layui-input-block">
<input class="layui-input" type="number" name="sort" lay-verify="required" value="{{$model->sort??10}}" placeholder="序号">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">字段提示</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="field_tips" value="{{$model->field_tips??''}}" placeholder="如:请输入提示">
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">可见性</label>
<div class="layui-input-block">
<input type="radio" name="visiable" value="1" title="显示" @if(!isset($model) || (isset($model)&&$model->required==1)) checked @endif >
<input type="radio" name="visiable" value="2" title="隐藏" @if(isset($model)&&$model->required==2) checked @endif>
</div>
</div>
<div class="layui-form-item">
<label for="" class="layui-form-label">是否必填</label>
<div class="layui-input-block">
<input type="radio" name="required" value="1" title="" @if(isset($model)&&$model->required==1) checked @endif >
<input type="radio" name="required" value="2" title="" @if(!isset($model) || (isset($model)&&$model->required==2)) checked @endif>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="button" class="layui-btn" lay-submit lay-filter="go-close-refresh" > </button>
</div>
</div>

View File

@ -0,0 +1,12 @@
@extends('base')
@section('content')
<div class="layui-card">
<div class="layui-card-body">
<form action="{{route('crm.customer_field.store')}}" method="post" class="layui-form">
@include('crm.customer_field._form')
</form>
</div>
</div>
@endsection

View File

@ -0,0 +1,12 @@
@extends('base')
@section('content')
<div class="layui-card">
<div class="layui-card-body">
<form action="{{route('crm.customer_field.update',['id'=>$model->id])}}" method="post" class="layui-form">
{{method_field('put')}}
@include('crm.customer_field._form')
</form>
</div>
</div>
@endsection

View File

@ -0,0 +1,96 @@
@extends('base')
@section('content')
<style>
.layui-table tbody .layui-table-cell{
height:50px;
line-height: 50px;
}
</style>
<div class="layui-card">
<div class="layui-card-header layuiadmin-card-header-auto">
<div class="layui-btn-group">
@can('crm.customer_field.create')
<a class="layui-btn layui-btn-sm" id="addBtn" >添加</a>
@endcan
</div>
</div>
<div class="layui-card-body">
<table id="dataTable" lay-filter="dataTable"></table>
<script type="text/html" id="options">
<div class="layui-btn-group">
@can('crm.customer_field.edit')
<a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
@endcan
@can('crm.customer_field.destroy')
<a class="layui-btn layui-btn-danger layui-btn-sm " lay-event="del">删除</a>
@endcan
</div>
</script>
</div>
</div>
@endsection
@section('script')
<script>
layui.use(['layer','table','form'],function () {
var $ = layui.jquery;
var layer = layui.layer;
var form = layui.form;
var table = layui.table;
//用户表格初始化
var dataTable = table.render({
elem: '#dataTable'
,height: 500
,url: "{{ route('crm.customer_field') }}" //数据接口
,page: true //开启分页
,cols: [[ //表头
{checkbox: true,fixed: true}
//,{field: 'id', title: 'ID', sort: true,width:80}
,{field: 'field_label', title: '字段名称'}
,{field: 'field_key', title: '字段Key'}
,{field: 'field_type_name', title: '字段类型'}
,{field: 'field_option', title: '字段配置项'}
,{field: 'field_value', title: '默认值'}
,{field: 'sort', title: '排序'}
,{field: 'visiable', title: '可见性',templet:function (d) {
return d.visiable==1?'显示':'隐藏';
}}
,{field: 'visiable', title: '是否必填',templet:function (d) {
return d.required==1?'是':'否';
}}
,{field: 'created_at', title: '创建时间'}
,{fixed: 'right', width: 150, align:'center', toolbar: '#options', title:'操作'}
]]
});
//监听工具条
table.on('tool(dataTable)', function(obj){ //注tool是工具条事件名dataTable是table原始容器的属性 lay-filter="对应的值"
var data = obj.data //获得当前行数据
,layEvent = obj.event; //获得 lay-event 对应的值
if(layEvent === 'del'){
deleteData(obj,"{{ route('crm.customer_field.destroy') }}");
} else if(layEvent === 'edit'){
layer.open({
type: 2,
title: "添加",
shadeClose: true,
area: ["800px","600px"],
content: '/crm/customer_field/'+data.id+'/edit',
})
}
});
$("#addBtn").click(function () {
layer.open({
type: 2,
title: "添加",
shadeClose: true,
area: ["800px","600px"],
content: "{{route("crm.customer_field.create")}}",
})
})
})
</script>
@endsection

View File

@ -220,4 +220,18 @@ Route::group(['prefix'=>'crm','namespace'=>'Crm','middleware'=>['auth','permissi
Route::delete('node/destroy','NodeController@destroy')->name('crm.node.destroy')->middleware('permission:crm.node.destroy');
});
//客户字段
Route::group([],function (){
Route::get('customer_field','CustomerFieldController@index')->name('crm.customer_field')->middleware('permission:crm.customer_field');
//添加
Route::get('customer_field/create','CustomerFieldController@create')->name('crm.customer_field.create')->middleware('permission:crm.customer_field');
Route::post('customer_field/store','CustomerFieldController@store')->name('crm.customer_field.store')->middleware('permission:crm.customer_field');
//编辑
Route::get('customer_field/{id}/edit','CustomerFieldController@edit')->name('crm.customer_field.edit')->middleware('permission:crm.customer_field');
Route::put('customer_field/{id}/update','CustomerFieldController@update')->name('crm.customer_field.update')->middleware('permission:crm.customer_field');
//删除
Route::delete('customer_field/destroy','CustomerFieldController@destroy')->name('crm.customer_field.destroy')->middleware('permission:crm.customer_field');
});
});