first commit

This commit is contained in:
2026-07-23 09:40:36 +08:00
commit 090abf48fa
989 changed files with 145728 additions and 0 deletions
+251
View File
@@ -0,0 +1,251 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\api\BaseController;
use app\customer\model\Customer;
use app\customer\model\CustomerTrace;
use app\customer\model\CustomerContact;
use app\customer\model\CustomerChance;
use think\facade\Db;
use think\facade\View;
class Api extends BaseController
{
//获取客户列表
public function get_customer()
{
$param = get_params();
$uid = $this->uid;
$where = array();
$whereOr = array();
if (!empty($param['keywords'])) {
$where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
}
$where[]=['delete_time','=',0];
$where[]=['discard_time','=',0];
if (!empty($param['uid'])) {
$where[] = ['belong_uid', '=', $param['uid']];
}
else{
//是否是客户管理员
$auth = isAuth($uid,'customer_admin','conf_1');
if($auth == 0){
$whereOr[] = ['belong_uid','=',$uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['belong_did','in',$dids];
}
}
}
$model = new Customer();
$list = $model->datalist($param,$where,$whereOr);
table_assign(0, '', $list);
}
//分配客户
public function distribute()
{
if (request()->isAjax()) {
$params = get_params();
//是否是客户管理员
$auth = isAuth($this->uid,'customer_admin','conf_1');
if($auth==0){
return to_assign(1, "只有客户管理员才有权限操作");
}
$data['id'] = $params['id'];
$data['belong_uid'] = $params['uid'];
$data['belong_did'] = $params['did'];
$data['distribute_time'] = time();
if (Db::name('Customer')->update($data) !== false) {
add_log('allot', $data['id'],[],'客户');
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//锁住、解锁客户
public function customer_lock()
{
if (request()->isAjax()) {
$params = get_params();
//是否是客户管理员
$auth = isAuth($this->uid,'customer_admin','conf_1');
if($auth==0){
return to_assign(1, "只有客户管理员才有权限操作");
}
$data['id'] = $params['id'];
$data['is_lock'] = $params['is_lock'];
if (Db::name('Customer')->update($data) !== false) {
if($data['is_lock']==1){
add_log('lock', $data['id'],[],'客户');
}
else{
add_log('unlock', $data['id'],[],'客户');
}
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//彻底删除客户
public function delete()
{
if (request()->isDelete()) {
$params = get_params();
//是否是客户管理员
$auth = isAuth($this->uid,'customer_admin','conf_1');
if($auth==0){
return to_assign(1, "只有客户管理员才有权限操作");
}
$data['id'] = $params['id'];
$data['delete_time'] = -1;
if (Db::name('Customer')->update($data) !== false) {
//删除客户联系人
Db::name('CustomerContact')->where(['cid' => $params['id']])->update(['delete_time'=>time()]);
//删除客户机会
Db::name('CustomerChance')->where(['cid' => $params['id']])->update(['delete_time'=>time()]);
add_log('delete', $params['id']);
return to_assign();
} else {
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//跟进记录列表
public function get_trace()
{
$param = get_params();
$where = array();
$where[] = ['a.delete_time', '=', 0];
$where[] = ['a.cid', '=', $param['cid']];
$model = new CustomerTrace();
$list = $model->datalist($param,$where);
return table_assign(0, '', $list);
}
//销售机会列表
public function get_chance()
{
$param = get_params();
$where = array();
$where[] = ['a.delete_time', '=', 0];
$where[] = ['a.cid', '=', $param['cid']];
if (!empty($param['keywords'])) {
$where[] = ['a.title|a.content', 'like', '%' . $param['keywords'] . '%'];
}
$model = new CustomerChance();
$list = $model->datalist($param,$where);
return table_assign(0, '', $list);
}
//获取联系人数据
public function get_contact()
{
$param = get_params();
$where = array();
$where[] = ['delete_time', '=', 0];
$where[] = ['cid', '=', $param['cid']];
$model = new CustomerContact();
$list = $model->datalist($param,$where);
return table_assign(0, '', $list);
}
//设置联系人
public function set_contact()
{
if (request()->isAjax()) {
$param = get_params();
$detail= Db::name('CustomerContact')->where(['id' => $param['id']])->find();
CustomerContact::where(['cid' => $detail['cid']])->update(['is_default'=>0]);
$res = CustomerContact::where(['id' => $param['id']])->update(['is_default'=>1]);
if ($res) {
add_log('edit', $param['id'], $param,'客户联系人');
return to_assign();
} else {
return to_assign(1, '操作失败');
}
} else {
return to_assign(1, '参数错误');
}
}
//添加附件
public function add_file()
{
$param = get_params();
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$fid = Db::name('CustomerFile')->strict(false)->field(true)->insertGetId($param);
if ($fid) {
return to_assign(0, '上传成功', $fid);
}
}
//删除附件
public function delete_file()
{
if (request()->isDelete()) {
$id = get_params("id");
$data['id'] = $id;
$data['delete_time'] = time();
if (Db::name('CustomerFile')->update($data) !== false) {
$detail = Db::name('CustomerFile')->where('id', $id)->find();
$file_name = Db::name('File')->where('id', $detail['file_id'])->value('name');
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//获取客户等级
public function get_customer_grade()
{
$list = get_base_data('customer_grade');
return to_assign(0, '', $list);
}
//获取客户状态
public function get_customer_status()
{
$list = get_base_type_data('basic_customer',1);
return to_assign(0, '', $list);
}
//获取客户意向
public function get_intent_status()
{
$list = get_base_type_data('basic_customer',2);
return to_assign(0, '', $list);
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\validate\BasicCustomerCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Basic extends BaseController
{
public function datalist()
{
if (request()->isAjax()) {
$param = get_params();
$where=[];
if (!empty($param['types'])) {
$where[] = ['types', '=', $param['types']];
}
$list = Db::name('BasicCustomer')->where($where)->order('create_time asc')->select();
return to_assign(0, '', $list);
} else {
return view();
}
}
//新建编辑
public function add()
{
if (request()->isAjax()) {
$param = get_params();
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(BasicCustomerCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['update_time'] = time();
$res = Db::name('BasicCustomer')->strict(false)->field('title,types,id,update_time')->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
try {
validate(BasicCustomerCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['create_time'] = time();
$insertId = Db::name('BasicCustomer')->strict(false)->field('title,types,id,create_time')->insertGetId($param);
if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign();
}
}
}
//设置
public function set()
{
$param = get_params();
$res = Db::name('BasicCustomer')->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
}
}
+161
View File
@@ -0,0 +1,161 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\CustomerChance as CustomerChanceModel;
use think\facade\Db;
use think\facade\View;
class Chance extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerChanceModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
$uid=$this->uid;
if (request()->isAjax()) {
$where=[];
$whereOr=[];
$where[]=['a.delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['a.title|a.content|c.name', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['stage'])) {
$where[] = ['a.stage','=',$param['stage']];
}
if (!empty($param['uid'])) {
$where[] = ['a.belong_uid','=',$param['uid']];
}
$map=[];
$mapOr=[];
$map[]=['delete_time','=',0];
$map[]=['discard_time','=',0];
$mapOr[] = ['belong_uid','=',$uid];
$mapOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$dids_a = get_leader_departments($uid);
//是否是客户管理员
$auth = isAuth($uid,'customer_admin','conf_1');
if($auth == 0){
if(!empty($dids_a)){
$mapOr[] = ['belong_did','in',$dids_a];
}
$cids = Db::name('Customer')
->where($map)
->where(function ($query) use($mapOr) {
if (!empty($mapOr)){
$query->whereOr($mapOr);
}
})->column('id');
$where[] = ['a.cid', 'in',$cids];
}
$list = $this->model->datalist($param,$where);
return table_assign(0, '', $list);
}
else{
View::assign('is_auth', isAuth($uid,'customer_admin','conf_1'));
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()){
if(isset($param['discovery_time'])){
$param['discovery_time'] = strtotime($param['discovery_time']);
}
if(isset($param['expected_time'])){
$param['expected_time'] = strtotime($param['expected_time']);
}
$param['update_time'] = time();
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
return view('edit');
}
$customer_id = isset($param['cid']) ? $param['cid'] : 0;
$customer_name = Db::name('Customer')->where('id',$customer_id)->value('name');
View::assign('customer_id', $customer_id);
View::assign('customer_name', $customer_name);
if(is_mobile()){
return view('qiye@/customer/chance_add');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$detail['contact'] = Db::name('CustomerContact')->where('id',$detail['contact_id'])->value('name');
$detail['stage_name'] =Db::name('BasicCustomer')->where('id',$detail['stage'])->value('title');
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/customer/chance_view');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+164
View File
@@ -0,0 +1,164 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\CustomerContact as CustomerContactModel;
use app\customer\validate\ContactValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Contact extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerContactModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$uid=$this->uid;
$where=[];
$whereOr=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|name|mobile|email', 'like', '%' . $param['keywords'] . '%'];
}
$map=[];
$mapOr=[];
$map[]=['delete_time','=',0];
$map[]=['discard_time','=',0];
$mapOr[] = ['belong_uid','=',$uid];
$mapOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$dids_a = get_leader_departments($uid);
//是否是客户管理员
$auth = isAuth($uid,'customer_admin','conf_1');
if($auth == 0){
if(!empty($dids_a)){
$mapOr[] = ['belong_did','in',$dids_a];
}
$cids = Db::name('Customer')
->where($map)
->where(function ($query) use($mapOr) {
if (!empty($mapOr)){
$query->whereOr($mapOr);
}
})->column('id');
$whereOr[] = ['cid', 'in',$cids];
}
$whereOr[] = ['admin_id','=',$uid];
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (isset($param['birthday'])) {
$param['birthday'] = strtotime($param['birthday']);
}
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(ContactValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(ContactValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['admin_id'] = $this->uid;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$cid = isset($param['cid']) ? $param['cid'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
return view('edit');
}
if($cid>0){
View::assign('customer_name', Db::name('Customer')->where('id',$cid)->value('name'));
}
View::assign('customer_id', $cid);
View::assign('customer_id', $cid);
if(is_mobile()){
return view('qiye@/customer/contact_add');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/customer/contact_view');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+236
View File
@@ -0,0 +1,236 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\Customer as CustomerModel;
use app\customer\validate\CustomerValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Customer extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$whereOr = [];
$uid = $this->uid;
$tab = isset($param['tab']) ? $param['tab'] : 0;
if (!empty($param['keywords'])) {
$where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['customer_status'])) {
$where[] = ['customer_status', '=', $param['customer_status']];
}
if (!empty($param['industry_id'])) {
$where[] = ['industry_id', '=', $param['industry_id']];
}
if (!empty($param['source_id'])) {
$where[] = ['source_id', '=', $param['source_id']];
}
if (!empty($param['grade_id'])) {
$where[] = ['grade_id', '=', $param['grade_id']];
}
if (!empty($param['intent_status'])) {
$where[] = ['intent_status', '=', $param['intent_status']];
}
if (!empty($param['follow_time'])) {
$follow_time =explode('~', $param['follow_time']);
$where[] = ['follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
}
if (!empty($param['next_time'])) {
$next_time =explode('~', $param['next_time']);
$where[] = ['next_time', 'between',[strtotime(urldecode($next_time[0])),strtotime(urldecode($next_time[1].' 23:59:59'))]];
}
$where[]=['delete_time','=',0];
$where[]=['discard_time','=',0];
if($tab == 0){
if (!empty($param['uid'])) {
$where[] = ['belong_uid', '=', $param['uid']];
}
else{
//是否是客户管理员
$auth = isAuth($uid,'customer_admin','conf_1');
if($auth == 0){
$whereOr[] = ['belong_uid','=',$uid];
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$dids_a = get_leader_departments($uid);
$dids_b = get_role_departments($uid);
$dids = array_merge($dids_a, $dids_b);
if(!empty($dids)){
$whereOr[] = ['belong_did','in',$dids];
}
}
else{
$where[] = ['belong_did','<>',0];
}
}
}
//我的客户
if($tab == 1){
$where[] = ['belong_uid','=',$uid];
}
//下属客户
if($tab == 2){
$where[] = ['belong_uid','<>',$uid];
$dids_a = get_leader_departments($uid);
if(!empty($dids_a)){
$where[] = ['belong_did','in',$dids_a];
}
}
//分享客户
if($tab == 3){
$where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
}
$list = $this->model->datalist($param,$where,$whereOr);
return table_assign(0, '', $list);
}
else{
View::assign('is_leader', isLeader($this->uid));
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
try {
validate(CustomerValidate::class)->scene($param['scene'])->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
if (!empty($param['id']) && $param['id'] > 0) {
$param['edit_id'] = $this->uid;
$this->model->edit($param);
} else {
$param['admin_id'] = $this->uid;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$sea = isset($param['sea']) ? $param['sea'] : 0;
View::assign('sea', $sea);
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
return view('edit');
}
if($this->uid>1){
View::assign('userinfo', get_admin($this->uid));
}
if(is_mobile()){
return view('qiye@/customer/add');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
$detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
if($detail['customer_status']>0){
$detail['customer_status_name'] = Db::name('BasicCustomer')->where(['id' => $detail['customer_status']])->value('title');
}
else{
$detail['customer_status_name']='-';
}
if($detail['intent_status']>0){
$detail['intent_status_name'] = Db::name('BasicCustomer')->where(['id' => $detail['intent_status']])->value('title');
}
else{
$detail['intent_status_name']='-';
}
$detail['industry'] = Db::name('Industry')->where(['id' => $detail['industry_id']])->value('title');
$detail['source'] = Db::name('CustomerSource')->where(['id' => $detail['source_id']])->value('title');
$detail['grade'] = Db::name('CustomerGrade')->where(['id' => $detail['grade_id']])->value('title');
//附件
$file_array = Db::name('CustomerFile')
->field('cf.id,f.filepath,f.name,f.filesize,f.fileext,f.create_time,f.admin_id')
->alias('cf')
->join('File f', 'f.id = cf.file_id', 'LEFT')
->order('cf.create_time asc')
->where(array('cf.customer_id' => $id, 'cf.delete_time' => 0))
->select()->toArray();
$detail['file_array'] = $file_array;
$role=0;
if($detail['belong_uid'] == $this->uid && $detail['is_lock'] == 0){
$role=1;
}
View::assign('detail', $detail);
View::assign('role', $role);
if(is_mobile()){
return view('qiye@/customer/view');
}
return view();
}
/**
* 删除
*/
public function del()
{
$param = get_params();
if (request()->isDelete()) {
$id = get_params("id");
$idArray = explode(',', strval($id));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'discard_time' => time()
];
}
foreach ($list as $key => $v) {
if (Db::name('Customer')->update($v) !== false) {
add_log('delete', $param['id']);
}
}
return to_assign(0, '操作成功');
} else {
return to_assign(1, "错误的请求");
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\CustomerGrade as CustomerGradeModel;
use app\customer\validate\GradeValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Grade extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerGradeModel();
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(GradeValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(GradeValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getCateById($id);
View::assign('detail', $detail);
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
* 设置
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
$res = $this->model->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+224
View File
@@ -0,0 +1,224 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\Customer as CustomerModel;
use think\facade\Db;
use think\facade\View;
class Index extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerModel();
}
//抢客宝
public function rush()
{
if (request()->isAjax()) {
$param = get_params();
$param['order'] = 'rand()';
$where = array();
$where[] = ['delete_time', '=', 0];
$where[] = ['discard_time', '=', 0];
$where[] = ['belong_uid', '=', 0];
$list = $this->model->datalist($param,$where);
return table_assign(0, '', $list);
} else {
$time = strtotime(date('Y-m-d')." 00:00:00");
$max_num = Db::name('DataAuth')->where('name','customer_admin')->value('conf_2');
$count = Db::name('Customer')->where([['belong_time','>',$time],['belong_uid','=',$this->uid]])->count();
View::assign('max_num', $max_num);
View::assign('count', $count);
return view();
}
}
//公海客户
public function sea()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
if (!empty($param['keywords'])) {
$where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['industry_id'])) {
$where[] = ['industry_id', '=', $param['industry_id']];
}
if (!empty($param['source_id'])) {
$where[] = ['source_id', '=', $param['source_id']];
}
if (!empty($param['grade_id'])) {
$where[] = ['grade_id', '=', $param['grade_id']];
}
if (!empty($param['follow_time'])) {
$follow_time =explode('~', $param['follow_time']);
$where[] = ['follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
}
$where[] = ['delete_time', '=', 0];
$where[] = ['discard_time', '=', 0];
$where[] = ['belong_uid', '=', 0];
$list = $this->model->datalist($param,$where);
return table_assign(0, '', $list);
} else {
return view();
}
}
//废池客户
public function trash()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
if (!empty($param['keywords'])) {
$where[] = ['id|name', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['industry_id'])) {
$where[] = ['industry_id', '=', $param['industry_id']];
}
if (!empty($param['source_id'])) {
$where[] = ['source_id', '=', $param['source_id']];
}
if (!empty($param['grade_id'])) {
$where[] = ['grade_id', '=', $param['grade_id']];
}
$where[] = ['delete_time', '>', 0];
$where[] = ['discard_time', '=', 0];
$where[] = ['belong_uid', '=', 0];
$list = $this->model->datalist($param,$where);
return table_assign(0, '', $list);
} else {
return view();
}
}
//移入公海
public function to_sea()
{
if (request()->isAjax()) {
$id = get_params("id");
$idArray = explode(',', strval($id));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'belong_uid' => 0,
'belong_did' => 0,
'belong_time' => 0
];
}
foreach ($list as $key => $v) {
if (Db::name('Customer')->update($v) !== false) {
add_log('tosea', $v['id']);
}
}
return to_assign(0, '操作成功');
} else {
return to_assign(1, "错误的请求");
}
}
//获取客户
public function to_get()
{
if (request()->isAjax()) {
$id = get_params("id");
$time = strtotime(date('Y-m-d')." 00:00:00");
$max_num_day = Db::name('DataAuth')->where('name','customer_admin')->value('conf_2');
$count_day = Db::name('Customer')->where([['belong_time','between',[$time,time()]],['belong_uid','=',$this->uid]])->count();
if($count_day>=$max_num_day){
return to_assign(1, "今日领取客户数已到达上限,请明天再来领取");
}
$max_num = Db::name('DataAuth')->where('name','customer_admin')->value('conf_3');
$count = Db::name('Customer')->where([['belong_uid','=',$this->uid]])->count();
if($count>=$max_num){
return to_assign(1, "领取客户数已到达上限,请把部分客户移到公海里再来领取");
}
$data['id'] = $id;
$data['belong_uid'] = $this->uid;
$data['belong_did'] = $this->did;
$data['belong_time'] = time();
if (Db::name('Customer')->update($data) !== false) {
add_log('tosea', $id);
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//客户移入废弃池
public function to_trash()
{
if (request()->isAjax()) {
$params = get_params();
$id = get_params("id");
$idArray = explode(',', strval($id));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'delete_time' => time()
];
}
foreach ($list as $key => $v) {
if (Db::name('Customer')->update($v) !== false) {
add_log('totrash', $params['id']);
}
}
return to_assign(0, '操作成功');
} else {
return to_assign(1, "错误的请求");
}
}
//还原客户
public function to_revert()
{
if (request()->isAjax()) {
$params = get_params();
$id = get_params("id");
$idArray = explode(',', strval($id));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'delete_time' => 0
];
}
foreach ($list as $key => $v) {
if (Db::name('Customer')->update($v) !== false) {
add_log('recovery', $params['id']);
}
}
return to_assign(0, '操作成功');
} else {
return to_assign(1, "错误的请求");
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\Industry as IndustryModel;
use app\customer\validate\IndustryValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Industry extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new IndustryModel();
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(IndustryValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(IndustryValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
* 设置
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
$res = $this->model->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\CustomerSource as CustomerSourceModel;
use app\customer\validate\SourceValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Source extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerSourceModel();
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(SourceValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(SourceValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getCateById($id);
View::assign('detail', $detail);
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
* 设置
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
$res = $this->model->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+168
View File
@@ -0,0 +1,168 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\customer\controller;
use app\base\BaseController;
use app\customer\model\CustomerTrace as CustomerTraceModel;
use think\facade\Db;
use think\facade\View;
class Trace extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CustomerTraceModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
$uid=$this->uid;
if (request()->isAjax()) {
$where=[];
$where[]=['a.delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['a.content|c.name|cc.title', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['follow_time'])) {
$follow_time =explode('~', $param['follow_time']);
$where[] = ['a.follow_time', 'between',[strtotime(urldecode($follow_time[0])),strtotime(urldecode($follow_time[1].' 23:59:59'))]];
}
if (!empty($param['uid'])) {
$where[] = ['a.admin_id','=',$param['uid']];
}
$map=[];
$mapOr=[];
$map[]=['delete_time','=',0];
$map[]=['discard_time','=',0];
$mapOr[] = ['belong_uid','=',$uid];
$mapOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$dids_a = get_leader_departments($uid);
//是否是客户管理员
$auth = isAuth($uid,'customer_admin','conf_1');
if($auth == 0){
if(!empty($dids_a)){
$mapOr[] = ['belong_did','in',$dids_a];
}
$cids = Db::name('Customer')
->where($map)
->where(function ($query) use($mapOr) {
if (!empty($mapOr)){
$query->whereOr($mapOr);
}
})->column('id');
$where[] = ['a.cid', 'in',$cids];
}
$list = $this->model->datalist($param,$where);
return table_assign(0, '', $list);
}
else{
View::assign('is_auth', isAuth($uid,'customer_admin','conf_1'));
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if(isset($param['follow_time'])){
$param['follow_time'] = strtotime($param['follow_time']);
}
if(isset($param['next_time'])){
$param['next_time'] = strtotime($param['next_time']);
}
$param['update_time'] = time();
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
View::assign('detail', $this->model->getById($id));
return view('edit');
}
$customer_id = isset($param['cid']) ? $param['cid'] : 0;
$customer_name = Db::name('Customer')->where('id',$customer_id)->value('name');
View::assign('customer_id', $customer_id);
View::assign('customer_name', $customer_name);
if(is_mobile()){
return view('qiye@/customer/trace_add');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
$detail['contact'] = Db::name('CustomerContact')->where('id',$detail['contact_id'])->value('name');
$detail['types_name'] = Db::name('BasicCustomer')->where('id',$detail['types'])->value('title');
$detail['stage_name'] = Db::name('BasicCustomer')->where('id',$detail['stage'])->value('title');
if($detail['chance_id']>0){
$detail['chance'] = Db::name('CustomerChance')->where(['id' => $detail['chance_id']])->value('title');
}
else{
$detail['chance']='-';
}
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/customer/trace_view');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}