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

@ -170,3 +170,25 @@ function sendRequest($url, $params = array() , $headers = array()) {
curl_close($ch);
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;
// $data['types'] = $param['types'];
$data = $param['data'];
$saveParam = []; # 新增数据
$updateParam = []; # 编辑数据
$delParam = []; # 删除数据
$fieldIds = []; # 删除数据兼容前端11.*.*版本)
$data = $param['data'];
$saveParam = []; # 新增数据
$updateParam = []; # 编辑数据
$delParam = []; # 删除数据
$fieldIds = []; # 删除数据兼容前端11.*.*版本)
$errorMessage = []; # 错误数据
$i = 0;
foreach ($data AS $k => $v) {
$i++;
# 必填的字段不可以隐藏
if (!empty($v['is_null']) && !empty($v['is_hidden'])) {
$errorMessage = '必填的字段不可以隐藏!';
break;
}
if ($v['field_id']) {
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 这段代码需要写在新增上面,不然会把新增的给删除掉
$oldFieldIds = Db::name('admin_field')->where('types', $types)->column('field_id');
@ -170,7 +178,7 @@ class Field extends ApiCommon
# 删除
if (!empty($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' :
$visit = new \app\crm\model\Visit();
$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']);
//读写权限
$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');
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');
exit(json_encode(['code'=>102,'error'=>'无权操作']));
}
@ -614,6 +627,10 @@ class Field extends ApiCommon
$userFieldModel = model('UserField');
$width = $param['width'] > 10 ? $param['width'] : '';
$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)) {
$res = $userFieldModel->setColumnWidth($param['types'], $param['field'], $width, $userInfo['id']);
if (!$res) {

@ -52,6 +52,7 @@ class Index extends ApiCommon
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'] == '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]);

@ -27,15 +27,15 @@ class Install extends Controller
$param = Request::instance()->param();
$this->param = $param;
$request = request();
$m = strtolower($request->module());
$c = strtolower($request->controller());
$a = strtolower($request->action());
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>";
die();
}
// $request = request();
// $m = strtolower($request->module());
// $c = strtolower($request->controller());
// $a = strtolower($request->action());
//
// 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>";
// die();
// }
}
private $upgrade_site = "http://message.72crm.com/";
@ -73,7 +73,7 @@ class Install extends Controller
public function version()
{
$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(){
@ -114,6 +114,7 @@ class Install extends Controller
$username = $param['root'];
$password = $param['pwd'];
$wkcode = $param['wkcode'];
if (empty($db_config['hostname'])) {
return resultArray(['error' => '请填写数据库主机!']);
}
@ -141,6 +142,17 @@ class Install extends Controller
if (empty($username)) {
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)) {
return resultArray(['error' => '请填写管理员密码!']);
}
@ -161,6 +173,7 @@ class Install extends Controller
}
$db_config['database'] = $database;
self::mkDatabase($db_config);
self::mkLicense($wkcode);
$C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
$sql = file_get_contents( $C_Patch.'/public/sql/5kcrm.sql');
$sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
@ -189,6 +202,11 @@ class Install extends Controller
return resultArray(['data'=>'安装成功']);
}
public function step5()
{
return $this->fetch();
}
//ajax 进度条
public function progress()
{
@ -314,7 +332,7 @@ INFO;
{
$items = [
'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'],
'openssl' => ['openssl', '开启', '开启', 'ok'],
'pdo' => ['pdo', '开启', '开启', 'ok'],
@ -379,4 +397,32 @@ INFO;
}
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) {
return resultArray(['error' => $userModel->getError()]);
}
$data['serverUserInfo'] = $this->queryLoginUser();
return resultArray(['data' => $data]);
}
@ -500,6 +501,7 @@ class Users extends ApiCommon
$data['username'] = $param['username'];
$data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
$data['userInfo'] = $userData;
$data['mobile'] = $param['username'];
$resSync = model('Sync')->syncData($data);
if ($resSync) {
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()
{
@ -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()
{
@ -720,4 +715,21 @@ class Users extends ApiCommon
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 = [];
$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) {
@ -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' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '客户', 'field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
$content[] = ['name' => '联系人', 'field' => 'contract_id', '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' => 'shape', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0];
$content[] = ['name' => '客户满意度', 'field' => 'satisfaction', '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' => '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' => 'contacts_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0];
Db::name('admin_field_grant')->insert([
'role_id' => $roleId,

@ -21,7 +21,7 @@ class MessageLogic
$where = array('in', [6, 7, 8]);
break;
case '4': //公告
$where = array('eq', 9);
$where = 9;
break;
case '5' : //日程
$where = 10;
@ -43,7 +43,7 @@ class MessageLogic
unset($param['user_id']);
//types 1表示已读 0表示未读
if (isset($param['is_read'])) {
$where['m.read_time'] = ['=', 0];
$where['m.read_time'] = 0;
}
$where['m.to_user_id'] = $userId;
$where['m.is_delete'] = ['eq', 1];
@ -74,11 +74,11 @@ class MessageLogic
->page($param['page'], $param['limit'])
->order($order)
->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表示未读
foreach ($list as $k => $v) {
if ($v['read_time'] == 0) {
@ -90,48 +90,38 @@ class MessageLogic
if ($v['type'] == 4) {
$content = db('admin_comment')
->where(
[ 'status' => 1,
'comment_id' => $v['action_id'],
['status' => 1,
'type_id' => $v['action_id'],
'type' => ['like', '%' . $v['controller_name' . '%']],
'user_id' => $v['from_user_id']
])
->find();
if (!empty($content)) {
$list[$k]['content'] = $content['content'];
}
} elseif (in_array($v['type'], ['12', '15'])) {
->select();
$list[$k]['content'] = $content[$k]['content'];
} elseif (in_array($v['type'], ['7','12', '15',25])) {
$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']) {
$list[$k]['content'] = $content['content'];
}
}
if ($v['type'] == 10) {
$item = db('oa_event_notice')->where('id', $v['action_id'])->find();
if ($item) {
$noticetype = $item['noticetype'];
if($item['noticetype'] == 1){
$advance_time =$v['advance_time'] - ($item['number'] * 60);
}elseif ($item['noticetype'] == 2){
$advance_time =$v['advance_time'] - ($item['number'] * 60 * 60);
}else{
$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);
if ($v['type'] == 10 && $v['advance_time'] < time()) {
$item = db('oa_event_notice')->where('id', $v['action_id'])->find();
if ($item) {
$type['value'] = $item['number'];
$type['type'] = $item['noticetype'];
$list[$k]['content'] = $type;
$list[$k]['action_id'] = $item['event_id'];
}
} elseif($v['type'] == 10 && $v['advance_time'] > time()) {
unset($list[$k]);
}
$time=time();
if (in_array($v['type'], ['17', '18', '19', '20', '27'])) {
$error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find();
if($error_file_path['error_data_file_path']==''){
$list[$k]['title'] = '';
$week = strtotime("+7 day", $error_file_path['create_time']);
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'];
}
@ -265,7 +255,7 @@ class MessageLogic
$where['type'] = 9;
$announceCount = db('admin_message')->where($where)->count();
$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);
$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' => '操作失败!'];
# 将项目权限变更为只读权限
$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];
}
}

@ -295,6 +295,7 @@ class Common extends Model
*/
public function exportHandle($list, $field_list, $type = '')
{
foreach ($list as &$val) {
foreach ($field_list as $field) {
switch ($field['form_type']) {
@ -310,7 +311,7 @@ class Common extends Model
$val[$field['field']] = implode(',', array_column($temp, 'name'));
break;
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;
case 'customer':
case 'business':

@ -324,7 +324,7 @@ class ExamineStep extends Common
$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;
}
@ -339,6 +339,7 @@ class ExamineStep extends Common
$createUserInfo['check_type'] = 3;
$newlist[0]['type'] = '3'; //创建
$newlist[0]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
}
$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;

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

@ -182,10 +182,6 @@ class Field extends Model
if ($param['types'] == 'crm_customer') {
$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();
foreach ($list as $k => $v) {
$list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : [];
@ -655,7 +651,7 @@ class Field extends Model
}
} 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'])) {
@ -754,7 +750,16 @@ class Field extends Model
];
} elseif ($v['form_type'] == 'user') {
$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']]) ?: [];
} elseif ($v['form_type'] == 'file') {
$fileIds = [];
@ -882,7 +887,8 @@ class Field extends Model
$userModel = new \app\admin\model\User();
$user_id = $param['user_id'];
$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')
->where($map)
->whereOr(['types' => ''])
@ -1026,12 +1032,16 @@ class Field extends Model
$userLevel = isSuperAdministrators($user_id);
$fieldList = $this->getFieldList($types, $types_id);
$where = [];
if ($userFieldData) {
$fieldArr = [];
$i = 0;
foreach ($userFieldData as $k => $v) {
if (empty($fieldList[$k])) {
unset($userFieldData[$k]);
continue;
}
if (empty($v['is_hide'])) {
$fieldArr[$i]['field'] = $k;
$fieldArr[$i]['name'] = $fieldList[$k]['name'];
@ -1081,8 +1091,9 @@ class Field extends Model
'form_type' => ['not in', ['file', 'form']],
'field' => ['not in', $unField],
'types_id' => ['eq', $types_id],
'is_hidden'=>0
])
->field(['field', 'name', 'form_type'])
->field(['field', 'name', 'form_type,is_hidden'])
->order('order_id asc')
->select();
@ -1192,7 +1203,6 @@ class Field extends Model
} else {
$listArr = $dataList;
}
$typesArray = explode('_', $types);
$type = array_pop($typesArray);
if (isset($this->orther_field_list[$types])) {
@ -1257,6 +1267,11 @@ class Field extends Model
if ($unFormType) $data['form_type'] = array('not in', $unFormType);
$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;
}
@ -1315,9 +1330,12 @@ class Field extends Model
$where = [];
$where[$field] = ['eq', $val];
if ($id) {
//为编辑时的验重
$where[$dataModel->getpk()] = ['neq', $id];
if ($id) {
//为编辑时的验重
$where[$dataModel->getpk()] = ['neq', $id];
}
if($types=='crm_product'){
$where['delete_user_id'] = 0;
}
if ($res = $dataModel->where($where)->find()) {
$this->error = '该数据已存在,请修改后提交!';
@ -1648,6 +1666,7 @@ class Field extends Model
break;
case 'owner_user_id' :
$data[$key]['fieldName'] = 'owner_user_name';
$data[$key]['name'] = '回访人';
break;
case 'contacts_id' :
$data[$key]['fieldName'] = 'contacts_name';

@ -609,7 +609,7 @@ class Record extends Common
}
$fileModel = new \app\admin\model\File();
$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);
return true;

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

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

@ -162,6 +162,8 @@ class UserField extends Model
$a = 0;
$b = 0;
foreach ($value as $k=>$v) {
if (empty($field_list[$k]['name'])) continue;
if (empty($v['is_hide'])) {
$valueList[] = $k;
$value_list[$a]['field'] = $k;
@ -193,6 +195,16 @@ class UserField extends Model
$data = [];
$data['value_list'] = $value_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 ? : [];
}
}

@ -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>
官方电话400-0812-558<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>
<br>
<p>一、协议中提到的名词约定</p>

@ -16,17 +16,23 @@
<div class="top">
<div class="step-group">
<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>
<div class="step line"></div>
<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>
<div class="step line"></div>
<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>
</div>
@ -34,7 +40,7 @@
<div class="container">
<div class="content">
<div class="base-top">
<span class="title">1 检查安装环境</span>
<span class="title">检查安装环境</span>
<span class="version">当前版本:{$data['version']['VERSION']} {$data['version']['RELEASE']}</span>
</div>
<div class="table">

@ -7,84 +7,111 @@
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
<link rel="stylesheet" href="__STATIC__/style/base.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>
</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">
{include file="public/header"}
</div>
<div class="top">
<div class="step-group">
<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>
<div class="step active line"></div>
<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>
<div class="step line"></div>
<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>
</div>
</div>
<div class="container">
<div class="content">
<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>
</div>
<div class="form">
<div class="form-sec-title">请填写数据库信息</div>
<div class="form-item">
<div class="form-label">数据库主机:</div>
<input type="text" name="databaseUrl">
<!--<div class="error" style="display: none">数据库主机不能空</div>-->
<div class="remind">数据库地址一般为127.0.0.1</div>
</div>
<div class="form-item">
<div class="form-label">数据库名:</div>
<input type="text" name="databaseName">
</div>
<div class="form-item">
<div class="form-label">端口:</div>
<input type="text" name="databasePort">
<div class="remind">一般为 3306</div>
</div>
<div class="form-item">
<div class="form-label">数据库用户名:</div>
<input type="text" name="databaseUser">
<div class="remind">生产环境建议创建独立账号</div>
</div>
<div class="form-item">
<div class="form-label">数据库密码:</div>
<input type="password" name="databasePwd">
</div>
<div class="form-item">
<div class="form-item">
<div class="form-label">数据库主机:</div>
<input type="text" class="wkform" name="databaseUrl" placeholder="127.0.0.1">
<!--<div class="error" style="display: none">数据库主机不能空</div>-->
<!-- <div class="remind">数据库地址一般为127.0.0.1</div> -->
</div>
<div class="form-item">
<div class="form-label">数据库名:</div>
<input type="text" class="wkform" name="databaseName">
</div>
<div class="form-item">
<div class="form-label">端口:</div>
<input type="text" class="wkform" name="databasePort" placeholder="一般为3306">
<!-- <div class="remind">一般为 3306</div> -->
</div>
<div class="form-item">
<div class="form-label">数据库用户名:</div>
<input type="text" class="wkform" name="databaseUser" placeholder="生产环境建议创建独立账号">
<!-- <div class="remind">生产环境建议创建独立账号</div> -->
</div>
<div class="form-item">
<div class="form-label">数据库密码:</div>
<input type="password" class="wkform" name="databasePwd">
</div>
<div class="form-item">
<div class="form-label">表前缀:</div>
<input type="text" name="databaseTable">
<div class="remind">默认为5kcrm_</div>
</div>
<div class="form-sec-title">请填写管理员信息</div>
<div class="form-item">
<div class="form-label">管理员账号:</div>
<input type="text" name="root" placeholder="请输入手机号码">
<input type="text" class="wkform" name="databaseTable" placeholder="默认我5kcrm-">
<!-- <div class="remind">默认为5kcrm_</div> -->
</div>
<div class="form-item">
<div class="form-label">安装序列号:</div>
<textarea name="wkcode" class="wkform" rows="6" placeholder="请输入您的序列号"></textarea>
<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 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>
<input type="password" name="pwd">
<input type="password" class="wkform" name="pwd" placeholder="6~20位字母加数字组合">
</div>
</div>
<div class="base-des">
</div>
<div class="install_progress_a">
<!-- <progress class="install_progress" max="97" value="8"></progress> -->
</div>
<div class="control">
<div class="prev btn">上一步</div>
<div class="next btn primary">下一步</div>
<div class="next btn primary">安装</div>
</div>
</div>
</div>

@ -16,17 +16,23 @@
<div class="top">
<div class="step-group">
<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>
<div class="step active line"></div>
<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>
<div class="step line active"></div>
<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>
</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">
<div class="content">
悟空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>
</footer>

@ -122,10 +122,11 @@ class Examine extends ApiCommon
unset($where['create_time']);
unset($where['create_user_id']);
unset($where['create_user_id']);
$where['check_status'] = 'all';
// $where['check_status'] = 'all';
$where['page'] = $param['page'];
$where['limit'] = $param['limit'];
$where['user_id'] = $user_id;
$where['bi_types'] = 'bi';
$where['between_time'] = array($start_time,$end_time);
$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['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 ($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) {
case 'business_id' :
$k = 'name';
@ -186,11 +205,11 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
break;
}
}
if ($types == 'receivables' && $v['name'] == '合同编号') {
if ($types == 'receivables' && $v['name'] == '合同编号' && !empty($v['value'])) {
$k = 'num';
$c = 'contract.';
}
if ($types == 'receivables' && $k == 'plan_id') {
if ($types == 'receivables' && $k == 'plan_id' && !empty($v['value'])) {
$planIds = [];
foreach ($v['value'] AS $kk => $vv) {
$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);
}
if ($types == 'invoice' && $v['type'] == 'invoice_status') {
if ($types == 'invoice' && $v['type'] == 'invoice_status' && !empty($v['value'])) {
foreach ($v['value'] AS $kk => $vv) {
if ($vv == '已开票') $v['value'][$kk] = 1;
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';
$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';
}
if (is_array($v)) {

@ -276,11 +276,6 @@ class Business extends ApiCommon
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:无权限;';
continue;
}
$resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
if (!$resBusiness) {
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
}
//团队成员
teamUserId(
@ -292,6 +287,24 @@ class Business extends ApiCommon
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);
}

@ -214,12 +214,6 @@ class Contract extends ApiCommon
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
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) {
//将合同审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流)
@ -244,7 +238,7 @@ class Contract extends ApiCommon
} else {
$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_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
@ -257,7 +251,7 @@ class Contract extends ApiCommon
}
$param['flow_user_id'] = '';
}
}
if ($contractModel->updateDataById($param, $param['id'])) {
//将审批记录至为无效
@ -314,7 +308,7 @@ class Contract extends ApiCommon
$isDel = false;
$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;
$errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前状态为审批中或已审批通过,不可删除';
}
@ -335,9 +329,9 @@ class Contract extends ApiCommon
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]);
// 删除回款记录
@ -395,15 +389,10 @@ class Contract extends ApiCommon
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:无权限;';
continue;
}
if (in_array($contractInfo['check_status'],['0','1'])) {
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;';
continue;
}
$resContract = db('crm_contract')->where(['contract_id' => $contract_id])->update($data);
if (!$resContract) {
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
}
// if (in_array($contractInfo['check_status'],['0','1'])) {
// $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;';
// continue;
// }
//团队成员
teamUserId(
@ -411,9 +400,29 @@ class Contract extends ApiCommon
$contract_id,
$type,
[$contractInfo['owner_user_id']],
$is_remove,
($is_remove == 1) ? 1 : '',
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);
}

@ -316,6 +316,19 @@ class Customer extends ApiCommon
if (!$resCustomer) {
$errorMessage[] = $customerInfo['name'].'转移失败,错误原因:数据出错;';
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)) {
@ -677,7 +690,7 @@ class Customer extends ApiCommon
$file = request()->file('file');
// $res = $excelModel->importExcel($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)
{
$actionRecordModel = new \app\admin\model\ActionRecord();
$fileModel = new \app\admin\model\File();
$idArray = $this->param['id'];
$userinfo = $this->userInfo['id'];
@ -326,7 +328,7 @@ class Invoice extends ApiCommon
if (!isSuperAdministrators($userinfo['id'])) {
$list = $invoiceLogic->getExamineStatus($idString, true);
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;
break;
}
@ -338,8 +340,9 @@ class Invoice extends ApiCommon
if (!$invoiceLogic->delete($idArray)) return resultArray(['error' => '删除失败!']);
# 删除附件
$fileModel = new \app\admin\model\File();
$fileModel->delRFileByModule('crm_invoice', $idArray);
//删除关联操作记录
$actionRecordModel->delDataById(['types'=>'crm_invoice','action_id'=>$idArray]);
return resultArray(['data' => '删除成功!']);
}

@ -226,7 +226,8 @@ class Leads extends ApiCommon
$data['deal_time'] = time();
$data['create_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();
//权限判断
@ -404,6 +405,9 @@ class Leads extends ApiCommon
$file = request()->file('file');
// $res = $excelModel->importExcel($file, $param);
$res = $excelModel->batchImportData($file, $param, $this);
if (!$res) {
return resultArray(['error' => $excelModel->getError()]);
}
return resultArray(['data' => $excelModel->getError()]);
}

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

@ -25,14 +25,14 @@ class Receivables extends ApiCommon
* @permission 无限制
* @allow 登录用户可访问
* @other 其他根据系统设置
**/
**/
public function _initialize()
{
$action = [
'permission'=>[''],
'allow'=>['check','revokecheck','system','count']
'permission' => [''],
'allow' => ['check', 'revokecheck', 'system', 'count']
];
Hook::listen('check_auth',$action);
Hook::listen('check_auth', $action);
$request = Request::instance();
$a = strtolower($request->action());
if (!in_array($a, $action['permission'])) {
@ -42,8 +42,8 @@ class Receivables extends ApiCommon
/**
* 回款列表
* @author Michael_xu
* @return
* @author Michael_xu
*/
public function index()
{
@ -55,6 +55,43 @@ class Receivables extends ApiCommon
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)) {
//保存为草稿
$param['check_status'] = 5; //草稿(未提交)
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
} else {
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
//审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) {
return resultArray(['error' => '暂无审批人,无法创建']);
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables');
if (!$examineFlowData) {
return resultArray(['error' => '无可用审批流,请联系管理员']);
}
$param['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
$check_user_id = $next_user_ids ? : [];
$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;
$param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
//审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) {
return resultArray(['error' => '暂无审批人,无法创建']);
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables');
if (!$examineFlowData) {
return resultArray(['error' => '无可用审批流,请联系管理员']);
}
$param['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1;
} else {
# 审批流停用,将状态改为审核通过
$param['check_status'] = 2;
$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 {
# 审批流停用,将状态改为审核通过
$param['check_status'] = 2;
}
$res = $receivablesModel->createData($param);
if ($res) {
//回款计划关联
@ -130,9 +167,9 @@ class Receivables extends ApiCommon
/**
* 回款详情
* @author Michael_xu
* @param
* @return
* @author Michael_xu
*/
public function read()
{
@ -143,7 +180,7 @@ class Receivables extends ApiCommon
//判断权限
$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;
return resultArray(['data' => $authData]);
}
@ -155,9 +192,9 @@ class Receivables extends ApiCommon
/**
* 编辑回款
* @author Michael_xu
* @param
* @return
* @author Michael_xu
*/
public function update()
{
@ -171,9 +208,9 @@ class Receivables extends ApiCommon
//判断权限
$dataInfo = $receivablesModel->getDataById($param['id']);
$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');
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)) {
//保存为草稿
$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 ($param['is_draft']) {
//保存为草稿
$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 {
//将回款审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流)
@ -217,16 +254,16 @@ class Receivables extends ApiCommon
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
$check_user_id = $next_user_ids ? : [];
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1;
} 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) {
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['flow_user_id'] = '';
}
@ -237,7 +274,7 @@ class Receivables extends ApiCommon
if ($res) {
//将审批记录至为无效
$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字段
if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
@ -249,12 +286,15 @@ class Receivables extends ApiCommon
/**
* 删除回款
* @author Michael_xu
* @param
* @return
* @author Michael_xu
*/
public function delete()
{
$actionRecordModel = new \app\admin\model\ActionRecord();
$fileModel = new \app\admin\model\File();
$recordModel = new \app\admin\model\Record();
$receivablesModel = model('Receivables');
$param = $this->param;
$userInfo = $this->userInfo;
@ -270,29 +310,29 @@ class Receivables extends ApiCommon
$userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'delete');
$adminTypes = adminGroupTypes($userInfo['id']);
foreach ($receivables_id as $k=>$v) {
foreach ($receivables_id as $k => $v) {
$isDel = true;
//数据详情
$data = $receivablesModel->getDataById($v);
if (!$data) {
$isDel = false;
$errorMessage[] = 'id为'.$v.'的回款删除失败,错误原因:'.$receivablesModel->getError();
$errorMessage[] = 'id为' . $v . '的回款删除失败,错误原因:' . $receivablesModel->getError();
continue;
}
if (!in_array($data['owner_user_id'],$auth_user_ids)) {
if (!in_array($data['owner_user_id'], $auth_user_ids)) {
$isDel = false;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:无权操作';
$errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:无权操作';
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;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:请先撤销审核';
$errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:请先撤销审核';
continue;
}
if ($isDel) {
if (db('crm_receivables_plan')->where('receivables_id', $v)->value('plan_id')) {
$isDel = false;
$errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:回款已关联回款计划,不能删除!';
$errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:回款已关联回款计划,不能删除!';
continue;
}
}
@ -305,8 +345,15 @@ class Receivables extends ApiCommon
if (!$data) {
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) {
return resultArray(['error' => $errorMessage]);
} else {
@ -316,9 +363,9 @@ class Receivables extends ApiCommon
/**
* 回款审核
* @author Michael_xu
* @param
* @return
* @author Michael_xu
*/
public function check()
{
@ -335,7 +382,7 @@ class Receivables extends ApiCommon
$receivablesData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_receivables', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]);
return resultArray(['error' => $examineStepModel->getError()]);
};
//审批主体详情
$dataInfo = $receivablesModel->getDataById($param['id']);
@ -350,7 +397,7 @@ class Receivables extends ApiCommon
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ? : 1;
$checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status;
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);
$next_user_ids = $nextStepData['next_user_ids'] ? : [];
$receivablesData['order_id'] = $nextStepData['order_id'] ? : '';
$next_user_ids = $nextStepData['next_user_ids'] ?: [];
$receivablesData['order_id'] = $nextStepData['order_id'] ?: '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
@ -372,7 +419,7 @@ class Receivables extends ApiCommon
} else {
//自选流程
$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)) {
return resultArray(['error' => '请选择下一审批人']);
}
@ -391,7 +438,7 @@ class Receivables extends ApiCommon
// $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['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);
if ($resReceivables) {
if ($status) {
@ -423,13 +470,13 @@ class Receivables extends ApiCommon
if ($is_end == 1 && !empty($status)) {
//发送站内信 通过
(new Message())->send(
Message::RECEIVABLES_PASS,
[
'title' => $dataInfo['number'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
Message::RECEIVABLES_PASS,
[
'title' => $dataInfo['number'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
}
return resultArray(['data' => '审批成功']);
} else {
@ -439,9 +486,9 @@ class Receivables extends ApiCommon
/**
* 回款撤销审核
* @author Michael_xu
* @param
* @return
* @author Michael_xu
*/
public function revokeCheck()
{
@ -505,12 +552,12 @@ class Receivables extends ApiCommon
*/
public function transfer()
{
$param = $this->param;
$userInfo = $this->userInfo;
$param = $this->param;
$userInfo = $this->userInfo;
$receivablesModel = model('Receivables');
$userModel = new \app\admin\model\User();
$authIds = $userModel->getUserByPer();
$authIds = $userModel->getUserByPer();
if (empty($param['owner_user_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 = [
'owner_user_id' => $param['owner_user_id'],
'update_time' => time(),
'update_time' => time(),
];
$errorMessage = [];
foreach ($param['receivables_id'] as $receivables_id) {
$receivables_info = $receivablesModel->getDataById($receivables_id);
if (!$receivables_info) {
$errorMessage[] = 'id:为《'.$receivables_id.'》的回款转移失败,错误原因:数据不存在;';
$errorMessage[] = 'id:为《' . $receivables_id . '》的回款转移失败,错误原因:数据不存在;';
continue;
}
@ -534,21 +581,21 @@ class Receivables extends ApiCommon
if ($param['owner_user_id'] == $receivables_info['owner_user_id']) continue;
if (!in_array($receivables_info['owner_user_id'], $authIds)) {
$errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:无权限;';
$errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:无权限;';
continue;
}
if (in_array($receivables_info['check_status'],['0','1'])) {
$errorMessage[] = $receivables_info['number'].'转移失败,错误原因:待审或审批中,无法转移;';
if (in_array($receivables_info['check_status'], ['0', '1'])) {
$errorMessage[] = $receivables_info['number'] . '转移失败,错误原因:待审或审批中,无法转移;';
continue;
}
$res = $receivablesModel->where(['receivables_id' => $receivables_id])->update($data);
if (!$res) {
$errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:数据出错;';
$errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:数据出错;';
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) {
return resultArray(['data' => '转移成功']);

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

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

@ -12,6 +12,7 @@ use app\admin\controller\ApiCommon;
use app\admin\model\User;
use app\crm\model\Customer;
use think\Db;
use think\Validate;
class CommonLogic
{
@ -39,7 +40,7 @@ class CommonLogic
*/
$actionId = $param['action_id'];
$types = $param['types'];
$types = $param['types'];
unset($param['action_id']);
unset($param['types']);
@ -48,26 +49,83 @@ class CommonLogic
# 主键
$primaryKey = '';
if ($types == 'crm_leads') $primaryKey = 'leads_id';
if ($types == 'crm_customer') $primaryKey = 'customer_id';
if ($types == 'crm_contacts') $primaryKey = 'contacts_id';
if ($types == 'crm_business') $primaryKey = 'business_id';
if ($types == 'crm_contract') $primaryKey = 'contract_id';
if ($types == 'crm_receivables') $primaryKey = 'receivables_id';
if ($types == 'crm_visit') $primaryKey = 'visit_id';
if ($types == 'crm_product') $primaryKey = 'product_id';
// author guogaobo $item模块
$info='';
switch ($types) {
case 'crm_leads' :
$primaryKey = 'leads_id';
$dataModel=new \app\crm\model\Leads();
$info=$dataModel->getDataById($actionId);
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();
$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') {
$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');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
$wherePool = (new Customer())->getWhereByPool();
$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 = '无权操作!';
return false;
}
@ -75,10 +133,10 @@ class CommonLogic
# 商机模块快捷编辑权限验证
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');
$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 = '无权操作!';
return false;
}
@ -86,7 +144,7 @@ class CommonLogic
# 合同模块快捷编辑权限验证
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');
$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) {
@ -95,51 +153,100 @@ class CommonLogic
}
}
foreach ($param AS $key => $value) {
# 查询自定义字段信息
$fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name'])
->where('types', $types)->where('field', $key)->find();
# 字符长度
if (!empty($fieldInfo['max_length']) && strlen($value) > $fieldInfo['max_length']) {
$this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!';
return false;
}
$fieldModel = new \app\admin\model\Field();
# 日期时间类型
$datetimeField = $fieldModel->getFieldByFormType($types, 'datetime');
# 附件类型
$fileField = $fieldModel->getFieldByFormType($types, 'file');
# 多选类型
$checkboxField = $fieldModel->getFieldByFormType($types, 'checkbox');
# 人员类型
$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)) {
$this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!';
return false;
}
# 必填
if (!empty($fieldInfo['is_null']) && empty($v)) {
$this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!';
return false;
}
# 唯一
if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($key, $value)->value($primaryKey)) {
$this->error = $fieldInfo['name'] . ' 内容重复!';
return false;
# 唯一
if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($k, $v)->value($primaryKey)) {
$this->error = $fieldInfo['name'] . ' 内容重复!';
return false;
}
}
}
# 编辑参数
$data = [];
$item=[];
if (!empty($param['list'])) {
foreach ($param['list'] AS $key => $value) {
foreach ($value AS $k => $v) {
# 处理下次联系时间格式
if ($k == 'next_time') {
foreach ($param['list'] as $key => $value) {
foreach ($value as $k => $v) {
if ($k == 'next_time' || in_array($k, $datetimeField)) {
# 处理下次联系时间格式、datetime类型数据
$data[$k] = !empty($v) ? strtotime($v) : '';
} else {
$data[$k] = $v;
}
# 处理产品类别
if ($types == 'crm_product' && $k == 'category_id') {
} elseif ($types == 'crm_product' && $k == 'category_id') {
# 处理产品类别
$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();
}
return $model->update($data);
$res = $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',
];
/**
* @param $param
* @return array
*/
public function index($param)
{
$adminModel = new \app\admin\model\Admin();
@ -69,17 +73,16 @@ class IndexLogic extends Common
$contract_auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'index');
$receivables_auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'index');
$record_auth_user_ids = $userModel->getUserByPer('crm', 'activity', 'index');
$resCount = queryCache(
$this->getCountSql([
'start_time' => $between_time[0],
'end_time' => $between_time[1],
'customer_auth_user_ids' => array_intersect($userIds, $customer_auth_user_ids),
'contacts_auth_user_ids' => array_intersect($userIds, $contacts_auth_user_ids),
'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids),
'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids),
'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids),
'record_auth_user_ids' => array_intersect($userIds, $record_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) ? :[-1],
'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids) ? :[-1],
'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids) ? :[-1],
'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids) ? :[-1],
'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');
$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 = [];
if (!$partMap) {
$a = 'index';
@ -68,20 +63,20 @@ class VisitLogic extends Common
if (!is_array($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]) ?: []; //取差集
} else {
$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'];
$authMap['visit.owner_user_id'] = array('in', $auth_user_ids);
unset($map['visit.owner_user_id']);
} else {
$authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id;
$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.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
};
@ -96,6 +91,7 @@ class VisitLogic extends Common
//人员类型
$userField = $fieldModel->getFieldByFormType('crm_visit', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_visit', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
@ -118,12 +114,11 @@ class VisitLogic extends Common
->where($partMap)
->where($authMap)
->limit($request['offset'], $request['length'])
->field(array_merge($indexField, [
'contract.num' => 'contract_number',
'customer.name' => 'customer_name',
'contacts.name' => 'contacts_name',
]))
->field('visit.*,
contract.num as contract_number,
customer.name as customer_name,
contacts.name as contacts_name'
)
->orderRaw($order)
->group('visit.visit_id')
->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]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
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]) : [];
$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']['name'] = $v['contract_name'];
@ -161,7 +161,7 @@ class VisitLogic extends Common
$is_update = 0;
$is_delete = 0;
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;
$permission['is_read'] = $is_read;
$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_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['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo;
@ -330,7 +335,7 @@ class VisitLogic extends Common
return resultArray(['error' => $this->getError()]);
}
//删除关联附件
$fileModel->delRFileByModule('crm_business', $delIds);
$fileModel->delRFileByModule('crm_visit', $delIds);
//删除关联操作记录
$actionRecordModel->delDataById(['types' => 'crm_visit', 'visit_id' => $delIds]);
actionLog($delIds, '', '', '');

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

@ -85,7 +85,7 @@ class Contacts extends Common
if (!is_array($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]) ? : []; //取差集
} else {
$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');
$userField = $fieldModel->getFieldByFormType('crm_contacts', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
@ -144,7 +145,6 @@ class Contacts extends Common
->where($customerWhere)
->limit($request['offset'], $request['length'])
->field('contacts.*,customer.name as customer_name')
->field(implode(',',$indexField).',customer.name as customer_name')
->orderRaw($order)
->select();
@ -154,11 +154,16 @@ class Contacts extends Common
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : '';
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]) : [];
$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 = [];
@ -173,9 +178,6 @@ class Contacts extends Common
$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;
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['contacts_id'], 'type' => 'crm_contacts'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -227,9 +229,6 @@ class Contacts extends Common
$param['primary'] = 1;
}
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) {
@ -249,7 +248,7 @@ class Contacts extends Common
'create_user_id' => $param['create_user_id'],
'update_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;
}
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) {
@ -382,7 +378,11 @@ class Contacts extends Common
# 处理决策人显示问题
$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['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;

@ -99,7 +99,7 @@ class Contract extends Common
if (!is_array($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]) ? : []; //取差集
} else {
$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');
$structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
$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]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
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]) : [];
$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']['name'] = $v['business_name'];
$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]['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]['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');
$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');
$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['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;
@ -510,10 +524,10 @@ class Contract extends Common
foreach ($ids as $id) {
$contractInfo = [];
$contractInfo = db('crm_contract')->where(['contract_id' => $id])->find();
if (in_array($contractInfo['check_status'],['0','1'])) {
$errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;';
continue;
}
// if (in_array($contractInfo['check_status'],['0','1'])) {
// $errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;';
// continue;
// }
//团队成员
$teamData = [];
$teamData['type'] = $type; //权限 1只读2读写
@ -529,7 +543,19 @@ class Contract extends Common
if (!db('crm_contract')->where(['contract_id' => $id])->update($data)) {
$errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:数据出错;';
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) {
return $errorMessage;

@ -127,7 +127,7 @@ class Customer extends Common
if (!is_array($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]) ? : []; //取差集
} else {
$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');
$userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
@ -190,8 +191,7 @@ class Customer extends Common
->where($poolMap)
->where($otherMap)
->limit($request['offset'], $request['length'])
->field(implode(',',$indexField))
->order($order_t) /*置顶*/
->field('customer.*')
->orderRaw($order)
->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'] : '';
foreach ($userField as $key => $val) {
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) {
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;
//距进入公海天数
@ -268,9 +273,6 @@ class Customer extends Common
$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;
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['customer_id'], 'type' => 'crm_customer'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -327,9 +329,6 @@ class Customer extends Common
return false;
}
unset($param['customer_id']);
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_customer');
@ -378,70 +377,67 @@ class Customer extends Common
* @param
* @return
*/
public function updateDataById($param, $customer_id = '')
{
$user_id = $param['user_id'];
$dataInfo = $this->get($customer_id);
if (!$dataInfo) {
$this->error = '数据不存在或已删除';
return false;
}
//数据权限判断
public function updateDataById($param, $customer_id = '')
{
$user_id = $param['user_id'];
$dataInfo = $this->get($customer_id);
if (!$dataInfo) {
$this->error = '数据不存在或已删除';
return false;
}
$id = $param['id']?:$customer_id;
//数据权限判断
$userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update');
//读写权限
$rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
//判断是否客户池数据
$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)) {
$this->error = '无权操作';
return false;
}
$param['customer_id'] = $customer_id;
//过滤不能修改的字段
$unUpdateField = ['create_user_id','is_deleted','delete_time','user_id'];
foreach ($unUpdateField as $v) {
unset($param[$v]);
}
$param['deal_status'] = $dataInfo['deal_status'];
$fieldModel = new \app\admin\model\Field();
// 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($param);
if (!$result) {
$this->error = $validate->getError();
return false;
}
//地址
$param['address'] = $param['address'] ? implode(chr(10),$param['address']) : '';
if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') {
$param['customer_id'] = $customer_id;
//过滤不能修改的字段
$unUpdateField = ['create_user_id','is_deleted','delete_time','user_id'];
foreach ($unUpdateField as $v) {
unset($param[$v]);
}
$param['deal_status'] = $dataInfo['deal_status'];
$fieldModel = new \app\admin\model\Field();
// 自动验证
$validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
$validate = new Validate($validateArr['rule'], $validateArr['message']);
$result = $validate->check($param);
if (!$result) {
$this->error = $validate->getError();
return false;
}
//地址
$param['address'] = $param['address'] ? implode(chr(10),$param['address']) : '';
if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') {
$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]);
}
$param['follow'] = '已跟进';
if ($this->update($param, ['customer_id' => $customer_id], true)) {
//修改记录
updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param);
$data = [];
$data['customer_id'] = $customer_id;
return $data;
} else {
$this->error = '编辑失败';
return false;
}
}
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_customer');
foreach ($arrFieldAtt as $k=>$v) {
$param[$v] = arrayToString($param[$v]);
}
$param['follow'] = '已跟进';
if ($this->update($param, ['customer_id' => $customer_id], true)) {
//修改记录
updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param);
$data = [];
$data['customer_id'] = $customer_id;
return $data;
} 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');
$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['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;

@ -14,6 +14,7 @@ class Invoice extends Common
{
protected $name = 'crm_invoice';
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])) {
$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]) ?: []; //取差集
} else {
$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');
$userField = $fieldModel->getFieldByFormType('crm_leads', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_leads', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型
//排序
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]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
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]) : [];
$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 = [];
@ -156,8 +162,6 @@ class Leads extends Common
$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;
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['leads_id'], 'type' => 'crm_leads'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@ -210,9 +214,6 @@ class Leads extends Common
$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()) {
//修改记录
updateActionLog($param['create_user_id'], 'crm_leads', $this->leads_id, '', '', '创建了线索');
@ -276,9 +277,6 @@ class Leads extends Common
return false;
}
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_leads');
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');
$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['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;

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

@ -83,7 +83,7 @@ class Receivables extends Common
if (!is_array($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]) ? : []; //取差集
} else {
$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');
$structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
if ($request['order_type'] && $request['order_field']) {
$order = $fieldModel->getOrderByFormtype('crm_receivables','receivables',$order_field,$order_type);
@ -134,7 +135,7 @@ class Receivables extends Common
->where($map)
->where($authMap)
->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)
->select();
@ -150,11 +151,16 @@ class Receivables extends Common
$list[$k]['contract_id_info']['money'] = $v['contract_money'] ? : '0.00';
$list[$k]['contract_money'] = $v['contract_money'] ? : '0.00';
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]) : [];
$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']];
//期数
$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['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['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo;

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

@ -468,7 +468,7 @@ class Examine extends ApiCommon
$is_end = 1;
//审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3;
$examineData['check_user_id'] = '';
// $examineData['check_user_id'] = '';
} else {
//修改主体相关审批信息
$examineData['check_user_id'] = arrayToString($next_user_ids);
@ -484,7 +484,7 @@ class Examine extends ApiCommon
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$examineData['check_user_id'] = '';
// $examineData['check_user_id'] = '';
$examineData['check_status'] = 2;
}
} else {
@ -588,8 +588,9 @@ class Examine extends ApiCommon
$checkData['status'] = $status;
$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);
if ($resExamine) {
//将审批记录至为无效

@ -137,7 +137,6 @@ class Task extends ApiCommon
} else {
$where['t.status'] = [['=', 1], ['=', 5], 'OR'];
}
if ($param['main_user_id']) {
$where['t.main_user_id'] = $param['main_user_id'];
}
@ -160,19 +159,19 @@ class Task extends ApiCommon
if ($type != 0) {
switch ($type) {
case '1' :
$type = 't.main_user_id in ('.$subStr.')';
$type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的
case '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; //下属参与的
}
} else {
if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} 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;
@ -195,13 +194,12 @@ class Task extends ApiCommon
$query->where($type);
})
->count();
$completeCount = db('task') ->alias('t')->where($where)
$completeCount = db('task')->alias('t')
->where($map)
->where(function ($query) use ($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) {
$temp = $v ?: [];
if ($v['pid']) {
@ -236,15 +234,15 @@ class Task extends ApiCommon
$type = 't.main_user_id =' . $userInfo['id'] . '';
break; //我负责的
case '3' :
$type = 't.owner_user_id like "%,'.$userInfo['id'].',%"';
$type = 't.owner_user_id like "%,' . $userInfo['id'] . ',%"';
break; //我参与的
}
} else {
$adminIds = $userModel->getAdminId();
if (in_array($userInfo['id'],$adminIds)) {
if (in_array($userInfo['id'], $adminIds)) {
$type = 't.is_open = 1';
} 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;
@ -259,29 +257,31 @@ class Task extends ApiCommon
->order('t.task_id desc')
->select();
$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) {
$pname = '';
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]['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]['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]['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]['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]['lableList'] = $value['lable_id'] ? $lableModel->getDataByStr($value['lable_id']) : [];
$taskList[$key]['create_time'] = date('Y-m-d', $value['create_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]['stop_time'] = $value['stop_time']==0?null:date('Y-m-d', $value['stop_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]['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]['main_user'] = $value['main_user_id'] ? $userModel->getDataById($value['main_user_id']) : array();
$taskList[$key]['relationCount'] = $taskModel->getRelationCount($value['task_id']);
$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;
}
}

@ -11,6 +11,192 @@ class ExamineLogic extends Common
{
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
@ -19,33 +205,123 @@ class ExamineLogic extends Common
public function excelExport($param)
{
$excelModel = new \app\admin\model\Excel();
$field_list1 = [
array('name' => '审批类型', 'field' => 'category_name', 'form_type' => 'text'),
array('name' => '创建时间', 'field' => 'create_time', 'form_type' => ''),
array('name' => '创建人', 'field' => 'create_user_id', 'form_type' => 'user'),
array('name' => '状态', 'field' => 'check_status_info','form_type' => ''),
array('name' => '当前审批人', 'field' => 'check_user_id','form_type' => 'userStr'),
// array('name' => '下一审批人', 'field' => 'last_user_id','form_type' => 'user'),
// array('name' => '关联业务', 'field' => 'relation','form_type' => ''),
];
// 导出的字段列表
$fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('oa_examine', $param['user_id'], $param['category_id']);
$data = $this->getDataList($param);
$list = [];
switch ($param['category_id']) {
case '1' :
$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'],
];
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';
$temp_file = $param['temp_file'];
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;
});
return $excelModel->dataExportCsv($file_name, $field_list, $data);
}
/**
@ -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 . '%']);
};
} elseif ($param['status'] == 1) {
$where['a.check_status'] = ['in', [2,3]];
$whereOr = function ($query) use ( $user_id) {
$query->where('a.check_user_id',['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
$where['a.check_status'] = ['in', [2, 3]];
$whereOr = function ($query) use ($user_id) {
$query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
};
} elseif ($param['status'] == 3) {
$where['a.check_status'] = ['lt', 5];

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

@ -15,7 +15,7 @@ class TaskLogic
$userModel = new \app\admin\model\User();
$taskModel = new TaskModel();
$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];
@ -56,9 +56,9 @@ class TaskLogic
$where = [];
$where['ishidden'] = 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'])) {
$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']);
@ -76,7 +76,6 @@ class TaskLogic
->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')
->where($where)
->where($whereStr)
->where($timeWhere)
->where($labelWhere)
->order('t.task_id desc')
@ -96,19 +95,19 @@ class TaskLogic
if ($type != 0) {
switch ($type) {
case '1' :
$type = 't.main_user_id in ('.$subStr.')';
$type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的
case '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; //下属参与的
}
} else {
if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} 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;
@ -126,7 +125,7 @@ class TaskLogic
->where($map)
->order('t.task_id desc')
->select();
} else {
} else {
$map['t.pid'] = 0;
// $map['t.work_id'] = 0;
if ($type != 0) {
@ -135,15 +134,15 @@ class TaskLogic
$type = 't.main_user_id =' . $param['user_id'] . '';
break; //我负责的
case '3' :
$type = 't.owner_user_id like "%,'.$param['user_id'].',%"';
$type = 't.owner_user_id like "%,' . $param['user_id'] . ',%"';
break; //我参与的
}
} else {
$adminIds = $userModel->getAdminId();
if (in_array($param['user_id'],$adminIds)) {
if (in_array($param['user_id'], $adminIds)) {
$type = 't.is_open = 1';
} 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;
@ -154,7 +153,6 @@ class TaskLogic
->where($where)
->where($type)
->where($map)
->page($param['page'], $param['limit'])
->order('t.task_id desc')
->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]['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']) : '';
//优先级

@ -27,42 +27,49 @@ class UserLogic
$initials_type = ($param['initials'] == 1) ? 1 : 2;
$where['user.status'] = 1;
if ($search) {
$where = function ($query) use ($search) {
$whereMap = function ($query) use ($search) {
$query->where('user.realname', array('like', '%' . $search . '%'))
->whereOr('user.mobile', array('like', '%' . $search . '%'));
};
}
if ($param['star_type'] == 1) {
$item = Db::name('crm_star')->where('user_id', $user_id)->column('target_id');
$where['user.id'] = ['in', $item];
}
if ($param['structure_id'] == '') {
$list = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile')
->page($param['page'], $param['limit'])
->select();
foreach ($list as $k => $v) {
$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;
if($param['structure_id']){
$where['user.id']= $param['structure_id'];
}
if (isset($param['star_type'])) {
if ($param['star_type'] == 1) {
$item = Db::name('crm_star')->where(['user_id'=>$user_id,'type'=>'admin_user'])->column('target_id');
if(!empty($item)) {
$where['user.id'] = ['in', $item];
$list = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
->where($whereMap)
->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile')
->page($param['page'], $param['limit'])
->select();
foreach ($list as $k => $v) {
$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 {
$list = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->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')
->page($param['page'], $param['limit'])
->select();
@ -70,7 +77,6 @@ class UserLogic
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
->where('structure.id', $param['structure_id'])
->count();
foreach ($list as $k => $v) {
$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 ( 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();
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]['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']);
$event_date[$k]['businessList'] = $relationArr['businessList'];
$event_date[$k]['contactsList'] = $relationArr['contactsList'];
$event_date[$k]['contractList'] = $relationArr['contractList'];
$event_date[$k]['customerList'] = $relationArr['customerList'];
$event_date[$k]['type'] = 'event';
$event_date[$k]['remindtype'] = (int)$v['remindtype'];
$noticeInfo = Db::name('OaEventNotice')->where(['event_id' => $v['event_id']])->find();
$is_repeat = 0;
if ($noticeInfo) {
$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]['stop_time'] = $noticeInfo ? $noticeInfo['stop_time'] : '';
$event_date[$k]['noticetype'] = $noticeInfo ? $noticeInfo['noticetype'] : '';
if ($noticeInfo['noticetype'] == '2') {
$event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||', $noticeInfo['repeated']) : [];
$event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||',$noticeInfo['repeated']) : [];
} else {
$event_date[$k]['repeat'] = '';
$event_date[$k]['repeat'] = '';
}
//权限
$is_update = 0;
@ -93,15 +90,13 @@ class Event extends Common
}
$permission['is_update'] = $is_update;
$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]['end_time'] = !empty($v['end_time']) ? $v['end_time'] * 1000 : null;
$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 . '))
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();
$item = [];
foreach ($event_date as $k2 => $v) {
@ -780,9 +775,9 @@ class Event extends Common
# 关联数据
$relation = [];
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['business_ids'])) $relation['business_ids'] = arrayToString($param['customer_ids']);
if (!empty($param['contract_ids'])) $relation['contract_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['business_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;
actionLog($event_id, $param['owner_user_ids'], '', '修改了日程');
$list = db('oa_event_notice')->where('event_id', $eventId)->select();
$item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete();
if (!$item) {
if ($list) {
foreach ($list as $k => $v) {
Db::name('admin_message')->where(['type' => 9, 'action_id' => $v['id']])->delete();
}
}
$item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete();
# 提醒
if (!empty($notice)) {
$noticeData = [];
@ -822,40 +817,47 @@ class Event extends Common
'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;
} else {
$this->error = '编辑失败';

@ -23,7 +23,7 @@ class Examine extends Common
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true;
private $statusArr = ['待审核','审核中','审核通过','已拒绝','已撤回'];
private $statusArr = ['待审核', '审核中', '审核通过', '已拒绝', '已撤回'];
/**
* [getDataList 审批list]
@ -41,8 +41,10 @@ class Examine extends Common
$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']);
@ -56,7 +58,7 @@ class Examine extends Common
}
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 = '';
$logmap = '';
@ -71,7 +73,9 @@ class Examine extends Common
$map['check_user_id'] = [['like', '%,' . $user_id . ',%']];
break; //待审
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; //已审
default:
$map['examine.create_user_id'] = $user_id;
@ -87,7 +91,7 @@ class Examine extends Common
unset($map['examine.between_time']);
//审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部
if ($check_status) {
if (isset($check_status)) {
if ($check_status == 'all') {
$map['examine.check_status'] = ['egt', 0];
if (isSuperAdministrators($user_id)) {
@ -95,13 +99,20 @@ class Examine extends Common
}
} 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 {
$map['examine.check_status'] = ['egt', 0];
}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'],
@ -131,7 +142,7 @@ class Examine extends Common
$duration = $v['duration'] ?: '0.0';
$money = $v['money'] ?: '0.00';
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'] == 5) $causeTitle = $causeCount . '个报销事项,共' . $money . '元';
@ -155,7 +166,7 @@ class Examine extends Common
}
$list[$k]['causeTitle'] = $causeTitle;
$list[$k]['causeCount'] = $causeCount ? : 0;
$list[$k]['causeCount'] = $causeCount ?: 0;
//关联业务
$relationArr = [];
@ -210,25 +221,25 @@ class Examine extends Common
if ($examineFlowData['config'] == 1) {
//固定审批流
$examineStepModel = new \app\admin\model\ExamineStep();
$nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
$is_check = $nextStepData['next_user_ids'] ? 1 : 0;
// $nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
$is_check = in_array($user_id, stringToArray($v['check_user_id'])) && in_array($v['check_status'], [0, 1]) ? 1 : 0;
$is_end = 1;
} else {
$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;
}else{
} else {
$is_check = 0;
}
}
if ($v['last_user_id'] == 0) {
$user_name = $userModel->getListByStr(stringToArray($v['check_user_id']));
$list[$k]['examine_name'] = $user_name[0]['realname'];
} else {
$user_name = $userModel->getListByStr(stringToArray($v['last_user_id']));
$list[$k]['examine_name'] = $user_name[0]['realname'];
if($v['check_status']==4){
$usernames = db('admin_user')->whereIn('id', stringToArray($user_id))->column('realname');
}else{
$usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
}
$list[$k]['examine_name'] = implode($usernames, '');
$permission['is_check'] = $is_check;
$permission['is_delete'] = $is_delete;
$permission['is_recheck'] = $is_recheck;
@ -236,7 +247,8 @@ class Examine extends Common
$list[$k]['permission'] = $permission;
$list[$k]['config'] = $is_end;
$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['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();
# 是否是公开项目
$userId = empty($workInfo['is_open']) ? $userInfo['id'] : 0;
$groupId = !empty($workInfo['is_open']) ? $workInfo['group_id '] : 0;
$userId = $userInfo['id'];
$groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
# 获取项目下的权限
$taskData['auth'] = !empty($taskData['work_id']) ? $this->getRuleList($workInfo['work_id'], $userId, $groupId) : [];

@ -84,6 +84,9 @@ class Tasklable extends ApiCommon
$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['work_id'] = ['neq', 0];
$resData = $taskModel->getTaskList($param);
$taskList = $resData['list'] ? : [];

@ -147,7 +147,7 @@ class work extends ApiCommon
$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;
# 项目成员
@ -632,5 +632,25 @@ class work extends ApiCommon
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';
$orderSort = 'asc';
$orderSort = 'asc';
if (!empty($param['sort_type']) && $param['sort_type'] == 1) {
$orderField = 'work_id';
$orderSort = 'asc';
$orderSort = 'asc';
}
if (!empty($param['sort_type']) && $param['sort_type'] == 2) {
$orderField = 'work_id';
$orderSort = 'desc';
$orderSort = 'desc';
}
if (!empty($param['sort_type']) && $param['sort_type'] == 3) {
$orderField = 'update_time';
$orderSort = 'desc';
$orderSort = 'desc';
}
# 搜索
$searchWhere = '';
$dateWhere = [];
$userWhere = [];
$dateWhere = [];
$userWhere = [];
$ownerUserId = !empty($param['owner_user_id']) ? $param['owner_user_id'] : '';
$search = !empty($param['search']) ? $param['search'] : '';
$type = !empty($param['type']) ? $param['type'] : 0;
$startTime = !empty($param['start_time']) ? $param['start_time'] : '';
$endTime = !empty($param['end_time']) ? $param['end_time'] : '';
$search = !empty($param['search']) ? $param['search'] : '';
$type = !empty($param['type']) ? $param['type'] : 0;
$startTime = !empty($param['start_time']) ? $param['start_time'] : '';
$endTime = !empty($param['end_time']) ? $param['end_time'] : '';
unset($param['search']);
unset($param['type']);
unset($param['start_time']);
@ -72,7 +72,7 @@ class WorkLogic
# 时间区间
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 . '%")';
@ -83,32 +83,122 @@ class WorkLogic
$userWhere['work_id'] = ['in', $userIds];
}
$userModel = new \app\admin\model\User();
$userModel = new \app\admin\model\User();
$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')
->where(function($query) {
$query->where('status', 1);
$query->where('ishidden', 0);
})
->where(function ($query) use ($param, $authUser) {
$query->whereOr(['create_user_id' => ['in', $authUser]]);
$query->whereOr('is_open', 1);
$query->whereOr(function ($query) use ($param) {
$query->where('is_open', 0);
$query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%');
});
})
->where($searchWhere)
->where($dateWhere)
->where($userWhere)
->order($orderField, $orderSort)->select();
->where(function ($query) {
$query->where('status', 1);
$query->where('ishidden', 0);
})
->where(function ($query) use ($param, $authUser) {
$query->whereOr(['create_user_id' => ['in', $authUser]]);
$query->whereOr('is_open', 1);
$query->whereOr(function ($query) use ($param) {
$query->where('is_open', 0);
$query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%');
});
})
->where($searchWhere)
->where($dateWhere)
->where($userWhere)
->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']);
}
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');
$userModel = new \app\admin\model\User();
$work_id = $request['work_id'];
$map=[];
$ret = $workModel->checkWork($work_id, $user_id);
if (!$ret) {
$this->error = $workModel->getError();
@ -69,10 +70,6 @@ class Task extends Common
$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'] == '5') { //没有截至日期
$map['stop_time'] = '0';
@ -104,6 +101,7 @@ class Task extends Common
$map['stop_time'] = ['between', [$timeAry[0], $timeAry[1]]];
}
}
if ($request['lable_id']) {
$taskIds = [];
$task_ids = [];
@ -125,18 +123,20 @@ class Task extends Common
}
$map['task_id'] = ['in', $task_ids];
}
$data = array();
foreach ($newList as $key => $value) {
$data[$key]['class_id'] = $value['class_id'] ?: -1;
$data[$key]['class_name'] = $value['name'];
$map['status'] = $map['status'] ?: ['in', ['1', '5']];
$map['ishidden'] = 0;
$map['work_id'] = $request['work_id'];
$map['class_id'] = $value['class_id'];
$map['pid'] = 0;
$map['is_archive'] = 0;
$map['main_user_id']=$request['main_user_id'];
$taskList = [];
$resTaskList = $this->getTaskList($map);
$data[$key]['count'] = $resTaskList['count'];
@ -414,7 +414,7 @@ class Task extends Common
unset($param[$value]);
}
$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['start_time'] = !empty($param['start_time']) ? strtotime($param['start_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, '', '', '新建了任务');
//抄送站内信
// (new Message())->send(
// Message::TASK_ALLOCATION,
// [
// 'title' => $param['name'],
// 'action_id' => $task_id
// ],
// $param['owner_user_id']
// );
(new Message())->send(
Message::TASK_ALLOCATION,
[
'title' => $param['name'],
'action_id' => $task_id
],
trim(',',$param['owner_user_id'])
);
}
# 添加活动记录
@ -642,14 +642,14 @@ class Task extends Common
//设置负责人
$userdet = $userModel->getDataById($param['main_user_id']);
$data['after'] = '设定' . $userdet['realname'] . '为主要负责人!';
// (new Message())->send(
// Message::TASK_ALLOCATION,
// [
// 'title' => $taskInfo['name'],
// 'action_id' => $param['task_id']
// ],
// $param['main_user_id']
// );
(new Message())->send(
Message::TASK_ALLOCATION,
[
'title' => $taskInfo['name'],
'action_id' => $param['task_id']
],
$param['main_user_id']
);
break;
}
@ -899,15 +899,17 @@ class Task extends Common
*/
public function getTaskList($request)
{
$search = $request['search'];
$search = $request['search']?:'';
$whereStr = $request['whereStr'] ?: [];
$lable_id = $request['lable_id'] ?: '';
$main_user_id = $request['main_user_id'] ?: '';
$taskSearch = !empty($request['taskSearch']) ? $request['taskSearch'] : '';
$isArchive = !empty($request['is_archive']) ? $request['is_archive'] : 0;
unset($request['search']);
unset($request['whereStr']);
unset($request['lable_id']);
unset($request['taskSearch']);
// unset($request['search']);
// unset($request['whereStr']);
// unset($request['lable_id']);
unset($request['main_user_id']);
$request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: [];
$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();
$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) {
$taskList = db('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')
->where($map)
->where($whereStr)
->where($logWhere)
->where($taskSearch)
->order('task.status asc,task.order_id asc')
->select();
@ -1036,7 +1046,6 @@ class Task extends Common
->where($labelWhere)
->order($order)
->select();
foreach ($taskList as $key => $value) {
if ($value['pid'] > 0) {
$p_det = $this->field('task_id,name')->where(['task_id' => $value['pid']])->find();
@ -1084,35 +1093,38 @@ class Task extends Common
# 今天
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) {
$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) {
$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) {
$timestamp = mktime(0, 0, 0, date('m'), 1, 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) {
$result = $result = '(task.stop_time = 0)';;
$result = '(task.stop_time = 0)';;
}
# 已延期
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['create_user_id'] = $createUserId;
$ownerData['owner_user_id'] = $ownerUserId;
$ownerData['group_id'] = !empty($param['group_id']) ? $param['group_id'] : 0;
# 创建项目下的相关成员
$this->addOwner($ownerData);
@ -129,6 +130,10 @@ class Work extends Common
$ownerData['is_open'] = $param['is_open'];
$ownerData['group_id'] = $param['group_id'];
$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);
if ($resUpdata) {
@ -307,7 +312,7 @@ class Work extends Common
$group_id = 1;
} 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;
$saveData[] = $data;

@ -265,5 +265,8 @@ return [
// 商业智能查询缓存时间(秒)
'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/step3' => ['admin/install/step3', ['method' => 'GET']],
'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']],
//子部门列表

@ -233,6 +233,8 @@ return [
'crm/receivables/system' => ['crm/receivables/system', ['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']],

@ -1,5 +1,5 @@
<?php
return array(
'VERSION'=>'11.0.0',
'RELEASE'=>'20210205',
'VERSION'=>'11.0.1',
'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_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_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', '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', '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');
@ -1751,7 +1751,7 @@ DROP TABLE IF EXISTS `5kcrm_crm_visit`;
CREATE TABLE `5kcrm_crm_visit` (
`visit_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '回访id',
`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',
`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 '合同编号',
@ -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_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');
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`='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`='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`='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`='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`='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 ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0');
@ -1955,7 +1955,7 @@ CREATE TABLE `5kcrm_crm_receivables_file` (
`receivables_id` int(10) unsigned NOT NULL,
`file_id` int(10) unsigned NOT NULL,
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 ('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_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 ('155', '0', '日志欢迎语', 'welcome', '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,
regexp: /^(?=.*[a-zA-Z])(?=.*\d).{6,20}$/,
label: '管理员密码(6~20位字母加数字组合)'
}
},
wkcode: {
required: false,
regexp: null,
label: '序列号'
},
};
var timer = null;
@ -63,32 +68,36 @@ $('.next').click(function () {
// 校验form数据 true 校验通过 false 校验失败
var forms = getFormData();
var result = checkForm();
console.log('result---', result, forms);
// console.log('result---', result, forms);
if (result) {
$.ajax({
cache: true,
type: "POST",
dataType: 'json',
url: "./step4",
data: {
form: forms
},
async: false,
success: function (result) {
if (result.code == '200') {
alert(result.data);
window.location = '../../../index.html';
} else if (result.code == '400') {
alert(result.error); //失败
return false;
// window.location = 'step3.html'
} else {
window.location = 'step3.html'
alert('安装失败');
$('#cover').css('display', 'block');//显示遮罩层
setTimeout(()=>{
$.ajax({
cache: true,
type: "POST",
dataType: 'json',
url: "./step4",
data: {
form: forms
},
async: false,
success: function (result) {
if (result.code == '200') {
window.location = 'step5.html';
} else if (result.code == '400') {
$('#cover').css('display', 'none');
alert(result.error); //失败
return false;
// window.location = 'step3.html'
} else {
window.location = 'step3.html'
alert('安装失败');
}
}
}
// getRes();
});
// getRes();
});
})
}
});
@ -168,7 +177,7 @@ function _initFormValue() {
* @return {form}
*/
function getFormData() {
$('input').each(function (index, item) {
$('.wkform').each(function (index, item) {
form[item.name] = item.value;
// 重置表单状态
$(item).removeClass('input-error');
@ -186,6 +195,7 @@ function getFormData() {
* @return {boolean}
*/
function checkForm() {
var result = {};
for (var key in rules) {
var rule = rules[key];
@ -229,8 +239,3 @@ function renderErrorMsg(key, msg) {
}
})
}
/**
* 提交表单
*/
function submitForm() {}

@ -10,6 +10,11 @@ html, body {
background-color: #f2f2f2;
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 {
list-style: none;
@ -72,7 +77,10 @@ li {
.top {
width: 790px;
height: 65px;
margin: 0 auto;
margin:40px auto 20px auto;
border: 1px solid white;
border-radius: 5px ;
background-color: #fff ;
}
/* container */
@ -81,6 +89,7 @@ li {
min-height: 493px;
background-color: white;
border: 1px solid #e1e1e1;
border-radius:5px;
margin: 0 auto;
}
@ -93,7 +102,7 @@ li {
width: 820px;
text-align: center;
font-size: 15px;
color: #8c8c8c;
color: #fff;
line-height: 30px;
margin: 0 auto;
padding: 30px 0;
@ -112,6 +121,9 @@ li {
text-align: center;
margin: 20px 0;
float: left;
display: flex;
align-items: center;
justify-content: center;
}
.step.line {
width: 10%;
@ -122,12 +134,12 @@ li {
.step .sort {
width: 25px;
height: 25px;
color: white;
color: #8c8c8c;
line-height: 25px;
text-align: center;
font-size: 14px;
border-radius: 50%;
background-color: #d1d1d1;
/* background-color: #d1d1d1; */
margin-right: 5px;
display: inline-block;
}
@ -139,13 +151,13 @@ li {
}
.step.active .sort {
background-color: #3e84e9;
background-color: #fff;
}
.step.active .desc {
color: #3e84e9;
color: black;
}
.step.active.line {
background-color: #3e84e9;
/* background-color: #fff; */
}
@ -156,7 +168,7 @@ li {
line-height: 40px;
font-size: 16px;
color: #3e84e9;
border-radius: 40px;
border-radius: 5px;
background-color: white;
border: 1px solid #3e84e9;
display: inline-block;
@ -172,16 +184,44 @@ li {
width: 100%;
height: 54px;
line-height: 54px;
background-color: #f7f7f7;
/* background-color: #f7f7f7; */
padding: 0 26px;
border-bottom: 1px solid #e1e1e1;
/* border-bottom: 1px solid #e1e1e1; */
font-weight: 600;
}
.base-top .title {
color: #8c8c8c;
/* color: #8c8c8c; */
font-size: 16px;
}
.base-top .version {
font-size: 13px;
color: #d1d1d1;
color: #8c8c8c;
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 {
padding: 20px;
border-radius: 10px;
}
.agreement-title {
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 {
width: 100%;
border: 1px solid #e1e1e1;
border-collapse: collapse;
/* border-collapse: collapse; */
border-collapse: separate;
border-spacing: 0;
border-radius:5px;
overflow: hidden;
}
.table tr {
height: 34px;
text-align: center;
}
th, td {
border: 1px solid #e1e1e1;
border-bottom: 1px solid #f7f7f7;
width: 30%;
}
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 {
font-weight: normal;
background-color: #3e84e9;
color: white;
background-color: #f7f7f7;
/* color: white; */
font-weight: 600;
}

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