pull/1/head
旭晓耿 4 years ago
parent 2b7b3791a1
commit 97662ba32e

@ -170,3 +170,25 @@ function sendRequest($url, $params = array() , $headers = array()) {
curl_close($ch); curl_close($ch);
return $return; return $return;
} }
/**
* 验证序列号
* @param
* @return
*/
function checkWkCode($wkcode) {
$pub = config('public_key');
$openssl_pub = openssl_pkey_get_public($pub);
// 验签
$resArr = openssl_public_decrypt(Hex2String($wkcode), $decrypted, $pub);
if(!$resArr) return false;
return $decrypted;
}
function Hex2String($hex){
$string = '';
for ($i=0; $i < strlen($hex); $i+=2){
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}

@ -116,14 +116,22 @@ class Field extends ApiCommon
$types_id = $param['types_id'] ? : 0; $types_id = $param['types_id'] ? : 0;
// $data['types'] = $param['types']; // $data['types'] = $param['types'];
$data = $param['data']; $data = $param['data'];
$saveParam = []; # 新增数据 $saveParam = []; # 新增数据
$updateParam = []; # 编辑数据 $updateParam = []; # 编辑数据
$delParam = []; # 删除数据 $delParam = []; # 删除数据
$fieldIds = []; # 删除数据兼容前端11.*.*版本) $fieldIds = []; # 删除数据兼容前端11.*.*版本)
$errorMessage = []; # 错误数据
$i = 0; $i = 0;
foreach ($data AS $k => $v) { foreach ($data AS $k => $v) {
$i++; $i++;
# 必填的字段不可以隐藏
if (!empty($v['is_null']) && !empty($v['is_hidden'])) {
$errorMessage = '必填的字段不可以隐藏!';
break;
}
if ($v['field_id']) { if ($v['field_id']) {
if (isset($v['is_deleted']) && $v['is_deleted'] == '1') { if (isset($v['is_deleted']) && $v['is_deleted'] == '1') {
# 删除 # 删除
@ -143,8 +151,8 @@ class Field extends ApiCommon
} }
} }
# 错误数据 # 必填的字段不可以隐藏
$errorMessage = []; if ($errorMessage) return resultArray(['error' => $errorMessage]);
# 兼容前端11.*.*版本的删除条件处理,通过比较差异,来确定谁被前端给删除了 todo 这段代码需要写在新增上面,不然会把新增的给删除掉 # 兼容前端11.*.*版本的删除条件处理,通过比较差异,来确定谁被前端给删除了 todo 这段代码需要写在新增上面,不然会把新增的给删除掉
$oldFieldIds = Db::name('admin_field')->where('types', $types)->column('field_id'); $oldFieldIds = Db::name('admin_field')->where('types', $types)->column('field_id');
@ -170,7 +178,7 @@ class Field extends ApiCommon
# 删除 # 删除
if (!empty($delParam)) { if (!empty($delParam)) {
if (!$data = $fieldModel->delDataById($delParam)) { if (!$data = $fieldModel->delDataById($delParam)) {
$errorMessage[] = $fieldModel->getError(); if (!empty($fieldModel->getError())) $errorMessage[] = $fieldModel->getError();
} }
} }
@ -312,12 +320,17 @@ class Field extends ApiCommon
case 'crm_visit' : case 'crm_visit' :
$visit = new \app\crm\model\Visit(); $visit = new \app\crm\model\Visit();
$dataInfo = $visit->getDataById(intval($param['action_id'])); $dataInfo = $visit->getDataById(intval($param['action_id']));
$fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'visit', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'visit', $param['action']);
//读写权限 //读写权限
$roPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'read'); $roPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'read');
$rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$roPre && !$rwPre) { if (!in_array($user_id, stringToArray($dataInfo['owner_user_id'])) && !in_array($user_id,$auth_user_ids) && !$roPre && !$rwPre) {
header('Content-Type:application/json; charset=utf-8'); header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code'=>102,'error'=>'无权操作'])); exit(json_encode(['code'=>102,'error'=>'无权操作']));
} }
@ -614,6 +627,10 @@ class Field extends ApiCommon
$userFieldModel = model('UserField'); $userFieldModel = model('UserField');
$width = $param['width'] > 10 ? $param['width'] : ''; $width = $param['width'] > 10 ? $param['width'] : '';
$unField = array('pool_day','owner_user_name','is_lock','create_user_name'); $unField = array('pool_day','owner_user_name','is_lock','create_user_name');
switch ($param['field']) {
case 'status_id_info' : $param['field'] = 'status_id';
break;
}
if (!in_array($param['field'],$unField)) { if (!in_array($param['field'],$unField)) {
$res = $userFieldModel->setColumnWidth($param['types'], $param['field'], $width, $userInfo['id']); $res = $userFieldModel->setColumnWidth($param['types'], $param['field'], $width, $userInfo['id']);
if (!$res) { if (!$res) {

@ -52,6 +52,7 @@ class Index extends ApiCommon
if ($value['field'] == 'address') $field_arr[$key]['form_type'] = 'map_address'; if ($value['field'] == 'address') $field_arr[$key]['form_type'] = 'map_address';
if ($value['field'] == 'deal_status') $field_arr[$key]['form_type'] = 'deal_status'; if ($value['field'] == 'deal_status') $field_arr[$key]['form_type'] = 'deal_status';
if ($value['field'] == 'check_status') $field_arr[$key]['form_type'] = 'check_status'; if ($value['field'] == 'check_status') $field_arr[$key]['form_type'] = 'check_status';
if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
} }
return resultArray(['data' => $field_arr]); return resultArray(['data' => $field_arr]);

@ -27,15 +27,15 @@ class Install extends Controller
$param = Request::instance()->param(); $param = Request::instance()->param();
$this->param = $param; $this->param = $param;
$request = request(); // $request = request();
$m = strtolower($request->module()); // $m = strtolower($request->module());
$c = strtolower($request->controller()); // $c = strtolower($request->controller());
$a = strtolower($request->action()); // $a = strtolower($request->action());
//
if (!in_array($a, array('upgrade','upgradeprocess','checkversion')) && file_exists(CONF_PATH . "install.lock")) { // if (!in_array($a, array('upgrade','upgradeprocess','checkversion')) && file_exists(CONF_PATH . "install.lock")) {
echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('请勿重复安装!');location.href='".$_SERVER["HTTP_HOST"]."';</script>"; // echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('请勿重复安装!');location.href='".$_SERVER["HTTP_HOST"]."';</script>";
die(); // die();
} // }
} }
private $upgrade_site = "http://message.72crm.com/"; private $upgrade_site = "http://message.72crm.com/";
@ -73,7 +73,7 @@ class Install extends Controller
public function version() public function version()
{ {
$res = include(CONF_PATH.'version.php'); $res = include(CONF_PATH.'version.php');
return $res ? : array('VERSION' => '9.0.0','RELEASE' => '20190330'); return $res ? : array('VERSION' => '11.0.0','RELEASE' => '20210219');
} }
public function step2(){ public function step2(){
@ -114,6 +114,7 @@ class Install extends Controller
$username = $param['root']; $username = $param['root'];
$password = $param['pwd']; $password = $param['pwd'];
$wkcode = $param['wkcode'];
if (empty($db_config['hostname'])) { if (empty($db_config['hostname'])) {
return resultArray(['error' => '请填写数据库主机!']); return resultArray(['error' => '请填写数据库主机!']);
} }
@ -141,6 +142,17 @@ class Install extends Controller
if (empty($username)) { if (empty($username)) {
return resultArray(['error' => '请填写管理员用户名!']); return resultArray(['error' => '请填写管理员用户名!']);
} }
if (empty($wkcode)) {
return resultArray(['error' => '请填写序列号!']);
}
$resCheckData = checkWkCode($wkcode);
if (!$resCheckData) {
return resultArray(['error' => '序列号错误!']);
}
$resData = object_to_array(json_decode($resCheckData));
if ($resData['date'] != date('Y-m-d')) {
return resultArray(['error' => '序列号已失效,请前往悟空官网个人中心获取最新数据!']);
}
if (empty($password)) { if (empty($password)) {
return resultArray(['error' => '请填写管理员密码!']); return resultArray(['error' => '请填写管理员密码!']);
} }
@ -161,6 +173,7 @@ class Install extends Controller
} }
$db_config['database'] = $database; $db_config['database'] = $database;
self::mkDatabase($db_config); self::mkDatabase($db_config);
self::mkLicense($wkcode);
$C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10); $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
$sql = file_get_contents( $C_Patch.'/public/sql/5kcrm.sql'); $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm.sql');
$sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]); $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
@ -189,6 +202,11 @@ class Install extends Controller
return resultArray(['data'=>'安装成功']); return resultArray(['data'=>'安装成功']);
} }
public function step5()
{
return $this->fetch();
}
//ajax 进度条 //ajax 进度条
public function progress() public function progress()
{ {
@ -314,7 +332,7 @@ INFO;
{ {
$items = [ $items = [
'os' => ['操作系统', PHP_OS, '类Unix', 'ok'], 'os' => ['操作系统', PHP_OS, '类Unix', 'ok'],
'php' => ['PHP版本', PHP_VERSION, '7.2 ( <em style="color: #888; font-size: 12px;">>= 5.6</em> )', 'ok','性能更佳'], 'php' => ['PHP版本', PHP_VERSION, '7.3 ( <em style="color: #888; font-size: 12px;">>= 5.6</em> )', 'ok','性能更佳'],
'gd' => ['gd', '开启', '开启', 'ok'], 'gd' => ['gd', '开启', '开启', 'ok'],
'openssl' => ['openssl', '开启', '开启', 'ok'], 'openssl' => ['openssl', '开启', '开启', 'ok'],
'pdo' => ['pdo', '开启', '开启', 'ok'], 'pdo' => ['pdo', '开启', '开启', 'ok'],
@ -379,4 +397,32 @@ INFO;
} }
return $items; return $items;
} }
/**
* 验证序列号
* @param
* @return
*/
public function checkCodeOld($username) {
$encryption = md5($username);
$substr = substr($username, strlen($username)-6);
$subArr = str_split($substr, 1);
$code = '';
for ($i = 0; $i <= 5; $i++) {
$code .= $encryption[$subArr[$i]];
}
return $code;
}
//写入license文件
private function mkLicense($wkcode)
{
file_put_contents( CONF_PATH.'license.dat', $wkcode);
// 判断写入是否成功
// $config = include CONF_PATH.'license.dat';
// if (empty($config)) {
// return resultArray(['error' => 'license配置写入失败']);
// }
return true;
}
} }

@ -92,6 +92,7 @@ class Users extends ApiCommon
if (!$data) { if (!$data) {
return resultArray(['error' => $userModel->getError()]); return resultArray(['error' => $userModel->getError()]);
} }
$data['serverUserInfo'] = $this->queryLoginUser();
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
@ -500,6 +501,7 @@ class Users extends ApiCommon
$data['username'] = $param['username']; $data['username'] = $param['username'];
$data['password'] = user_md5($param['password'], $userData['salt'], $param['username']); $data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
$data['userInfo'] = $userData; $data['userInfo'] = $userData;
$data['mobile'] = $param['username'];
$resSync = model('Sync')->syncData($data); $resSync = model('Sync')->syncData($data);
if ($resSync) { if ($resSync) {
unset($data['userInfo']); unset($data['userInfo']);
@ -658,9 +660,6 @@ class Users extends ApiCommon
/** /**
* 设置关注 * 设置关注
* *
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\exception\PDOException
*/ */
public function userStar() public function userStar()
{ {
@ -700,10 +699,6 @@ class Users extends ApiCommon
/** /**
* 获取下属(全部层级) * 获取下属(全部层级)
* *
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function subordinate() public function subordinate()
{ {
@ -720,4 +715,21 @@ class Users extends ApiCommon
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/**
* 获取当前登录人信息
*
*/
public function queryLoginUser()
{
$resData = [];
$wkcode = file_get_contents(CONF_PATH.'license.dat');
if ($wkcode) {
$resCheckData = checkWkCode($wkcode);
if ($resCheckData) {
$resData = object_to_array(json_decode($resCheckData));
}
}
return $resData;
}
} }

@ -535,7 +535,7 @@ class FieldGrantLogic
{ {
$content = []; $content = [];
$visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_visit')->select(); $visitList = Db::name('admin_field')->field(['name', 'field'])->where(['type' => 'crm_visit', 'operating' => 0])->select();
# 处理自定义字段 # 处理自定义字段
foreach ($visitList AS $key => $value) { foreach ($visitList AS $key => $value) {
@ -551,14 +551,19 @@ class FieldGrantLogic
} }
# 处理固定字段 # 处理固定字段
// $content[] = ['name' => '回访时间', 'field' => 'visit_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0]; $content[] = ['name' => '回访编号', 'field' => 'number', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '负责人', 'field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0]; $content[] = ['name' => '回访形式', 'field' => 'shape', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '客户', 'field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0]; $content[] = ['name' => '客户满意度', 'field' => 'satisfaction', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '联系人', 'field' => 'contract_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0]; $content[] = ['name' => '回访时间', 'field' => 'visit_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '客户名称', 'field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '联系人', 'field' => 'contacts_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '合同编号', 'field' => 'contract_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '客户反馈', 'field' => 'feedback', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '回访人', 'field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '创建时间', 'field' => 'create_time', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0]; $content[] = ['name' => '创建时间', 'field' => 'create_time', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '编辑时间', 'field' => 'update_time', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0]; $content[] = ['name' => '编辑时间', 'field' => 'update_time', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '创建人', 'field' => 'create_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0]; $content[] = ['name' => '创建人', 'field' => 'create_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '合同', 'field' => 'contacts_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,

@ -21,7 +21,7 @@ class MessageLogic
$where = array('in', [6, 7, 8]); $where = array('in', [6, 7, 8]);
break; break;
case '4': //公告 case '4': //公告
$where = array('eq', 9); $where = 9;
break; break;
case '5' : //日程 case '5' : //日程
$where = 10; $where = 10;
@ -43,7 +43,7 @@ class MessageLogic
unset($param['user_id']); unset($param['user_id']);
//types 1表示已读 0表示未读 //types 1表示已读 0表示未读
if (isset($param['is_read'])) { if (isset($param['is_read'])) {
$where['m.read_time'] = ['=', 0]; $where['m.read_time'] = 0;
} }
$where['m.to_user_id'] = $userId; $where['m.to_user_id'] = $userId;
$where['m.is_delete'] = ['eq', 1]; $where['m.is_delete'] = ['eq', 1];
@ -74,11 +74,11 @@ class MessageLogic
->page($param['page'], $param['limit']) ->page($param['page'], $param['limit'])
->order($order) ->order($order)
->select(); ->select();
$dataCount = db('admin_message')
->alias('m')
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
->where($where)->count();
} }
$dataCount = db('admin_message')
->alias('m')
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
->where($where)->count();
//1表示已读 0表示未读 //1表示已读 0表示未读
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
if ($v['read_time'] == 0) { if ($v['read_time'] == 0) {
@ -90,48 +90,38 @@ class MessageLogic
if ($v['type'] == 4) { if ($v['type'] == 4) {
$content = db('admin_comment') $content = db('admin_comment')
->where( ->where(
[ 'status' => 1, ['status' => 1,
'comment_id' => $v['action_id'], 'type_id' => $v['action_id'],
'type' => ['like', '%' . $v['controller_name' . '%']], 'type' => ['like', '%' . $v['controller_name' . '%']],
'user_id' => $v['from_user_id'] 'user_id' => $v['from_user_id']
]) ])
->find(); ->select();
if (!empty($content)) { $list[$k]['content'] = $content[$k]['content'];
$list[$k]['content'] = $content['content']; } elseif (in_array($v['type'], ['7','12', '15',25])) {
}
} elseif (in_array($v['type'], ['12', '15'])) {
$content = db('admin_examine_record')->where(['types_id' => $v['action_id'], 'types' => ['like', '%' . $v['controller_name' . '%']], 'check_user_id' => $v['from_user_id']])->field('content')->find(); $content = db('admin_examine_record')->where(['types_id' => $v['action_id'], 'types' => ['like', '%' . $v['controller_name' . '%']], 'check_user_id' => $v['from_user_id']])->field('content')->find();
if ($content['content']) { if ($content['content']) {
$list[$k]['content'] = $content['content']; $list[$k]['content'] = $content['content'];
} }
} }
if ($v['type'] == 10) { if ($v['type'] == 10 && $v['advance_time'] < time()) {
$item = db('oa_event_notice')->where('id', $v['action_id'])->find(); $item = db('oa_event_notice')->where('id', $v['action_id'])->find();
if ($item) {
if ($item) { $type['value'] = $item['number'];
$noticetype = $item['noticetype']; $type['type'] = $item['noticetype'];
if($item['noticetype'] == 1){ $list[$k]['content'] = $type;
$advance_time =$v['advance_time'] - ($item['number'] * 60); $list[$k]['action_id'] = $item['event_id'];
}elseif ($item['noticetype'] == 2){ }
$advance_time =$v['advance_time'] - ($item['number'] * 60 * 60); } elseif($v['type'] == 10 && $v['advance_time'] > time()) {
}else{ unset($list[$k]);
$advance_time = $v['advance_time'] - ($item['number'] * 60 * 60 * 24);
}
$time = time();
if ($time == $advance_time ||$time>$advance_time) {
$type['value']=$item['number'];
$type['type']=$item['noticetype'];
$list[$k]['content']= $type;
$list[$k]['action_id'] = $item['event_id'];
}
}
// p(222);
} }
$time=time();
if (in_array($v['type'], ['17', '18', '19', '20', '27'])) { if (in_array($v['type'], ['17', '18', '19', '20', '27'])) {
$error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find(); $error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find();
if($error_file_path['error_data_file_path']==''){ $week = strtotime("+7 day", $error_file_path['create_time']);
$list[$k]['title'] = ''; if ($time > (int)$week && $error_file_path['error_data_file_path'] != '') {
$list[$k]['valid'] = 0;
} else {
$list[$k]['valid'] = 1;
} }
$list[$k]['error_file_path'] = $error_file_path['error_data_file_path']; $list[$k]['error_file_path'] = $error_file_path['error_data_file_path'];
} }
@ -265,7 +255,7 @@ class MessageLogic
$where['type'] = 9; $where['type'] = 9;
$announceCount = db('admin_message')->where($where)->count(); $announceCount = db('admin_message')->where($where)->count();
$where['type'] = $this->label(5); $where['type'] = $this->label(5);
$eventCount = db('admin_message')->where($where)->where('advance_time', '>=', time())->count(); $eventCount = db('admin_message')->where($where)->where(['advance_time'=>['<', time()],'advance_time'=>['<>',0]])->count();
$where['type'] = $this->label(6); $where['type'] = $this->label(6);
$crmCount = db('admin_message')->where($where)->count(); $crmCount = db('admin_message')->where($where)->count();

@ -109,6 +109,13 @@ class WorkLogic
if (!Db::name('admin_group')->where('id', $id)->delete()) return ['status' => false, 'error' => '操作失败!']; if (!Db::name('admin_group')->where('id', $id)->delete()) return ['status' => false, 'error' => '操作失败!'];
# 将项目权限变更为只读权限
$readOnlyId = db('admin_group')->where(['title' => '只读', 'types' => 7, 'system' => 1])->value('id');
if (!empty($readOnlyId)) {
db('work')->where('group_id', $id)->update(['group_id' => $readOnlyId]); # 处理公开项目的权限
db('work_user')->where('group_id', $id)->update(['group_id' => $readOnlyId]); # 处理私有项目的权限
}
return ['status' => true]; return ['status' => true];
} }
} }

@ -295,6 +295,7 @@ class Common extends Model
*/ */
public function exportHandle($list, $field_list, $type = '') public function exportHandle($list, $field_list, $type = '')
{ {
foreach ($list as &$val) { foreach ($list as &$val) {
foreach ($field_list as $field) { foreach ($field_list as $field) {
switch ($field['form_type']) { switch ($field['form_type']) {
@ -310,7 +311,7 @@ class Common extends Model
$val[$field['field']] = implode(',', array_column($temp, 'name')); $val[$field['field']] = implode(',', array_column($temp, 'name'));
break; break;
case 'datetime': case 'datetime':
$val[$field['field']] = strtotime($val[$field['field']]) ? $val[$field['field']] : date('Y-m-d H:i:s', $val[$field['field']]); $val[$field['field']] = strtotime($val[$field['field']]) ? $val[$field['field']] : '';
break; break;
case 'customer': case 'customer':
case 'business': case 'business':

@ -324,7 +324,7 @@ class ExamineStep extends Common
$is_recheck = 1; $is_recheck = 1;
} }
} }
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3'])) { if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4'])) {
$is_check = 1; $is_check = 1;
} }
@ -339,6 +339,7 @@ class ExamineStep extends Common
$createUserInfo['check_type'] = 3; $createUserInfo['check_type'] = 3;
$newlist[0]['type'] = '3'; //创建 $newlist[0]['type'] = '3'; //创建
$newlist[0]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
} }
$newlist[0]['user_id_info'] = array($createUserInfo); $newlist[0]['user_id_info'] = array($createUserInfo);
$newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;

@ -13,7 +13,6 @@ use app\work\model\Task;
use com\PseudoQueue as Queue; use com\PseudoQueue as Queue;
use think\Cache; use think\Cache;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use think\cache\driver\Redis;
class Excel extends Common class Excel extends Common
{ {
@ -407,7 +406,7 @@ class Excel extends Common
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 单次响应条数 (必须是单次查询条数的整数倍) // 单次响应条数 (必须是单次查询条数的整数倍)
$response_size = $config['response_size'] ?: 1000; $response_size = $config['response_size'] ?: 10000;
// 单次查询条数 // 单次查询条数
$page_size = $config['page_size'] ?: 200; $page_size = $config['page_size'] ?: 200;
@ -423,6 +422,10 @@ class Excel extends Common
$data = $callback($i + ($page - 1) * ($response_size / $page_size), $page_size); $data = $callback($i + ($page - 1) * ($response_size / $page_size), $page_size);
$total = $data['dataCount']; $total = $data['dataCount'];
foreach ($data['list'] as $val) { foreach ($data['list'] as $val) {
$val['create_time']=strtotime($val['create_time']);
$val['update_time']=strtotime($val['update_time']);
$val['last_time']=strtotime($val['last_time']);
$val['next_time']=strtotime($val['next_time']);
$rows = []; $rows = [];
foreach ($field_list as $rule) { foreach ($field_list as $rule) {
if ($rule['form_type'] == 'customer_address') { if ($rule['form_type'] == 'customer_address') {
@ -689,12 +692,7 @@ class Excel extends Common
} }
} }
} }
if ($temp !== count($field_list)) {
$this->error = '请使用最新导入模板';
@unlink($save_path);
$queue->dequeue();
return false;
}
// 每次导入条数 // 每次导入条数
$page_size = 100; $page_size = 100;
@ -713,7 +711,6 @@ class Excel extends Common
// $queue->dequeue(); // $queue->dequeue();
// return false; // return false;
} }
// 开始行 +3 跳过表头 // 开始行 +3 跳过表头
$start_row = ($page - 1) * $page_size + 3; $start_row = ($page - 1) * $page_size + 3;
// 结束行 // 结束行
@ -734,202 +731,251 @@ class Excel extends Common
'create_time' => time(), 'create_time' => time(),
'update_time' => time(), 'update_time' => time(),
]; ];
if ($temp !== count($field_list)) {
// 开始导入数据 // $this->error = '请使用最新导入模板';
foreach ($dataList as $val) { @unlink($save_path);
$data = []; $queue->dequeue();
$unique_where = []; foreach ($dataList as $val) {
$empty_count = 0; $error_data_func($val,'请使用最新导入模板');
$not_null_field = []; }
$fk = 0; // 错误数据文件保存
foreach ($field_list as $field) { $objWriter = \PHPExcel_IOFactory::createWriter($err_PHPExcel, 'Excel5');
if ($field['form_type'] == 'map_address') { $objWriter->save($error_path);
$data['address'] = $address = [ $error = [
trim((string)$val[$fk]), // 文件总计条数
trim((string)$val[$fk + 1]), 'total' => $total,
trim((string)$val[$fk + 2]), // 已完成条数
]; 'done' => 0,
$data['detail_address'] = trim($val[$fk + 3]); // 覆盖
$fk += 4; 'cover' => 0,
continue; // 错误数据写入行号
} else { 'error' => $total,
$temp_value = trim($val[$fk]); 'error_file_path' =>'temp/' . $error_data_file_name
} ];
$queue->cache('last_import_cache', [
'total' => $total,
'done' => 0,
'cover' => 0,
'error' => $total
]);
(new ImportRecord())->createData([
'type' => $types,
'total' => $total,
'done' => 0,
'cover' => 0,
'error' => $total,
'user_id' => $user_id,
'error_data_file_path' =>'temp/' . $error_data_file_name
]);
Cache::rm('item');
Cache::rm('excel_item');
Cache::set('item', 1);
Cache::set('excel_item', serialize($error));
return true;
}else{
// 开始导入数据
foreach ($dataList as $val) {
$data = [];
$unique_where = [];
$empty_count = 0;
$not_null_field = [];
$fk = 0;
foreach ($field_list as $field) {
if ($field['form_type'] == 'map_address') {
$data['address'] = $address = [
trim((string)$val[$fk]),
trim((string)$val[$fk + 1]),
trim((string)$val[$fk + 2]),
];
$data['detail_address'] = trim($val[$fk + 3]);
$fk += 4;
continue;
} else {
$temp_value = trim($val[$fk]);
}
if ($field['field'] == 'category_id' && $types == 'crm_product') { if ($field['field'] == 'category_id' && $types == 'crm_product') {
$data['category_id'] = $productCategoryArr[$temp_value] ? : 0; $data['category_id'] = $productCategoryArr[$temp_value] ? : 0;
$data['category_str'] = $dataModel->getPidStr($productCategoryArr[$temp_value], '', 1); $data['category_str'] = $dataModel->getPidStr($productCategoryArr[$temp_value], '', 1);
} }
// 特殊字段特殊处理 // 特殊字段特殊处理
$temp_value = $this->handleData($temp_value, $field); $temp_value = $this->handleData($temp_value, $field);
$data[$field['field']] = $temp_value; $data[$field['field']] = $temp_value;
// 查重字段 // 查重字段
if ($field['is_unique'] && $temp_value) { if ($field['is_unique'] && $temp_value) {
$unique_where[$field['field']] = $temp_value; $unique_where[$field['field']] = $temp_value;
}
if ($temp_value == '') {
if ($field['is_null']) {
$not_null_field[] = $field['name'];
} }
$empty_count++; if ($temp_value == '') {
if ($field['is_null']) {
$not_null_field[] = $field['name'];
}
$empty_count++;
}
$fk++;
} }
$fk++; if (!empty($not_null_field)) {
} $error_data_func($val, implode(', ', $not_null_field) . '不能为空');
if (!empty($not_null_field)) { continue;
$error_data_func($val, implode(', ', $not_null_field) . '不能为空');
continue;
}
if ($empty_count == count($field_list)) {
$error_data_func($val, '空行');
continue;
}
$old_data_id_list = [];
if ($unique_where) {
if($types == 'crm_product'){
$old_data_id_list = $model->whereOr($unique_where)->column($db_id);
}else{
$old_data_id_list = $dataModel->whereOr($unique_where)->column($db_id);
} }
} if ($empty_count == count($field_list)) {
// 数据重复时 $error_data_func($val, '空行');
if ($old_data_id_list) { continue;
// 是否覆盖 }
if ($config) { $old_data_id_list = [];
$data = array_merge($data, $default_data); if ($unique_where) {
$data['user_id'] = $param['create_user_id']; if($types == 'crm_product'){
$data['update_time'] = time(); $old_data_id_list = $model->whereOr($unique_where)->where('delete_user_id',0)->column($db_id);
$data['update_time'] = time(); }else{
if(isset($data['next_time'])){ $old_data_id_list = $dataModel->whereOr($unique_where)->column($db_id);
$data['next_time']=date('Y-m-d H:i:s', $data['next_time']);
} }
$dataModel->startTrans(); }
try { // 数据重复时
$up_success_count = 0; if ($old_data_id_list) {
foreach ($old_data_id_list as $id) { // 是否覆盖
if($types=='crm_customer'){ if ($config) {
$owner = db('crm_customer')->where(['name' => $data['name']])->find(); $data = array_merge($data, $default_data);
if ($owner['owner_user_id'] == 0) { $data['user_id'] = $param['create_user_id'];
$temp_error = $owner['name'] . '的公海数据,无覆盖权限'; $data['update_time'] = time();
$error_data_func($owner, $temp_error); $data['update_time'] = time();
if(isset($data['next_time'])){
$data['next_time']=$data['next_time']?date('Y-m-d H:i:s', $data['next_time']):'';
}
$dataModel->startTrans();
try {
$up_success_count = 0;
foreach ($old_data_id_list as $id) {
if($types=='crm_customer'){
$owner = db('crm_customer')->where(['name' => $data['name']])->find();
if (!empty($owner) && $owner['owner_user_id'] == 0) {
$temp_error = $owner['name'] .' '. '公海数据,无覆盖权限';
$error_data_func($val, $temp_error);
break;
}
}
if (!$dataModel->updateDataById($data, $id)) {
$temp_error = $dataModel->getError();
if ($temp_error == '无权操作') {
$temp_error = '当前导入人员对该数据无写入权限';
}
$error_data_func($val, $temp_error);
$dataModel->rollback();
break; break;
} }
$up_success_count++;
} }
if($types=='crm_product'){ // 全部更新完成
$data['delete_user_id']=0; if ($up_success_count === count($old_data_id_list)) {
$data['delete_time'] = null; $cover++;
$dataModel->commit();
} }
if (!$dataModel->updateDataById($data, $id)) { } catch (\Exception $e) {
$temp_error = $dataModel->getError(); $dataModel->rollback();
if ($temp_error == '无权操作') { }
$temp_error = '当前导入人员对该数据无写入权限'; } else {
// 重复字段标记
$unique_field = [];
foreach ($old_data_id_list as $id) {
$old_data = $dataModel->getDataById($id);
foreach ($unique_where as $k => $v) {
if (trim($old_data[$k]) == $v) {
$unique_field[] = $field_key_name_list[$k];
} }
$error_data_func($val, $temp_error);
$dataModel->rollback();
break;
} }
$up_success_count++;
} }
// 全部更新完成 $unique_field = array_unique($unique_field);
if ($up_success_count === count($old_data_id_list)) { $error_data_func($val, implode(', ', $unique_field) . ' 根据查重规则,该条数据重复');
$cover++;
$dataModel->commit();
}
} catch (\Exception $e) {
$dataModel->rollback();
} }
} else { } else {
// 重复字段标记 $data = array_merge($data, $default_data);
$unique_field = []; if(isset($data['next_time'])){
foreach ($old_data_id_list as $id) { $data['next_time']=$data['next_time']?date('Y-m-d H:i:s', $data['next_time']):'';
$old_data = $dataModel->getDataById($id); }
foreach ($unique_where as $k => $v) { if (!$resData = $dataModel->createData($data)) {
if (trim($old_data[$k]) == $v) { $error_data_func($val, $dataModel->getError());
$unique_field[] = $field_key_name_list[$k];
}
}
} }
$unique_field = array_unique($unique_field);
$error_data_func($val, implode(', ', $unique_field) . ' 根据查重规则,该条数据重复');
}
} else {
$data = array_merge($data, $default_data);
if(isset($data['next_time'])){
$data['next_time']=date('Y-m-d H:i:s', $data['next_time']);
}
if (!$resData = $dataModel->createData($data)) {
$error_data_func($val, $dataModel->getError());
} }
} }
}
// 完成数(已导入数) // 完成数(已导入数)
$done = ($page - 1) * $page_size + count($dataList); $done = ($page - 1) * $page_size + count($dataList);
if ($page == $max_page) { if ($page == $max_page) {
$done = $total; $done = $total;
} }
// 错误数
$error = $error_row - 3;
// 错误数据文件保存
$objWriter = \PHPExcel_IOFactory::createWriter($err_PHPExcel, 'Excel5');
$objWriter->save($error_path);
$this->error = [
// 数据导入文件临时路径
'temp_file' => $save_name,
// 错误数据文件路径
'error_file' => $error_data_file_name,
// 文件总计条数
'total' => $total,
// 已完成条数
'done' => $done,
// 覆盖
'cover' => $cover,
// 错误数据写入行号
'error' => $error,
// 下次页码
'page' => $page + 1,
// 导入任务ID
'import_queue_index' => $import_queue_index
];
$queue->cache('last_import_cache', [
'total' => $total,
'done' => $done,
'cover' => $cover,
'error' => $error
]);
// 执行完成
if ($done >= $total) {
// 出队 // 错误数
$queue->dequeue(); $error = $error_row - 3;
// 错误数据文件路径
$this->error['error_file_path'] = 'temp/' . $error_data_file_name;
// 删除导入文件
@unlink($save_path);
// 没有错误数据时,删除错误文件 // 错误数据文件保存
if ($error == 0) { $objWriter = \PHPExcel_IOFactory::createWriter($err_PHPExcel, 'Excel5');
@unlink($error_path); $objWriter->save($error_path);
}
(new ImportRecord())->createData([ $this->error = [
'type' => $types, // 数据导入文件临时路径
'temp_file' => $save_name,
// 错误数据文件路径
'error_file' => $error_data_file_name,
// 文件总计条数
'total' => $total, 'total' => $total,
// 已完成条数
'done' => $done, 'done' => $done,
// 覆盖
'cover' => $cover, 'cover' => $cover,
// 错误数据写入行号
'error' => $error, 'error' => $error,
'user_id' => $user_id, // 下次页码
'error_data_file_path' => $error ? 'temp/' . $error_data_file_name : '' 'page' => $page + 1,
// 导入任务ID
'import_queue_index' => $import_queue_index
];
$queue->cache('last_import_cache', [
'total' => $total,
'done' => $done,
'cover' => $cover,
'error' => $error
]); ]);
Cache::set('item', 1); // 执行完成
Cache::set('excel_item', serialize($this->error)); if ($done >= $total) {
} else { // 出队
Cache::set('item', 0); $queue->dequeue();
// 错误数据文件路径
$this->error['error_file_path'] = 'temp/' . $error_data_file_name;
// 删除导入文件
@unlink($save_path);
// 没有错误数据时,删除错误文件
if ($error == 0) {
@unlink($error_path);
}
(new ImportRecord())->createData([
'type' => $types,
'total' => $total,
'done' => $done,
'cover' => $cover,
'error' => $error,
'user_id' => $user_id,
'error_data_file_path' => $error ? 'temp/' . $error_data_file_name : ''
]);
Cache::set('item', 1);
Cache::set('excel_item', serialize($this->error));
}else{
$excelData['cover']=$cover;
$excelData['page']=$page+1;
$excelData['types']=$types;
$excelData['temp_file']=$save_name;
$excelData['error_file']=$error_data_file_name;
$excelData['create_user_id']=$param['create_user_id'];
$excelData['import_queue_index']=$import_queue_index;
$excelData['config']=$config;
$excelData['owner_user_id']=$user_id;
$excelData['base']='batchImportData';
Cache::set('item', 0);
Cache::set('excel', $excelData);
}
return true;
} }
} else { } else {
@ -1385,8 +1431,6 @@ class Excel extends Common
'page' => $page + 1, 'page' => $page + 1,
'import_queue_index' => $import_queue_index 'import_queue_index' => $import_queue_index
]; ];
// $redis = new \Redis();
// $redis->del('item'); $redis->del('excel_item');
// 执行完成 // 执行完成
if ($done >= $total) { if ($done >= $total) {
$queue->dequeue(); $queue->dequeue();
@ -1395,8 +1439,19 @@ class Excel extends Common
Cache::set('item', 1); Cache::set('item', 1);
Cache::set('excel_item', serialize($this->error)); Cache::set('excel_item', serialize($this->error));
} else { } else {
$excelData['page']=$page+1;
$excelData['types']=$types;
$excelData['temp_file']=$save_name;
$excelData['error_file']=$error_data_file_name;
$excelData['create_user_id']=$param['create_user_id'];
$excelData['import_queue_index']=$import_queue_index;
$excelData['config']=$config;
$excelData['owner_user_id']=$user_id;
$excelData['base']='importExcel';
Cache::set('item', 0); Cache::set('item', 0);
Cache::set('excel', $excelData);
} }
return true;
} else { } else {
$this->error = '请选择导入文件'; $this->error = '请选择导入文件';
$queue->dequeue(); $queue->dequeue();
@ -1650,8 +1705,8 @@ class Excel extends Common
} }
// 将标题名称通过fputcsv写到文件句柄 // 将标题名称通过fputcsv写到文件句柄
fputcsv($fp, $title_cell); fputcsv($fp, $title_cell);
$export_data = $callback(0); // $export_data = $callback(0);
foreach ($export_data as $item) { foreach ($callback as $item) {
$rows = []; $rows = [];
foreach ($field_list as $rule) { foreach ($field_list as $rule) {
$rows[] = $item[$rule['field']]; $rows[] = $item[$rule['field']];
@ -1969,8 +2024,6 @@ class Excel extends Common
'cover' => $cover, 'cover' => $cover,
'error' => $error 'error' => $error
]); ]);
// $redis = new \Redis();
// $redis->del('item'); $redis->del('excel_item');
// 执行完成 // 执行完成
if ($done >= $total) { if ($done >= $total) {
// 出队 // 出队
@ -1997,8 +2050,19 @@ class Excel extends Common
Cache::set('item', 1); Cache::set('item', 1);
Cache::set('excel_item', serialize($this->error)); Cache::set('excel_item', serialize($this->error));
} else { } else {
$excelData['cover']=$cover;
$excelData['page']=$page+1;
$excelData['types']=$types;
$excelData['temp_file']=$save_name;
$excelData['error_file']=$error_data_file_name;
$excelData['create_user_id']=$param['create_user_id'];
$excelData['import_queue_index']=$import_queue_index;
$excelData['owner_user_id']=$user_id;
$excelData['base']='batchTaskImportData';
Cache::set('item', 0); Cache::set('item', 0);
Cache::set('excel', $excelData);
} }
return true;
} else { } else {
$this->error = '请选择导入文件'; $this->error = '请选择导入文件';
$queue->dequeue(); $queue->dequeue();
@ -2269,8 +2333,11 @@ class Excel extends Common
*/ */
public function importNum() public function importNum()
{ {
$param = Cache::pull('item'); $param = Cache::get('item');
$excelData=Cache::get('excel');
$base=$excelData['base'];
if ($param == 0) { if ($param == 0) {
$this->$base('',$excelData);
$data = 0; $data = 0;
} elseif ($param == 1) { } elseif ($param == 1) {
$data = ''; $data = '';
@ -2286,7 +2353,7 @@ class Excel extends Common
*/ */
public function importInfo() public function importInfo()
{ {
$param = Cache::pull('excel_item'); ; $param = Cache::get('excel_item');
$param = unserialize($param); $param = unserialize($param);
return $param; return $param;
} }
@ -2301,16 +2368,20 @@ class Excel extends Common
$list = db('admin_import_record')->alias('i') $list = db('admin_import_record')->alias('i')
->join('admin_user user', 'i.user_id=user.id') ->join('admin_user user', 'i.user_id=user.id')
->where(['i.type'=>$param['type'],'i.user_id'=>$param['user_id']])->page($param['page'], $param['limit']) ->where(['i.type'=>$param['type'],'i.user_id'=>$param['user_id']])->page($param['page'], $param['limit'])
->field('i.*,user.realname as user_name')->select(); ->field('i.*,user.realname as user_name')->order('create_time desc')->select();
$dataCount = db('admin_import_record')->where('type', $param['type'])->count(); $dataCount = db('admin_import_record')->where('type', $param['type'])->count();
$week = strtotime(date("Y-m-d H:i:s", strtotime("+7 day"))); $week = strtotime(date("Y-m-d H:i:s", strtotime("+7 day")));
$time = time(); $time = time();
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
if ($time > (int)($week + $v['create_time'])) { $week = strtotime("+7 day",$v['create_time']);
if ($time > (int)$week) {
$list[$k]['valid'] = 0; $list[$k]['valid'] = 0;
} else { } else {
$list[$k]['valid'] = 1; $list[$k]['valid'] = 1;
} }
if($v['error_data_file_path']==''){
$list[$k]['valid'] = -1;
}
$list[$k]['create_time'] = date('Y-m-d', $v['create_time']); $list[$k]['create_time'] = date('Y-m-d', $v['create_time']);
} }
$data = []; $data = [];

@ -182,10 +182,6 @@ class Field extends Model
if ($param['types'] == 'crm_customer') { if ($param['types'] == 'crm_customer') {
$map['field'] = array('not in', ['deal_status']); $map['field'] = array('not in', ['deal_status']);
} }
if ($param['types'] == 'crm_visit') {
$map['types'] = array('in', ['', $types]);
$map['field'] = ['not in', ['create_user_id', 'update_time', 'create_time']];
}
$list = Db::name('AdminField')->where($map)->order('order_id')->select(); $list = Db::name('AdminField')->where($map)->order('order_id')->select();
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : []; $list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : [];
@ -655,7 +651,7 @@ class Field extends Model
} }
} else { } else {
$field_list = $this->where($map)->field('field,types,name,form_type,default_value,is_unique,is_null,input_tips,setting')->order($order)->select(); $field_list = $this->where($map)->where( 'is_hidden',0)->field('field,types,name,form_type,default_value,is_unique,is_null,input_tips,setting,is_hidden')->order($order)->select();
//客户 //客户
if (in_array($param['types'], ['crm_customer'])) { if (in_array($param['types'], ['crm_customer'])) {
@ -754,7 +750,16 @@ class Field extends Model
]; ];
} elseif ($v['form_type'] == 'user') { } elseif ($v['form_type'] == 'user') {
$value = $userModel->getListByStr($dataInfo[$v['field']]) ?: []; $value = $userModel->getListByStr($dataInfo[$v['field']]) ?: [];
} elseif ($v['form_type'] == 'structure') { if (empty($value)) $default_value = $userModel->getListByStr($param['user_id']) ? : [];
} elseif ($v['form_type'] == 'single_user') {
# 单用户
$userInfo = $userModel->getListByStr($dataInfo[$v['field']]);
$value = !empty($userInfo[0]) ? $userInfo[0] : [];
if (empty($value)) {
$userInfo = $userModel->getListByStr($param['user_id']);
$default_value = !empty($userInfo[0]) ? $userInfo[0] : [];
}
}elseif ($v['form_type'] == 'structure') {
$value = $structureModel->getListByStr($dataInfo[$v['field']]) ?: []; $value = $structureModel->getListByStr($dataInfo[$v['field']]) ?: [];
} elseif ($v['form_type'] == 'file') { } elseif ($v['form_type'] == 'file') {
$fileIds = []; $fileIds = [];
@ -882,7 +887,8 @@ class Field extends Model
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$user_id = $param['user_id']; $user_id = $param['user_id'];
$map['types'] = ['in', ['', $types]]; $map['types'] = ['in', ['', $types]];
$map['form_type'] = ['not in', ['file', 'form', 'checkbox', 'structure', 'business_status']]; $map['form_type'] = ['not in', ['file', 'form', 'business_status']];
$map['is_hidden'] = 0;
$field_list = db('admin_field') $field_list = db('admin_field')
->where($map) ->where($map)
->whereOr(['types' => '']) ->whereOr(['types' => ''])
@ -1026,12 +1032,16 @@ class Field extends Model
$userLevel = isSuperAdministrators($user_id); $userLevel = isSuperAdministrators($user_id);
$fieldList = $this->getFieldList($types, $types_id); $fieldList = $this->getFieldList($types, $types_id);
$where = []; $where = [];
if ($userFieldData) { if ($userFieldData) {
$fieldArr = []; $fieldArr = [];
$i = 0; $i = 0;
foreach ($userFieldData as $k => $v) { foreach ($userFieldData as $k => $v) {
if (empty($fieldList[$k])) {
unset($userFieldData[$k]);
continue;
}
if (empty($v['is_hide'])) { if (empty($v['is_hide'])) {
$fieldArr[$i]['field'] = $k; $fieldArr[$i]['field'] = $k;
$fieldArr[$i]['name'] = $fieldList[$k]['name']; $fieldArr[$i]['name'] = $fieldList[$k]['name'];
@ -1081,8 +1091,9 @@ class Field extends Model
'form_type' => ['not in', ['file', 'form']], 'form_type' => ['not in', ['file', 'form']],
'field' => ['not in', $unField], 'field' => ['not in', $unField],
'types_id' => ['eq', $types_id], 'types_id' => ['eq', $types_id],
'is_hidden'=>0
]) ])
->field(['field', 'name', 'form_type']) ->field(['field', 'name', 'form_type,is_hidden'])
->order('order_id asc') ->order('order_id asc')
->select(); ->select();
@ -1192,7 +1203,6 @@ class Field extends Model
} else { } else {
$listArr = $dataList; $listArr = $dataList;
} }
$typesArray = explode('_', $types); $typesArray = explode('_', $types);
$type = array_pop($typesArray); $type = array_pop($typesArray);
if (isset($this->orther_field_list[$types])) { if (isset($this->orther_field_list[$types])) {
@ -1257,6 +1267,11 @@ class Field extends Model
if ($unFormType) $data['form_type'] = array('not in', $unFormType); if ($unFormType) $data['form_type'] = array('not in', $unFormType);
$field_arr = $this->fieldSearch($data); $field_arr = $this->fieldSearch($data);
} }
if ($types == 'crm_visit') {
foreach ($field_arr AS $key => $value) {
if ($value['name'] == '负责人') unset($field_arr[(int)$key]);
}
}
return $field_arr; return $field_arr;
} }
@ -1315,9 +1330,12 @@ class Field extends Model
$where = []; $where = [];
$where[$field] = ['eq', $val]; $where[$field] = ['eq', $val];
if ($id) { if ($id) {
//为编辑时的验重 //为编辑时的验重
$where[$dataModel->getpk()] = ['neq', $id]; $where[$dataModel->getpk()] = ['neq', $id];
}
if($types=='crm_product'){
$where['delete_user_id'] = 0;
} }
if ($res = $dataModel->where($where)->find()) { if ($res = $dataModel->where($where)->find()) {
$this->error = '该数据已存在,请修改后提交!'; $this->error = '该数据已存在,请修改后提交!';
@ -1648,6 +1666,7 @@ class Field extends Model
break; break;
case 'owner_user_id' : case 'owner_user_id' :
$data[$key]['fieldName'] = 'owner_user_name'; $data[$key]['fieldName'] = 'owner_user_name';
$data[$key]['name'] = '回访人';
break; break;
case 'contacts_id' : case 'contacts_id' :
$data[$key]['fieldName'] = 'contacts_name'; $data[$key]['fieldName'] = 'contacts_name';

@ -609,7 +609,7 @@ class Record extends Common
} }
$fileModel = new \app\admin\model\File(); $fileModel = new \app\admin\model\File();
$record_ids = db('crm_activity')->where(['activity_type' => $types,'activity_type_id' => ['in',$types_id]])->column('activity_id'); $record_ids = db('crm_activity')->where(['activity_type' => $types,'activity_type_id' => ['in',$types_id]])->column('activity_id');
db('crm_activity')->where(['activity_type' => $types,'activity_type_id' => ['in',$types_id],'type'=>1])->delete(); db('crm_activity')->where(['activity_type' => $types,'activity_type_id' => ['in',$types_id]])->delete();
//删除关联附件 //删除关联附件
$fileModel->delRFileByModule('crm_activity',$record_ids); $fileModel->delRFileByModule('crm_activity',$record_ids);
return true; return true;

@ -53,10 +53,10 @@ class Scene extends Common
foreach ($value AS $k => $v) { foreach ($value AS $k => $v) {
$sceneData[$k] = [ $sceneData[$k] = [
'condition' => trim($v['condition']), 'condition' => trim($v['condition']),
'value' => $v['value'], 'value' => $v['value'],
'form_type' => $v['form_type'], 'form_type' => $v['form_type'],
'name' => $v['name'], 'name' => $v['name'],
'type' => $v['type'] 'type' => $v['type']
]; ];
} }
} }
@ -200,7 +200,13 @@ class Scene extends Common
$sceneData = []; $sceneData = [];
foreach ($param['data'] AS $key => $value) { foreach ($param['data'] AS $key => $value) {
foreach ($value AS $k => $v) { foreach ($value AS $k => $v) {
$sceneData[$k] = $v; $sceneData[$k] = [
'condition' => trim($v['condition']),
'value' => $v['value'],
'form_type' => $v['form_type'],
'name' => $v['name'],
'type' => $v['type']
];
} }
} }
if (!empty($sceneData)) $param['data'] = $sceneData; if (!empty($sceneData)) $param['data'] = $sceneData;
@ -210,7 +216,9 @@ class Scene extends Common
$res = $this->allowField(true)->save($param, ['scene_id' => $id]); $res = $this->allowField(true)->save($param, ['scene_id' => $id]);
if ($param['is_default'] == 1) { if ($param['is_default'] == 1) {
$this->defaultDataById($param,$param['id']); $this->defaultDataById($param,$param['id']);
} } else {
db('admin_scene_default')->where(['user_id' => $user_id, 'types' => $param['types'], 'scene_id' => $id])->delete();
}
if ($res) { if ($res) {
return true; return true;
} else { } else {

@ -47,7 +47,7 @@ class User extends Common
'name' => '手机号(登录名)', 'name' => '手机号(登录名)',
'form_type' => 'mobile', 'form_type' => 'mobile',
'is_null' => 1, 'is_null' => 1,
'is_unique' => 1 // 'is_unique' => 1 //guogaobo 导入此字段会进行验重查询调用修改用户方法
], ],
[ [
'field' => 'password', 'field' => 'password',
@ -256,6 +256,10 @@ class User extends Common
} }
$param = $temp; $param = $temp;
$param['structure_id'] = 0; $param['structure_id'] = 0;
if(db('admin_user')->where('username',$param['username'])->find()){
$this->error = '手机号已存在';
return false;
}
} else { } else {
if (empty($param['group_id']) || !is_array($param['group_id'])) { if (empty($param['group_id']) || !is_array($param['group_id'])) {
$this->error = '请至少勾选一个用户组'; $this->error = '请至少勾选一个用户组';
@ -269,7 +273,6 @@ class User extends Common
return false; return false;
} }
$syncModel = new \app\admin\model\Sync(); $syncModel = new \app\admin\model\Sync();
$this->startTrans(); $this->startTrans();
try { try {
$salt = substr(md5(time()),0,4); $salt = substr(md5(time()),0,4);
@ -350,6 +353,7 @@ class User extends Common
*/ */
public function updateDataById($param, $id) public function updateDataById($param, $id)
{ {
if ($param['user_id']) { if ($param['user_id']) {
//修改个人信息 //修改个人信息
$data['email'] = $param['email']; $data['email'] = $param['email'];
@ -396,6 +400,7 @@ class User extends Common
$this->error = '直属上级不能是自己或下属'; $this->error = '直属上级不能是自己或下属';
return false; return false;
} }
p(2333);
if (db('admin_user')->where(['id' => ['neq',$id],'username' => $param['username']])->find()) { if (db('admin_user')->where(['id' => ['neq',$id],'username' => $param['username']])->find()) {
$this->error = '手机号已存在'; $this->error = '手机号已存在';
return false; return false;
@ -925,8 +930,6 @@ class User extends Common
$authList['jxc'] = (Object)[]; $authList['jxc'] = (Object)[];
$authList['knowledge'] = (Object)[]; $authList['knowledge'] = (Object)[];
$authList['crm']['receivables']['excelexport'] = false;
return $authList; return $authList;
} }

@ -162,6 +162,8 @@ class UserField extends Model
$a = 0; $a = 0;
$b = 0; $b = 0;
foreach ($value as $k=>$v) { foreach ($value as $k=>$v) {
if (empty($field_list[$k]['name'])) continue;
if (empty($v['is_hide'])) { if (empty($v['is_hide'])) {
$valueList[] = $k; $valueList[] = $k;
$value_list[$a]['field'] = $k; $value_list[$a]['field'] = $k;
@ -193,6 +195,16 @@ class UserField extends Model
$data = []; $data = [];
$data['value_list'] = $value_list ? : []; //展示列 $data['value_list'] = $value_list ? : []; //展示列
$data['hide_list'] = $hide_list ? : []; //隐藏列 $data['hide_list'] = $hide_list ? : []; //隐藏列
if ($types == 'crm_visit') {
foreach ($data['value_list'] AS $key => $value) {
if ($value['name'] == '负责人') $data['value_list'][$key]['name'] = '回访人';
}
foreach ($data['hide_list'] AS $key => $value) {
if ($value['name'] == '负责人') $data['hide_list'][$key]['name'] = '回访人';
}
}
return $data ? : []; return $data ? : [];
} }
} }

@ -28,7 +28,7 @@
官方地址:<a target="_blank" href="http://www.5kcrm.com">www.5kcrm.com</a> / <a target="_blank" href="https://www.72crm.com">www.72crm.com</a><br> 官方地址:<a target="_blank" href="http://www.5kcrm.com">www.5kcrm.com</a> / <a target="_blank" href="https://www.72crm.com">www.72crm.com</a><br>
官方电话400-0812-558<br> 官方电话400-0812-558<br>
官方邮箱service@5kcrm.com<br> 官方邮箱service@5kcrm.com<br>
官方社区:<a target="_blank" href="http://www.72crm.net">bbs.72crm.net</a><br> 官方社区:<a target="_blank" href="https://bbs.72crm.com">bbs.72crm.com</a><br>
官方社群:<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=f4687b809bf63f08f707aa1c56dee8dbcb9526237c429c4532222021d65bf83c">悟空CRM交流10群486745026</a><br> 官方社群:<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=f4687b809bf63f08f707aa1c56dee8dbcb9526237c429c4532222021d65bf83c">悟空CRM交流10群486745026</a><br>
<br> <br>
<p>一、协议中提到的名词约定</p> <p>一、协议中提到的名词约定</p>

@ -16,17 +16,23 @@
<div class="top"> <div class="top">
<div class="step-group"> <div class="step-group">
<div class="step active"> <div class="step active">
<div class="sort">1</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">检查安装环境</div> <div class="desc">检查安装环境</div>
</div> </div>
<div class="step line"></div> <div class="step line"></div>
<div class="step"> <div class="step">
<div class="sort">2</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success_gray.png" alt="">
</div>
<div class="desc">创建数据库</div> <div class="desc">创建数据库</div>
</div> </div>
<div class="step line"></div> <div class="step line"></div>
<div class="step"> <div class="step">
<div class="sort">3</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success_gray.png" alt="">
</div>
<div class="desc">安装成功</div> <div class="desc">安装成功</div>
</div> </div>
</div> </div>
@ -34,7 +40,7 @@
<div class="container"> <div class="container">
<div class="content"> <div class="content">
<div class="base-top"> <div class="base-top">
<span class="title">1 检查安装环境</span> <span class="title">检查安装环境</span>
<span class="version">当前版本:{$data['version']['VERSION']} {$data['version']['RELEASE']}</span> <span class="version">当前版本:{$data['version']['VERSION']} {$data['version']['RELEASE']}</span>
</div> </div>
<div class="table"> <div class="table">

@ -7,84 +7,111 @@
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico"> <link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
<link rel="stylesheet" href="__STATIC__/style/base.css"> <link rel="stylesheet" href="__STATIC__/style/base.css">
<link rel="stylesheet" href="__STATIC__/style/step2.css"> <link rel="stylesheet" href="__STATIC__/style/step2.css">
<link rel="stylesheet" href="__STATIC__/style/loading.css">
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script> <script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
</head> </head>
<body>
<body style="width: 100%; height: 100%;position: relative;">
<div id="cover">
<div id="loader-container">
<p id="loadingText">creating...</p>
</div>
</div>
<div class="header-wrapper"> <div class="header-wrapper">
{include file="public/header"} {include file="public/header"}
</div> </div>
<div class="top"> <div class="top">
<div class="step-group"> <div class="step-group">
<div class="step active"> <div class="step active">
<div class="sort">1</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">检查安装环境</div> <div class="desc">检查安装环境</div>
</div> </div>
<div class="step active line"></div> <div class="step active line"></div>
<div class="step active"> <div class="step active">
<div class="sort">2</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">创建数据库</div> <div class="desc">创建数据库</div>
</div> </div>
<div class="step line"></div> <div class="step line"></div>
<div class="step"> <div class="step">
<div class="sort">3</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success_gray.png" alt="">
</div>
<div class="desc">安装成功</div> <div class="desc">安装成功</div>
</div> </div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<div class="content"> <div class="content">
<div class="base-top"> <div class="base-top">
<span class="title">2 创建数据库</span> <span class="title">创建数据库</span>
<span class="version">当前版本:{$envir_data['version']['VERSION']} {$envir_data['version']['RELEASE']}</span> <span class="version">当前版本:{$envir_data['version']['VERSION']} {$envir_data['version']['RELEASE']}</span>
</div> </div>
<div class="form"> <div class="form">
<div class="form-sec-title">请填写数据库信息</div> <div class="form-sec-title">请填写数据库信息</div>
<div class="form-item"> <div class="form-item">
<div class="form-label">数据库主机:</div> <div class="form-label">数据库主机:</div>
<input type="text" name="databaseUrl"> <input type="text" class="wkform" name="databaseUrl" placeholder="127.0.0.1">
<!--<div class="error" style="display: none">数据库主机不能空</div>--> <!--<div class="error" style="display: none">数据库主机不能空</div>-->
<div class="remind">数据库地址一般为127.0.0.1</div> <!-- <div class="remind">数据库地址一般为127.0.0.1</div> -->
</div> </div>
<div class="form-item"> <div class="form-item">
<div class="form-label">数据库名:</div> <div class="form-label">数据库名:</div>
<input type="text" name="databaseName"> <input type="text" class="wkform" name="databaseName">
</div> </div>
<div class="form-item"> <div class="form-item">
<div class="form-label">端口:</div> <div class="form-label">端口:</div>
<input type="text" name="databasePort"> <input type="text" class="wkform" name="databasePort" placeholder="一般为3306">
<div class="remind">一般为 3306</div> <!-- <div class="remind">一般为 3306</div> -->
</div> </div>
<div class="form-item"> <div class="form-item">
<div class="form-label">数据库用户名:</div> <div class="form-label">数据库用户名:</div>
<input type="text" name="databaseUser"> <input type="text" class="wkform" name="databaseUser" placeholder="生产环境建议创建独立账号">
<div class="remind">生产环境建议创建独立账号</div> <!-- <div class="remind">生产环境建议创建独立账号</div> -->
</div> </div>
<div class="form-item"> <div class="form-item">
<div class="form-label">数据库密码:</div> <div class="form-label">数据库密码:</div>
<input type="password" name="databasePwd"> <input type="password" class="wkform" name="databasePwd">
</div> </div>
<div class="form-item"> <div class="form-item">
<div class="form-label">表前缀:</div> <div class="form-label">表前缀:</div>
<input type="text" name="databaseTable"> <input type="text" class="wkform" name="databaseTable" placeholder="默认我5kcrm-">
<div class="remind">默认为5kcrm_</div> <!-- <div class="remind">默认为5kcrm_</div> -->
</div> </div>
<div class="form-sec-title">请填写管理员信息</div> <div class="form-item">
<div class="form-item"> <div class="form-label">安装序列号:</div>
<div class="form-label">管理员账号:</div> <textarea name="wkcode" class="wkform" rows="6" placeholder="请输入您的序列号"></textarea>
<input type="text" name="root" placeholder="请输入手机号码"> <div class="remind">
<span class="title">您需要通过手机号来<a class="base-a" target="_blank" href="https://www.72crm.com/login">注册悟空ID</a>,该手机号将作为您登录系统的管理员账号。您需要进入【悟空个人中心】,点击【开源版下载】<a class="base-a" target="_blank" href="https://www.72crm.com/login">获取您的序列号</a>如您已经注册悟空ID您只需要点击<a class="base-a" target="_blank" href="https://www.72crm.com/login">登录个人中心</a>即可查看您的序列号</span>
</div> </div>
<div class="form-item"> </div>
<div class="form-sec-title">请填写管理员信息</div>
<p style="color:#d5d5d5;font-size: 12px;">
请填写以下管理员信息,是指完成且系统安装成功后,您可以使用管理员信息登录系统.
</p>
<div class="form-item">
<div class="form-label">管理员账号:</div>
<input type="text" class="wkform" name="root" placeholder="请输入您的手机号码">
</div>
<div class="form-item">
<div class="form-label">管理员密码:</div> <div class="form-label">管理员密码:</div>
<input type="password" name="pwd"> <input type="password" class="wkform" name="pwd" placeholder="6~20位字母加数字组合">
</div> </div>
</div>
<div class="base-des">
</div> </div>
<div class="install_progress_a"> <div class="install_progress_a">
<!-- <progress class="install_progress" max="97" value="8"></progress> --> <!-- <progress class="install_progress" max="97" value="8"></progress> -->
</div> </div>
<div class="control"> <div class="control">
<div class="prev btn">上一步</div> <div class="prev btn">上一步</div>
<div class="next btn primary">下一步</div> <div class="next btn primary">安装</div>
</div> </div>
</div> </div>
</div> </div>

@ -16,17 +16,23 @@
<div class="top"> <div class="top">
<div class="step-group"> <div class="step-group">
<div class="step active"> <div class="step active">
<div class="sort">1</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">检查安装环境</div> <div class="desc">检查安装环境</div>
</div> </div>
<div class="step active line"></div> <div class="step active line"></div>
<div class="step active"> <div class="step active">
<div class="sort">2</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">创建数据库</div> <div class="desc">创建数据库</div>
</div> </div>
<div class="step line active"></div> <div class="step line active"></div>
<div class="step"> <div class="step">
<div class="sort">3</div> <div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success_gray.png" alt="">
</div>
<div class="desc">安装成功</div> <div class="desc">安装成功</div>
</div> </div>
</div> </div>

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title>悟空CRM安装向导</title>
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
<link rel="stylesheet" href="__STATIC__/style/base.css">
<link rel="stylesheet" href="__STATIC__/style/step3.css">
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
</head>
<body>
<div class="header-wrapper">
{include file="public/header"}
</div>
<div class="top">
<div class="step-group">
<div class="step active">
<div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">检查安装环境</div>
</div>
<div class="step active line"></div>
<div class="step active">
<div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">创建数据库</div>
</div>
<div class="step line active"></div>
<div class="step">
<div class="sort">
<img class="pic" style="width:100%; height: 100%;" src="__STATIC__/icon/success.png" alt="">
</div>
<div class="desc">安装成功</div>
</div>
</div>
</div>
<div class="container">
<div class="result">
<div class="status-box" style="display:flex; align-items:center;justify-content:center">
<img class="pic" style="width: 50px; height: 50px;" src="__STATIC__/icon/success.png" alt="">
</div>
<h1 style="text-align:center">恭喜您,已成功安装悟空CRM</h1>
<div class="desc" style="color:#acacac; font-weight: 600; margin-top: 50px; line-height:30px">
<p>您已经成功安装开源PHP悟空CRM,您可以尽情享用悟空CRM开源版算有功能及服务.</p>
<p>使用管理员账号即可登录</p>
</div>
<div class="control">
<div class="btn primary login">立即登录</div>
</div>
</div>
</div>
<div class="footer-wrapper">
{include file="public/footer"}
</div>
</body>
<script>
$('.login').click(function () {
window.location = '../../../index.html'
})
</script>
</html>

@ -1,6 +1,6 @@
<footer class="footer"> <footer class="footer">
<div class="content"> <div class="content">
悟空CRM受国家计算机软件著作权保护未经授权不得进行商业行为违者必究。<br> 悟空CRM受国家计算机软件著作权保护未经授权不得进行商业行为违者必究。<br>
&copy;2021 悟空软件<a target="_blank" href="http://www.5kcrm.com">www.5kcrm.com</a> &copy;2021 悟空软件 <a target="_blank" style="color: #fff;" href="http://www.5kcrm.com">www.5kcrm.com</a>
</div> </div>
</footer> </footer>

@ -122,10 +122,11 @@ class Examine extends ApiCommon
unset($where['create_time']); unset($where['create_time']);
unset($where['create_user_id']); unset($where['create_user_id']);
unset($where['create_user_id']); unset($where['create_user_id']);
$where['check_status'] = 'all'; // $where['check_status'] = 'all';
$where['page'] = $param['page']; $where['page'] = $param['page'];
$where['limit'] = $param['limit']; $where['limit'] = $param['limit'];
$where['user_id'] = $user_id; $where['user_id'] = $user_id;
$where['bi_types'] = 'bi';
$where['between_time'] = array($start_time,$end_time); $where['between_time'] = array($start_time,$end_time);
$list = $examineModel->getDataList($where); $list = $examineModel->getDataList($where);

@ -165,10 +165,29 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
if (!empty($v['start'])) $v['start'] = date('Y-m-d', $v['start']); if (!empty($v['start'])) $v['start'] = date('Y-m-d', $v['start']);
if (!empty($v['end'])) $v['end'] = date('Y-m-d', $v['end']); if (!empty($v['end'])) $v['end'] = date('Y-m-d', $v['end']);
} }
if ($v['form_type'] == 'user') { # 创建人、负责人、回访人(非自定义字段)
if ($v['form_type'] == 'user' && in_array($k, ['create_user_id', 'owner_user_id'])) {
if ($v['condition'] == 'is') $v['condition'] = 'contains'; if ($v['condition'] == 'is') $v['condition'] = 'contains';
} }
if ($types == 'contract') { # 自定义字段的user、structure类型
if (($v['form_type'] == 'user' && !in_array($k, ['create_user_id', 'owner_user_id'])) || $v['form_type'] == 'structure') {
if ($v['condition'] == 'is') $v['condition'] = 'contains';
if ($v['condition'] == 'isNot') {
return "(".$c.$k." not like '%".$v['value'][0]."%' OR ".$c.$k." is null)";
}
}
# 处理多选字段的精确搜索
if ($v['form_type'] == 'checkbox' && !empty($v['value'])) {
if ($v['condition'] == 'is' && count($v['value']) == 1) $v['value'][0] = ',' . $v['value'][0] . ',';
if ($v['condition'] == 'is' && count($v['value']) > 1) {
$checkboxLike = '';
foreach ($v['value'] AS $kk => $vv) {
$checkboxLike .= $c.$k." like "."'%".$vv."%' AND ";
}
return "(".$checkboxLike."LENGTH(".$c.$k.") = LENGTH('".arrayToString($v['value'])."'))";
}
}
if ($types == 'contract' && !empty($v['value'])) {
switch ($k) { switch ($k) {
case 'business_id' : case 'business_id' :
$k = 'name'; $k = 'name';
@ -186,11 +205,11 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
break; break;
} }
} }
if ($types == 'receivables' && $v['name'] == '合同编号') { if ($types == 'receivables' && $v['name'] == '合同编号' && !empty($v['value'])) {
$k = 'num'; $k = 'num';
$c = 'contract.'; $c = 'contract.';
} }
if ($types == 'receivables' && $k == 'plan_id') { if ($types == 'receivables' && $k == 'plan_id' && !empty($v['value'])) {
$planIds = []; $planIds = [];
foreach ($v['value'] AS $kk => $vv) { foreach ($v['value'] AS $kk => $vv) {
$planIdArray = db('crm_receivables_plan')->whereLike('num', '%' . $vv . '%')->column('plan_id'); $planIdArray = db('crm_receivables_plan')->whereLike('num', '%' . $vv . '%')->column('plan_id');
@ -200,17 +219,21 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
} }
$v['value'] = array_unique($planIds); $v['value'] = array_unique($planIds);
} }
if ($types == 'invoice' && $v['type'] == 'invoice_status') { if ($types == 'invoice' && $v['type'] == 'invoice_status' && !empty($v['value'])) {
foreach ($v['value'] AS $kk => $vv) { foreach ($v['value'] AS $kk => $vv) {
if ($vv == '已开票') $v['value'][$kk] = 1; if ($vv == '已开票') $v['value'][$kk] = 1;
if ($vv == '未开票') $v['value'][$kk] = 0; if ($vv == '未开票') $v['value'][$kk] = 0;
} }
} }
if ($types == 'visit' && $v['type'] == 'contract_name') { if ($types == 'visit' && $v['type'] == 'contract_name' && !empty($v['value'])) {
$k = 'num'; $k = 'num';
$c = 'contract.'; $c = 'contract.';
} }
if ($k == 'check_status' && is_array($v) && in_array($v['value'][0], $checkStatusList)) { if ($types == 'visit' && $v['type'] == 'contacts_name' && !empty($v['value'])) {
$k = 'name';
$c = 'contacts.';
}
if ($k == 'check_status' && is_array($v) && in_array($v['value'][0], $checkStatusList) && !empty($v['value'])) {
$v['value'] = $checkStatusArray[$v['value'][0]] ?: '0'; $v['value'] = $checkStatusArray[$v['value'][0]] ?: '0';
} }
if (is_array($v)) { if (is_array($v)) {

@ -276,11 +276,6 @@ class Business extends ApiCommon
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:无权限;'; $errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:无权限;';
continue; continue;
} }
$resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
if (!$resBusiness) {
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
}
//团队成员 //团队成员
teamUserId( teamUserId(
@ -292,6 +287,24 @@ class Business extends ApiCommon
0 0
); );
$resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
if (!$resBusiness) {
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
} else {
$businessArray = [];
$teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $business_id)->find();
if (!empty($teamBusiness['ro_user_id'])) {
$businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
$businessArray['ro_user_id'] = $businessRo;
}
if (!empty($teamBusiness['rw_user_id'])) {
$businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
$businessArray['rw_user_id'] = $businessRo;
}
db('crm_business')->where('business_id', $business_id)->update($businessArray);
}
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_business', $business_id, '', '', '将商机转移给:'.$ownerUserName); updateActionLog($userInfo['id'], 'crm_business', $business_id, '', '', '将商机转移给:'.$ownerUserName);
} }

@ -214,12 +214,6 @@ class Contract extends ApiCommon
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) { if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']); return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
} }
if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿
$param['check_status'] = 5; //草稿(未提交)
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
} else {
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) { if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
//将合同审批状态至为待审核,提交后重新进行审批 //将合同审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流) //审核判断(是否有符合条件的审批流)
@ -244,7 +238,7 @@ class Contract extends ApiCommon
} else { } else {
$check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
} }
if ($param['is_draft']) { if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿 //保存为草稿
$param['check_status'] = 5; $param['check_status'] = 5;
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
@ -257,7 +251,7 @@ class Contract extends ApiCommon
} }
$param['flow_user_id'] = ''; $param['flow_user_id'] = '';
} }
}
if ($contractModel->updateDataById($param, $param['id'])) { if ($contractModel->updateDataById($param, $param['id'])) {
//将审批记录至为无效 //将审批记录至为无效
@ -314,7 +308,7 @@ class Contract extends ApiCommon
$isDel = false; $isDel = false;
$errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前合同已作废,非超级管理员,不可删除'; $errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前合同已作废,非超级管理员,不可删除';
} }
if (!in_array($data['check_status'],['0','4','5','6']) && !in_array(1,$adminTypes)) { if (!in_array($data['check_status'], [4, 5]) && !in_array(1,$adminTypes)) {
$isDel = false; $isDel = false;
$errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前状态为审批中或已审批通过,不可删除'; $errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前状态为审批中或已审批通过,不可删除';
} }
@ -335,9 +329,9 @@ class Contract extends ApiCommon
return resultArray(['error' => $contractModel->getError()]); return resultArray(['error' => $contractModel->getError()]);
} }
//删除跟进记录 //删除跟进记录
$recordModel->delDataByTypes('crm_contract',$delIds); $recordModel->delDataByTypes(6,$delIds);
//删除关联附件 //删除关联附件
$fileModel->delRFileByModule(6,$delIds); $fileModel->delRFileByModule('crm_contract',$delIds);
//删除关联操作记录 //删除关联操作记录
$actionRecordModel->delDataById(['types'=>'crm_contract','action_id'=>$delIds]); $actionRecordModel->delDataById(['types'=>'crm_contract','action_id'=>$delIds]);
// 删除回款记录 // 删除回款记录
@ -395,15 +389,10 @@ class Contract extends ApiCommon
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:无权限;'; $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:无权限;';
continue; continue;
} }
if (in_array($contractInfo['check_status'],['0','1'])) { // if (in_array($contractInfo['check_status'],['0','1'])) {
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;'; // $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;';
continue; // continue;
} // }
$resContract = db('crm_contract')->where(['contract_id' => $contract_id])->update($data);
if (!$resContract) {
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
}
//团队成员 //团队成员
teamUserId( teamUserId(
@ -411,9 +400,29 @@ class Contract extends ApiCommon
$contract_id, $contract_id,
$type, $type,
[$contractInfo['owner_user_id']], [$contractInfo['owner_user_id']],
$is_remove, ($is_remove == 1) ? 1 : '',
0 0
); );
$resContract = db('crm_contract')->where(['contract_id' => $contract_id])->update($data);
if (!$resContract) {
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
} else {
# 处理负责人重复显示在团队成员中的bug
$contractArray = [];
$teamContract = db('crm_contract')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('contract_id', $contract_id)->find();
if (!empty($teamContract['ro_user_id'])) {
$contractRo = arrayToString(array_diff(stringToArray($teamContract['ro_user_id']), [$teamContract['owner_user_id']]));
$contractArray['ro_user_id'] = $contractRo;
}
if (!empty($teamContract['rw_user_id'])) {
$contractRo = arrayToString(array_diff(stringToArray($teamContract['rw_user_id']), [$teamContract['owner_user_id']]));
$contractArray['rw_user_id'] = $contractRo;
}
db('crm_contract')->where('contract_id', $contract_id)->update($contractArray);
}
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_contract', $contract_id, '', '', '将合同转移给:'.$ownerUserName); updateActionLog($userInfo['id'], 'crm_contract', $contract_id, '', '', '将合同转移给:'.$ownerUserName);
} }

@ -316,6 +316,19 @@ class Customer extends ApiCommon
if (!$resCustomer) { if (!$resCustomer) {
$errorMessage[] = $customerInfo['name'].'转移失败,错误原因:数据出错;'; $errorMessage[] = $customerInfo['name'].'转移失败,错误原因:数据出错;';
continue; continue;
} else {
# 处理转移时,负责人出现在只读和读写成员列表中
$customerArray = [];
$teamCustomer = db('crm_customer')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('customer_id', $customer_id)->find();
if (!empty($teamCustomer['ro_user_id'])) {
$customerRo = arrayToString(array_diff(stringToArray($teamCustomer['ro_user_id']), [$teamCustomer['owner_user_id']]));
$customerArray['ro_user_id'] = $customerRo;
}
if (!empty($teamCustomer['rw_user_id'])) {
$customerRo = arrayToString(array_diff(stringToArray($teamCustomer['rw_user_id']), [$teamCustomer['owner_user_id']]));
$customerArray['rw_user_id'] = $customerRo;
}
db('crm_customer')->where('customer_id', $customer_id)->update($customerArray);
} }
if (in_array('crm_contacts',$types)) { if (in_array('crm_contacts',$types)) {
@ -677,7 +690,7 @@ class Customer extends ApiCommon
$file = request()->file('file'); $file = request()->file('file');
// $res = $excelModel->importExcel($file, $param, $this); // $res = $excelModel->importExcel($file, $param, $this);
$res = $excelModel->batchImportData($file, $param, $this); $res = $excelModel->batchImportData($file, $param, $this);
return resultArray(['data' => '导入成功']); return resultArray(['data' => $excelModel->getError()]);
} }
/** /**

@ -315,6 +315,8 @@ class Invoice extends ApiCommon
*/ */
public function delete(InvoiceLogic $invoiceLogic) public function delete(InvoiceLogic $invoiceLogic)
{ {
$actionRecordModel = new \app\admin\model\ActionRecord();
$fileModel = new \app\admin\model\File();
$idArray = $this->param['id']; $idArray = $this->param['id'];
$userinfo = $this->userInfo['id']; $userinfo = $this->userInfo['id'];
@ -326,7 +328,7 @@ class Invoice extends ApiCommon
if (!isSuperAdministrators($userinfo['id'])) { if (!isSuperAdministrators($userinfo['id'])) {
$list = $invoiceLogic->getExamineStatus($idString, true); $list = $invoiceLogic->getExamineStatus($idString, true);
foreach ($list AS $key => $value) { foreach ($list AS $key => $value) {
if (!in_array($value['check_status'], ['3', '4', '5', '6'])) { if (!in_array($value['check_status'], [4, 5])) {
$status = false; $status = false;
break; break;
} }
@ -338,8 +340,9 @@ class Invoice extends ApiCommon
if (!$invoiceLogic->delete($idArray)) return resultArray(['error' => '删除失败!']); if (!$invoiceLogic->delete($idArray)) return resultArray(['error' => '删除失败!']);
# 删除附件 # 删除附件
$fileModel = new \app\admin\model\File();
$fileModel->delRFileByModule('crm_invoice', $idArray); $fileModel->delRFileByModule('crm_invoice', $idArray);
//删除关联操作记录
$actionRecordModel->delDataById(['types'=>'crm_invoice','action_id'=>$idArray]);
return resultArray(['data' => '删除成功!']); return resultArray(['data' => '删除成功!']);
} }

@ -226,7 +226,8 @@ class Leads extends ApiCommon
$data['deal_time'] = time(); $data['deal_time'] = time();
$data['create_time'] = time(); $data['create_time'] = time();
$data['update_time'] = time(); $data['update_time'] = time();
$data['next_time'] = $leadsInfo['next_time'] ? date('Y-m-d H:i:s', $leadsInfo['next_time']) : 0; $data['next_time'] = $leadsInfo['next_time'];
if (empty($data['telephone'])) $data['telephone'] = 0;
# 获取客户的时间 # 获取客户的时间
$data['obtain_time'] = time(); $data['obtain_time'] = time();
//权限判断 //权限判断
@ -404,6 +405,9 @@ class Leads extends ApiCommon
$file = request()->file('file'); $file = request()->file('file');
// $res = $excelModel->importExcel($file, $param); // $res = $excelModel->importExcel($file, $param);
$res = $excelModel->batchImportData($file, $param, $this); $res = $excelModel->batchImportData($file, $param, $this);
if (!$res) {
return resultArray(['error' => $excelModel->getError()]);
}
return resultArray(['data' => $excelModel->getError()]); return resultArray(['data' => $excelModel->getError()]);
} }

@ -10,6 +10,7 @@ namespace app\crm\controller;
use app\admin\controller\ApiCommon; use app\admin\controller\ApiCommon;
use app\crm\model\Product as ProductModel; use app\crm\model\Product as ProductModel;
use app\admin\model\File as FileModel; use app\admin\model\File as FileModel;
use app\admin\model\ActionRecord as ActionRecordModel;
use think\Db; use think\Db;
use think\Hook; use think\Hook;
use think\Request; use think\Request;
@ -294,6 +295,8 @@ class Product extends ApiCommon
ProductModel::commit(); ProductModel::commit();
// 删除关联附件 // 删除关联附件
(new FileModel)->delRFileByModule('crm_product', $delIds); (new FileModel)->delRFileByModule('crm_product', $delIds);
// 操作记录
(new ActionRecordModel)->delDataById('crm_product', $delIds);
// 添加删除记录 // 添加删除记录
actionLog($delIds, '', '', ''); actionLog($delIds, '', '', '');
return resultArray(['data' => '删除成功']); return resultArray(['data' => '删除成功']);

@ -25,14 +25,14 @@ class Receivables extends ApiCommon
* @permission 无限制 * @permission 无限制
* @allow 登录用户可访问 * @allow 登录用户可访问
* @other 其他根据系统设置 * @other 其他根据系统设置
**/ **/
public function _initialize() public function _initialize()
{ {
$action = [ $action = [
'permission'=>[''], 'permission' => [''],
'allow'=>['check','revokecheck','system','count'] 'allow' => ['check', 'revokecheck', 'system', 'count']
]; ];
Hook::listen('check_auth',$action); Hook::listen('check_auth', $action);
$request = Request::instance(); $request = Request::instance();
$a = strtolower($request->action()); $a = strtolower($request->action());
if (!in_array($a, $action['permission'])) { if (!in_array($a, $action['permission'])) {
@ -42,8 +42,8 @@ class Receivables extends ApiCommon
/** /**
* 回款列表 * 回款列表
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function index() public function index()
{ {
@ -55,6 +55,43 @@ class Receivables extends ApiCommon
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/**
* 导出
* @param
* @return
* @author guogaobo
*/
public function excelExport()
{
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id'];
if ($param['receivables_id']) {
$param['receivables_id'] = ['condition' => 'in', 'value' => $param['receivables_id'], 'form_type' => 'text', 'name' => ''];
$param['is_excel'] = 1;
}
$excelModel = new \app\admin\model\Excel();
// 导出的字段列表
$fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id']);
// 文件名
$file_name = '5kcrm_receivables_' . date('Ymd');
$model = model('Receivables');
$temp_file = $param['temp_file'];
unset($param['temp_file']);
$page = $param['page'] ?: 1;
unset($param['page']);
unset($param['export_queue_index']);
return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
$param['page'] = $page;
$param['limit'] = $limit;
$data = $model->getDataList($param);
$data['list'] = $model->exportHandle($data['list'], $field_list, 'Receivables');
return $data;
});
}
/** /**
* 添加回款 * 添加回款
* *
@ -80,39 +117,39 @@ class Receivables extends ApiCommon
if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) { if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿 //保存为草稿
$param['check_status'] = 5; //草稿(未提交) $param['check_status'] = 5; //草稿(未提交)
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} else { }
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) { if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
//审核判断(是否有符合条件的审批流) //审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow(); $examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) { if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) {
return resultArray(['error' => '暂无审批人,无法创建']); return resultArray(['error' => '暂无审批人,无法创建']);
} }
//添加审批相关信息 //添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables'); $examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables');
if (!$examineFlowData) { if (!$examineFlowData) {
return resultArray(['error' => '无可用审批流,请联系管理员']); return resultArray(['error' => '无可用审批流,请联系管理员']);
} }
$param['flow_id'] = $examineFlowData['flow_id']; $param['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息 //获取审批人信息
if ($examineFlowData['config'] == 1) { if ($examineFlowData['config'] == 1) {
//固定审批流 //固定审批流
$nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0); $nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : ''; $next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ? : []; $check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1; $param['order_id'] = 1;
} else {
$check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
}
if (!$check_user_id) {
return resultArray(['error' => '无可用审批人,请联系管理员']);
}
$param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
} else { } else {
# 审批流停用,将状态改为审核通过 $check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
$param['check_status'] = 2;
} }
if (!$check_user_id) {
return resultArray(['error' => '无可用审批人,请联系管理员']);
}
$param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else {
# 审批流停用,将状态改为审核通过
$param['check_status'] = 2;
} }
$res = $receivablesModel->createData($param); $res = $receivablesModel->createData($param);
if ($res) { if ($res) {
//回款计划关联 //回款计划关联
@ -130,9 +167,9 @@ class Receivables extends ApiCommon
/** /**
* 回款详情 * 回款详情
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function read() public function read()
{ {
@ -143,7 +180,7 @@ class Receivables extends ApiCommon
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'read'); $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'read');
if (!in_array($data['owner_user_id'],$auth_user_ids)) { if (!in_array($data['owner_user_id'], $auth_user_ids)) {
$authData['dataAuth'] = 0; $authData['dataAuth'] = 0;
return resultArray(['data' => $authData]); return resultArray(['data' => $authData]);
} }
@ -155,9 +192,9 @@ class Receivables extends ApiCommon
/** /**
* 编辑回款 * 编辑回款
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function update() public function update()
{ {
@ -171,9 +208,9 @@ class Receivables extends ApiCommon
//判断权限 //判断权限
$dataInfo = $receivablesModel->getDataById($param['id']); $dataInfo = $receivablesModel->getDataById($param['id']);
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'update');
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) { if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
header('Content-Type:application/json; charset=utf-8'); header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code'=>102,'error'=>'无权操作'])); exit(json_encode(['code' => 102, 'error' => '无权操作']));
} }
# 自动设置回款编号 # 自动设置回款编号
@ -192,13 +229,13 @@ class Receivables extends ApiCommon
if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) { if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿 //保存为草稿
$param['check_status'] = 5; //草稿(未提交) $param['check_status'] = 5; //草稿(未提交)
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} else { } else {
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) { if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
if ($param['is_draft']) { if ($param['is_draft']) {
//保存为草稿 //保存为草稿
$param['check_status'] = 5; $param['check_status'] = 5;
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} else { } else {
//将回款审批状态至为待审核,提交后重新进行审批 //将回款审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流) //审核判断(是否有符合条件的审批流)
@ -217,16 +254,16 @@ class Receivables extends ApiCommon
if ($examineFlowData['config'] == 1) { if ($examineFlowData['config'] == 1) {
//固定审批流 //固定审批流
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0); $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : ''; $next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ? : []; $check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1; $param['order_id'] = 1;
} else { } else {
$check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : ''; $check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} }
if (!$check_user_id) { if (!$check_user_id) {
return resultArray(['error' => '无可用审批人,请联系管理员']); return resultArray(['error' => '无可用审批人,请联系管理员']);
} }
$param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id; $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
$param['check_status'] = 0; $param['check_status'] = 0;
$param['flow_user_id'] = ''; $param['flow_user_id'] = '';
} }
@ -237,7 +274,7 @@ class Receivables extends ApiCommon
if ($res) { if ($res) {
//将审批记录至为无效 //将审批记录至为无效
$examineRecordModel = new \app\admin\model\ExamineRecord(); $examineRecordModel = new \app\admin\model\ExamineRecord();
$examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]); $examineRecordModel->setEnd(['types' => 'crm_receivables', 'types_id' => $param['id']]);
# 更新crm_number_sequence表中的last_date、create_time字段 # 更新crm_number_sequence表中的last_date、create_time字段
if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']); if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
@ -249,12 +286,15 @@ class Receivables extends ApiCommon
/** /**
* 删除回款 * 删除回款
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function delete() public function delete()
{ {
$actionRecordModel = new \app\admin\model\ActionRecord();
$fileModel = new \app\admin\model\File();
$recordModel = new \app\admin\model\Record();
$receivablesModel = model('Receivables'); $receivablesModel = model('Receivables');
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
@ -270,29 +310,29 @@ class Receivables extends ApiCommon
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'delete'); $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'delete');
$adminTypes = adminGroupTypes($userInfo['id']); $adminTypes = adminGroupTypes($userInfo['id']);
foreach ($receivables_id as $k=>$v) { foreach ($receivables_id as $k => $v) {
$isDel = true; $isDel = true;
//数据详情 //数据详情
$data = $receivablesModel->getDataById($v); $data = $receivablesModel->getDataById($v);
if (!$data) { if (!$data) {
$isDel = false; $isDel = false;
$errorMessage[] = 'id为'.$v.'的回款删除失败,错误原因:'.$receivablesModel->getError(); $errorMessage[] = 'id为' . $v . '的回款删除失败,错误原因:' . $receivablesModel->getError();
continue; continue;
} }
if (!in_array($data['owner_user_id'],$auth_user_ids)) { if (!in_array($data['owner_user_id'], $auth_user_ids)) {
$isDel = false; $isDel = false;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:无权操作'; $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:无权操作';
continue; continue;
} }
if (!in_array($data['check_status'],['0','4','5']) && !in_array(1,$adminTypes)) { if (!in_array($data['check_status'], [4, 5]) && !in_array(1, $adminTypes)) {
$isDel = false; $isDel = false;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:请先撤销审核'; $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:请先撤销审核';
continue; continue;
} }
if ($isDel) { if ($isDel) {
if (db('crm_receivables_plan')->where('receivables_id', $v)->value('plan_id')) { if (db('crm_receivables_plan')->where('receivables_id', $v)->value('plan_id')) {
$isDel = false; $isDel = false;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:回款已关联回款计划,不能删除!'; $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:回款已关联回款计划,不能删除!';
continue; continue;
} }
} }
@ -305,8 +345,15 @@ class Receivables extends ApiCommon
if (!$data) { if (!$data) {
return resultArray(['error' => $receivablesModel->getError()]); return resultArray(['error' => $receivablesModel->getError()]);
} }
actionLog($delIds,'','',''); //删除跟进记录
$recordModel->delDataByTypes(7,$delIds);
# 删除附件
$fileModel->delRFileByModule('crm_receivables', $delIds);
//删除关联操作记录
$actionRecordModel->delDataById(['types' => 'crm_receivables', 'action_id' => $delIds]);
actionLog($delIds, '', '', '');
} }
if ($errorMessage) { if ($errorMessage) {
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} else { } else {
@ -316,9 +363,9 @@ class Receivables extends ApiCommon
/** /**
* 回款审核 * 回款审核
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function check() public function check()
{ {
@ -335,7 +382,7 @@ class Receivables extends ApiCommon
$receivablesData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过 $receivablesData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断 //权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_receivables', $param['id'])) { if (!$examineStepModel->checkExamine($user_id, 'crm_receivables', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]); return resultArray(['error' => $examineStepModel->getError()]);
}; };
//审批主体详情 //审批主体详情
$dataInfo = $receivablesModel->getDataById($param['id']); $dataInfo = $receivablesModel->getDataById($param['id']);
@ -350,7 +397,7 @@ class Receivables extends ApiCommon
$checkData['check_time'] = time(); $checkData['check_time'] = time();
$checkData['content'] = $param['content']; $checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id']; $checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ? : 1; $checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status; $checkData['status'] = $status;
if ($status == 1) { if ($status == 1) {
@ -358,8 +405,8 @@ class Receivables extends ApiCommon
//固定流程 //固定流程
//获取下一审批信息 //获取下一审批信息
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_receivables', $param['id'], $dataInfo['order_id'], $user_id); $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_receivables', $param['id'], $dataInfo['order_id'], $user_id);
$next_user_ids = $nextStepData['next_user_ids'] ? : []; $next_user_ids = $nextStepData['next_user_ids'] ?: [];
$receivablesData['order_id'] = $nextStepData['order_id'] ? : ''; $receivablesData['order_id'] = $nextStepData['order_id'] ?: '';
if (!$next_user_ids) { if (!$next_user_ids) {
$is_end = 1; $is_end = 1;
//审批结束 //审批结束
@ -372,7 +419,7 @@ class Receivables extends ApiCommon
} else { } else {
//自选流程 //自选流程
$is_end = $param['is_end'] ? 1 : ''; $is_end = $param['is_end'] ? 1 : '';
$check_user_id = $param['check_user_id'] ? : ''; $check_user_id = $param['check_user_id'] ?: '';
if ($is_end !== 1 && empty($check_user_id)) { if ($is_end !== 1 && empty($check_user_id)) {
return resultArray(['error' => '请选择下一审批人']); return resultArray(['error' => '请选择下一审批人']);
} }
@ -391,7 +438,7 @@ class Receivables extends ApiCommon
// $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]); // $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]);
} }
//已审批人ID //已审批人ID
$receivablesData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]); $receivablesData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$resReceivables = db('crm_receivables')->where(['receivables_id' => $param['id']])->update($receivablesData); $resReceivables = db('crm_receivables')->where(['receivables_id' => $param['id']])->update($receivablesData);
if ($resReceivables) { if ($resReceivables) {
if ($status) { if ($status) {
@ -423,13 +470,13 @@ class Receivables extends ApiCommon
if ($is_end == 1 && !empty($status)) { if ($is_end == 1 && !empty($status)) {
//发送站内信 通过 //发送站内信 通过
(new Message())->send( (new Message())->send(
Message::RECEIVABLES_PASS, Message::RECEIVABLES_PASS,
[ [
'title' => $dataInfo['number'], 'title' => $dataInfo['number'],
'action_id' => $param['id'] 'action_id' => $param['id']
], ],
$dataInfo['owner_user_id'] $dataInfo['owner_user_id']
); );
} }
return resultArray(['data' => '审批成功']); return resultArray(['data' => '审批成功']);
} else { } else {
@ -439,9 +486,9 @@ class Receivables extends ApiCommon
/** /**
* 回款撤销审核 * 回款撤销审核
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function revokeCheck() public function revokeCheck()
{ {
@ -505,12 +552,12 @@ class Receivables extends ApiCommon
*/ */
public function transfer() public function transfer()
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$receivablesModel = model('Receivables'); $receivablesModel = model('Receivables');
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$authIds = $userModel->getUserByPer(); $authIds = $userModel->getUserByPer();
if (empty($param['owner_user_id'])) return resultArray(['error' => '变更负责人不能为空']); if (empty($param['owner_user_id'])) return resultArray(['error' => '变更负责人不能为空']);
if (empty($param['receivables_id']) || !is_array($param['receivables_id'])) return resultArray(['error' => '请选择需要转移的回款']); if (empty($param['receivables_id']) || !is_array($param['receivables_id'])) return resultArray(['error' => '请选择需要转移的回款']);
@ -519,14 +566,14 @@ class Receivables extends ApiCommon
$data = [ $data = [
'owner_user_id' => $param['owner_user_id'], 'owner_user_id' => $param['owner_user_id'],
'update_time' => time(), 'update_time' => time(),
]; ];
$errorMessage = []; $errorMessage = [];
foreach ($param['receivables_id'] as $receivables_id) { foreach ($param['receivables_id'] as $receivables_id) {
$receivables_info = $receivablesModel->getDataById($receivables_id); $receivables_info = $receivablesModel->getDataById($receivables_id);
if (!$receivables_info) { if (!$receivables_info) {
$errorMessage[] = 'id:为《'.$receivables_id.'》的回款转移失败,错误原因:数据不存在;'; $errorMessage[] = 'id:为《' . $receivables_id . '》的回款转移失败,错误原因:数据不存在;';
continue; continue;
} }
@ -534,21 +581,21 @@ class Receivables extends ApiCommon
if ($param['owner_user_id'] == $receivables_info['owner_user_id']) continue; if ($param['owner_user_id'] == $receivables_info['owner_user_id']) continue;
if (!in_array($receivables_info['owner_user_id'], $authIds)) { if (!in_array($receivables_info['owner_user_id'], $authIds)) {
$errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:无权限;'; $errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:无权限;';
continue; continue;
} }
if (in_array($receivables_info['check_status'],['0','1'])) { if (in_array($receivables_info['check_status'], ['0', '1'])) {
$errorMessage[] = $receivables_info['number'].'转移失败,错误原因:待审或审批中,无法转移;'; $errorMessage[] = $receivables_info['number'] . '转移失败,错误原因:待审或审批中,无法转移;';
continue; continue;
} }
$res = $receivablesModel->where(['receivables_id' => $receivables_id])->update($data); $res = $receivablesModel->where(['receivables_id' => $receivables_id])->update($data);
if (!$res) { if (!$res) {
$errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:数据出错;'; $errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:数据出错;';
continue; continue;
} }
updateActionLog($userInfo['id'], 'crm_receivables', $receivables_id, '', '', '将回款转移给:' . $owner_user_info['realname']); updateActionLog($userInfo['id'], 'crm_receivables', $receivables_id, '', '', '将回款转移给:' . $owner_user_info['realname']);
} }
if (!$errorMessage) { if (!$errorMessage) {
return resultArray(['data' => '转移成功']); return resultArray(['data' => '转移成功']);

@ -68,9 +68,8 @@ class Visit extends ApiCommon
if (empty($numberInfo['number'])) return resultArray(['error' => '请填写回访编号!']); if (empty($numberInfo['number'])) return resultArray(['error' => '请填写回访编号!']);
$param['number'] = $numberInfo['number']; $param['number'] = $numberInfo['number'];
} }
$param['owner_user_id'] = $param['visit_user_id'] ? : $userInfo['id']; $param['owner_user_id'] = $param['owner_user_id'] ? : $userInfo['id'];
$param['create_user_id'] = $userInfo['id']; $param['create_user_id'] = $userInfo['id'];
$param['visit_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
$param['update_time'] = time(); $param['update_time'] = time();
$res = $Visit->createData($param); $res = $Visit->createData($param);
if ($res) { if ($res) {
@ -119,8 +118,7 @@ class Visit extends ApiCommon
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$param['owner_user_id'] = $param['visit_user_id'] ? : $userInfo['id']; $param['owner_user_id'] = $param['owner_user_id'] ? : $userInfo['id'];
$param['visit_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
# 设置回访编号 # 设置回访编号
$numberInfo = []; $numberInfo = [];
if (empty($param['number'])) { if (empty($param['number'])) {

@ -359,8 +359,9 @@ class ActivityLogic
$fileModel = new \app\admin\model\File(); $fileModel = new \app\admin\model\File();
foreach ($dataArray AS $key => $value) { foreach ($dataArray AS $key => $value) {
# 用户信息 todo 有模型文件,时间问题,暂时将查询写在循环中 # 用户信息 todo 有模型文件,时间问题,暂时将查询写在循环中
$realname = Db::name('admin_user')->where('id', $dataArray[$key]['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $dataArray[$key]['create_user_id'])->find();
$dataArray[$key]['create_user_name'] = $realname; $dataArray[$key]['create_user_name'] = $realname['realname'];
$dataArray[$key]['thumb_img'] = $realname['thumb_img'] ? getFullPath($realname['thumb_img']) : '';;
# 附件信息 # 附件信息
if ($value['type'] = 1) { if ($value['type'] = 1) {
@ -785,7 +786,7 @@ class ActivityLogic
# 审批 # 审批
if ($activityType == 9) { if ($activityType == 9) {
$categoryId = Db::name('oa_examine')->where('examine_id', $activityTypeId)->value('category_id'); $categoryId = Db::name('oa_examine')->where('examine_id', $activityTypeId)->value('category_id');
$activityTypeName = Db::name('oa_examine_category')->where('category_id', $categoryId); $activityTypeName = Db::name('oa_examine_category')->where('category_id', $categoryId)->value('title');
} }
# 日程 # 日程
if ($activityType == 10) { if ($activityType == 10) {

@ -12,6 +12,7 @@ use app\admin\controller\ApiCommon;
use app\admin\model\User; use app\admin\model\User;
use app\crm\model\Customer; use app\crm\model\Customer;
use think\Db; use think\Db;
use think\Validate;
class CommonLogic class CommonLogic
{ {
@ -39,7 +40,7 @@ class CommonLogic
*/ */
$actionId = $param['action_id']; $actionId = $param['action_id'];
$types = $param['types']; $types = $param['types'];
unset($param['action_id']); unset($param['action_id']);
unset($param['types']); unset($param['types']);
@ -48,26 +49,83 @@ class CommonLogic
# 主键 # 主键
$primaryKey = ''; $primaryKey = '';
if ($types == 'crm_leads') $primaryKey = 'leads_id'; // author guogaobo $item模块
if ($types == 'crm_customer') $primaryKey = 'customer_id'; $info='';
if ($types == 'crm_contacts') $primaryKey = 'contacts_id'; switch ($types) {
if ($types == 'crm_business') $primaryKey = 'business_id'; case 'crm_leads' :
if ($types == 'crm_contract') $primaryKey = 'contract_id'; $primaryKey = 'leads_id';
if ($types == 'crm_receivables') $primaryKey = 'receivables_id'; $dataModel=new \app\crm\model\Leads();
if ($types == 'crm_visit') $primaryKey = 'visit_id'; $info=$dataModel->getDataById($actionId);
if ($types == 'crm_product') $primaryKey = 'product_id'; break;
case 'crm_customer' :
$primaryKey = 'customer_id';
$info=db('crm_customer')->where('customer_id',$actionId)->find();
break;
case 'crm_contacts' :
$primaryKey = 'contacts_id';
$dataModel=new \app\crm\model\Contacts();
$info=$dataModel->getDataById($actionId);
break;
case 'crm_business' :
$primaryKey = 'business_id';
$dataModel=new \app\crm\model\Business();
$info=$dataModel->getDataById($actionId);
break;
case 'crm_contract' :
$primaryKey = 'contract_id';
$info=db('crm_contract')->where('customer_id',$actionId)->find();
break;
case 'crm_receivables' :
$primaryKey = 'receivables_id';
$info=db('crm_receivables')->where('customer_id',$actionId)->find();
break;
case 'crm_visit' :
$primaryKey = 'visit_id';
$dataModel=new \app\crm\logic\VisitLogic();
$info=$dataModel->getDataById($actionId);
break;
case 'crm_product' :
$primaryKey = 'product_id';
$dataModel=new \app\crm\model\Product();
$info=$dataModel->getDataById($actionId);
break;
}
$apiCommon = new ApiCommon(); $apiCommon = new ApiCommon();
$userModel = new User(); $userModel = new User();
if (in_array($types, ['crm_contract', 'crm_receivables'])) {
$checkStatus = $model->where($primaryKey, $actionId)->value('check_status');
if (!in_array($checkStatus, [4, 5, 6])) {
$this->error = '只能编辑状态为撤销、草稿或作废的信息!';
return false;
}
}
# 产品修改验证
if($types == 'crm_product'){
foreach ($param['list'] as $val){
$infoData=db('crm_product')->where(['name'=>$val['name'],'delete_user_id'=>0])->find();
if(!empty($infoData)){
$fieldModel = new \app\admin\model\Field();
$validateArr = $fieldModel->validateField('crm_product'); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($val);
if (!$result) {
$this->error = $validate->getError();
return false;
}
}
}
}
# 客户模块快捷编辑权限验证 # 客户模块快捷编辑权限验证
if ($types == 'crm_customer') { if ($types == 'crm_customer') {
$dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
$wherePool = (new Customer())->getWhereByPool(); $wherePool = (new Customer())->getWhereByPool();
$resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['action_id']])->where($wherePool)->find(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['action_id']])->where($wherePool)->find();
if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) { if ($resPool || (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre)) {
$this->error = '无权操作!'; $this->error = '无权操作!';
return false; return false;
} }
@ -75,10 +133,10 @@ class CommonLogic
# 商机模块快捷编辑权限验证 # 商机模块快捷编辑权限验证
if ($types == 'crm_business') { if ($types == 'crm_business') {
$dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre) { if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
$this->error = '无权操作!'; $this->error = '无权操作!';
return false; return false;
} }
@ -86,7 +144,7 @@ class CommonLogic
# 合同模块快捷编辑权限验证 # 合同模块快捷编辑权限验证
if ($types == 'crm_contract') { if ($types == 'crm_contract') {
$dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find(); $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) { if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
@ -95,51 +153,100 @@ class CommonLogic
} }
} }
foreach ($param AS $key => $value) { $fieldModel = new \app\admin\model\Field();
# 查询自定义字段信息 # 日期时间类型
$fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name']) $datetimeField = $fieldModel->getFieldByFormType($types, 'datetime');
->where('types', $types)->where('field', $key)->find(); # 附件类型
$fileField = $fieldModel->getFieldByFormType($types, 'file');
# 字符长度 # 多选类型
if (!empty($fieldInfo['max_length']) && strlen($value) > $fieldInfo['max_length']) { $checkboxField = $fieldModel->getFieldByFormType($types, 'checkbox');
$this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!'; # 人员类型
return false; $userField = $fieldModel->getFieldByFormType($types, 'user');
} # 部门类型
$structureField = $fieldModel->getFieldByFormType($types, 'structure');
foreach ($param['list'] as $key => $value) {
foreach ($value as $k => $v) {
# 查询自定义字段信息
$fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name'])
->where('types', $types)->where('field', $k)->find();
# 字符长度
if (!empty($fieldInfo['max_length']) && strlen($v) > $fieldInfo['max_length']) {
$this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!';
return false;
}
# 必填 # 必填
if (!empty($fieldInfo['is_null']) && empty($value)) { if (!empty($fieldInfo['is_null']) && empty($v)) {
$this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!'; $this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!';
return false; return false;
} }
# 唯一 # 唯一
if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($key, $value)->value($primaryKey)) { if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($k, $v)->value($primaryKey)) {
$this->error = $fieldInfo['name'] . ' 内容重复!'; $this->error = $fieldInfo['name'] . ' 内容重复!';
return false; return false;
}
} }
} }
# 编辑参数 # 编辑参数
$data = []; $data = [];
$item=[];
if (!empty($param['list'])) { if (!empty($param['list'])) {
foreach ($param['list'] AS $key => $value) { foreach ($param['list'] as $key => $value) {
foreach ($value AS $k => $v) { foreach ($value as $k => $v) {
# 处理下次联系时间格式 if ($k == 'next_time' || in_array($k, $datetimeField)) {
if ($k == 'next_time') { # 处理下次联系时间格式、datetime类型数据
$data[$k] = !empty($v) ? strtotime($v) : ''; $data[$k] = !empty($v) ? strtotime($v) : '';
} else { } elseif ($types == 'crm_product' && $k == 'category_id') {
$data[$k] = $v; # 处理产品类别
}
# 处理产品类别
if ($types == 'crm_product' && $k == 'category_id') {
$categorys = explode(',', $v); $categorys = explode(',', $v);
$data[$k] = $categorys[count($categorys) - 1]; $data[$k] = $categorys[count($categorys) - 1];
} elseif (in_array($k, $fileField)) {
# 处理附件类型数据
$fileArray = [];
foreach ($v AS $kk => $vv) {
if (!empty($vv['file_id'])) $fileArray[] = $vv['file_id'];
}
if (!empty($fileArray)) $data[$k] = arrayToString($fileArray);
} elseif (in_array($k, $checkboxField)) {
# 处理多选类型数据
$data[$k] = arrayToString($v);
} elseif (in_array($k, $userField)) {
# 处理人员类型数据
$userArray = [];
foreach ($v AS $kk => $vv) {
if (!empty($vv['id'])) $userArray[] = $vv['id'];
}
$data[$k] = !empty($userArray) ? arrayToString($userArray) : '';
} elseif (in_array($k, $structureField)) {
# 处理部门类型数据
$structureArray = [];
foreach ($v AS $kk => $vv) {
if (!empty($vv['id'])) $structureArray[] = $vv['id'];
}
$data[$k] = !empty($structureArray) ? arrayToString($structureArray) : '';
} elseif ($types == 'crm_visit' && $k == 'contract_id') {
# 处理回访提交过来的合同编号
if (!empty($v[0]['contract_id'])) $data[$k] = $v[0]['contract_id'];
}else {
$data[$k] = $v;
} }
} }
$item=$value;
} }
$data[$primaryKey] = $actionId; $data[$primaryKey] = $actionId;
$data['update_time'] = time();
} }
$res = $model->update($data);
return $model->update($data); //详细信息修改新增操作记录
if ($res) {
//修改记录
$user_id = $apiCommon->userInfo;
updateActionLog($user_id['id'], $types, $actionId, $info, $item);
}
return $res;
} }
} }

@ -23,6 +23,10 @@ class IndexLogic extends Common
'12' => 'december', '12' => 'december',
]; ];
/**
* @param $param
* @return array
*/
public function index($param) public function index($param)
{ {
$adminModel = new \app\admin\model\Admin(); $adminModel = new \app\admin\model\Admin();
@ -69,17 +73,16 @@ class IndexLogic extends Common
$contract_auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'index'); $contract_auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'index');
$receivables_auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'index'); $receivables_auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'index');
$record_auth_user_ids = $userModel->getUserByPer('crm', 'activity', 'index'); $record_auth_user_ids = $userModel->getUserByPer('crm', 'activity', 'index');
$resCount = queryCache( $resCount = queryCache(
$this->getCountSql([ $this->getCountSql([
'start_time' => $between_time[0], 'start_time' => $between_time[0],
'end_time' => $between_time[1], 'end_time' => $between_time[1],
'customer_auth_user_ids' => array_intersect($userIds, $customer_auth_user_ids), 'customer_auth_user_ids' => array_intersect($userIds, $customer_auth_user_ids) ? :[-1],
'contacts_auth_user_ids' => array_intersect($userIds, $contacts_auth_user_ids), 'contacts_auth_user_ids' => array_intersect($userIds, $contacts_auth_user_ids) ? :[-1],
'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids), 'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids) ? :[-1],
'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids), 'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids) ? :[-1],
'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids), 'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids) ? :[-1],
'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids), 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? :[-1],
]) ])
); );

@ -54,12 +54,7 @@ class VisitLogic extends Common
//高级筛选 //高级筛选
$map = where_arr($map, 'crm', 'visit', 'index'); $map = where_arr($map, 'crm', 'visit', 'index');
$order = ['visit.update_time desc'];
if (isset($map['visit.visit_time'])) {
$map['visit.visit_time'][1][0] = date('Y-m-d', $map['visit.visit_time'][1][0]);
$map['visit.visit_time'][1][1] = date('Y-m-d', $map['visit.visit_time'][1][1]);
}
$authMap = []; $authMap = [];
if (!$partMap) { if (!$partMap) {
$a = 'index'; $a = 'index';
@ -68,20 +63,20 @@ class VisitLogic extends Common
if (!is_array($map['visit.owner_user_id'][1])) { if (!is_array($map['visit.owner_user_id'][1])) {
$map['visit.owner_user_id'][1] = [$map['visit.owner_user_id'][1]]; $map['visit.owner_user_id'][1] = [$map['visit.owner_user_id'][1]];
} }
if ($map['visit.owner_user_id'][0] == 'neq') { if (in_array($map['visit.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['visit.owner_user_id'][1]) ?: []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['visit.owner_user_id'][1]) ?: []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['visit.owner_user_id'][1], $auth_user_ids) ?: []; //取交集 $auth_user_ids = array_intersect($map['visit.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
} }
unset($map['visit.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1']; $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['visit.owner_user_id'] = array('in', $auth_user_ids); $authMap['visit.owner_user_id'] = array('in', $auth_user_ids);
unset($map['visit.owner_user_id']);
} else { } else {
$authMapData = []; $authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids; $authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id; $authMapData['user_id'] = $user_id;
$authMap = function ($query) use ($authMapData) { $authMap = function ($query) use ($authMapData) {
$query->where('visit.owner_user_id', array('in', $authMapData['auth_user_ids'])) $query->where('visit.owner_user_id', ['in', $authMapData['auth_user_ids']])
->whereOr('visit.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%')) ->whereOr('visit.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'))
->whereOr('visit.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%')); ->whereOr('visit.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
}; };
@ -96,6 +91,7 @@ class VisitLogic extends Common
//人员类型 //人员类型
$userField = $fieldModel->getFieldByFormType('crm_visit', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_visit', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_visit', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_visit', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
@ -118,12 +114,11 @@ class VisitLogic extends Common
->where($partMap) ->where($partMap)
->where($authMap) ->where($authMap)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field(array_merge($indexField, [ ->field('visit.*,
'contract.num' => 'contract_number', contract.num as contract_number,
'customer.name' => 'customer_name', customer.name as customer_name,
'contacts.name' => 'contacts_name', contacts.name as contacts_name'
)
]))
->orderRaw($order) ->orderRaw($order)
->group('visit.visit_id') ->group('visit.visit_id')
->select(); ->select();
@ -140,10 +135,15 @@ class VisitLogic extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val . '_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val . '_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
}
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
} }
$list[$k]['contract_id_info']['contract_id'] = $v['contract_id']; $list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
$list[$k]['contract_id_info']['name'] = $v['contract_name']; $list[$k]['contract_id_info']['name'] = $v['contract_name'];
@ -161,7 +161,7 @@ class VisitLogic extends Common
$is_update = 0; $is_update = 0;
$is_delete = 0; $is_delete = 0;
if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1; if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1; if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1; if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
$permission['is_read'] = $is_read; $permission['is_read'] = $is_read;
$permission['is_update'] = $is_update; $permission['is_update'] = $is_update;
@ -198,6 +198,11 @@ class VisitLogic extends Common
$dataInfo['contacts_id_info'] = db('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->field('contacts_id,name')->find(); $dataInfo['contacts_id_info'] = db('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->field('contacts_id,name')->find();
$dataInfo['contacts_name'] = !empty($dataInfo['contacts_id_info']['name']) ? $dataInfo['contacts_id_info']['name'] : ''; $dataInfo['contacts_name'] = !empty($dataInfo['contacts_id_info']['name']) ? $dataInfo['contacts_id_info']['name'] : '';
# 处理日期格式 # 处理日期格式
$fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo; return $dataInfo;
@ -330,7 +335,7 @@ class VisitLogic extends Common
return resultArray(['error' => $this->getError()]); return resultArray(['error' => $this->getError()]);
} }
//删除关联附件 //删除关联附件
$fileModel->delRFileByModule('crm_business', $delIds); $fileModel->delRFileByModule('crm_visit', $delIds);
//删除关联操作记录 //删除关联操作记录
$actionRecordModel->delDataById(['types' => 'crm_visit', 'visit_id' => $delIds]); $actionRecordModel->delDataById(['types' => 'crm_visit', 'visit_id' => $delIds]);
actionLog($delIds, '', '', ''); actionLog($delIds, '', '', '');

@ -14,14 +14,14 @@ use app\crm\model\Business as CrmBusinessModel;
class Business extends Common class Business extends Common
{ {
/** /**
* 为了数据库的整洁同时又不影响Model和Controller的名称 * 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀 * 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/ */
protected $name = 'crm_business'; protected $name = 'crm_business';
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
/** /**
* [getDataList 商机list] * [getDataList 商机list]
@ -32,190 +32,196 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getDataList($request) public function getDataList($request)
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure(); $structureModel = new \app\admin\model\Structure();
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$search = $request['search']; $search = $request['search'];
$user_id = $request['user_id']; $user_id = $request['user_id'];
$scene_id = (int)$request['scene_id']; $scene_id = (int)$request['scene_id'];
$contacts_id = $request['contacts_id']; $contacts_id = $request['contacts_id'];
$order_field = $request['order_field']; $order_field = $request['order_field'];
$order_type = $request['order_type']; $order_type = $request['order_type'];
$is_excel = $request['is_excel']; //导出 $is_excel = $request['is_excel']; //导出
$getCount = $request['getCount']; $getCount = $request['getCount'];
unset($request['scene_id']); unset($request['scene_id']);
unset($request['search']); unset($request['search']);
unset($request['user_id']); unset($request['user_id']);
unset($request['contacts_id']); unset($request['contacts_id']);
unset($request['order_field']); unset($request['order_field']);
unset($request['order_type']); unset($request['order_type']);
unset($request['is_excel']); unset($request['is_excel']);
unset($request['getCount']); unset($request['getCount']);
$request = $this->fmtRequest( $request ); $request = $this->fmtRequest($request);
$requestMap = $request['map'] ? : []; $requestMap = $request['map'] ?: [];
$sceneModel = new \app\admin\model\Scene(); $sceneModel = new \app\admin\model\Scene();
# getCount是代办事项传来的参数代办事项不需要使用场景 # getCount是代办事项传来的参数代办事项不需要使用场景
$sceneMap = []; $sceneMap = [];
if (empty($getCount)) { if (empty($getCount)) {
if ($scene_id) { if ($scene_id) {
//自定义场景 //自定义场景
$sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'business') ? : []; $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'business') ?: [];
} else { } else {
//默认场景 //默认场景
$sceneMap = $sceneModel->getDefaultData('crm_business', $user_id) ? : []; $sceneMap = $sceneModel->getDefaultData('crm_business', $user_id) ?: [];
}
}
if ($search) {
//普通筛选
$sceneMap['name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '商机名称'];
}
if (isset($requestMap['type_id'])) {
$requestMap['type_id']['value'] = $requestMap['type_id']['type_id'];
if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id'];
}
if ($sceneMap['type_id']) {
$requestMap['type_id']['value'] = $sceneMap['type_id']['type_id'];
if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id'];
unset($sceneMap['type_id']);
}
$partMap = [];
//优先级:普通筛选>高级筛选>场景
if ($sceneMap['ro_user_id'] && $sceneMap['rw_user_id']) {
//相关团队查询
$map = $requestMap;
$partMap = function ($query) use ($sceneMap) {
$query->where('business.ro_user_id', array('like', '%,' . $sceneMap['ro_user_id'] . ',%'))
->whereOr('business.rw_user_id', array('like', '%,' . $sceneMap['rw_user_id'] . ',%'));
};
} else {
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
}
//高级筛选
$map = where_arr($map, 'crm', 'business', 'index');
$authMap = [];
if (!$partMap) {
$a = 'index';
if ($is_excel) $a = 'excelExport';
$auth_user_ids = $userModel->getUserByPer('crm', 'business', $a);
if (isset($map['business.owner_user_id']) && $map['business.owner_user_id'][0] != 'like') {
if (!is_array($map['business.owner_user_id'][1])) {
$map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]];
}
if (in_array($map['business.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ?: []; //取差集
} else {
$auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
}
unset($map['business.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['business.owner_user_id'] = array('in', $auth_user_ids);
} else {
$authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id;
$authMap = function ($query) use ($authMapData) {
$query->where('business.owner_user_id', array('in', $authMapData['auth_user_ids']))
->whereOr('business.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'))
->whereOr('business.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
};
}
}
//联系人商机
if ($contacts_id) {
$business_id = Db::name('crm_contacts_business')->where(['contacts_id' => $contacts_id])->column('business_id');
if ($business_id) {
$map['business.business_id'] = array('in', $business_id);
} else {
$map['business.business_id'] = array('eq', -1);
} }
} }
if ($search) { //列表展示字段
//普通筛选 $indexField = $fieldModel->getIndexField('crm_business', $user_id, 1) ?: array('name');
$sceneMap['name'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '商机名称']; if (!empty($indexField)) {
} foreach ($indexField as $key => $value) {
if (isset($requestMap['type_id'])) { if ($value == 'business.customer_name') unset($indexField[(int)$key]);
$requestMap['type_id']['value'] = $requestMap['type_id']['type_id'];
if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id'];
}
if ($sceneMap['type_id']) {
$requestMap['type_id']['value'] = $sceneMap['type_id']['type_id'];
if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id'];
unset($sceneMap['type_id']);
}
$partMap = [];
//优先级:普通筛选>高级筛选>场景
if ($sceneMap['ro_user_id'] && $sceneMap['rw_user_id']) {
//相关团队查询
$map = $requestMap;
$partMap = function($query) use ($sceneMap){
$query->where('business.ro_user_id',array('like','%,'.$sceneMap['ro_user_id'].',%'))
->whereOr('business.rw_user_id',array('like','%,'.$sceneMap['rw_user_id'].',%'));
};
} else {
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
}
//高级筛选
$map = where_arr($map, 'crm', 'business', 'index');
$authMap = [];
if (!$partMap) {
$a = 'index';
if ($is_excel) $a = 'excelExport';
$auth_user_ids = $userModel->getUserByPer('crm', 'business', $a);
if (isset($map['business.owner_user_id']) && $map['business.owner_user_id'][0] != 'like') {
if (!is_array($map['business.owner_user_id'][1])) {
$map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]];
}
if ($map['business.owner_user_id'][0] == 'neq') {
$auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ? : []; //取差集
} else {
$auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
}
unset($map['business.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ? : ['-1'];
$authMap['business.owner_user_id'] = array('in',$auth_user_ids);
} else {
$authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id;
$authMap = function($query) use ($authMapData){
$query->where('business.owner_user_id',array('in',$authMapData['auth_user_ids']))
->whereOr('business.ro_user_id',array('like','%,'.$authMapData['user_id'].',%'))
->whereOr('business.rw_user_id',array('like','%,'.$authMapData['user_id'].',%'));
};
}
}
//联系人商机
if ($contacts_id) {
$business_id = Db::name('crm_contacts_business')->where(['contacts_id' => $contacts_id])->column('business_id');
if ($business_id) {
$map['business.business_id'] = array('in',$business_id);
}else{
$map['business.business_id'] = array('eq',-1);
}
}
//列表展示字段
$indexField = $fieldModel->getIndexField('crm_business', $user_id, 1) ? : array('name');
if (!empty($indexField)) {
foreach ($indexField AS $key => $value) {
if ($value == 'business.customer_name') unset($indexField[(int)$key]);
} }
} }
$userField = $fieldModel->getFieldByFormType('crm_business', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_business', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_business', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_business', 'structure'); //部门类型
//排序 $datetimeField = $fieldModel->getFieldByFormType('crm_business', 'datetime'); //日期时间类型
if ($order_type && $order_field) { //排序
$order = $fieldModel->getOrderByFormtype('crm_business','business',$order_field,$order_type); if ($order_type && $order_field) {
} else { $order = $fieldModel->getOrderByFormtype('crm_business', 'business', $order_field, $order_type);
$order = 'business.update_time desc'; } else {
} $order = 'business.update_time desc';
}
$readAuthIds = $userModel->getUserByPer('crm', 'business', 'read');
$readAuthIds = $userModel->getUserByPer('crm', 'business', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'business', 'update'); $updateAuthIds = $userModel->getUserByPer('crm', 'business', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'business', 'delete'); $deleteAuthIds = $userModel->getUserByPer('crm', 'business', 'delete');
$dataCount = db('crm_business') $dataCount = db('crm_business')
->alias('business') ->alias('business')
->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT') ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map)->where($partMap)->where($authMap)->count('business_id'); ->where($map)->where($partMap)->where($authMap)->count('business_id');
if (!empty($getCount) && $getCount == 1) { if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0; $data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
# 商机总金额 # 商机总金额
$sumMoney = Db::name('crm_business')->alias('business') $sumMoney = Db::name('crm_business')->alias('business')
->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money'); ->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money');
$data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00]; $data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data; return $data;
} }
$list = db('crm_business') $list = db('crm_business')
->alias('business') ->alias('business')
->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT') ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map) ->where($map)
->where($partMap) ->where($partMap)
->where($authMap) ->where($authMap)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field(implode(',',$indexField).',business.is_end,customer.name as customer_name') ->field('business.*,customer.name as customer_name')
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
$endStatus = ['1' => '赢单','2' => '输单','3' => '无效']; $endStatus = ['1' => '赢单', '2' => '输单', '3' => '无效'];
foreach ($list as $k=>$v) { foreach ($list as $k => $v) {
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id']; $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
$list[$k]['customer_id_info']['name'] = $v['customer_name']; $list[$k]['customer_id_info']['name'] = $v['customer_name'];
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
} $list[$k][$val] = implode($usernameField, ',');
foreach ($structureField as $key => $val) { }
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; foreach ($structureField as $key => $val) {
} $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$statusInfo = []; $list[$k][$val] = implode($structureNameField, ',');
$status_count = 0; }
if (!$v['is_end']) { foreach ($datetimeField as $key => $val) {
$statusInfo = db('crm_business_status')->where('status_id',$v['status_id'])->find(); $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
if ($statusInfo['order_id'] < 99) { }
$status_count = db('crm_business_status')->where('type_id',['eq',$v['type_id']])->count(); $statusInfo = [];
} $status_count = 0;
//进度 if (!$v['is_end']) {
$list[$k]['status_progress'] = [$statusInfo['order_id'], $status_count+1]; $statusInfo = db('crm_business_status')->where('status_id', $v['status_id'])->find();
} else { if ($statusInfo['order_id'] < 99) {
$statusInfo['name'] = $endStatus[$v['is_end']]; $status_count = db('crm_business_status')->where('type_id', ['eq', $v['type_id']])->count();
} }
$list[$k]['status_id_info'] = $statusInfo['name'];//销售阶段 //进度
$list[$k]['type_id_info'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组 $list[$k]['status_progress'] = [$statusInfo['order_id'], $status_count + 1];
} else {
//权限 $statusInfo['name'] = $endStatus[$v['is_end']];
$roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read'); }
$rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update'); $list[$k]['status_id_info'] = $statusInfo['name'];//销售阶段
$permission = []; $list[$k]['type_id_info'] = db('crm_business_type')->where('type_id', $v['type_id'])->value('name');//商机状态组
$is_read = 0;
$is_update = 0; //权限
$is_delete = 0; $roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read');
if (in_array($v['owner_user_id'],$readAuthIds) || $roPre || $rwPre) $is_read = 1; $rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update');
if (in_array($v['owner_user_id'],$updateAuthIds) || $rwPre) $is_update = 1; $permission = [];
if (in_array($v['owner_user_id'],$deleteAuthIds)) $is_delete = 1; $is_read = 0;
$permission['is_read'] = $is_read; $is_update = 0;
$permission['is_update'] = $is_update; $is_delete = 0;
$permission['is_delete'] = $is_delete; if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
$list[$k]['permission'] = $permission; if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
$permission['is_read'] = $is_read;
$permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission;
# 下次联系时间 # 下次联系时间
$list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null; $list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注 # 关注
@ -225,159 +231,159 @@ class Business extends Common
# 日期 # 日期
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null; $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
$list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null; $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
} }
$data = []; $data = [];
$data['list'] = $list ? : []; $data['list'] = $list ?: [];
$data['dataCount'] = $dataCount ? : 0; $data['dataCount'] = $dataCount ?: 0;
# 商机总金额 # 商机总金额
$sumMoney = Db::name('crm_business')->alias('business') $sumMoney = Db::name('crm_business')->alias('business')
->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT') ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money'); ->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money');
$data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00]; $data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data; return $data;
} }
/** /**
* 创建商机主表信息 * 创建商机主表信息
* @author Michael_xu * @param
* @param * @return
* @return * @author Michael_xu
*/ */
public function createData($param) public function createData($param)
{ {
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$productModel = new \app\crm\model\Product(); $productModel = new \app\crm\model\Product();
// 自动验证 // 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则 $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']); $validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($param); $result = $validate->check($param);
if (!$result) { if (!$result) {
$this->error = $validate->getError(); $this->error = $validate->getError();
return false; return false;
} }
if (!$param['customer_id']) { if (!$param['customer_id']) {
$this->error = '请选择相关客户'; $this->error = '请选择相关客户';
return false; return false;
} }
# 处理下次联系时间 # 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']); if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_business'); $arrFieldAtt = $fieldModel->getArrayField('crm_business');
foreach ($arrFieldAtt as $k=>$v) { foreach ($arrFieldAtt as $k => $v) {
$param[$v] = arrayToString($param[$v]); $param[$v] = arrayToString($param[$v]);
} }
$param['money'] = $param['money'] ? : '0.00'; $param['money'] = $param['money'] ?: '0.00';
$param['discount_rate'] = $param['discount_rate'] ? : '0.00'; $param['discount_rate'] = $param['discount_rate'] ?: '0.00';
if ($this->data($param)->allowField(true)->save()) { if ($this->data($param)->allowField(true)->save()) {
$business_id = $this->business_id; $business_id = $this->business_id;
if ($param['product']) { if ($param['product']) {
//产品数据处理 //产品数据处理
$resProduct = $productModel->createObject('crm_business', $param, $business_id); $resProduct = $productModel->createObject('crm_business', $param, $business_id);
if ($resProduct == false) { if ($resProduct == false) {
$this->error = '产品添加失败'; $this->error = '产品添加失败';
return false; return false;
} }
} }
//添加商机日志 //添加商机日志
$data_log['business_id'] = $business_id; $data_log['business_id'] = $business_id;
$data_log['is_end'] = 0; $data_log['is_end'] = 0;
$data_log['status_id'] = $param['status_id']; $data_log['status_id'] = $param['status_id'];
$data_log['create_time'] = time(); $data_log['create_time'] = time();
$data_log['owner_user_id'] = $param['owner_user_id']; $data_log['owner_user_id'] = $param['owner_user_id'];
$data_log['remark'] = '新建商机'; $data_log['remark'] = '新建商机';
Db::name('CrmBusinessLog')->insert($data_log); Db::name('CrmBusinessLog')->insert($data_log);
$data = []; $data = [];
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
# 添加活动记录 # 添加活动记录
Db::name('crm_activity')->insert([ Db::name('crm_activity')->insert([
'type' => 2, 'type' => 2,
'activity_type' => 5, 'activity_type' => 5,
'activity_type_id' => $data['business_id'], 'activity_type_id' => $data['business_id'],
'content' => $param['name'], 'content' => $param['name'],
'create_user_id' => $param['create_user_id'], 'create_user_id' => $param['create_user_id'],
'update_time' => time(), 'update_time' => time(),
'create_time' => time(), 'create_time' => time(),
'customer_ids' => $param['customer_id'] 'customer_ids' => $param['customer_id']
]); ]);
return $data; return $data;
} else { } else {
$this->error = '添加失败'; $this->error = '添加失败';
return false; return false;
} }
} }
/** /**
* 编辑商机主表信息 * 编辑商机主表信息
* @author Michael_xu * @param
* @param * @return
* @return * @author Michael_xu
*/ */
public function updateDataById($param, $business_id = '') public function updateDataById($param, $business_id = '')
{ {
$productModel = new \app\crm\model\Product(); $productModel = new \app\crm\model\Product();
$dataInfo = $this->getDataById($business_id); $dataInfo = $this->getDataById($business_id);
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '数据不存在或已删除'; $this->error = '数据不存在或已删除';
return false; return false;
} }
$param['business_id'] = $business_id; $param['business_id'] = $business_id;
//过滤不能修改的字段 //过滤不能修改的字段
$unUpdateField = ['create_user_id','is_deleted','delete_time']; $unUpdateField = ['create_user_id', 'is_deleted', 'delete_time'];
foreach ($unUpdateField as $v) { foreach ($unUpdateField as $v) {
unset($param[$v]); unset($param[$v]);
} }
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 自动验证 // 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则 $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']); $validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($param); $result = $validate->check($param);
if (!$result) { if (!$result) {
$this->error = $validate->getError(); $this->error = $validate->getError();
return false; return false;
} }
# 处理下次联系时间 # 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']); if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_business'); $arrFieldAtt = $fieldModel->getArrayField('crm_business');
foreach ($arrFieldAtt as $k=>$v) { foreach ($arrFieldAtt as $k => $v) {
$param[$v] = arrayToString($param[$v]); $param[$v] = arrayToString($param[$v]);
} }
$param['money'] = $param['money'] ? : '0.00'; $param['money'] = $param['money'] ?: '0.00';
$param['discount_rate'] = $param['discount_rate'] ? : '0.00'; $param['discount_rate'] = $param['discount_rate'] ?: '0.00';
//商机状态改变 //商机状态改变
$statusInfo = db('crm_business_status')->where(['status_id' => $param['status_id']])->find(); $statusInfo = db('crm_business_status')->where(['status_id' => $param['status_id']])->find();
if ($statusInfo['type_id']) { if ($statusInfo['type_id']) {
$param['is_end'] = 0; $param['is_end'] = 0;
} else { } else {
$param['is_end'] = $param['status_id']; $param['is_end'] = $param['status_id'];
} }
if ($this->update($param, ['business_id' => $business_id], true)) { if ($this->update($param, ['business_id' => $business_id], true)) {
//产品数据处理 //产品数据处理
$resProduct = $productModel->createObject('crm_business', $param, $business_id); $resProduct = $productModel->createObject('crm_business', $param, $business_id);
//修改记录 //修改记录
updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param); updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param);
$data = []; $data = [];
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
return $data; return $data;
} else { } else {
$this->rollback(); $this->rollback();
$this->error = '编辑失败'; $this->error = '编辑失败';
return false; return false;
} }
} }
/** /**
* 商机数据 * 商机数据
@ -389,84 +395,89 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getDataById($id = '', $userId = 0) public function getDataById($id = '', $userId = 0)
{ {
$dataInfo = db('crm_business')->where('business_id', $id)->find(); $dataInfo = db('crm_business')->where('business_id', $id)->find();
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
$dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : ''; $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
$dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : ''; $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
$dataInfo['type_id_info'] = db('crm_business_type')->where(['type_id' => $dataInfo['type_id']])->value('name'); $dataInfo['type_id_info'] = db('crm_business_type')->where(['type_id' => $dataInfo['type_id']])->value('name');
$dataInfo['status_id_info'] = db('crm_business_status')->where(['status_id' => $dataInfo['status_id']])->value('name'); $dataInfo['status_id_info'] = db('crm_business_status')->where(['status_id' => $dataInfo['status_id']])->value('name');
$dataInfo['customer_id_info'] = db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find(); $dataInfo['customer_id_info'] = db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find();
$dataInfo['customer_name'] = !empty($dataInfo['customer_id_info']['name']) ? $dataInfo['customer_id_info']['name'] : ''; $dataInfo['customer_name'] = !empty($dataInfo['customer_id_info']['name']) ? $dataInfo['customer_id_info']['name'] : '';
# 关注 # 关注
$starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_business'])->value('star_id'); $starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_business'])->value('star_id');
$dataInfo['star'] = !empty($starId) ? 1 : 0; $dataInfo['star'] = !empty($starId) ? 1 : 0;
# 首要联系人 # 首要联系人
$primaryId = Db::name('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->value('contacts_id'); $primaryId = Db::name('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->value('contacts_id');
$dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0; $dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0;
# 处理日期格式 # 处理日期格式
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_business', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null; $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
return $dataInfo; return $dataInfo;
} }
//根据IDs获取数组 //根据IDs获取数组
public function getDataByStr($idstr) public function getDataByStr($idstr)
{ {
$idArr = stringToArray($idstr); $idArr = stringToArray($idstr);
if (!$idArr) { if (!$idArr) {
return []; return [];
} }
$list = Db::name('CrmBusiness')->where(['business_id' => ['in',$idArr]])->select(); $list = Db::name('CrmBusiness')->where(['business_id' => ['in', $idArr]])->select();
return $list; return $list;
} }
/** /**
* [商机漏斗] * [商机漏斗]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getFunnel($request) public function getFunnel($request)
{ {
$merge = $request['merge'] ? : 0; $merge = $request['merge'] ?: 0;
$perUserIds = $request['perUserIds'] ? : []; $perUserIds = $request['perUserIds'] ?: [];
$adminModel = new \app\admin\model\Admin(); $adminModel = new \app\admin\model\Admin();
$whereArr = $adminModel->getWhere($request, $merge, $perUserIds); //统计查询 $whereArr = $adminModel->getWhere($request, $merge, $perUserIds); //统计查询
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
$between_time = $whereArr['between_time']; $between_time = $whereArr['between_time'];
$where['owner_user_id'] = array('in',$userIds); $where['owner_user_id'] = array('in', $userIds);
$where['create_time'] = array('between',$between_time); $where['create_time'] = array('between', $between_time);
//商机状态组 //商机状态组
$default_type_id = db('crm_business_type')->order('type_id asc')->value('type_id'); $default_type_id = db('crm_business_type')->order('type_id asc')->value('type_id');
$type_id = $request['type_id'] ? $request['type_id'] : $default_type_id; $type_id = $request['type_id'] ? $request['type_id'] : $default_type_id;
$statusList = db('crm_business_status')->where(['type_id' => $type_id])->select(); $statusList = db('crm_business_status')->where(['type_id' => $type_id])->select();
$map = []; $map = [];
$map['create_time'] = $where['create_time']; $map['create_time'] = $where['create_time'];
$map['owner_user_id'] = ['in',$userIds]; $map['owner_user_id'] = ['in', $userIds];
$sql_a = CrmBusinessModel::field([ $sql_a = CrmBusinessModel::field([
'SUM(CASE WHEN status_id = 1 THEN money ELSE 0 END) AS sum_ying', 'SUM(CASE WHEN status_id = 1 THEN money ELSE 0 END) AS sum_ying',
'SUM(CASE WHEN status_id = 2 THEN money ELSE 0 END) AS sum_shu' 'SUM(CASE WHEN status_id = 2 THEN money ELSE 0 END) AS sum_shu'
]) ])
->where($map) ->where($map)
->fetchSql() ->fetchSql()
->select(); ->select();
$res_a = queryCache($sql_a, 200); $res_a = queryCache($sql_a, 200);
$sql = CrmBusinessModel::field([ $sql = CrmBusinessModel::field([
"status_id", "status_id",
'COUNT(*)' => 'count', 'COUNT(*)' => 'count',
'SUM(`money`)' => 'sum' 'SUM(`money`)' => 'sum'
]) ])
->where($where) ->where($where)
->whereNotIn('is_end', '1,2,3') ->whereNotIn('is_end', '1,2,3')
->group('status_id') ->group('status_id')
@ -476,45 +487,45 @@ class Business extends Common
$res = array_column($res, null, 'status_id'); $res = array_column($res, null, 'status_id');
$sum_money = 0; $sum_money = 0;
$count = 0; # 商机数总和 $count = 0; # 商机数总和
$moneyCount = 0; # 金额总和 $moneyCount = 0; # 金额总和
foreach ($statusList as $k=>$v) { foreach ($statusList as $k => $v) {
$v['count'] = $res[$v['status_id']]['count'] ? : 0; $v['count'] = $res[$v['status_id']]['count'] ?: 0;
$v['money'] = $res[$v['status_id']]['sum'] ? : 0; $v['money'] = $res[$v['status_id']]['sum'] ?: 0;
$v['status_name'] = $v['name']; $v['status_name'] = $v['name'];
$statusList[$k] = $v; $statusList[$k] = $v;
$sum_money += $v['money']; $sum_money += $v['money'];
$moneyCount += $v['money']; $moneyCount += $v['money'];
$count += $v['count']; $count += $v['count'];
} }
$data['list'] = $statusList; $data['list'] = $statusList;
$data['list'] = $statusList; $data['list'] = $statusList;
$data['sum_ying'] = $res_a[0]['sum_ying'] ? : 0; $data['sum_ying'] = $res_a[0]['sum_ying'] ?: 0;
$data['sum_shu'] = $res_a[0]['sum_shu'] ? : 0; $data['sum_shu'] = $res_a[0]['sum_shu'] ?: 0;
$data['sum_money'] = $sum_money ? : 0; $data['sum_money'] = $sum_money ?: 0;
$data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count]; $data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count];
return $data ? : []; return $data ?: [];
} }
/** /**
* [商机转移] * [商机转移]
* @author Michael_xu
* @param ids 商机ID数组 * @param ids 商机ID数组
* @param owner_user_id 变更负责人 * @param owner_user_id 变更负责人
* @param is_remove 1移出2转为团队成员 * @param is_remove 1移出2转为团队成员
* @return * @return
* @author Michael_xu
*/ */
public function transferDataById($ids, $owner_user_id, $type = 1, $is_remove) public function transferDataById($ids, $owner_user_id, $type = 1, $is_remove)
{ {
$settingModel = new \app\crm\model\Setting(); $settingModel = new \app\crm\model\Setting();
$errorMessage = []; $errorMessage = [];
foreach ($ids as $id) { foreach ($ids as $id) {
$businessInfo = db('crm_business')->where(['business_id' => $id])->find(); $businessInfo = db('crm_business')->where(['business_id' => $id])->find();
//团队成员 //团队成员
$teamData = []; $teamData = [];
$teamData['type'] = $type; //权限 1只读2读写 $teamData['type'] = $type; //权限 1只读2读写
$teamData['user_id'] = [$businessInfo['owner_user_id']]; //协作人 $teamData['user_id'] = [$businessInfo['owner_user_id']]; //协作人
$teamData['types'] = 'crm_business'; //类型 $teamData['types'] = 'crm_business'; //类型
@ -522,19 +533,31 @@ class Business extends Common
$teamData['is_del'] = ($is_remove == 1) ? 1 : ''; $teamData['is_del'] = ($is_remove == 1) ? 1 : '';
$res = $settingModel->createTeamData($teamData); $res = $settingModel->createTeamData($teamData);
$data = []; $data = [];
$data['owner_user_id'] = $owner_user_id; $data['owner_user_id'] = $owner_user_id;
$data['update_time'] = time(); $data['update_time'] = time();
if (!db('crm_business')->where(['business_id' => $id])->update($data)) { if (!db('crm_business')->where(['business_id' => $id])->update($data)) {
$errorMessage[] = '商机:'.$businessInfo['name'].'"转移失败,错误原因:数据出错;'; $errorMessage[] = '商机:' . $businessInfo['name'] . '"转移失败,错误原因:数据出错;';
continue; continue;
} } else {
} $businessArray = [];
if ($errorMessage) { $teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $id)->find();
return $errorMessage; if (!empty($teamBusiness['ro_user_id'])) {
} else { $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
return true; $businessArray['ro_user_id'] = $businessRo;
} }
if (!empty($teamBusiness['rw_user_id'])) {
$businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
$businessArray['rw_user_id'] = $businessRo;
}
db('crm_business')->where('business_id', $id)->update($businessArray);
}
}
if ($errorMessage) {
return $errorMessage;
} else {
return true;
}
} }
/** /**
@ -542,10 +565,10 @@ class Business extends Common
* @param * @param
* @return * @return
*/ */
public function getTrendql($map) public function getTrendql($map)
{ {
$prefix = config('database.prefix'); $prefix = config('database.prefix');
$sql = "SELECT $sql = "SELECT
'{$map['type']}' AS type, '{$map['type']}' AS type,
'{$map['start_time']}' AS start_time, '{$map['start_time']}' AS start_time,
'{$map['end_time']}' AS end_time, '{$map['end_time']}' AS end_time,
@ -570,18 +593,18 @@ class Business extends Common
WHERE WHERE
create_time BETWEEN {$map['start_time']} AND {$map['end_time']} create_time BETWEEN {$map['start_time']} AND {$map['end_time']}
AND owner_user_id IN ({$map['owner_user_id']})"; AND owner_user_id IN ({$map['owner_user_id']})";
return $sql; return $sql;
} }
/** /**
* [赢单机会转化率趋势分析] * [赢单机会转化率趋势分析]
* @param * @param
* @return * @return
*/ */
public function getWinSql($map) public function getWinSql($map)
{ {
$prefix = config('database.prefix'); $prefix = config('database.prefix');
$sql = "SELECT $sql = "SELECT
'{$map['type']}' AS type, '{$map['type']}' AS type,
'{$map['start_time']}' AS start_time, '{$map['start_time']}' AS start_time,
'{$map['end_time']}' AS end_time, '{$map['end_time']}' AS end_time,
@ -607,8 +630,8 @@ class Business extends Common
WHERE WHERE
create_time BETWEEN {$map['start_time']} AND {$map['end_time']} create_time BETWEEN {$map['start_time']} AND {$map['end_time']}
AND owner_user_id IN ({$map['owner_user_id']})"; AND owner_user_id IN ({$map['owner_user_id']})";
return $sql; return $sql;
} }
/** /**
* 获取系统信息 * 获取系统信息
@ -619,7 +642,7 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 商机 # 商机
$business = Db::name('crm_business')->field(['create_user_id', 'create_time', 'update_time'])->where('business_id', $id)->find(); $business = Db::name('crm_business')->field(['create_user_id', 'create_time', 'update_time'])->where('business_id', $id)->find();
@ -630,9 +653,9 @@ class Business extends Common
return [ return [
'create_user_name' => $realname, 'create_user_name' => $realname,
'create_time' => date('Y-m-d H:i:s', $business['create_time']), 'create_time' => date('Y-m-d H:i:s', $business['create_time']),
'update_time' => date('Y-m-d H:i:s', $business['update_time']), 'update_time' => date('Y-m-d H:i:s', $business['update_time']),
'follow_time' => !empty($followTime) ? date('Y-m-d H:i:s', $followTime) : '' 'follow_time' => !empty($followTime) ? date('Y-m-d H:i:s', $followTime) : ''
]; ];
} }

@ -85,7 +85,7 @@ class Contacts extends Common
if (!is_array($map['contacts.owner_user_id'][1])) { if (!is_array($map['contacts.owner_user_id'][1])) {
$map['contacts.owner_user_id'][1] = [$map['contacts.owner_user_id'][1]]; $map['contacts.owner_user_id'][1] = [$map['contacts.owner_user_id'][1]];
} }
if ($map['contacts.owner_user_id'][0] == 'neq') { if (in_array($map['contacts.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['contacts.owner_user_id'][1]) ? : []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['contacts.owner_user_id'][1]) ? : []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['contacts.owner_user_id'][1], $auth_user_ids) ? : []; //取交集 $auth_user_ids = array_intersect($map['contacts.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@ -108,6 +108,7 @@ class Contacts extends Common
$indexField = $fieldModel->getIndexField('crm_contacts', $user_id, 1) ? : array('name'); $indexField = $fieldModel->getIndexField('crm_contacts', $user_id, 1) ? : array('name');
$userField = $fieldModel->getFieldByFormType('crm_contacts', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_contacts', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
@ -144,7 +145,6 @@ class Contacts extends Common
->where($customerWhere) ->where($customerWhere)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field('contacts.*,customer.name as customer_name') ->field('contacts.*,customer.name as customer_name')
->field(implode(',',$indexField).',customer.name as customer_name')
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
@ -154,11 +154,16 @@ class Contacts extends Common
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : ''; $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : ''; $list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
} }
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
//权限 //权限
$permission = []; $permission = [];
@ -173,9 +178,6 @@ class Contacts extends Common
$permission['is_delete'] = $is_delete; $permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission; $list[$k]['permission'] = $permission;
# 下次联系时间
$list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注 # 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['contacts_id'], 'type' => 'crm_contacts']; $starWhere = ['user_id' => $user_id, 'target_id' => $v['contacts_id'], 'type' => 'crm_contacts'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id'); $star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -227,9 +229,6 @@ class Contacts extends Common
$param['primary'] = 1; $param['primary'] = 1;
} }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts'); $arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) { foreach ($arrFieldAtt as $k=>$v) {
@ -249,7 +248,7 @@ class Contacts extends Common
'create_user_id' => $param['create_user_id'], 'create_user_id' => $param['create_user_id'],
'update_time' => time(), 'update_time' => time(),
'create_time' => time(), 'create_time' => time(),
'customer_ids' => $param['customer_id'] 'customer_ids' => $param['customer_id']
]); ]);
# 处理商机首要联系人 # 处理商机首要联系人
@ -319,9 +318,6 @@ class Contacts extends Common
return false; return false;
} }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts'); $arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) { foreach ($arrFieldAtt as $k=>$v) {
@ -382,7 +378,11 @@ class Contacts extends Common
# 处理决策人显示问题 # 处理决策人显示问题
$dataInfo['decision'] = !empty($dataInfo['decision']) && $dataInfo['decision'] == '是' ? '是' : ''; $dataInfo['decision'] = !empty($dataInfo['decision']) && $dataInfo['decision'] == '是' ? '是' : '';
# 处理时间格式 # 处理时间格式
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null; $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;

@ -99,7 +99,7 @@ class Contract extends Common
if (!is_array($map['contract.owner_user_id'][1])) { if (!is_array($map['contract.owner_user_id'][1])) {
$map['contract.owner_user_id'][1] = [$map['contract.owner_user_id'][1]]; $map['contract.owner_user_id'][1] = [$map['contract.owner_user_id'][1]];
} }
if ($map['contract.owner_user_id'][0] == 'neq') { if (in_array($map['contract.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['contract.owner_user_id'][1]) ? : []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['contract.owner_user_id'][1]) ? : []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['contract.owner_user_id'][1], $auth_user_ids) ? : []; //取交集 $auth_user_ids = array_intersect($map['contract.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@ -127,6 +127,7 @@ class Contract extends Common
//人员类型 //人员类型
$userField = $fieldModel->getFieldByFormType('crm_contract', 'user'); $userField = $fieldModel->getFieldByFormType('crm_contract', 'user');
$structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_contract','contract',$order_field,$order_type); $order = $fieldModel->getOrderByFormtype('crm_contract','contract',$order_field,$order_type);
@ -186,11 +187,16 @@ class Contract extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
} }
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
$list[$k]['business_id_info']['business_id'] = $v['business_id']; $list[$k]['business_id_info']['business_id'] = $v['business_id'];
$list[$k]['business_id_info']['name'] = $v['business_name']; $list[$k]['business_id_info']['name'] = $v['business_name'];
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id']; $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
@ -226,6 +232,9 @@ class Contract extends Common
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null; $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
$list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null; $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
$list[$k]['order_date'] = ($v['order_date']!='0000-00-00') ? $v['order_date'] : null;
$list[$k]['start_time'] = ($v['start_time']!='0000-00-00') ? $v['start_time'] : null;
$list[$k]['end_time'] = ($v['end_time']!='0000-00-00') ? $v['end_time'] : null;
# 签约人姓名 # 签约人姓名
$orderNames = Db::name('admin_user')->whereIn('id', trim($v['order_user_id'], ','))->column('realname'); $orderNames = Db::name('admin_user')->whereIn('id', trim($v['order_user_id'], ','))->column('realname');
$list[$k]['order_user_name'] = implode(',', $orderNames); $list[$k]['order_user_name'] = implode(',', $orderNames);
@ -488,6 +497,11 @@ class Contract extends Common
$orderNames = Db::name('admin_user')->whereIn('id', trim($dataInfo['order_user_id'], ','))->column('realname'); $orderNames = Db::name('admin_user')->whereIn('id', trim($dataInfo['order_user_id'], ','))->column('realname');
$dataInfo['order_user_name'] = implode(',', $orderNames); $dataInfo['order_user_name'] = implode(',', $orderNames);
# 处理时间根式 # 处理时间根式
$fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
@ -510,10 +524,10 @@ class Contract extends Common
foreach ($ids as $id) { foreach ($ids as $id) {
$contractInfo = []; $contractInfo = [];
$contractInfo = db('crm_contract')->where(['contract_id' => $id])->find(); $contractInfo = db('crm_contract')->where(['contract_id' => $id])->find();
if (in_array($contractInfo['check_status'],['0','1'])) { // if (in_array($contractInfo['check_status'],['0','1'])) {
$errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;'; // $errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;';
continue; // continue;
} // }
//团队成员 //团队成员
$teamData = []; $teamData = [];
$teamData['type'] = $type; //权限 1只读2读写 $teamData['type'] = $type; //权限 1只读2读写
@ -529,7 +543,19 @@ class Contract extends Common
if (!db('crm_contract')->where(['contract_id' => $id])->update($data)) { if (!db('crm_contract')->where(['contract_id' => $id])->update($data)) {
$errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:数据出错;'; $errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:数据出错;';
continue; continue;
} } else {
$contractArray = [];
$teamContract = db('crm_contract')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('contract_id', $id)->find();
if (!empty($teamContract['ro_user_id'])) {
$contractRo = arrayToString(array_diff(stringToArray($teamContract['ro_user_id']), [$teamContract['owner_user_id']]));
$contractArray['ro_user_id'] = $contractRo;
}
if (!empty($teamContract['rw_user_id'])) {
$contractRo = arrayToString(array_diff(stringToArray($teamContract['rw_user_id']), [$teamContract['owner_user_id']]));
$contractArray['rw_user_id'] = $contractRo;
}
db('crm_contract')->where('contract_id', $id)->update($contractArray);
}
} }
if ($errorMessage) { if ($errorMessage) {
return $errorMessage; return $errorMessage;

@ -127,7 +127,7 @@ class Customer extends Common
if (!is_array($map['customer.owner_user_id'][1])) { if (!is_array($map['customer.owner_user_id'][1])) {
$map['customer.owner_user_id'][1] = [$map['customer.owner_user_id'][1]]; $map['customer.owner_user_id'][1] = [$map['customer.owner_user_id'][1]];
} }
if ($map['customer.owner_user_id'][0] == 'neq') { if (in_array($map['customer.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['customer.owner_user_id'][1]) ? : []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['customer.owner_user_id'][1]) ? : []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['customer.owner_user_id'][1], $auth_user_ids) ? : []; //取交集 $auth_user_ids = array_intersect($map['customer.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@ -169,6 +169,7 @@ class Customer extends Common
$indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ? : array('name'); $indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ? : array('name');
$userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type); $order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
@ -190,8 +191,7 @@ class Customer extends Common
->where($poolMap) ->where($poolMap)
->where($otherMap) ->where($otherMap)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field(implode(',',$indexField)) ->field('customer.*')
->order($order_t) /*置顶*/
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
//保护规则 //保护规则
@ -228,14 +228,19 @@ class Customer extends Common
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
if (in_array($val, $field_list)) { if (in_array($val, $field_list)) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
if (in_array($val, $field_list)) { if (in_array($val, $field_list)) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
} }
} }
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
//商机数 //商机数
$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0; $list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
//距进入公海天数 //距进入公海天数
@ -268,9 +273,6 @@ class Customer extends Common
$permission['is_delete'] = $is_delete; $permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission; $list[$k]['permission'] = $permission;
# 下次联系时间
$list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注 # 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['customer_id'], 'type' => 'crm_customer']; $starWhere = ['user_id' => $user_id, 'target_id' => $v['customer_id'], 'type' => 'crm_customer'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id'); $star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -327,9 +329,6 @@ class Customer extends Common
return false; return false;
} }
unset($param['customer_id']); unset($param['customer_id']);
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_customer'); $arrFieldAtt = $fieldModel->getArrayField('crm_customer');
@ -378,70 +377,67 @@ class Customer extends Common
* @param * @param
* @return * @return
*/ */
public function updateDataById($param, $customer_id = '') public function updateDataById($param, $customer_id = '')
{ {
$user_id = $param['user_id']; $user_id = $param['user_id'];
$dataInfo = $this->get($customer_id); $dataInfo = $this->get($customer_id);
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '数据不存在或已删除'; $this->error = '数据不存在或已删除';
return false; return false;
} }
$id = $param['id']?:$customer_id;
//数据权限判断 //数据权限判断
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update');
//读写权限 //读写权限
$rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); $rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
//判断是否客户池数据 //判断是否客户池数据
$wherePool = $this->getWhereByPool(); $wherePool = $this->getWhereByPool();
$resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $id])->where($wherePool)->find();
if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) { if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) {
$this->error = '无权操作'; $this->error = '无权操作';
return false; return false;
} }
$param['customer_id'] = $customer_id; $param['customer_id'] = $customer_id;
//过滤不能修改的字段 //过滤不能修改的字段
$unUpdateField = ['create_user_id','is_deleted','delete_time','user_id']; $unUpdateField = ['create_user_id','is_deleted','delete_time','user_id'];
foreach ($unUpdateField as $v) { foreach ($unUpdateField as $v) {
unset($param[$v]); unset($param[$v]);
} }
$param['deal_status'] = $dataInfo['deal_status']; $param['deal_status'] = $dataInfo['deal_status'];
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 自动验证 // 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则 $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']); $validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($param); $result = $validate->check($param);
if (!$result) { if (!$result) {
$this->error = $validate->getError(); $this->error = $validate->getError();
return false; return false;
} }
//地址 //地址
$param['address'] = $param['address'] ? implode(chr(10),$param['address']) : ''; $param['address'] = $param['address'] ? implode(chr(10),$param['address']) : '';
if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') { if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') {
$param['deal_time'] = time(); $param['deal_time'] = time();
} }
# 处理下次联系时间 //处理部门、员工、附件、多选类型字段
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']); $arrFieldAtt = $fieldModel->getArrayField('crm_customer');
foreach ($arrFieldAtt as $k=>$v) {
//处理部门、员工、附件、多选类型字段 $param[$v] = arrayToString($param[$v]);
$arrFieldAtt = $fieldModel->getArrayField('crm_customer'); }
foreach ($arrFieldAtt as $k=>$v) { $param['follow'] = '已跟进';
$param[$v] = arrayToString($param[$v]); if ($this->update($param, ['customer_id' => $customer_id], true)) {
} //修改记录
$param['follow'] = '已跟进'; updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param);
if ($this->update($param, ['customer_id' => $customer_id], true)) { $data = [];
//修改记录 $data['customer_id'] = $customer_id;
updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param); return $data;
$data = []; } else {
$data['customer_id'] = $customer_id; $this->error = '编辑失败';
return $data; return false;
} else { }
$this->error = '编辑失败'; }
return false;
}
}
/** /**
* 客户数据 * 客户数据
@ -495,7 +491,11 @@ class Customer extends Common
$primaryId = Db::name('crm_contacts')->where(['customer_id' => $id, 'primary' => 1])->value('contacts_id'); $primaryId = Db::name('crm_contacts')->where(['customer_id' => $id, 'primary' => 1])->value('contacts_id');
$dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0; $dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0;
# 处理时间格式 # 处理时间格式
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null; $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;

@ -14,6 +14,7 @@ class Invoice extends Common
{ {
protected $name = 'crm_invoice'; protected $name = 'crm_invoice';
protected $pk = 'invoice_id'; protected $pk = 'invoice_id';
protected $dateFormat = "Y-m-d H:i:s";
/** /**
* 关联用户模型 * 关联用户模型

@ -90,7 +90,7 @@ class Leads extends Common
if (!is_array($map['leads.owner_user_id'][1])) { if (!is_array($map['leads.owner_user_id'][1])) {
$map['leads.owner_user_id'][1] = [$map['leads.owner_user_id'][1]]; $map['leads.owner_user_id'][1] = [$map['leads.owner_user_id'][1]];
} }
if ($map['leads.owner_user_id'][0] == 'neq') { if (in_array($map['leads.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['leads.owner_user_id'][1]) ?: []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['leads.owner_user_id'][1]) ?: []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['leads.owner_user_id'][1], $auth_user_ids) ?: []; //取交集 $auth_user_ids = array_intersect($map['leads.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
@ -104,6 +104,7 @@ class Leads extends Common
$indexField = $fieldModel->getIndexField('crm_leads', $user_id, 1) ?: array('name'); $indexField = $fieldModel->getIndexField('crm_leads', $user_id, 1) ?: array('name');
$userField = $fieldModel->getFieldByFormType('crm_leads', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_leads', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_leads', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_leads', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
@ -139,10 +140,15 @@ class Leads extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val . '_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val . '_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
}
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
} }
//权限 //权限
$permission = []; $permission = [];
@ -156,8 +162,6 @@ class Leads extends Common
$permission['is_update'] = $is_update; $permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete; $permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission; $list[$k]['permission'] = $permission;
# 下次联系时间
$list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注 # 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['leads_id'], 'type' => 'crm_leads']; $starWhere = ['user_id' => $user_id, 'target_id' => $v['leads_id'], 'type' => 'crm_leads'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id'); $star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -210,9 +214,6 @@ class Leads extends Common
$param[$v] = arrayToString($param[$v]); $param[$v] = arrayToString($param[$v]);
} }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
if ($this->data($param)->allowField(true)->isUpdate(false)->save()) { if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
//修改记录 //修改记录
updateActionLog($param['create_user_id'], 'crm_leads', $this->leads_id, '', '', '创建了线索'); updateActionLog($param['create_user_id'], 'crm_leads', $this->leads_id, '', '', '创建了线索');
@ -276,9 +277,6 @@ class Leads extends Common
return false; return false;
} }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_leads'); $arrFieldAtt = $fieldModel->getArrayField('crm_leads');
foreach ($arrFieldAtt as $k => $v) { foreach ($arrFieldAtt as $k => $v) {
@ -323,7 +321,11 @@ class Leads extends Common
$starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_leads'])->value('star_id'); $starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_leads'])->value('star_id');
$dataInfo['star'] = !empty($starId) ? 1 : 0; $dataInfo['star'] = !empty($starId) ? 1 : 0;
# 处理时间格式处理 # 处理时间格式处理
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null; $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;

@ -87,7 +87,7 @@ class Product extends Common
if (!is_array($map['product.owner_user_id'][1])) { if (!is_array($map['product.owner_user_id'][1])) {
$map['product.owner_user_id'][1] = [$map['product.owner_user_id'][1]]; $map['product.owner_user_id'][1] = [$map['product.owner_user_id'][1]];
} }
if ($map['product.owner_user_id'][0] == 'neq') { if (in_array($map['product.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['product.owner_user_id'][1]) ?: []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['product.owner_user_id'][1]) ?: []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['product.owner_user_id'][1], $auth_user_ids) ?: []; //取交集 $auth_user_ids = array_intersect($map['product.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
@ -102,6 +102,7 @@ class Product extends Common
$indexField = $fieldModel->getIndexField('crm_product', $user_id, 1) ? : ['name']; $indexField = $fieldModel->getIndexField('crm_product', $user_id, 1) ? : ['name'];
$userField = $fieldModel->getFieldByFormType('crm_product', 'user'); //人员类型 $userField = $fieldModel->getFieldByFormType('crm_product', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_product', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_product', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_product', 'datetime'); //日期时间类型
//排序 //排序
if ($order_type && $order_field) { if ($order_type && $order_field) {
@ -113,14 +114,14 @@ class Product extends Common
$join = [ $join = [
['__CRM_PRODUCT_CATEGORY__ product_category', 'product_category.category_id = product.category_id', 'LEFT'], ['__CRM_PRODUCT_CATEGORY__ product_category', 'product_category.category_id = product.category_id', 'LEFT'],
]; ];
$map['product.delete_user_id']=0;
$list = db('crm_product')->alias('product') $list = db('crm_product')->alias('product')
->join($join) ->join($join)
->where($map) ->where($map)
->where($authMap) ->where($authMap)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field($indexField) ->field($indexField)
->field(array_merge($indexField, ['product_category.name' => 'category_name'])) ->field('product.*,product_category.name as category_name')
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
$dataCount = db('crm_product')->alias('product') $dataCount = db('crm_product')->alias('product')
@ -132,11 +133,16 @@ class Product extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
} }
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
//产品类型 //产品类型
$list[$k]['category_id_info'] = $v['category_name']; $list[$k]['category_id_info'] = $v['category_name'];
# 处理日期格式 # 处理日期格式
@ -160,16 +166,18 @@ class Product extends Common
{ {
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$productCategoryModel = model('ProductCategory'); $productCategoryModel = model('ProductCategory');
// 自动验证 $dataInfo = db('crm_product')->where(['name'=>$param['name'],'delete_user_id'=>0])->find();
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则 if(isset($dataInfo)){
$validate = new Validate($validateArr['rule'], $validateArr['message']); // 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$result = $validate->check($param); $validate = new Validate($validateArr['rule'], $validateArr['message']);
if (!$result) {
$this->error = $validate->getError(); $result = $validate->check($param);
return false; if (!$result) {
} $this->error = $validate->getError();
return false;
}
}
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_product'); $arrFieldAtt = $fieldModel->getArrayField('crm_product');
foreach ($arrFieldAtt as $k=>$v) { foreach ($arrFieldAtt as $k=>$v) {
@ -211,6 +219,7 @@ class Product extends Common
*/ */
public function updateDataById($param, $product_id = '') public function updateDataById($param, $product_id = '')
{ {
$userModel = new \app\admin\model\User();
$dataInfo = $this->getDataById($product_id); $dataInfo = $this->getDataById($product_id);
$productCategoryModel = model('ProductCategory'); $productCategoryModel = model('ProductCategory');
if (!$dataInfo) { if (!$dataInfo) {
@ -232,15 +241,16 @@ class Product extends Common
} }
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 自动验证 // 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则 // $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']); // $validate = new Validate($validateArr['rule'], $validateArr['message']);
//
// $result = $validate->check($param);
// if (!$result) {
// $this->error = $validate->getError();
// return false;
// }
$result = $validate->check($param);
if (!$result) {
$this->error = $validate->getError();
return false;
}
//处理部门、员工、附件、多选类型字段 //处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_product'); $arrFieldAtt = $fieldModel->getArrayField('crm_product');
@ -250,17 +260,16 @@ class Product extends Common
//产品分类 //产品分类
$category_id = $param['category_id']; $category_id = $param['category_id'];
if (is_array($category_id)) { // if (is_array($category_id)) {
$param['category_id'] = $productCategoryModel->getIdByStr($category_id); // $param['category_id'] = $productCategoryModel->getIdByStr($category_id);
$param['category_str'] = arrayToString($category_id); // $param['category_str'] = arrayToString($category_id);
} // }
if(!is_int($category_id)){ if(!is_int($category_id)){
$list=db('crm_product_category')->column('category_id','name'); $list=db('crm_product_category')->column('category_id','name');
$param['category_id']=1;
foreach ($list as $k=>$v){ foreach ($list as $k=>$v){
if($k==$param['category_id']){ if($k==$category_id){
$param['category_id']=$v; $param['category_id']=$v;
}else{
$param['category_id']=0;
} }
} }
} }
@ -289,6 +298,7 @@ class Product extends Common
public function getDataById($id = '') public function getDataById($id = '')
{ {
$map['product_id'] = $id; $map['product_id'] = $id;
$map['delete_user_id'] = 0;
$dataInfo = db('crm_product')->where($map)->find(); $dataInfo = db('crm_product')->where($map)->find();
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '暂无此数据'; $this->error = '暂无此数据';
@ -304,6 +314,11 @@ class Product extends Common
$dataInfo['create_user_id_info'] = $userModel->getUserById($dataInfo['create_user_id']); $dataInfo['create_user_id_info'] = $userModel->getUserById($dataInfo['create_user_id']);
$dataInfo['category_id_info'] = db('crm_product_category')->where(['category_id' => $dataInfo['category_id']])->value('name'); $dataInfo['category_id_info'] = db('crm_product_category')->where(['category_id' => $dataInfo['category_id']])->value('name');
# 处理日期格式 # 处理日期格式
$fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_product', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo; return $dataInfo;
@ -320,19 +335,15 @@ class Product extends Common
*/ */
private function getProductImages($fileIds) private function getProductImages($fileIds)
{ {
$result = []; $files = Db::name('admin_file')->whereIn('file_id', $fileIds)->select();
$files = Db::name('admin_file')->field(['file_id', 'file_path_thumb', 'file_path', 'save_name'])->whereIn('file_id', $fileIds)->select();
foreach ($files AS $key => $value) { foreach ($files AS $key => $value) {
$result[] = [ $files[$key]['file_path'] = getFullPath($value['file_path']);
'file_id' => $value['file_id'], $files[$key]['file_path_thumb'] = getFullPath($value['file_path_thumb']);
'file_path_thumb' => getFullPath($value['file_path_thumb']), $files[$key]['size'] = format_bytes($value['size']);
'file_path' => getFullPath($value['file_path']),
'save_name' => $value['save_name']
];
} }
return $result; return $files;
} }
/** /**

@ -83,7 +83,7 @@ class Receivables extends Common
if (!is_array($map['receivables.owner_user_id'][1])) { if (!is_array($map['receivables.owner_user_id'][1])) {
$map['receivables.owner_user_id'][1] = [$map['receivables.owner_user_id'][1]]; $map['receivables.owner_user_id'][1] = [$map['receivables.owner_user_id'][1]];
} }
if ($map['receivables.owner_user_id'][0] == 'neq') { if (in_array($map['receivables.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['receivables.owner_user_id'][1]) ? : []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['receivables.owner_user_id'][1]) ? : []; //取差集
} else { } else {
$auth_user_ids = array_intersect($map['receivables.owner_user_id'][1], $auth_user_ids) ? : []; //取交集 $auth_user_ids = array_intersect($map['receivables.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@ -98,6 +98,7 @@ class Receivables extends Common
//人员类型 //人员类型
$userField = $fieldModel->getFieldByFormType('crm_receivables', 'user'); $userField = $fieldModel->getFieldByFormType('crm_receivables', 'user');
$structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
if ($request['order_type'] && $request['order_field']) { if ($request['order_type'] && $request['order_field']) {
$order = $fieldModel->getOrderByFormtype('crm_receivables','receivables',$order_field,$order_type); $order = $fieldModel->getOrderByFormtype('crm_receivables','receivables',$order_field,$order_type);
@ -134,7 +135,7 @@ class Receivables extends Common
->where($map) ->where($map)
->where($authMap) ->where($authMap)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field(implode(',',$indexField).',customer.name as customer_name,contract.name as contract_name,contract.num as contract_num,contract.money as contract_money') ->field('receivables.*,customer.name as customer_name,contract.name as contract_name,contract.num as contract_num,contract.money as contract_money')
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
@ -150,11 +151,16 @@ class Receivables extends Common
$list[$k]['contract_id_info']['money'] = $v['contract_money'] ? : '0.00'; $list[$k]['contract_id_info']['money'] = $v['contract_money'] ? : '0.00';
$list[$k]['contract_money'] = $v['contract_money'] ? : '0.00'; $list[$k]['contract_money'] = $v['contract_money'] ? : '0.00';
foreach ($userField as $key => $val) { foreach ($userField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
} }
foreach ($structureField as $key => $val) { foreach ($structureField as $key => $val) {
$list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : []; $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
} }
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
$list[$k]['check_status_info'] = $this->statusArr[$v['check_status']]; $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
//期数 //期数
$plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num'); $plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num');
@ -403,6 +409,11 @@ class Receivables extends Common
$dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : []; $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
$dataInfo['receivables_id'] = $id; $dataInfo['receivables_id'] = $id;
# 处理时间格式 # 处理时间格式
$fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
}
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo; return $dataInfo;

@ -236,7 +236,9 @@ class Event extends ApiCommon
$eventModel = model('Event'); $eventModel = model('Event');
$data = $eventModel->getDataById($this->param['event_id']); $data = $eventModel->getDataById($this->param['event_id']);
if(!$data['title']){
return resultArray(['error' => '日程已删除']);
}
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }

@ -468,7 +468,7 @@ class Examine extends ApiCommon
$is_end = 1; $is_end = 1;
//审批结束 //审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3; $checkData['check_status'] = !empty($status) ? 2 : 3;
$examineData['check_user_id'] = ''; // $examineData['check_user_id'] = '';
} else { } else {
//修改主体相关审批信息 //修改主体相关审批信息
$examineData['check_user_id'] = arrayToString($next_user_ids); $examineData['check_user_id'] = arrayToString($next_user_ids);
@ -484,7 +484,7 @@ class Examine extends ApiCommon
} }
if ($is_end == 1) { if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3; $checkData['check_status'] = !empty($status) ? 2 : 3;
$examineData['check_user_id'] = ''; // $examineData['check_user_id'] = '';
$examineData['check_status'] = 2; $examineData['check_status'] = 2;
} }
} else { } else {
@ -588,8 +588,9 @@ class Examine extends ApiCommon
$checkData['status'] = $status; $checkData['status'] = $status;
$examineData['check_status'] = 4; $examineData['check_status'] = 4;
$examineData['check_user_id'] = ''; # 如果将审批人置空,会导致普通员工在右上角消息中无法查看审批
$examineData['flow_user_id'] = ''; $examineData['check_user_id'] = $dataInfo['check_user_id'];
$examineData['flow_user_id'] = '';
$resExamine = db('oa_examine')->where(['examine_id' => $examine_id])->update($examineData); $resExamine = db('oa_examine')->where(['examine_id' => $examine_id])->update($examineData);
if ($resExamine) { if ($resExamine) {
//将审批记录至为无效 //将审批记录至为无效

@ -137,7 +137,6 @@ class Task extends ApiCommon
} else { } else {
$where['t.status'] = [['=', 1], ['=', 5], 'OR']; $where['t.status'] = [['=', 1], ['=', 5], 'OR'];
} }
if ($param['main_user_id']) { if ($param['main_user_id']) {
$where['t.main_user_id'] = $param['main_user_id']; $where['t.main_user_id'] = $param['main_user_id'];
} }
@ -160,19 +159,19 @@ class Task extends ApiCommon
if ($type != 0) { if ($type != 0) {
switch ($type) { switch ($type) {
case '1' : case '1' :
$type = 't.main_user_id in ('.$subStr.')'; $type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的 break; //下属负责的
case '3' : case '3' :
//使用正则查询 //使用正则查询
// SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)'; // SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)';
$type = $subValue ? 't.owner_user_id REGEXP "('.$subValue.')"' : ''; $type = $subValue ? 't.owner_user_id REGEXP "(' . $subValue . ')"' : '';
break; //下属参与的 break; //下属参与的
} }
} else { } else {
if (!$subValue) { if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))'; $type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} else { } else {
$type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "('.$subValue.')")'; $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "(' . $subValue . ')")';
} }
} }
// $where['t.work_id'] = 0; // $where['t.work_id'] = 0;
@ -195,13 +194,12 @@ class Task extends ApiCommon
$query->where($type); $query->where($type);
}) })
->count(); ->count();
$completeCount = db('task')->alias('t')
$completeCount = db('task') ->alias('t')->where($where)
->where($map) ->where($map)
->where(function ($query) use ($type) { ->where(function ($query) use ($type) {
$query->where($type); $query->where($type);
})->where('t.status', 5)->count(); })
->where($map)->where(['t.status' => 5, 't.ishidden' => 0, 'priority' => $priority])->count();
foreach ($taskList as $k => $v) { foreach ($taskList as $k => $v) {
$temp = $v ?: []; $temp = $v ?: [];
if ($v['pid']) { if ($v['pid']) {
@ -236,15 +234,15 @@ class Task extends ApiCommon
$type = 't.main_user_id =' . $userInfo['id'] . ''; $type = 't.main_user_id =' . $userInfo['id'] . '';
break; //我负责的 break; //我负责的
case '3' : case '3' :
$type = 't.owner_user_id like "%,'.$userInfo['id'].',%"'; $type = 't.owner_user_id like "%,' . $userInfo['id'] . ',%"';
break; //我参与的 break; //我参与的
} }
} else { } else {
$adminIds = $userModel->getAdminId(); $adminIds = $userModel->getAdminId();
if (in_array($userInfo['id'],$adminIds)) { if (in_array($userInfo['id'], $adminIds)) {
$type = 't.is_open = 1'; $type = 't.is_open = 1';
} else { } else {
$type = 't.is_open = 1 AND (t.main_user_id =' . $userInfo['id'] .' OR t.owner_user_id like "%,'.$userInfo['id'].',%")'; $type = 't.is_open = 1 AND (t.main_user_id =' . $userInfo['id'] . ' OR t.owner_user_id like "%,' . $userInfo['id'] . ',%")';
} }
} }
$where['t.ishidden'] = 0; $where['t.ishidden'] = 0;
@ -259,29 +257,31 @@ class Task extends ApiCommon
->order('t.task_id desc') ->order('t.task_id desc')
->select(); ->select();
$dataCount = db('task')->alias('t')->where($where)->where($type)->where($map)->count(); $dataCount = db('task')->alias('t')->where($where)->where($type)->where($map)->count();
$completeCount = db('task')->alias('t')->where($where)->where($type)->where($map)->where('t.status', 5)->count(); $completeCount = db('task')->alias('t')
->where($type)
->where($map)->where(['t.status' => 5, 't.ishidden' => 0, 'priority' => $priority])->count();
foreach ($taskList as $key => $value) { foreach ($taskList as $key => $value) {
$pname = ''; $pname = '';
if ($value['pid']) { if ($value['pid']) {
$pname = Db::name('Task')->where('task_id ='.$value['pid'])->value('name'); $pname = Db::name('Task')->where('task_id =' . $value['pid'])->value('name');
} }
$taskList[$key]['pname'] = $pname ? : ''; $taskList[$key]['pname'] = $pname ?: '';
$taskList[$key]['thumb_img'] = $value['thumb_img'] ? getFullPath($value['thumb_img']) : ''; $taskList[$key]['thumb_img'] = $value['thumb_img'] ? getFullPath($value['thumb_img']) : '';
$taskList[$key]['subcount'] = Db::name('Task')->where(['ishidden' => 0,'status' => 1,'pid' => $value['task_id']])->count(); //子任务 $taskList[$key]['subcount'] = Db::name('Task')->where(['ishidden' => 0, 'status' => 1, 'pid' => $value['task_id']])->count(); //子任务
$taskList[$key]['subdonecount'] = Db::name('Task')->where(['ishidden' => 0,'status' => 5,'pid' => $value['task_id']])->count(); //已完成子任务 $taskList[$key]['subdonecount'] = Db::name('Task')->where(['ishidden' => 0, 'status' => 5, 'pid' => $value['task_id']])->count(); //已完成子任务
$taskList[$key]['commentcount'] = Db::name('AdminComment')->where(['type' => 'task','type_id' => $value['task_id']])->count(); $taskList[$key]['commentcount'] = Db::name('AdminComment')->where(['type' => 'task', 'type_id' => $value['task_id']])->count();
$taskList[$key]['filecount'] = Db::name('WorkTaskFile')->where('task_id ='.$value['task_id'])->count(); $taskList[$key]['filecount'] = Db::name('WorkTaskFile')->where('task_id =' . $value['task_id'])->count();
$taskList[$key]['lableList'] = $value['lable_id'] ? $lableModel->getDataByStr($value['lable_id']) : []; $taskList[$key]['lableList'] = $value['lable_id'] ? $lableModel->getDataByStr($value['lable_id']) : [];
$taskList[$key]['create_time'] = date('Y-m-d', $value['create_time']) ?: ''; $taskList[$key]['create_time'] = date('Y-m-d', $value['create_time']) ?: '';
$taskList[$key]['update_time'] = date('Y-m-d', $value['update_time']) ?: ''; $taskList[$key]['update_time'] = date('Y-m-d', $value['update_time']) ?: '';
$taskList[$key]['start_time'] = $value['start_time']==0?null:date('Y-m-d', $value['start_time']);; $taskList[$key]['start_time'] = $value['start_time'] == 0 ? null : date('Y-m-d', $value['start_time']);;
$taskList[$key]['stop_time'] = $value['stop_time']==0?null:date('Y-m-d', $value['stop_time']); $taskList[$key]['stop_time'] = $value['stop_time'] == 0 ? null : date('Y-m-d', $value['stop_time']);
//负责人信息 //负责人信息
$taskList[$key]['main_user'] = $value['main_user_id'] ? $userModel->getDataById($value['main_user_id']) : array(); $taskList[$key]['main_user'] = $value['main_user_id'] ? $userModel->getDataById($value['main_user_id']) : array();
$taskList[$key]['relationCount'] = $taskModel->getRelationCount($value['task_id']); $taskList[$key]['relationCount'] = $taskModel->getRelationCount($value['task_id']);
$is_end = 0; $is_end = 0;
if (!empty($value['stop_time']) && (strtotime(date('Ymd'))+86399 > $value['stop_time'])) $is_end = 1; if (!empty($value['stop_time']) && (strtotime(date('Ymd')) + 86399 > $value['stop_time'])) $is_end = 1;
$taskList[$key]['is_end'] = $is_end; $taskList[$key]['is_end'] = $is_end;
} }
} }

@ -11,6 +11,192 @@ class ExamineLogic extends Common
{ {
private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回']; private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回'];
public function getDataList($request)
{
$userModel = new \app\admin\model\User();
$fileModel = new \app\admin\model\File();
$recordModel = new \app\admin\model\Record();
$examine_by = $request['examine_by']; //1待我审批 2我已审批 all 全部
$user_id = $request['user_id'];
$bi = $request['bi_types'];
$check_status = $request['check_status']; //0 待审批 2 审批通过 4 审批拒绝 all 全部
unset($request['by']);
unset($request['bi_types']);
unset($request['user_id']);
unset($request['check_status']);
unset($request['examine_by']);
$request = $this->fmtRequest($request);
$map = $request['map'] ?: [];
if (isset($map['search']) && $map['search']) {
//普通筛选
$map['examine.content'] = ['like', '%' . $map['search'] . '%'];
} else {
$map = where_arr($map, 'oa', 'examine', 'index'); //高级筛选
}
unset($map['search']);
//审批类型
$map['examine.category_id'] = $map['examine.category_id'] ?: array('gt', 0);
$map_str = '';
$logmap = '';
switch ($examine_by) {
case 'all' :
//如果超管则能看到全部
if (!isSuperAdministrators($user_id)) {
$map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " ) OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
}
break;
case '1' :
$map['check_user_id'] = [['like', '%,' . $user_id . ',%']];
break; //待审
case '2' :
$map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " )
OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
// $map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or'];
break; //已审
default:
$map['examine.create_user_id'] = $user_id;
break;
}
$order = 'examine.create_time desc,examine.update_time desc';
//发起时间
if ($map['examine.between_time'][0] && $map['examine.between_time'][1]) {
$start_time = $map['examine.between_time'][0];
$end_time = $map['examine.between_time'][1];
$map['examine.create_time'] = array('between', array($start_time, $end_time));
}
unset($map['examine.between_time']);
//审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部
if (isset($check_status)) {
if ($check_status == 'all') {
$map['examine.check_status'] = ['egt', 0];
if (isSuperAdministrators($user_id)) {
unset($map['examine.create_user_id']);
}
} elseif ($check_status == 4) {
$map['examine.check_status'] = ['eq', 3];
} elseif ($check_status == 0) {
$map['examine.check_status'] = ['<=', 1];
} else {
$map['examine.check_status'] = $check_status;
}
} else {
if ($examine_by == 'all') {
$map['examine.check_status'] = ['egt', 0];
} elseif ($examine_by == 1) {
$map['examine.check_status'] = ['elt', 1];
} elseif ($examine_by == 2) {
$map['examine.check_status'] = ['egt', 2];
}
}
$join = [
['__ADMIN_USER__ user', 'user.id = examine.create_user_id', 'LEFT'],
['__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT'],
];
$list_view = db('oa_examine')
->alias('examine')
->where($map_str)
->where($map)
->join($join);
$res = [];
$list = $list_view
->page($request['page'], $request['limit'])
->field('examine.*,user.realname,user.thumb_img,examine_category.title as category_name,examine_category.category_id as examine_config,examine_category.icon as examineIcon')
->order($order)
->select();
foreach ($list as $k => $v) {
$causeCount = 0;
$causeTitle = '';
$duration = $v['duration'] ?: '0.0';
$money = $v['money'] ?: '0.00';
$list[$k]['causeTitle'] = $causeTitle;
$list[$k]['causeCount'] = $causeCount ?: 0;
$item = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->select();
if ($item) {
foreach ($item as $key => $value) {
if($v['check_status']==4){
$usernames = '';
}else{
$usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
}
//关联业务
$relationArr = [];
$relationArr = $recordModel->getListByRelationId('examine', $v['examine_id']);
$item[$key]['relation'] = arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['contactsList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['contractList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['customerList'], 'name'));
$res[] = [
'category_name' => $v['category_name'],
'create_time' => !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null,
'realname' => $v['realname'],
'check_status_info' => $this->statusArr[(int)$v['check_status']],
'examine_name' => implode($usernames, ''),
'content' => $v['content'],
'remark' => $v['remark'],
'duration' => $v['duration'],
'vehicle' => $value['vehicle'],
'trip' => $value['trip'],
'money' => $value['money'],
'traffic' => $value['traffic'],
'stay' => $value['stay'],
'diet' => $value['diet'],
'other' => $value['other'],
'start_address' => $value['start_address'],
'end_address' => $value['end_address'],
'start_time' => !empty($value['start_time']) ? date('Y-m-d H:i:s', $value['start_time']) : null,
'end_time' => !empty($value['end_time']) ? date('Y-m-d H:i:s', $value['end_time']) : null,
'description' => $value['description'],
'replyList' => str_replace(',', ' ', $item[$key]['relation']),
];
}
} else {
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['start_time'] = !empty($v['start_time']) ? date('Y-m-d H:i:s', $v['start_time']) : null;
$list[$k]['end_time'] = !empty($v['end_time']) ? date('Y-m-d H:i:s', $v['end_time']) : null;
if($v['check_status']==4){
$usernames = '';
}else{
$usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
}
//关联业务
$relationArr = [];
$relationArr = $recordModel->getListByRelationId('examine', $v['examine_id']);
$list[$k]['relation'] = arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['contactsList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['contractList'], 'name')) . ' ' .
arrayToString(array_column($relationArr['customerList'], 'name'));
$res[] = [
'category_name' => $v['category_name'],
'create_time' => !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null,
'realname' => $v['realname'],
'check_status_info' => $this->statusArr[(int)$v['check_status']],
'examine_name' => implode($usernames, ''),
'content' => $v['content'],
'remark' => $v['remark'],
'duration' => $v['duration'],
'vehicle' => '',
'money' => $v['money'],
'traffic' => '',
'stay' => '',
'diet' => '',
'other' => '',
'start_address' => '',
'end_address' => '',
'start_time' => !empty($v['start_time']) ? date('Y-m-d H:i:s', $v['start_time']) : null,
'end_time' => !empty($v['end_time']) ? date('Y-m-d H:i:s', $v['end_time']) : null,
'description' => '',
'replyList' => str_replace(',', ' ', $item[$key]['relation']),
];
}
}
return $res;
}
/** /**
* 审批导出 * 审批导出
* @param $param * @param $param
@ -19,33 +205,123 @@ class ExamineLogic extends Common
public function excelExport($param) public function excelExport($param)
{ {
$excelModel = new \app\admin\model\Excel(); $excelModel = new \app\admin\model\Excel();
$field_list1 = [ $data = $this->getDataList($param);
array('name' => '审批类型', 'field' => 'category_name', 'form_type' => 'text'), $list = [];
array('name' => '创建时间', 'field' => 'create_time', 'form_type' => ''), switch ($param['category_id']) {
array('name' => '创建人', 'field' => 'create_user_id', 'form_type' => 'user'), case '1' :
array('name' => '状态', 'field' => 'check_status_info','form_type' => ''), $field_list = [
array('name' => '当前审批人', 'field' => 'check_user_id','form_type' => 'userStr'), '0' => ['name' => '审批类型', 'field' => 'category_name'],
// array('name' => '下一审批人', 'field' => 'last_user_id','form_type' => 'user'), '1' => ['name' => '创建时间', 'field' => 'create_time'],
// array('name' => '关联业务', 'field' => 'relation','form_type' => ''), '2' => ['name' => '创建人', 'field' => 'realname'],
]; '3' => ['name' => '状态', 'field' => 'check_status_info'],
// 导出的字段列表 '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
$fieldModel = new \app\admin\model\Field(); '5' => ['name' => '备注', 'field' => 'description'],
$field_list = $fieldModel->getIndexFieldConfig('oa_examine', $param['user_id'], $param['category_id']); '6' => ['name' => '关联业务', 'field' => 'replyList'],
];
break;
case '2' :
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname'],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '审批内容', 'field' => 'content'],
'6' => ['name' => '开始时间', 'field' => 'start_time'],
'7' => ['name' => '结束时间', 'field' => 'end_time'],
'8' => ['name' => '时长', 'field' => 'duration'],
'9' => ['name' => '备注', 'field' => 'description'],
'10' => ['name' => '关联业务', 'field' => 'replyList'],
];
break;
case '3' :
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname'],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '出差事由', 'field' => 'content'],
'6' => ['name' => '备注', 'field' => 'remark'],
'7' => ['name' => '出差总天数', 'field' => 'duration'],
'8' => ['name' => '交通工具', 'field' => 'vehicle'],
'9' => ['name' => '单程往返', 'field' => 'trip'],
'10' => ['name' => '出发城市', 'field' => 'start_address'],
'11' => ['name' => '目的城市', 'field' => 'end_address'],
'12' => ['name' => '开始时间', 'field' => 'start_time'],
'13' => ['name' => '结束时间', 'field' => 'end_time'],
'14' => ['name' => '出差备注', 'field' => 'description'],
'15' => ['name' => '时长', 'field' => 'duration'],
'16' => ['name' => '关联业务', 'field' => 'replyList'],
];
break;
case '4' :
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname',],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '加班原因', 'field' => 'content'],
'6' => ['name' => '开始时间', 'field' => 'start_time'],
'7' => ['name' => '结束时间', 'field' => 'end_time'],
'8' => ['name' => '加班总天数', 'field' => 'duration'],
'9' => ['name' => '备注', 'field' => 'description'],
'10' => ['name' => '关联业务', 'field' => 'replyList'],
];
break;
case '5':
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname'],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '差旅内容', 'field' => 'content'],
'6' => ['name' => '报销总金额', 'field' => 'money'],
'7' => ['name' => '备注', 'field' => 'remark'],
'8' => ['name' => '出发城市', 'field' => 'start_address'],
'9' => ['name' => '目的城市', 'field' => 'end_address'],
'10' => ['name' => '开始时间', 'field' => 'start_time'],
'11' => ['name' => '结束时间', 'field' => 'end_time'],
'12' => ['name' => '交通费', 'field' => 'traffic'],
'13' => ['name' => '住宿费', 'field' => 'stay'],
'14' => ['name' => '餐饮费', 'field' => 'diet'],
'15' => ['name' => '其他费用', 'field' => 'other'],
'16' => ['name' => '合计', 'field' => 'money'],
'17' => ['name' => '费用明细描述', 'field' => 'description'],
'18' => ['name' => '关联业务', 'field' => 'relation'],
];
break;
case '6' :
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname'],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '借款事由', 'field' => 'content'],
'6' => ['name' => '开始时间', 'field' => 'start_time'],
'7' => ['name' => '结束时间', 'field' => 'end_time'],
'8' => ['name' => '借款金额', 'field' => 'money'],
'9' => ['name' => '备注', 'field' => 'description'],
'10' => ['name' => '关联业务', 'field' => 'replyList'],
];
break;
default :
$field_list = [
'0' => ['name' => '审批类型', 'field' => 'category_name'],
'1' => ['name' => '创建时间', 'field' => 'create_time'],
'2' => ['name' => '创建人', 'field' => 'realname'],
'3' => ['name' => '状态', 'field' => 'check_status_info'],
'4' => ['name' => '当前审批人', 'field' => 'examine_name'],
'5' => ['name' => '备注', 'field' => 'description'],
'6' => ['name' => '关联业务', 'field' => 'replyList'],
];
}
$file_name = 'oa_examine'; $file_name = 'oa_examine';
$temp_file = $param['temp_file']; return $excelModel->dataExportCsv($file_name, $field_list, $data);
unset($param['temp_file']);
$page = $param['page'] ?: 1;
$model = model('Examine');
$field_list = array_merge_recursive($field_list1, $field_list);
return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
$param['page'] = $page;
$param['limit'] = $limit;
$data = $model->getDataList($param);
// $newData['list'] = $model->exportHandle($data['page']['list'], $field_list, 'oa_examine');
$newData['list'] = $data['page']['list'];
return $newData;
});
} }
/** /**
@ -65,9 +341,9 @@ class ExamineLogic extends Common
$query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']); $query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
}; };
} elseif ($param['status'] == 1) { } elseif ($param['status'] == 1) {
$where['a.check_status'] = ['in', [2,3]]; $where['a.check_status'] = ['in', [2, 3]];
$whereOr = function ($query) use ( $user_id) { $whereOr = function ($query) use ($user_id) {
$query->where('a.check_user_id',['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']); $query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
}; };
} elseif ($param['status'] == 3) { } elseif ($param['status'] == 3) {
$where['a.check_status'] = ['lt', 5]; $where['a.check_status'] = ['lt', 5];

@ -38,15 +38,8 @@ class LogLogic extends Common
public function getDataList($request) public function getDataList($request)
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure();
$fileModel = new \app\admin\model\File();
$commonModel = new \app\admin\model\Comment(); $commonModel = new \app\admin\model\Comment();
$BusinessModel = new \app\crm\model\Business();
$ContactsModel = new \app\crm\model\Contacts();
$ContractModel = new \app\crm\model\Contract();
$CustomerModel = new \app\crm\model\Customer();
$recordModel = new \app\admin\model\Record(); $recordModel = new \app\admin\model\Record();
$user_id = $request['read_user_id']; $user_id = $request['read_user_id'];
$by = $request['by'] ?: ''; $by = $request['by'] ?: '';
@ -78,44 +71,39 @@ class LogLogic extends Common
} }
$requestData = $this->requestData(); $requestData = $this->requestData();
//获取权限范围内的员工 //获取权限范围内的员工
//获取权限范围内的员工
$auth_user_ids = getSubUserId(); $auth_user_ids = getSubUserId();
if ($request['send_user_id'] && !in_array(trim(arrayToString($request['send_user_id']), ','), $auth_user_ids)) { $dataWhere['user_id'] = $user_id;
$map['log.create_user_id'] = $user_id; $dataWhere['structure_id'] = $request['structure_id'];
} else { $dataWhere['auth_user_ids'] = $auth_user_ids;
if ($request['send_user_id'] && in_array(trim(arrayToString($request['send_user_id']), ','), $auth_user_ids)) { $logMap = '';
$map['log.create_user_id'] = ['in', trim(arrayToString($request['send_user_id']), ',')]; if ($request['send_user_id'] != '') {
$map['log.send_user_ids'] = ['like', '%,' . $request['read_user_id'] . ',%']; $map['log.create_user_id'] = ['in', trim(arrayToString($request['send_user_id']), ',')];
} else { }
$dataWhere['user_id'] = $user_id; switch ($by) {
$dataWhere['structure_id'] = $request['structure_id']; case 'me' :
$dataWhere['auth_user_ids'] = $auth_user_ids; $map['log.create_user_id'] = $user_id;
$logMap = ''; break;
switch ($by) { case 'other':
case 'me' : $logMap = function ($query) use ($dataWhere) {
$map['log.create_user_id'] = $user_id; $query->where('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
break; ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
case 'other': };
$logMap = function ($query) use ($dataWhere) { break;
$query->where('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%')) default :
->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%')); $logMap = function ($query) use ($dataWhere) {
}; $query->where('log.create_user_id', array('in', implode(',', $dataWhere['auth_user_ids'])))
break; ->whereOr('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
default : ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
$logMap = function ($query) use ($dataWhere) { };
$query->where('log.create_user_id', array('in', implode(',', $dataWhere['auth_user_ids']))) break;
->whereOr('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
};
break;
}
}
} }
$list = Db::name('OaLog') $list = Db::name('OaLog')
->where($map) ->where($map)
->where($logMap)
->where($searchMap) ->where($searchMap)
->alias('log') ->alias('log')
->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT') ->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT')
->page($request['page'], $request['limit'])
->field('log.*,user.realname') ->field('log.*,user.realname')
->order('log.update_time desc') ->order('log.update_time desc')
->select(); ->select();
@ -651,11 +639,8 @@ class LogLogic extends Common
/** /**
* 销售简报跟进数量统计 * 销售简报跟进数量统计
* @param $param *
* @return array * @param $param 参数
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function activityCount($param) public function activityCount($param)
{ {
@ -665,17 +650,18 @@ class LogLogic extends Common
if (empty($param['log_id'])) { if (empty($param['log_id'])) {
$between_time = [$start_time['start_time'], $start_time['end_time']]; $between_time = [$start_time['start_time'], $start_time['end_time']];
$map['create_time'] = array('between', $between_time); $map['create_time'] = array('between', $between_time);
$map['create_user_id'] =$user_id;
} else { } else {
$start_time = strtotime(date("Y-m-d", $item['create_time'])); $start_time = strtotime(date("Y-m-d", $item['create_time']));
$end_time = strtotime(date("Y-m-d H:i:s", $item['create_time'])); $end_time = strtotime(date("Y-m-d H:i:s", $item['create_time']));
$between_time = [$start_time, $end_time]; $between_time = [$start_time, $end_time];
$map['create_time'] = array('between', $between_time); $map['create_time'] = array('between', $between_time);
$map['create_user_id'] = $item['create_user_id'];
} }
$map['status']=1; $map['status']=1;
$typesList = ['1', '2', '3', '5', '6']; $typesList = ['1', '2', '3', '5', '6'];
foreach ($typesList as $k => $v) { foreach ($typesList as $k => $v) {
$activityData = db('crm_activity')->where($map)->where(['create_user_id' => $item['create_user_id'], 'type' => 1, 'activity_type' => $v])->count(); $activityData = db('crm_activity')->where($map)->where(['type' => 1, 'activity_type' => $v])->count();
if($v==1){ if($v==1){
$arr[$k]['types'] ='crm_leads'; $arr[$k]['types'] ='crm_leads';
$arr[$k]['activity_type'] =1; $arr[$k]['activity_type'] =1;
@ -693,7 +679,6 @@ class LogLogic extends Common
$arr[$k]['activity_type'] =6; $arr[$k]['activity_type'] =6;
} }
$arr[$k]['dataCount'] = $activityData; $arr[$k]['dataCount'] = $activityData;
} }
$data = $arr; $data = $arr;
return $data; return $data;

@ -15,7 +15,7 @@ class TaskLogic
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$taskModel = new TaskModel(); $taskModel = new TaskModel();
$recordModel = new \app\admin\model\Record(); $recordModel = new \app\admin\model\Record();
$str = ','.$param['user_id'].','; $str = ',' . $param['user_id'] . ',';
//自定义时间 //自定义时间
$map['t.stop_time'] = $param['dueDate'] ? strtotime($param['dueDate'] . ' +1 month -1 day') : ['>=', 0]; $map['t.stop_time'] = $param['dueDate'] ? strtotime($param['dueDate'] . ' +1 month -1 day') : ['>=', 0];
@ -56,9 +56,9 @@ class TaskLogic
$where = []; $where = [];
$where['ishidden'] = 0; $where['ishidden'] = 0;
$where['pid'] = 0; $where['pid'] = 0;
$where['whereStr'] = ' ( task.create_user_id =' . $param['user_id'] . ' or ( task.owner_user_id like "%,'.$param['user_id'].',%") or ( task.main_user_id = '.$param['user_id'].' ) )'; $where['whereStr'] = ' ( task.create_user_id =' . $param['user_id'] . ' or ( task.owner_user_id like "%,' . $param['user_id'] . ',%") or ( task.main_user_id = ' . $param['user_id'] . ' ) )';
if (!empty($this->param['search'])) { if (!empty($this->param['search'])) {
$where['taskSearch'] = ' and (task.name like "%'.$this->param['search'].'%" OR task.description like "%'.$this->param['search'].'%")'; $where['taskSearch'] = ' and (task.name like "%' . $this->param['search'] . '%" OR task.description like "%' . $this->param['search'] . '%")';
} }
# 截止日期 # 截止日期
$timeWhere = $this->getTimeParam($param['time_type']); $timeWhere = $this->getTimeParam($param['time_type']);
@ -76,7 +76,6 @@ class TaskLogic
->join('AdminUser u', 'u.id = t.main_user_id', 'LEFT') ->join('AdminUser u', 'u.id = t.main_user_id', 'LEFT')
->field('t.task_id,t.name as task_name,t.main_user_id,t.description,t.priority,t.stop_time,t.create_time,t.owner_user_id,t.start_time,t.create_user_id,u.realname as main_user_name,t.is_top') ->field('t.task_id,t.name as task_name,t.main_user_id,t.description,t.priority,t.stop_time,t.create_time,t.owner_user_id,t.start_time,t.create_user_id,u.realname as main_user_name,t.is_top')
->where($where) ->where($where)
->where($whereStr)
->where($timeWhere) ->where($timeWhere)
->where($labelWhere) ->where($labelWhere)
->order('t.task_id desc') ->order('t.task_id desc')
@ -96,19 +95,19 @@ class TaskLogic
if ($type != 0) { if ($type != 0) {
switch ($type) { switch ($type) {
case '1' : case '1' :
$type = 't.main_user_id in ('.$subStr.')'; $type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的 break; //下属负责的
case '3' : case '3' :
//使用正则查询 //使用正则查询
// SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)'; // SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)';
$type = $subValue ? 't.owner_user_id REGEXP "('.$subValue.')"' : ''; $type = $subValue ? 't.owner_user_id REGEXP "(' . $subValue . ')"' : '';
break; //下属参与的 break; //下属参与的
} }
} else { } else {
if (!$subValue) { if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))'; $type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} else { } else {
$type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "('.$subValue.')")'; $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "(' . $subValue . ')")';
} }
} }
$map['t.pid'] = 0; $map['t.pid'] = 0;
@ -126,7 +125,7 @@ class TaskLogic
->where($map) ->where($map)
->order('t.task_id desc') ->order('t.task_id desc')
->select(); ->select();
} else { } else {
$map['t.pid'] = 0; $map['t.pid'] = 0;
// $map['t.work_id'] = 0; // $map['t.work_id'] = 0;
if ($type != 0) { if ($type != 0) {
@ -135,15 +134,15 @@ class TaskLogic
$type = 't.main_user_id =' . $param['user_id'] . ''; $type = 't.main_user_id =' . $param['user_id'] . '';
break; //我负责的 break; //我负责的
case '3' : case '3' :
$type = 't.owner_user_id like "%,'.$param['user_id'].',%"'; $type = 't.owner_user_id like "%,' . $param['user_id'] . ',%"';
break; //我参与的 break; //我参与的
} }
} else { } else {
$adminIds = $userModel->getAdminId(); $adminIds = $userModel->getAdminId();
if (in_array($param['user_id'],$adminIds)) { if (in_array($param['user_id'], $adminIds)) {
$type = 't.is_open = 1'; $type = 't.is_open = 1';
} else { } else {
$type = 't.is_open = 1 AND (t.main_user_id =' . $param['user_id'] .' OR t.owner_user_id like "%,'.$param['user_id'].',%")'; $type = 't.is_open = 1 AND (t.main_user_id =' . $param['user_id'] . ' OR t.owner_user_id like "%,' . $param['user_id'] . ',%")';
} }
} }
$where['t.ishidden'] = 0; $where['t.ishidden'] = 0;
@ -154,7 +153,6 @@ class TaskLogic
->where($where) ->where($where)
->where($type) ->where($type)
->where($map) ->where($map)
->page($param['page'], $param['limit'])
->order('t.task_id desc') ->order('t.task_id desc')
->select(); ->select();
} }
@ -185,7 +183,7 @@ class TaskLogic
//创建时间 //创建时间
$taskList[$key]['create_time'] = $value['create_time'] ? date('Y-m-d H:i:s', $value['create_time']) : ''; $taskList[$key]['create_time'] = $value['create_time'] ? date('Y-m-d H:i:s', $value['create_time']) : '';
//开始时间 //开始时间
$taskList[$key]['start_time'] = $value['start_time'] ? date('Y-m-d H:i:s', $value['start_time']) : ''; $taskList[$key]['start_time'] = $value['start_time'] ? date('Y-m-d H:i:s', $value['start_time']) : '';
//结束时间 //结束时间
$taskList[$key]['stop_time'] = $value['stop_time'] ? date('Y-m-d H:i:s', $value['stop_time']) : ''; $taskList[$key]['stop_time'] = $value['stop_time'] ? date('Y-m-d H:i:s', $value['stop_time']) : '';
//优先级 //优先级

@ -27,42 +27,49 @@ class UserLogic
$initials_type = ($param['initials'] == 1) ? 1 : 2; $initials_type = ($param['initials'] == 1) ? 1 : 2;
$where['user.status'] = 1; $where['user.status'] = 1;
if ($search) { if ($search) {
$where = function ($query) use ($search) { $whereMap = function ($query) use ($search) {
$query->where('user.realname', array('like', '%' . $search . '%')) $query->where('user.realname', array('like', '%' . $search . '%'))
->whereOr('user.mobile', array('like', '%' . $search . '%')); ->whereOr('user.mobile', array('like', '%' . $search . '%'));
}; };
} }
if ($param['star_type'] == 1) { if($param['structure_id']){
$item = Db::name('crm_star')->where('user_id', $user_id)->column('target_id'); $where['user.id']= $param['structure_id'];
$where['user.id'] = ['in', $item]; }
} if (isset($param['star_type'])) {
if ($param['structure_id'] == '') { if ($param['star_type'] == 1) {
$list = Db::name('admin_user') $item = Db::name('crm_star')->where(['user_id'=>$user_id,'type'=>'admin_user'])->column('target_id');
->alias('user') if(!empty($item)) {
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT') $where['user.id'] = ['in', $item];
->where($where) $list = Db::name('admin_user')
->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile') ->alias('user')
->page($param['page'], $param['limit']) ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->select(); ->where($where)
->where($whereMap)
foreach ($list as $k => $v) { ->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile')
$starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user']; ->page($param['page'], $param['limit'])
$star = Db::name('crm_star')->where($starWhere)->value('star_id'); ->select();
$list[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : ''; foreach ($list as $k => $v) {
$list[$k]['star'] = !empty($star) ? 1 : 0; $starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
$list[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
$list[$k]['star'] = !empty($star) ? 1 : 0;
}
$dataCount = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
->count();
$newarray = $this->groupByInitials($list, 'realname', $initials_type);
}else{
return false;
}
} }
$dataCount = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
->count();
$newarray = $this->groupByInitials($list, 'realname', $initials_type);
} else { } else {
$list = Db::name('admin_user') $list = Db::name('admin_user')
->alias('user') ->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT') ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where) ->where($where)
->where('structure.id', $param['structure_id']) ->where($whereMap)
->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name') ->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name')
->page($param['page'], $param['limit']) ->page($param['page'], $param['limit'])
->select(); ->select();
@ -70,7 +77,6 @@ class UserLogic
->alias('user') ->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT') ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where) ->where($where)
->where('structure.id', $param['structure_id'])
->count(); ->count();
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user']; $starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user'];

@ -56,33 +56,30 @@ class Event extends Common
OR ( ( end_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) ) OR ( ( end_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )
OR ( start_time < ' . $start_time . ' AND end_time > ' . $end_time . ' AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )'; OR ( start_time < ' . $start_time . ' AND end_time > ' . $end_time . ' AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )';
$event_date = Db::name('OaEvent')->where($where)->select(); $event_date = Db::name('OaEvent')->where($where)->select();
foreach ($event_date as $k=>$v) {
foreach ($event_date as $k => $v) {
$event_date[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']); $event_date[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
$event_date[$k]['ownerList'] = $userModel->getDataByStr($v['owner_user_ids']) ?: []; $event_date[$k]['ownerList'] = $userModel->getDataByStr($v['owner_user_ids']) ? : [];
$relationArr = []; $relationArr= [];
$relationArr = $recordModel->getListByRelationId('event', $v['event_id']); $relationArr = $recordModel->getListByRelationId('event', $v['event_id']);
$event_date[$k]['businessList'] = $relationArr['businessList']; $event_date[$k]['businessList'] = $relationArr['businessList'];
$event_date[$k]['contactsList'] = $relationArr['contactsList']; $event_date[$k]['contactsList'] = $relationArr['contactsList'];
$event_date[$k]['contractList'] = $relationArr['contractList']; $event_date[$k]['contractList'] = $relationArr['contractList'];
$event_date[$k]['customerList'] = $relationArr['customerList']; $event_date[$k]['customerList'] = $relationArr['customerList'];
$event_date[$k]['type'] = 'event';
$event_date[$k]['remindtype'] = (int)$v['remindtype']; $event_date[$k]['remindtype'] = (int)$v['remindtype'];
$noticeInfo = Db::name('OaEventNotice')->where(['event_id' => $v['event_id']])->find(); $noticeInfo = Db::name('OaEventNotice')->where(['event_id' => $v['event_id']])->find();
$is_repeat = 0; $is_repeat = 0;
if ($noticeInfo) { if ($noticeInfo) {
$is_repeat = 1; $is_repeat = 1;
} }
$color = db('admin_oa_schedule')->where('schedule_id', $v['schedule_id'])->find();
$event_date[$k]['color'] = $color['color'];
$event_date[$k]['is_repeat'] = $is_repeat; $event_date[$k]['is_repeat'] = $is_repeat;
$event_date[$k]['stop_time'] = $noticeInfo ? $noticeInfo['stop_time'] : ''; $event_date[$k]['stop_time'] = $noticeInfo ? $noticeInfo['stop_time'] : '';
$event_date[$k]['noticetype'] = $noticeInfo ? $noticeInfo['noticetype'] : ''; $event_date[$k]['noticetype'] = $noticeInfo ? $noticeInfo['noticetype'] : '';
if ($noticeInfo['noticetype'] == '2') { if ($noticeInfo['noticetype'] == '2') {
$event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||', $noticeInfo['repeated']) : []; $event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||',$noticeInfo['repeated']) : [];
} else { } else {
$event_date[$k]['repeat'] = ''; $event_date[$k]['repeat'] = '';
} }
//权限 //权限
$is_update = 0; $is_update = 0;
@ -93,15 +90,13 @@ class Event extends Common
} }
$permission['is_update'] = $is_update; $permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete; $permission['is_delete'] = $is_delete;
$event_date[$k]['permission'] = $permission; $event_date[$k]['permission'] = $permission;
$event_date[$k]['start_time'] = !empty($v['start_time']) ? $v['start_time'] * 1000 : null; $event_date[$k]['start_time'] = !empty($v['start_time']) ? $v['start_time'] * 1000 : null;
$event_date[$k]['end_time'] = !empty($v['end_time']) ? $v['end_time'] * 1000 : null; $event_date[$k]['end_time'] = !empty($v['end_time']) ? $v['end_time'] * 1000 : null;
$event_date[$k]['type_id'] = $v['schedule_id']; $event_date[$k]['type_id'] = $v['schedule_id'];
} }
return $event_date ? : [];
return $event_date ?: [];
} }
/** /**
@ -174,7 +169,7 @@ class Event extends Common
$between_time = '((next_time BETWEEN ' . $start_time . ' AND ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ')) $between_time = '((next_time BETWEEN ' . $start_time . ' AND ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . '))
OR ((next_time > ' . $start_time . ' AND next_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id =' . $user_id . ')) OR ((next_time > ' . $start_time . ' AND next_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id =' . $user_id . '))
OR ((next_time > ' . $start_time . ' AND next_time > ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . '))'; OR ((next_time > ' . $start_time . ' AND next_time > ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . '))';
$event_date = db('crm_customer')->where(['next_time'=> ['>', 0],'owner_user_id'=>['<>',0]])->where($between_time)->where('') $event_date = db('crm_customer')->where(['next_time' => ['>', 0], 'owner_user_id' => ['<>', 0]])->where($between_time)->where('')
->field('next_time as start_time,customer_id,name ')->group('start_time')->select(); ->field('next_time as start_time,customer_id,name ')->group('start_time')->select();
$item = []; $item = [];
foreach ($event_date as $k2 => $v) { foreach ($event_date as $k2 => $v) {
@ -780,9 +775,9 @@ class Event extends Common
# 关联数据 # 关联数据
$relation = []; $relation = [];
if (!empty($param['customer_ids'])) $relation['customer_ids'] = arrayToString($param['customer_ids']); if (!empty($param['customer_ids'])) $relation['customer_ids'] = arrayToString($param['customer_ids']);
if (!empty($param['contacts_ids'])) $relation['contacts_ids'] = arrayToString($param['customer_ids']); if (!empty($param['contacts_ids'])) $relation['contacts_ids'] = arrayToString($param['contacts_ids']);
if (!empty($param['business_ids'])) $relation['business_ids'] = arrayToString($param['customer_ids']); if (!empty($param['business_ids'])) $relation['business_ids'] = arrayToString($param['business_ids']);
if (!empty($param['contract_ids'])) $relation['contract_ids'] = arrayToString($param['customer_ids']); if (!empty($param['contract_ids'])) $relation['contract_ids'] = arrayToString($param['contract_ids']);
# 提醒数据 # 提醒数据
@ -799,12 +794,12 @@ class Event extends Common
$eventId = $this->event_id; $eventId = $this->event_id;
actionLog($event_id, $param['owner_user_ids'], '', '修改了日程'); actionLog($event_id, $param['owner_user_ids'], '', '修改了日程');
$list = db('oa_event_notice')->where('event_id', $eventId)->select(); $list = db('oa_event_notice')->where('event_id', $eventId)->select();
$item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete(); if ($list) {
if (!$item) {
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
Db::name('admin_message')->where(['type' => 9, 'action_id' => $v['id']])->delete(); Db::name('admin_message')->where(['type' => 9, 'action_id' => $v['id']])->delete();
} }
} }
$item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete();
# 提醒 # 提醒
if (!empty($notice)) { if (!empty($notice)) {
$noticeData = []; $noticeData = [];
@ -822,40 +817,47 @@ class Event extends Common
'stop_time' => $param['end_time'] 'stop_time' => $param['end_time']
]; ];
} }
if (!empty($noticeData)) Db::name('oa_event_notice')->insertAll($noticeData); if (!empty($noticeData)) {
$item = Db::name('oa_event_notice')->insertAll($noticeData);
if ($item) {
$item = Db::name('oa_event_notice')->where('event_id', $eventId)->select();
foreach ($item as $val) {
if ($value['noticetype'] == '1') { //分
$dd = strtotime($param['start_time']) - ($val['number'] * 60);
} else if ($val['noticetype'] == '2') { //时
$dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60);
} else if ($val['noticetype'] == '3') {//天
$dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60 * 24);
}
// 站内信
(new Message())->send(
Message::EVENT_MESSAGE,
[
'title' => $param['title'],
'action_id' => $val['id'],
'advance_time' => $dd ?: 0
],
stringToArray($param['owner_user_ids'])
);
}
}
}
} }
if (!$item) {
$item = Db::name('OaEventNotice')->where('event_id', $eventId)->select();
foreach ($item as $val) {
if ($value['noticetype'] == '1') { //分
$dd = strtotime($param['start_time']) - ($val['number'] * 60);
} else if ($val['noticetype'] == '2') { //时
$dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60);
} else if ($val['noticetype'] == '3') {//天
$dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60 * 24);
}
// 站内信
(new Message())->send(
Message::EVENT_MESSAGE,
[
'title' => $param['title'],
'action_id' => $val['id'],
'advance_time' => $dd ?: 0
],
array_diff(stringToArray($param['owner_user_ids']), stringToArray($dataInfo['owner_user_ids']))
);
$data['event_id'] = $event_id;
if (Db::name('OaEventRelation')->where(['event_id' => $event_id])->find()) {
Db::name('OaEventRelation')->where(['event_id' => $event_id])->update($relation);
} else {
if (!empty($relation)) {
$relation['event_id'] = $eventId;
$relation['status'] = 1;
$relation['create_time'] = time();
Db::name('OaEventRelation')->where(['event_id' => $event_id])->insert($relation);
} }
} }
$data['event_id'] = $event_id;
Db::name('OaEventRelation')->where(['event_id' => $event_id])->update([
'customer_ids' => trim($relation['customer_ids'], ','),
'contacts_ids' => trim($relation['contacts_ids'], ','),
'business_ids' => trim($relation['business_ids'], ','),
'contract_ids' => trim($relation['contract_ids'], ','),
]);
return $data; return $data;
} else { } else {
$this->error = '编辑失败'; $this->error = '编辑失败';

@ -23,7 +23,7 @@ class Examine extends Common
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
private $statusArr = ['待审核','审核中','审核通过','已拒绝','已撤回']; private $statusArr = ['待审核', '审核中', '审核通过', '已拒绝', '已撤回'];
/** /**
* [getDataList 审批list] * [getDataList 审批list]
@ -41,8 +41,10 @@ class Examine extends Common
$examine_by = $request['examine_by']; //1待我审批 2我已审批 all 全部 $examine_by = $request['examine_by']; //1待我审批 2我已审批 all 全部
$user_id = $request['user_id']; $user_id = $request['user_id'];
$bi = $request['bi_types'];
$check_status = $request['check_status']; //0 待审批 2 审批通过 4 审批拒绝 all 全部 $check_status = $request['check_status']; //0 待审批 2 审批通过 4 审批拒绝 all 全部
unset($request['by']); unset($request['by']);
unset($request['bi_types']);
unset($request['user_id']); unset($request['user_id']);
unset($request['check_status']); unset($request['check_status']);
unset($request['examine_by']); unset($request['examine_by']);
@ -56,7 +58,7 @@ class Examine extends Common
} }
unset($map['search']); unset($map['search']);
//审批类型 //审批类型
$map['examine.category_id'] = $map['examine.category_id'] ? : array('gt', 0); $map['examine.category_id'] = $map['examine.category_id'] ?: array('gt', 0);
$map_str = ''; $map_str = '';
$logmap = ''; $logmap = '';
@ -71,7 +73,9 @@ class Examine extends Common
$map['check_user_id'] = [['like', '%,' . $user_id . ',%']]; $map['check_user_id'] = [['like', '%,' . $user_id . ',%']];
break; //待审 break; //待审
case '2' : case '2' :
$map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or']; $map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " )
OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
// $map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or'];
break; //已审 break; //已审
default: default:
$map['examine.create_user_id'] = $user_id; $map['examine.create_user_id'] = $user_id;
@ -87,7 +91,7 @@ class Examine extends Common
unset($map['examine.between_time']); unset($map['examine.between_time']);
//审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部 //审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部
if ($check_status) { if (isset($check_status)) {
if ($check_status == 'all') { if ($check_status == 'all') {
$map['examine.check_status'] = ['egt', 0]; $map['examine.check_status'] = ['egt', 0];
if (isSuperAdministrators($user_id)) { if (isSuperAdministrators($user_id)) {
@ -95,13 +99,20 @@ class Examine extends Common
} }
} elseif ($check_status == 4) { } elseif ($check_status == 4) {
$map['examine.check_status'] = ['eq', 3]; $map['examine.check_status'] = ['eq', 3];
} elseif ($check_status == 0) {
$map['examine.check_status'] = ['<=', 1];
} else { } else {
$map['examine.check_status'] = $check_status; $map['examine.check_status'] = $check_status;
} }
} else { }else{
$map['examine.check_status'] = ['egt', 0]; if ($examine_by == 'all') {
$map['examine.check_status'] = ['egt', 0];
} elseif ($examine_by == 1) {
$map['examine.check_status'] = ['elt', 1];
} elseif($examine_by == 2) {
$map['examine.check_status'] = ['egt', 2];
}
} }
$join = [ $join = [
['__ADMIN_USER__ user', 'user.id = examine.create_user_id', 'LEFT'], ['__ADMIN_USER__ user', 'user.id = examine.create_user_id', 'LEFT'],
['__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT'], ['__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT'],
@ -131,7 +142,7 @@ class Examine extends Common
$duration = $v['duration'] ?: '0.0'; $duration = $v['duration'] ?: '0.0';
$money = $v['money'] ?: '0.00'; $money = $v['money'] ?: '0.00';
if (in_array($v['category_id'], ['3', '5'])) { if (in_array($v['category_id'], ['3', '5'])) {
$causeCount = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->count() ? : 0; $causeCount = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->count() ?: 0;
if ($v['category_id'] == 3) $causeTitle = $causeCount . '个行程,共' . $duration . '天'; if ($v['category_id'] == 3) $causeTitle = $causeCount . '个行程,共' . $duration . '天';
if ($v['category_id'] == 5) $causeTitle = $causeCount . '个报销事项,共' . $money . '元'; if ($v['category_id'] == 5) $causeTitle = $causeCount . '个报销事项,共' . $money . '元';
@ -155,7 +166,7 @@ class Examine extends Common
} }
$list[$k]['causeTitle'] = $causeTitle; $list[$k]['causeTitle'] = $causeTitle;
$list[$k]['causeCount'] = $causeCount ? : 0; $list[$k]['causeCount'] = $causeCount ?: 0;
//关联业务 //关联业务
$relationArr = []; $relationArr = [];
@ -210,25 +221,25 @@ class Examine extends Common
if ($examineFlowData['config'] == 1) { if ($examineFlowData['config'] == 1) {
//固定审批流 //固定审批流
$examineStepModel = new \app\admin\model\ExamineStep(); $examineStepModel = new \app\admin\model\ExamineStep();
$nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0); // $nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
$is_check = $nextStepData['next_user_ids'] ? 1 : 0; $is_check = in_array($user_id, stringToArray($v['check_user_id'])) && in_array($v['check_status'], [0, 1]) ? 1 : 0;
$is_end = 1; $is_end = 1;
} else { } else {
$is_end = 0; $is_end = 0;
if ($v['check_user_id'] == (',' . $user_id . ',')) { if ($v['check_user_id'] == (',' . $user_id . ',') && in_array($v['check_status'], [0, 1])) {
$is_check = 1; $is_check = 1;
}else{ } else {
$is_check = 0; $is_check = 0;
} }
} }
if ($v['last_user_id'] == 0) { if($v['check_status']==4){
$user_name = $userModel->getListByStr(stringToArray($v['check_user_id'])); $usernames = db('admin_user')->whereIn('id', stringToArray($user_id))->column('realname');
$list[$k]['examine_name'] = $user_name[0]['realname']; }else{
} else { $usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
$user_name = $userModel->getListByStr(stringToArray($v['last_user_id']));
$list[$k]['examine_name'] = $user_name[0]['realname'];
} }
$list[$k]['examine_name'] = implode($usernames, '');
$permission['is_check'] = $is_check; $permission['is_check'] = $is_check;
$permission['is_delete'] = $is_delete; $permission['is_delete'] = $is_delete;
$permission['is_recheck'] = $is_recheck; $permission['is_recheck'] = $is_recheck;
@ -236,7 +247,8 @@ class Examine extends Common
$list[$k]['permission'] = $permission; $list[$k]['permission'] = $permission;
$list[$k]['config'] = $is_end; $list[$k]['config'] = $is_end;
$list[$k]['check_status_info'] = $this->statusArr[(int)$v['check_status']]; $list[$k]['check_status_info'] = $this->statusArr[(int)$v['check_status']];
$list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']); $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
} }
$data = []; $data = [];
$data['page']['list'] = $list; $data['page']['list'] = $list;

@ -333,8 +333,8 @@ class Task extends ApiCommon
# 获取任务的项目信息 # 获取任务的项目信息
$workInfo = Db::name('work')->field(['work_id', 'group_id', 'is_open'])->where('work_id', $taskData['work_id'])->find(); $workInfo = Db::name('work')->field(['work_id', 'group_id', 'is_open'])->where('work_id', $taskData['work_id'])->find();
# 是否是公开项目 # 是否是公开项目
$userId = empty($workInfo['is_open']) ? $userInfo['id'] : 0; $userId = $userInfo['id'];
$groupId = !empty($workInfo['is_open']) ? $workInfo['group_id '] : 0; $groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
# 获取项目下的权限 # 获取项目下的权限
$taskData['auth'] = !empty($taskData['work_id']) ? $this->getRuleList($workInfo['work_id'], $userId, $groupId) : []; $taskData['auth'] = !empty($taskData['work_id']) ? $this->getRuleList($workInfo['work_id'], $userId, $groupId) : [];

@ -84,6 +84,9 @@ class Tasklable extends ApiCommon
$str = ','.$userInfo['id'].','; $str = ','.$userInfo['id'].',';
$param['whereStr'] = ' ( task.create_user_id ='.$userInfo['id'].' or ( task.owner_user_id like "%'.$str.'%") or ( task.main_user_id = '.$userInfo['id'].' ) )'; $param['whereStr'] = ' ( task.create_user_id ='.$userInfo['id'].' or ( task.owner_user_id like "%'.$str.'%") or ( task.main_user_id = '.$userInfo['id'].' ) )';
} }
# 标签列表只查询项目下的任务
$param['work_id'] = ['neq', 0];
$resData = $taskModel->getTaskList($param); $resData = $taskModel->getTaskList($param);
$taskList = $resData['list'] ? : []; $taskList = $resData['list'] ? : [];

@ -147,7 +147,7 @@ class work extends ApiCommon
$workInfo = $workModel->getDataById($this->param['work_id']); $workInfo = $workModel->getDataById($this->param['work_id']);
# 是否是公开项目 # 是否是公开项目
$userId = empty($workInfo['is_open']) ? $this->userInfo['id'] : 0; $userId = $this->userInfo['id'];
$groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0; $groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
# 项目成员 # 项目成员
@ -632,5 +632,25 @@ class work extends ApiCommon
return resultArray(['data' => '操作成功!']); return resultArray(['data' => '操作成功!']);
} }
/**
* 项目排序
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/2/23 0023 15:27
*/
// public function workStart(){
// $param=$this->param;
// $userInfo=$this->userInfo;
// $param['work']=serialize($param);
// $param['user_id']=$userInfo['id'];
// $workStart=new WorkLogic();
// $res=$workStart->workStart($param);
// if(!$res){
// return resultArray(['error'=>'操作失败']);
// }
// return resultArray(['data'=>'操作成功']);
// }
} }

@ -19,29 +19,29 @@ class WorkLogic
{ {
# 排序 # 排序
$orderField = 'work_id'; $orderField = 'work_id';
$orderSort = 'asc'; $orderSort = 'asc';
if (!empty($param['sort_type']) && $param['sort_type'] == 1) { if (!empty($param['sort_type']) && $param['sort_type'] == 1) {
$orderField = 'work_id'; $orderField = 'work_id';
$orderSort = 'asc'; $orderSort = 'asc';
} }
if (!empty($param['sort_type']) && $param['sort_type'] == 2) { if (!empty($param['sort_type']) && $param['sort_type'] == 2) {
$orderField = 'work_id'; $orderField = 'work_id';
$orderSort = 'desc'; $orderSort = 'desc';
} }
if (!empty($param['sort_type']) && $param['sort_type'] == 3) { if (!empty($param['sort_type']) && $param['sort_type'] == 3) {
$orderField = 'update_time'; $orderField = 'update_time';
$orderSort = 'desc'; $orderSort = 'desc';
} }
# 搜索 # 搜索
$searchWhere = ''; $searchWhere = '';
$dateWhere = []; $dateWhere = [];
$userWhere = []; $userWhere = [];
$ownerUserId = !empty($param['owner_user_id']) ? $param['owner_user_id'] : ''; $ownerUserId = !empty($param['owner_user_id']) ? $param['owner_user_id'] : '';
$search = !empty($param['search']) ? $param['search'] : ''; $search = !empty($param['search']) ? $param['search'] : '';
$type = !empty($param['type']) ? $param['type'] : 0; $type = !empty($param['type']) ? $param['type'] : 0;
$startTime = !empty($param['start_time']) ? $param['start_time'] : ''; $startTime = !empty($param['start_time']) ? $param['start_time'] : '';
$endTime = !empty($param['end_time']) ? $param['end_time'] : ''; $endTime = !empty($param['end_time']) ? $param['end_time'] : '';
unset($param['search']); unset($param['search']);
unset($param['type']); unset($param['type']);
unset($param['start_time']); unset($param['start_time']);
@ -72,7 +72,7 @@ class WorkLogic
# 时间区间 # 时间区间
if (!empty($startTime)) $dateWhere['update_time'] = ['egt', strtotime($startTime . '00:00:00')]; if (!empty($startTime)) $dateWhere['update_time'] = ['egt', strtotime($startTime . '00:00:00')];
if (!empty($endTime)) $dateWhere['update_time'] = ['elt', strtotime($endTime . '23:59:59')]; if (!empty($endTime)) $dateWhere['update_time'] = ['elt', strtotime($endTime . '23:59:59')];
# 搜索内容 # 搜索内容
if ($search) $searchWhere = '(name like "%' . $search . '%") OR (description like "%' . $search . '%")'; if ($search) $searchWhere = '(name like "%' . $search . '%") OR (description like "%' . $search . '%")';
@ -83,32 +83,122 @@ class WorkLogic
$userWhere['work_id'] = ['in', $userIds]; $userWhere['work_id'] = ['in', $userIds];
} }
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$perUserIds = $userModel->getUserByPer('work', 'work', 'index'); $perUserIds = $userModel->getUserByPer('work', 'work', 'index');
$authUser = array_unique(array_merge([$param['user_id']], $perUserIds)); $authUser = array_unique(array_merge([$param['user_id']], $perUserIds));
$data = Db::name('work') $data = Db::name('work')
->where(function($query) { ->where(function ($query) {
$query->where('status', 1); $query->where('status', 1);
$query->where('ishidden', 0); $query->where('ishidden', 0);
}) })
->where(function ($query) use ($param, $authUser) { ->where(function ($query) use ($param, $authUser) {
$query->whereOr(['create_user_id' => ['in', $authUser]]); $query->whereOr(['create_user_id' => ['in', $authUser]]);
$query->whereOr('is_open', 1); $query->whereOr('is_open', 1);
$query->whereOr(function ($query) use ($param) { $query->whereOr(function ($query) use ($param) {
$query->where('is_open', 0); $query->where('is_open', 0);
$query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%'); $query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%');
}); });
}) })
->where($searchWhere) ->where($searchWhere)
->where($dateWhere) ->where($dateWhere)
->where($userWhere) ->where($userWhere)
->order($orderField, $orderSort)->select(); ->order($orderField, $orderSort)->select();
foreach ($data AS $key => $value) { foreach ($data as $key => $value) {
$data[$key]['authList']['project'] = $this->getRuleList($value['work_id'], $param['user_id'], $value['group_id']); $data[$key]['authList']['project'] = $this->getRuleList($value['work_id'], $param['user_id'], $value['group_id']);
} }
return $data; return $data;
} }
/**
* @param $param work 排序数组值 user_id用户
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/2/23 15:42
*/
// public function workStart($param)
// {
// $item = Db::name('workStart')->where('user_id', $param['user_id'])->find();
// $data = [];
// $data['datas'] = $param['work'];
// $data['user_id'] = $param['user_id'];
// if (!$item) {
// return Db::name('workStart')->insertGetId($data);
// } else {
// return Db::name('workStart')->where('user_id', $param['user_id'])->update([$data]);
// }
// }
/**
* 根据数组指定键名排序数组
* @param $array array 被排序数组
* @param $key_name string 数组键名
* @param $sort string desc|asc 升序或者降序
* @return array 返回排序后的数组
*/
// function gw_sort($array, $param)
// {
// $whilr = array
// (
// [0] => ['work_id' => 5,
// 'name' => 222,
// 'status' => 1,
// 'create_time' => 1613628469,
// 'create_user_id' => 7,
// 'description' => 222,
// 'color' => '#53D397',
// 'is_open' => 1,
// 'owner_user_id' => ',1,2,3,4,5,7,',
// 'ishidden' => 0,
// 'archive_time' => 0,
// 'group_id' => 12,
// 'cover_url' => 'http://192.168.1.31/72crm-php/public/uploads/20210218/12ece02733c8684ce987f207062173b5.png',
// 'update_time' => 1613629916,
// 'is_follow' => 0,
// 'is_system_cover' => 0,],
//
// [1] => [
//
// 'work_id' => 7,
// 'name' => '啊啊',
// 'status' => 1,
// 'create_time' => 1614059388,
// 'create_user_id' => 1,
// 'description' => '',
// 'color' => '#53D397',
// 'is_open' => 0,
// 'owner_user_id' => ',1,3,',
// 'ishidden' => 0,
// 'archive_time' => 0,
// 'group_id' => 12,
// 'cover_url' => 'https://file.72crm.com/static/pc/images/pm/project-cover-1.jpg',
// 'update_time' => 1614059926,
// 'is_follow' => 0,
// 'is_system_cover' => 1,
// ]
//
// );
// $item = Db::name('workStart')->where('user_id', $param['user_id'])->find();
// $key_name_array = array();//保存被排序数组键名
// foreach ($whilr as $key => $val) {
// foreach ($item as $v){
// $key_name_array[] = array_merge(array_flip($val), $v);
// }
// }
// $key_name_array = array_flip($key_name_array);//反转键名和值得到数组排序后的位置
// $result = array();
// foreach($array as $k=>$v){
// foreach ($item as $vall){
// $this_key_name_value = $v[$vall];//当前数组键名值依次是20,10,30
// $save_position = $key_name_array[$this_key_name_value];//获取20,10,30排序后存储位置
// $result[$save_position] = $v;//当前项存储到数组指定位置
// }
// }
// ksort($result);
//
// return $result;
// }
} }

@ -50,6 +50,7 @@ class Task extends Common
$workModel = model('Work'); $workModel = model('Work');
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$work_id = $request['work_id']; $work_id = $request['work_id'];
$map=[];
$ret = $workModel->checkWork($work_id, $user_id); $ret = $workModel->checkWork($work_id, $user_id);
if (!$ret) { if (!$ret) {
$this->error = $workModel->getError(); $this->error = $workModel->getError();
@ -69,10 +70,6 @@ class Task extends Common
$newList = $classList['list']; $newList = $classList['list'];
} }
if ($request['main_user_id']) {
$map['main_user_id'] = ['in', $request['main_user_id']];
}
//截止时间
if ($request['stop_time_type']) { if ($request['stop_time_type']) {
if ($request['stop_time_type'] == '5') { //没有截至日期 if ($request['stop_time_type'] == '5') { //没有截至日期
$map['stop_time'] = '0'; $map['stop_time'] = '0';
@ -104,6 +101,7 @@ class Task extends Common
$map['stop_time'] = ['between', [$timeAry[0], $timeAry[1]]]; $map['stop_time'] = ['between', [$timeAry[0], $timeAry[1]]];
} }
} }
if ($request['lable_id']) { if ($request['lable_id']) {
$taskIds = []; $taskIds = [];
$task_ids = []; $task_ids = [];
@ -125,18 +123,20 @@ class Task extends Common
} }
$map['task_id'] = ['in', $task_ids]; $map['task_id'] = ['in', $task_ids];
} }
$data = array(); $data = array();
foreach ($newList as $key => $value) { foreach ($newList as $key => $value) {
$data[$key]['class_id'] = $value['class_id'] ?: -1; $data[$key]['class_id'] = $value['class_id'] ?: -1;
$data[$key]['class_name'] = $value['name']; $data[$key]['class_name'] = $value['name'];
$map['status'] = $map['status'] ?: ['in', ['1', '5']]; $map['status'] = $map['status'] ?: ['in', ['1', '5']];
$map['ishidden'] = 0; $map['ishidden'] = 0;
$map['work_id'] = $request['work_id']; $map['work_id'] = $request['work_id'];
$map['class_id'] = $value['class_id']; $map['class_id'] = $value['class_id'];
$map['pid'] = 0; $map['pid'] = 0;
$map['is_archive'] = 0; $map['is_archive'] = 0;
$map['main_user_id']=$request['main_user_id'];
$taskList = []; $taskList = [];
$resTaskList = $this->getTaskList($map); $resTaskList = $this->getTaskList($map);
$data[$key]['count'] = $resTaskList['count']; $data[$key]['count'] = $resTaskList['count'];
@ -414,7 +414,7 @@ class Task extends Common
unset($param[$value]); unset($param[$value]);
} }
$main_user_id = $param['main_user_id'] ?: $param['create_user_id']; $main_user_id = $param['main_user_id'] ?: $param['create_user_id'];
$param['owner_user_id'] = ','.$main_user_id.','; //参与人
$param['main_user_id'] = $main_user_id; //负责人 $param['main_user_id'] = $main_user_id; //负责人
$param['start_time'] = !empty($param['start_time']) ? strtotime($param['start_time']) : 0; $param['start_time'] = !empty($param['start_time']) ? strtotime($param['start_time']) : 0;
$param['stop_time'] = !empty($param['stop_time']) ? strtotime($param['stop_time']) : 0; $param['stop_time'] = !empty($param['stop_time']) ? strtotime($param['stop_time']) : 0;
@ -443,14 +443,14 @@ class Task extends Common
//操作日志 //操作日志
actionLog($task_id, '', '', '新建了任务'); actionLog($task_id, '', '', '新建了任务');
//抄送站内信 //抄送站内信
// (new Message())->send( (new Message())->send(
// Message::TASK_ALLOCATION, Message::TASK_ALLOCATION,
// [ [
// 'title' => $param['name'], 'title' => $param['name'],
// 'action_id' => $task_id 'action_id' => $task_id
// ], ],
// $param['owner_user_id'] trim(',',$param['owner_user_id'])
// ); );
} }
# 添加活动记录 # 添加活动记录
@ -642,14 +642,14 @@ class Task extends Common
//设置负责人 //设置负责人
$userdet = $userModel->getDataById($param['main_user_id']); $userdet = $userModel->getDataById($param['main_user_id']);
$data['after'] = '设定' . $userdet['realname'] . '为主要负责人!'; $data['after'] = '设定' . $userdet['realname'] . '为主要负责人!';
// (new Message())->send( (new Message())->send(
// Message::TASK_ALLOCATION, Message::TASK_ALLOCATION,
// [ [
// 'title' => $taskInfo['name'], 'title' => $taskInfo['name'],
// 'action_id' => $param['task_id'] 'action_id' => $param['task_id']
// ], ],
// $param['main_user_id'] $param['main_user_id']
// ); );
break; break;
} }
@ -899,15 +899,17 @@ class Task extends Common
*/ */
public function getTaskList($request) public function getTaskList($request)
{ {
$search = $request['search'];
$search = $request['search']?:'';
$whereStr = $request['whereStr'] ?: []; $whereStr = $request['whereStr'] ?: [];
$lable_id = $request['lable_id'] ?: ''; $lable_id = $request['lable_id'] ?: '';
$main_user_id = $request['main_user_id'] ?: '';
$taskSearch = !empty($request['taskSearch']) ? $request['taskSearch'] : ''; $taskSearch = !empty($request['taskSearch']) ? $request['taskSearch'] : '';
$isArchive = !empty($request['is_archive']) ? $request['is_archive'] : 0; $isArchive = !empty($request['is_archive']) ? $request['is_archive'] : 0;
unset($request['search']); // unset($request['search']);
unset($request['whereStr']); // unset($request['whereStr']);
unset($request['lable_id']); // unset($request['lable_id']);
unset($request['taskSearch']); unset($request['main_user_id']);
$request = $this->fmtRequest($request); $request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: []; $requestMap = $request['map'] ?: [];
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
@ -924,6 +926,13 @@ class Task extends Common
} }
$dataCount = db('task')->alias('task')->where($map)->where($whereStr)->where($taskSearch)->count(); $dataCount = db('task')->alias('task')->where($map)->where($whereStr)->where($taskSearch)->count();
$taskList = []; $taskList = [];
$logWhere='';
if ($main_user_id) {
foreach ($main_user_id as $key => $value) {
$logWhere.= '( task.owner_user_id like "%,' . $value . ',%") OR ';
}
if (!empty($logWhere)) $logWhere = '(' . rtrim($logWhere, 'OR ') . ')';
}
if ($dataCount) { if ($dataCount) {
$taskList = db('task') $taskList = db('task')
->alias('task') ->alias('task')
@ -932,6 +941,7 @@ class Task extends Common
->field('task.task_id,task.name,task.main_user_id,task.is_top,task.work_id,task.lable_id,task.priority,task.stop_time,task.status,task.pid,task.create_time,task.owner_user_id,u.realname as main_user_name,u.thumb_img,w.name as work_name,color') ->field('task.task_id,task.name,task.main_user_id,task.is_top,task.work_id,task.lable_id,task.priority,task.stop_time,task.status,task.pid,task.create_time,task.owner_user_id,u.realname as main_user_name,u.thumb_img,w.name as work_name,color')
->where($map) ->where($map)
->where($whereStr) ->where($whereStr)
->where($logWhere)
->where($taskSearch) ->where($taskSearch)
->order('task.status asc,task.order_id asc') ->order('task.status asc,task.order_id asc')
->select(); ->select();
@ -1036,7 +1046,6 @@ class Task extends Common
->where($labelWhere) ->where($labelWhere)
->order($order) ->order($order)
->select(); ->select();
foreach ($taskList as $key => $value) { foreach ($taskList as $key => $value) {
if ($value['pid'] > 0) { if ($value['pid'] > 0) {
$p_det = $this->field('task_id,name')->where(['task_id' => $value['pid']])->find(); $p_det = $this->field('task_id,name')->where(['task_id' => $value['pid']])->find();
@ -1084,35 +1093,38 @@ class Task extends Common
# 今天 # 今天
if ($type == 1) { if ($type == 1) {
$result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')'; $result = '(task.stop_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' AND task.stop_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')';
} }
# 明天 # 明天
if ($type == 2) { if ($type == 2) {
$tomorrow = date("Y-m-d 23:59:59", strtotime("+1 day")); $tomorrow = date("Y-m-d 23:59:59", strtotime("+1 day"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime($tomorrow) . ')'; $start = date("Y-m-d 00:00:00", strtotime("+1 day"));
$result = '(task.stop_time >= ' . strtotime($start) . ' AND task.stop_time <= ' . strtotime($tomorrow) . ')';
} }
# 本周 # 本周
if ($type == 3) { if ($type == 3) {
$week = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y")); $week = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . $week . ')'; $start_week=mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
$result = '(task.stop_time >= ' . $start_week . ' AND task.stop_time <= ' . $week . ')';
} }
# 本月 # 本月
if ($type == 4) { if ($type == 4) {
$timestamp = mktime(0, 0, 0, date('m'), 1, date('Y'));
$month = mktime(23, 59, 59, date("m"), date("t"), date("Y")); $month = mktime(23, 59, 59, date("m"), date("t"), date("Y"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . $month . ')'; $result = '(task.stop_time > ' . $timestamp . ' AND task.stop_time <= ' . $month . ')';
} }
# 未设置截止日期 # 未设置截止日期
if ($type == 5) { if ($type == 5) {
$result = $result = '(task.stop_time = 0)';; $result = '(task.stop_time = 0)';;
} }
# 已延期 # 已延期
if ($type == 6) { if ($type == 6) {
$result = '(task.status = 2 OR task.stop_time >= ' . time() . ')'; $result = '(task.status = 2 OR task.stop_time < ' . time() . ')'.'AND task.stop_time <> 0 AND task.status = 1';
} }
# 今日更新 # 今日更新

@ -75,6 +75,7 @@ class Work extends Common
$ownerData['work_id'] = $workId; $ownerData['work_id'] = $workId;
$ownerData['create_user_id'] = $createUserId; $ownerData['create_user_id'] = $createUserId;
$ownerData['owner_user_id'] = $ownerUserId; $ownerData['owner_user_id'] = $ownerUserId;
$ownerData['group_id'] = !empty($param['group_id']) ? $param['group_id'] : 0;
# 创建项目下的相关成员 # 创建项目下的相关成员
$this->addOwner($ownerData); $this->addOwner($ownerData);
@ -129,6 +130,10 @@ class Work extends Common
$ownerData['is_open'] = $param['is_open']; $ownerData['is_open'] = $param['is_open'];
$ownerData['group_id'] = $param['group_id']; $ownerData['group_id'] = $param['group_id'];
$this->addOwner($ownerData); $this->addOwner($ownerData);
}
# 公开项目更新时的权限变更
if ($param['is_open'] == 1 && !empty($param['group_id']) && $param['group_id'] != $workInfo['group_id']) {
db('work_user')->where(['work_id' => $workInfo['work_id'], 'user_id' => ['neq', $workInfo['create_user_id']]])->update(['group_id' => $param['group_id']]);
} }
$resUpdata = $this->where($map)->update($param); $resUpdata = $this->where($map)->update($param);
if ($resUpdata) { if ($resUpdata) {
@ -307,7 +312,7 @@ class Work extends Common
$group_id = 1; $group_id = 1;
} else { } else {
# 默认角色 # 默认角色
$group_id = db('admin_group')->where(['pid' => 5, 'system' => 1])->order('id asc')->value('id'); $group_id = !empty($param['group_id']) ? $param['group_id'] : db('admin_group')->where(['pid' => 5, 'system' => 1])->order('id asc')->value('id');
} }
$data['group_id'] = $group_id; $data['group_id'] = $group_id;
$saveData[] = $data; $saveData[] = $data;

@ -265,5 +265,8 @@ return [
// 商业智能查询缓存时间(秒) // 商业智能查询缓存时间(秒)
'bi_cache_time' => 1800, 'bi_cache_time' => 1800,
// 商业智能慢查询查询时间(查询超过该时间进行数据缓存)(毫秒) // 商业智能慢查询查询时间(查询超过该时间进行数据缓存)(毫秒)
'bi_slow_query_time' => 500 'bi_slow_query_time' => 500,
'public_key' => '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkqKFcAQtIp4rlkB5LOMnViyVY/hhA6x0R9ftwtEXsAFu4hBZrm9txdEvxSrDCUsx3Zwv/gdimeOzTtfSKffdoE/DwllNP9Zu6nsr2kGRgPrRwjtlO+j2FOM0b9UY1SQ/bWE+a9oQL2jL9xMSbtX1xG/+HcMo1bT+pa6FNQzs3egmvMt75/jaxINPSraj4kgNFawSBk7qDBEqDYiQwtPTuaNW1YZIs++/gZHsCRgGs/JrAbxNpl7+v/+Z503I3I2rs/8eUM5d16NXR8M7vtobUDCTIiQOgRahO8WMadgFlwavyVCYhy/TBXyj5RUfWaS26LrEN3vkj4TjoJu5m9LQ5QIDAQAB
-----END PUBLIC KEY-----',
]; ];

@ -15,6 +15,7 @@ return [
'admin/install/step2' => ['admin/install/step2', ['method' => 'GET']], 'admin/install/step2' => ['admin/install/step2', ['method' => 'GET']],
'admin/install/step3' => ['admin/install/step3', ['method' => 'GET']], 'admin/install/step3' => ['admin/install/step3', ['method' => 'GET']],
'admin/install/step4' => ['admin/install/step4', ['method' => 'POST|AJAX']], 'admin/install/step4' => ['admin/install/step4', ['method' => 'POST|AJAX']],
'admin/install/step5' => ['admin/install/step5', ['method' => 'GET']],
'admin/install/progress' => ['admin/install/progress', ['method' => 'POST']], 'admin/install/progress' => ['admin/install/progress', ['method' => 'POST']],
//子部门列表 //子部门列表

@ -233,6 +233,8 @@ return [
'crm/receivables/system' => ['crm/receivables/system', ['method' => 'POST']], 'crm/receivables/system' => ['crm/receivables/system', ['method' => 'POST']],
// 【回款】菜单数量 // 【回款】菜单数量
'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']], 'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']],
//【回款】导出
'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']],
// 【回款计划】列表 // 【回款计划】列表
'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']], 'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']],

@ -1,5 +1,5 @@
<?php <?php
return array( return array(
'VERSION'=>'11.0.0', 'VERSION'=>'11.0.1',
'RELEASE'=>'20210205', 'RELEASE'=>'20210227',
); );

@ -1708,10 +1708,10 @@ INSERT INTO `5kcrm_admin_scene` (`types`, `name`, `user_id`, `order_id`, `data`,
INSERT INTO `5kcrm_admin_scene` (`types`, `name`, `user_id`, `order_id`, `data`, `is_hide`, `type`, `bydata`, `create_time`, `update_time`) VALUES ('crm_visit', '下属负责的回访', '0', '1', '', '0', '1', 'sub', '1546272000', '1551515457'); INSERT INTO `5kcrm_admin_scene` (`types`, `name`, `user_id`, `order_id`, `data`, `is_hide`, `type`, `bydata`, `create_time`, `update_time`) VALUES ('crm_visit', '下属负责的回访', '0', '1', '', '0', '1', 'sub', '1546272000', '1551515457');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'number', '回访编号', 'text', '', '0', '0', '1', '', NULL, '1', '1', '1553788800', '1553788800', '0', NULL, '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'number', '回访编号', 'text', '', '0', '0', '1', '', NULL, '1', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'visit_time', '回访时间', 'date', '', '0', '0', '1', '', '', '2', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'visit_time', '回访时间', 'date', '', '0', '0', '1', '', '', '2', '1', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'visit_user_id', '回访人', 'user', '', '0', '0', '1', '', '', '3', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'owner_user_id', '回访人', 'single_user', '', '0', '0', '1', '', '', '9', '3', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'shape', '回访形式', 'select', '', '0', '0', '0', '', '见面拜访\r\n电话\r\n短信\r\n邮件\r\n微信', '4', '1', '1553788800', '1553788800', '0', NULL, '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'shape', '回访形式', 'select', '', '0', '0', '0', '', '见面拜访\r\n电话\r\n短信\r\n邮件\r\n微信', '4', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'customer_id', '客户名称', 'customer', '', '0', '0', '1', '', '', '5', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'customer_id', '客户名称', 'customer', '', '0', '0', '1', '', '', '5', '1', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contacts_id', '联系人', 'contacts', '', '0', '0', '0', '', '', '6', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contacts_id', '联系人', 'contacts', '', '0', '0', '0', '', '', '6', '3', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contract_id', '合同编号', 'contract', '', '0', '0', '1', '', '', '7', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contract_id', '合同编号', 'contract', '', '0', '0', '1', '', '', '7', '1', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'satisfaction', '客户满意度', 'select', '', '0', '0', '0', '', '很满意\r\n满意\r\n一般不满意\r\n很不满意', '8', '1', '1553788800', '1553788800', '0', NULL, '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'satisfaction', '客户满意度', 'select', '', '0', '0', '0', '', '很满意\r\n满意\r\n一般不满意\r\n很不满意', '8', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'feedback', '客户反馈', 'textarea', '', '0', '0', '0', '', '', '9', '1', '1553788800', '1553788800', '0', '', '0'); INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'feedback', '客户反馈', 'textarea', '', '0', '0', '0', '', '', '9', '1', '1553788800', '1553788800', '0', '', '0');
@ -1751,7 +1751,7 @@ DROP TABLE IF EXISTS `5kcrm_crm_visit`;
CREATE TABLE `5kcrm_crm_visit` ( CREATE TABLE `5kcrm_crm_visit` (
`visit_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '回访id', `visit_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '回访id',
`owner_user_id` int(11) NOT NULL COMMENT '负责人', `owner_user_id` int(11) NOT NULL COMMENT '负责人',
`visit_user_id` int(11) NOT NULL COMMENT '回访人', `owner_user_id` int(11) NOT NULL COMMENT '回访人',
`create_user_id` int(11) NOT NULL COMMENT '创建人id', `create_user_id` int(11) NOT NULL COMMENT '创建人id',
`customer_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称', `customer_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称',
`contract_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '合同编号', `contract_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '合同编号',
@ -1840,12 +1840,12 @@ ALTER TABLE `5kcrm_oa_examine` ADD COLUMN `last_user_id` varchar(200) not null d
ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读'; ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读';
ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色'; ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色';
UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='65' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='63' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='2' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='3' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='4' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='5' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6'); UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='6' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6');
INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0'); INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0'); INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0');
@ -1955,7 +1955,7 @@ CREATE TABLE `5kcrm_crm_receivables_file` (
`receivables_id` int(10) unsigned NOT NULL, `receivables_id` int(10) unsigned NOT NULL,
`file_id` int(10) unsigned NOT NULL, `file_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`r_id`) USING BTREE PRIMARY KEY (`r_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED; ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;
INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('activity_phrase', 'a:5:{i:0;s:18:\\\"电话无人接听\\\";i:1;s:15:\\\"客户无意向\\\";i:2;s:42:\\\"客户意向度适中,后续继续跟进\\\";i:3;s:42:\\\"客户意向度较强,成交几率较大\\\";i:4;s:3:\\\"312\\\";}', '跟进记录常用语'); INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('activity_phrase', 'a:5:{i:0;s:18:\\\"电话无人接听\\\";i:1;s:15:\\\"客户无意向\\\";i:2;s:42:\\\"客户意向度适中,后续继续跟进\\\";i:3;s:42:\\\"客户意向度较强,成交几率较大\\\";i:4;s:3:\\\"312\\\";}', '跟进记录常用语');
INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_config', '1', '是否开启回访提醒1开启0不开启'); INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_config', '1', '是否开启回访提醒1开启0不开启');

@ -1,3 +1,3 @@
insert into `5kcrm_admin_user` (`username`, `password`, `salt`, `realname`, `create_time`, `status`, `structure_id`, `parent_id`, `type`) values ( '18888888888', '302dd3f6dba54513f2a5a1bf696e2d8d', '1b2d', '管理员', '1487217060', 1, 1, 0, 1); insert into `5kcrm_admin_user` (`username`, `password`, `salt`, `realname`, `create_time`, `status`, `structure_id`, `parent_id`, `type`) values ( '18888888888', '05a9918b455b2209673c36676422bb81', '7217', '管理员', '1613611667', 1, 1, 0, 1);
insert into `5kcrm_hrm_user_det` (`user_id`, `join_time`, `type`, `status`, `userstatus`, `create_time`, `update_time`) values ( 1, '1487217060', 1, 1, 2, '1487217060', '1487217060'); insert into `5kcrm_hrm_user_det` (`user_id`, `join_time`, `type`, `status`, `userstatus`, `create_time`, `update_time`) values ( 1, '1613611667', 1, 1, 2, '1613611667', '1613611667');

@ -380,13 +380,6 @@ ALTER TABLE `5kcrm_oa_examine` ADD COLUMN `last_user_id` varchar(200) not null d
ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读'; ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读';
ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色'; ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色';
UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='65' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='63' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5');
UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6');
INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0'); INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0'); INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('156', '0', '设置欢迎语', 'setWelcome', '3', '154', '0'); INSERT INTO `5kcrm_admin_rule` VALUES ('156', '0', '设置欢迎语', 'setWelcome', '3', '154', '0');

@ -0,0 +1,2 @@
UPDATE `5kcrm_admin_field` SET `operating`= 3, `field` = 'owner_user_id', `form_type` = 'single_user' WHERE `types` = 'crm_visit' AND `field` = 'visit_user_id';
UPDATE `5kcrm_admin_field` SET `operating`= 3 WHERE `types` = 'crm_visit' AND `field` = 'contacts_id';

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

@ -45,7 +45,12 @@ var rules = {
required: true, required: true,
regexp: /^(?=.*[a-zA-Z])(?=.*\d).{6,20}$/, regexp: /^(?=.*[a-zA-Z])(?=.*\d).{6,20}$/,
label: '管理员密码(6~20位字母加数字组合)' label: '管理员密码(6~20位字母加数字组合)'
} },
wkcode: {
required: false,
regexp: null,
label: '序列号'
},
}; };
var timer = null; var timer = null;
@ -63,32 +68,36 @@ $('.next').click(function () {
// 校验form数据 true 校验通过 false 校验失败 // 校验form数据 true 校验通过 false 校验失败
var forms = getFormData(); var forms = getFormData();
var result = checkForm(); var result = checkForm();
console.log('result---', result, forms); // console.log('result---', result, forms);
if (result) { if (result) {
$.ajax({
cache: true, $('#cover').css('display', 'block');//显示遮罩层
type: "POST", setTimeout(()=>{
dataType: 'json', $.ajax({
url: "./step4", cache: true,
data: { type: "POST",
form: forms dataType: 'json',
}, url: "./step4",
async: false, data: {
success: function (result) { form: forms
if (result.code == '200') { },
alert(result.data); async: false,
window.location = '../../../index.html'; success: function (result) {
} else if (result.code == '400') { if (result.code == '200') {
alert(result.error); //失败 window.location = 'step5.html';
return false; } else if (result.code == '400') {
// window.location = 'step3.html' $('#cover').css('display', 'none');
} else { alert(result.error); //失败
window.location = 'step3.html' return false;
alert('安装失败'); // window.location = 'step3.html'
} else {
window.location = 'step3.html'
alert('安装失败');
}
} }
} // getRes();
// getRes(); });
}); })
} }
}); });
@ -168,7 +177,7 @@ function _initFormValue() {
* @return {form} * @return {form}
*/ */
function getFormData() { function getFormData() {
$('input').each(function (index, item) { $('.wkform').each(function (index, item) {
form[item.name] = item.value; form[item.name] = item.value;
// 重置表单状态 // 重置表单状态
$(item).removeClass('input-error'); $(item).removeClass('input-error');
@ -186,6 +195,7 @@ function getFormData() {
* @return {boolean} * @return {boolean}
*/ */
function checkForm() { function checkForm() {
var result = {}; var result = {};
for (var key in rules) { for (var key in rules) {
var rule = rules[key]; var rule = rules[key];
@ -229,8 +239,3 @@ function renderErrorMsg(key, msg) {
} }
}) })
} }
/**
* 提交表单
*/
function submitForm() {}

@ -10,6 +10,11 @@ html, body {
background-color: #f2f2f2; background-color: #f2f2f2;
font-family: ,Microsoft Yahei,LiHei Pro,Hiragino Sans,GBHelvetica Neue,Helvetica,Arial,PingFang SC,WenQuanYi Micro Hei,sans-serif; font-family: ,Microsoft Yahei,LiHei Pro,Hiragino Sans,GBHelvetica Neue,Helvetica,Arial,PingFang SC,WenQuanYi Micro Hei,sans-serif;
} }
body {
background-image: url('../img/bg.png');
background-size: 100% 100%;
background-repeat: no-repeat;
}
li { li {
list-style: none; list-style: none;
@ -72,7 +77,10 @@ li {
.top { .top {
width: 790px; width: 790px;
height: 65px; height: 65px;
margin: 0 auto; margin:40px auto 20px auto;
border: 1px solid white;
border-radius: 5px ;
background-color: #fff ;
} }
/* container */ /* container */
@ -81,6 +89,7 @@ li {
min-height: 493px; min-height: 493px;
background-color: white; background-color: white;
border: 1px solid #e1e1e1; border: 1px solid #e1e1e1;
border-radius:5px;
margin: 0 auto; margin: 0 auto;
} }
@ -93,7 +102,7 @@ li {
width: 820px; width: 820px;
text-align: center; text-align: center;
font-size: 15px; font-size: 15px;
color: #8c8c8c; color: #fff;
line-height: 30px; line-height: 30px;
margin: 0 auto; margin: 0 auto;
padding: 30px 0; padding: 30px 0;
@ -112,6 +121,9 @@ li {
text-align: center; text-align: center;
margin: 20px 0; margin: 20px 0;
float: left; float: left;
display: flex;
align-items: center;
justify-content: center;
} }
.step.line { .step.line {
width: 10%; width: 10%;
@ -122,12 +134,12 @@ li {
.step .sort { .step .sort {
width: 25px; width: 25px;
height: 25px; height: 25px;
color: white; color: #8c8c8c;
line-height: 25px; line-height: 25px;
text-align: center; text-align: center;
font-size: 14px; font-size: 14px;
border-radius: 50%; border-radius: 50%;
background-color: #d1d1d1; /* background-color: #d1d1d1; */
margin-right: 5px; margin-right: 5px;
display: inline-block; display: inline-block;
} }
@ -139,13 +151,13 @@ li {
} }
.step.active .sort { .step.active .sort {
background-color: #3e84e9; background-color: #fff;
} }
.step.active .desc { .step.active .desc {
color: #3e84e9; color: black;
} }
.step.active.line { .step.active.line {
background-color: #3e84e9; /* background-color: #fff; */
} }
@ -156,7 +168,7 @@ li {
line-height: 40px; line-height: 40px;
font-size: 16px; font-size: 16px;
color: #3e84e9; color: #3e84e9;
border-radius: 40px; border-radius: 5px;
background-color: white; background-color: white;
border: 1px solid #3e84e9; border: 1px solid #3e84e9;
display: inline-block; display: inline-block;
@ -172,16 +184,44 @@ li {
width: 100%; width: 100%;
height: 54px; height: 54px;
line-height: 54px; line-height: 54px;
background-color: #f7f7f7; /* background-color: #f7f7f7; */
padding: 0 26px; padding: 0 26px;
border-bottom: 1px solid #e1e1e1; /* border-bottom: 1px solid #e1e1e1; */
font-weight: 600;
} }
.base-top .title { .base-top .title {
color: #8c8c8c; /* color: #8c8c8c; */
font-size: 16px; font-size: 16px;
} }
.base-top .version { .base-top .version {
font-size: 13px; font-size: 13px;
color: #d1d1d1; color: #8c8c8c;
float: right; float: right;
} }
.base-des {
margin: 0 auto;
line-height: 35px;
width: 790px;
background-color: #fff;
padding: 0 40px;
margin-bottom: 20px;
color: #8c8c8c;
}
.base-a{
cursor: pointer;
user-select: none;
text-decoration: none;
color: #3e84e9;
}
#cover{
position:absolute;left:0px;top:0px;
background:rgba(0, 0, 0, 0.4);
width:100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
height:100%;
opacity:0.6; /*非IE浏览器下设置透明度为60%*/
display:none;
z-Index:99;
}

@ -1,5 +1,6 @@
.container { .container {
padding: 20px; padding: 20px;
border-radius: 10px;
} }
.agreement-title { .agreement-title {
width: 100%; width: 100%;

@ -0,0 +1,52 @@
#loader-container {
width: 200px;
height: 200px;
color: white;
margin: 0 auto;
position: fixed;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
border: 5px solid #3498db;
border-radius: 50%;
-webkit-animation: borderScale 1s infinite ease-in-out;
animation: borderScale 1s infinite ease-in-out;
z-index: 100;
opacity:1
}
#loadingText {
font-family: 'Raleway', sans-serif;
font-weight: bold;
font-size: 2em;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
@-webkit-keyframes borderScale {
0% {
border: 5px solid white;
}
50% {
border: 25px solid #3498db;
}
100% {
border: 5px solid white;
}
}
@keyframes borderScale {
0% {
border: 5px solid white;
}
50% {
border: 25px solid #3498db;
}
100% {
border: 5px solid white;
}
}

@ -15,14 +15,18 @@
table { table {
width: 100%; width: 100%;
border: 1px solid #e1e1e1; border: 1px solid #e1e1e1;
border-collapse: collapse; /* border-collapse: collapse; */
border-collapse: separate;
border-spacing: 0;
border-radius:5px;
overflow: hidden;
} }
.table tr { .table tr {
height: 34px; height: 34px;
text-align: center; text-align: center;
} }
th, td { th, td {
border: 1px solid #e1e1e1; border-bottom: 1px solid #f7f7f7;
width: 30%; width: 30%;
} }
th:first-child, td:first-child, th:last-child, td:last-child { th:first-child, td:first-child, th:last-child, td:last-child {
@ -31,8 +35,9 @@ th:first-child, td:first-child, th:last-child, td:last-child {
th { th {
font-weight: normal; font-weight: normal;
background-color: #3e84e9; background-color: #f7f7f7;
color: white; /* color: white; */
font-weight: 600;
} }

@ -28,13 +28,15 @@
float: left; float: left;
} }
.content .form .form-item input { .content .form .form-item input {
width: 276px; width: 550px;
height: 34px; height: 40px;
line-height: 34px; line-height: 40px;
border: 1px solid #d7d7d7; border: 1px solid #d7d7d7;
padding: 0 10px; padding: 0 10px;
margin-right: 20px; /* margin-right: 20px; */
float: left; float: left;
border-radius: 5px;
color: #8c8c8c;
} }
.content .form .form-item input:focus { .content .form .form-item input:focus {
border-color: transparent !important; border-color: transparent !important;
@ -51,13 +53,17 @@
float: left; float: left;
} }
.content .form .form-item .remind { .content .form .form-item .remind {
width: 292px; font-size: 12px;
line-height: 34px; margin-top: 10px;
margin-left: 120px;
width: 550px;
line-height: 20px;
color: #777; color: #777;
background-color: #ecf8ff; background-color: #fff6e7;
padding: 0 16px; padding: 0 12px;
border-radius: 3px; border-radius: 3px;
float: left; float: left;
border:1px solid #d7d7d7;
} }
.install_progress_a { .install_progress_a {
@ -69,5 +75,20 @@
text-align: center; text-align: center;
padding: 20px 0; padding: 20px 0;
color: #777; color: #777;
}
.content .form .form-item textarea {
height: 100px;
width: 550px;
line-height: 25px;
border: 1px solid #d7d7d7;
padding: 0 10px;
/* margin-right: 20px; */
float: left;
border-radius: 5px;
color: #8c8c8c;
}
.content .form .form-item textarea:focus {
border-color: transparent !important;
outline-color: #3e84e9;
} }

@ -0,0 +1,2 @@
UPDATE `5kcrm_admin_field` SET `operating`= 3, `field` = 'owner_user_id', `form_type` = 'single_user' WHERE `types` = 'crm_visit' AND `field` = 'visit_user_id';
UPDATE `5kcrm_admin_field` SET `operating`= 3 WHERE `types` = 'crm_visit' AND `field` = 'contacts_id';
Loading…
Cancel
Save