diff --git a/application/admin/common.php b/application/admin/common.php index 54d3320..7b61f94 100644 --- a/application/admin/common.php +++ b/application/admin/common.php @@ -173,9 +173,9 @@ function sendRequest($url, $params = array() , $headers = array()) { /** * 验证序列号 - * @param + * @param * @return - */ + */ function checkWkCode($wkcode) { $pub = formatPubKey(config('public_key')); $openssl_pub = openssl_pkey_get_public($pub); diff --git a/application/admin/controller/ApiCommon.php b/application/admin/controller/ApiCommon.php index 15b1ed6..a2184d8 100644 --- a/application/admin/controller/ApiCommon.php +++ b/application/admin/controller/ApiCommon.php @@ -7,6 +7,7 @@ namespace app\admin\controller; +use think\Cache; use think\Request; use think\Db; use app\common\adapter\AuthAdapter; @@ -22,11 +23,12 @@ class ApiCommon extends Common $header = Request::instance()->header(); $request = Request::instance(); - $authKey = $header['authkey']; - $sessionId = $header['sessionid']; + $authKey = trim($header['authkey']); + $sessionId = trim($header['sessionid']); $paramArr = $request->param(); $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding) - $cache = cache('Auth_'.$authKey.$platform); + $cache = Cache::get('Auth_'.$authKey.$platform); +// $cache = cache('Auth_'.$authKey.$platform); // 校验sessionid和authKey if (empty($sessionId) || empty($authKey) || empty($cache)) { @@ -36,7 +38,7 @@ class ApiCommon extends Common } //登录有效时间 $cacheConfig = config('cache'); - $loginExpire = $cacheConfig['expire'] ? : 86400*3; + $loginExpire = !empty($cacheConfig['expire']) ? $cacheConfig['expire'] : 86400 * 30; // 检查账号有效性 $userInfo = $cache['userInfo']; @@ -49,7 +51,8 @@ class ApiCommon extends Common } session('user_id', $userInfo['id']); // 更新缓存 - cache('Auth_'.$authKey, $cache, $loginExpire); + Cache::set('Auth_'.$authKey, $cache, $loginExpire); +// cache('Auth_'.$authKey, $cache, $loginExpire, 'UserToken'); // $GLOBALS['userInfo'] = $userInfo; } } diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index 99ba973..a7dbe0e 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -9,6 +9,7 @@ namespace app\admin\controller; use com\verify\HonrayVerify; use app\common\controller\Common; +use think\Cache; use think\Request; use think\Session; @@ -41,7 +42,7 @@ class Base extends Common $request = Request::instance(); $paramArr = $request->param(); $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding) - $cache = cache('Auth_'.$authKey.$platform,null); + $cache = Cache::set('Auth_'.trim($header['authkey']).$platform,null); cookie(null, '72crm_'); cookie(null, '5kcrm_'); session('user_id','null'); diff --git a/application/admin/controller/ExamineFlow.php b/application/admin/controller/ExamineFlow.php index 175b7ad..9f4e9ce 100644 --- a/application/admin/controller/ExamineFlow.php +++ b/application/admin/controller/ExamineFlow.php @@ -258,9 +258,22 @@ class ExamineFlow extends ApiCommon { $param = $this->param; $userInfo = $this->userInfo; + $data= $this->checkFlow($param,$userInfo); + return resultArray(['data' => $data]); + } + + /** + * 固定审批流审批流程人员数据 + * @param $param + * @param $userInfo + * + * @author alvin guogaobo + * @version 1.0 版本号 + * @since 2021/3/15 0015 13:37 + */ + public function checkFlow($param,$userInfo){ $examineStepModel = model('ExamineStep'); $examineFlowModel = model('ExamineFlow'); - $check_user_id = $userInfo['id']; $flow_id = $param['flow_id']; $types = $param['types']; @@ -269,7 +282,7 @@ class ExamineFlow extends ApiCommon if (!$types || !in_array($types, $typesArr)) { return resultArray(['error' => '参数错误']); } - + if ($flow_id) { $examineFlowData = $examineFlowModel->getDataById($param['flow_id']); if (!$examineFlowData) { @@ -281,8 +294,8 @@ class ExamineFlow extends ApiCommon $user_id = $typesInfo['dataInfo']['create_user_id']; } if (!$user_id) { - return resultArray(['error' => '参数错误']); - } + return resultArray(['error' => '参数错误']); + } } else { $user_id = $check_user_id; // 获取符合条件的审批流 @@ -292,10 +305,10 @@ class ExamineFlow extends ApiCommon if (in_array($types, ['crm_contract', 'crm_receivables', 'crm_invoice'])) { return resultArray(['data' => ['examineStatus' => false]]); } - + return resultArray(['error' => '无可用审批流,请联系管理员']); - } - $flow_id = $examineFlowData['flow_id']; + } + $flow_id = $examineFlowData['flow_id']; } if ($types == 'oa_examine') { $category_id = db('oa_examine')->where(['examine_id' => $types_id])->value('category_id'); @@ -320,14 +333,13 @@ class ExamineFlow extends ApiCommon } $data = []; $data['config'] = (int) $examineFlowData['config']; //1固定,0自选 - $data['stepList'] = $stepList ? : []; + $data['stepList'] = $stepList ? : []; $data['examine_user'] = $list ? : []; $data['is_check'] = $stepInfo['is_check'] ? : 0; $data['is_recheck'] = $stepInfo['is_recheck'] ? : 0; $data['examineStatus'] = true; - return resultArray(['data' => $data]); + return $data; } - /** * 自选审批人列表(授权审批类型) * @author Michael_xu @@ -360,10 +372,8 @@ class ExamineFlow extends ApiCommon */ public function recordList() { - $param = $this->param; - $userInfo = $this->userInfo; $examineRecordModel = model('ExamineRecord'); - $list = $examineRecordModel->getDataList($param) ? : []; - return resultArray(['data' => $list]); - } + $data = $examineRecordModel->getDataList($this->param); + return resultArray(['data' => $data]); + } } \ No newline at end of file diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 777976e..510a67f 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -24,7 +24,7 @@ class Index extends ApiCommon $action = [ 'permission' => [], 'allow' => ['fields', 'fieldrecord', 'authlist','sort','updatesort', - 'importnum','importinfo','importlist'], + 'importnum','importinfo','importlist','readnotice'], ]; Hook::listen('check_auth', $action); $request = Request::instance(); @@ -152,4 +152,19 @@ class Index extends ApiCommon $data = $excelModel->importList($param); return resultArray(['data'=>$data]); } + + /** + * 升级公告 + * @author fanqi + * @date 2021-03-15 + * @return \think\response\Json + */ + public function readNotice() + { + $userInfo = $this->userInfo; + + if (!empty($userInfo['id'])) db('admin_user')->where('id', $userInfo['id'])->update(['is_read_notice' => 1]); + + return resultArray(['data' => '']); + } } diff --git a/application/admin/controller/Install.php b/application/admin/controller/Install.php index b37d95f..0feb35a 100644 --- a/application/admin/controller/Install.php +++ b/application/admin/controller/Install.php @@ -110,8 +110,9 @@ class Install extends Controller $db_config['database'] = $param['databaseName']; $db_config['username'] = $param['databaseUser']; $db_config['password'] = $param['databasePwd']; - $db_config['prefix'] = $param['databaseTable']; - + $db_config['prefix'] = '5kcrm_'; +// $db_config['prefix'] = $param['databaseTable']; + $username = $param['root']; $password = $param['pwd']; $wkcode = $param['wkcode']; @@ -202,7 +203,26 @@ class Install extends Controller return resultArray(['data'=>'安装成功']); } + /** + * 安装成功界面 + * + * @author fnqi + * @date 2021-03-11 + * @return mixed + */ public function step5() + { + return $this->fetch(); + } + + /** + * 安装超时界面 + * + * @author fanqi + * @date 2021-03-11 + * @return mixed + */ + public function step6() { return $this->fetch(); } diff --git a/application/admin/controller/Users.php b/application/admin/controller/Users.php index b87b62d..8ed5872 100644 --- a/application/admin/controller/Users.php +++ b/application/admin/controller/Users.php @@ -305,6 +305,9 @@ class Users extends ApiCommon $param = $this->param; $userInfo = $this->userInfo; $userModel = model('User'); + + if (empty($param['new_pwd']) || empty($param['old_pwd'])) return resultArray(['error' => '密码不能为空!']); + if ($param['id'] && (int)$param['id'] !== $userInfo['id']) { //权限判断 if (!checkPerByAction('admin', 'users', 'update')) { diff --git a/application/admin/logic/InitializeLogic.php b/application/admin/logic/InitializeLogic.php index 9d42628..d65d748 100644 --- a/application/admin/logic/InitializeLogic.php +++ b/application/admin/logic/InitializeLogic.php @@ -80,7 +80,22 @@ class InitializeLogic # 查询产品文件数据 $productFileInfo = $this->getFileList($productFileIds); + # 获取产品图和产品详情图附件ID + $productDetailsIds = []; + $productDetailFiles = Db::name('crm_product')->field(['cover_images', 'details_images'])->select(); + foreach ($productDetailFiles AS $key => $value) { + if (!empty($value['cover_images'])) $productDetailsIds = array_merge($productDetailsIds, explode(',', $value['cover_images'])); + if (!empty($value['details_images'])) $productDetailsIds = array_merge($productDetailsIds, explode(',', $value['details_images'])); + } + + # 合并附件ID数据 + $productFileIds = array_merge($productFileIds, $productDetailsIds); + + # 获取产品图和产品详情图文件数据 + $productDetailsFiles = $this->getFileList($productDetailsIds); + # 合并附件数据 + $files = array_merge($files, $productDetailsFiles); $files = array_merge($files, $productFileInfo); # 删除产品分类表 @@ -385,6 +400,41 @@ class InitializeLogic # ------ 清除跟客户模块有关的管理数据表 END ------ # + # ------ 清除自动编号数据 START ------ # + $time = time(); + Db::query("TRUNCATE TABLE ".$prefix."crm_number_sequence"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (1, 1, 1, 'HT', null, null, null, null, ".$time.", 1, null, 0, 1)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (2, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 1)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (3, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 1)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (4, 1, 1, 'HK', null, null, null, null, ".$time.", 1, null, 0, 2)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (5, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 2)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (6, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 2)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (7, 1, 1, 'HF', null, null, null, null, ".$time.", 1, null, 0, 3)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (8, 2, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 3)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (9, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 3)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (10, 1, 2, 'yyyyMMdd', null, null, null, null, ".$time.", 1, null, 0, 4)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (11, 2, 1, 'FP', null, null, null, null, ".$time.", 1, null, 0, 4)"); + Db::query("INSERT INTO `".$prefix."crm_number_sequence` VALUES (12, 3, 3, 1, 1, 1, 1, ".$time.", ".$time.", 1, null, 0, 4)"); + # ------ 清除自动编号数据 END ------ # + + + # ------ 设置跟进记录常用语 START ------ # + $phrase = ['电话无人接听', '客户无意向', '客户意向度适中,后续继续跟进', '客户意向度较强,成交几率较大']; + $phraseId = db('crm_config')->where('name', 'activity_phrase')->value('id'); + if (!empty($phraseId)) { + db('crm_config')->where('id', $phraseId)->update([ + 'value' => serialize($phrase) + ]); + } else { + db('crm_config')->insert([ + 'name' => 'activity_phrase', + 'value' => serialize($phrase), + 'description' => '跟进记录常用语' + ]); + } + # ------ 设置跟进记录常用语 END ------ # + + # ------ 删除审批记录 START ------ # Db::name('admin_examine_record')->whereLike('types', 'crm%')->delete(); Db::query("ALTER TABLE ".$prefix."admin_examine_record AUTO_INCREMENT = 1"); @@ -833,6 +883,10 @@ class InitializeLogic # ------ 清除评论和消息数据 END ------ # + # 清除任务关联客户模块表并重置字段ID + Db::query("TRUNCATE TABLE ".$prefix."task_relation"); + + # ------ 重置附件表自增ID START ------ # Db::query("ALTER TABLE ".$prefix."admin_file AUTO_INCREMENT = 1"); # ------ 重置附件表自增ID END ------ # diff --git a/application/admin/logic/MessageLogic.php b/application/admin/logic/MessageLogic.php index 5ab707c..a9ffa27 100644 --- a/application/admin/logic/MessageLogic.php +++ b/application/admin/logic/MessageLogic.php @@ -12,7 +12,7 @@ class MessageLogic switch ($label) { case '1': //任务 - $where = array('in', [1, 2, 3]);// + $where = array('in', [1, 2, 3,27]);// break; case '2': //日志 $where = array('in', [4, 5]);//27项目导入 @@ -27,12 +27,12 @@ class MessageLogic $where = 10; break; case '6' : //客户管理 - $where = array('in', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 27, 28, 29, 30]); + $where = array('in', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30]); break; case '4' : break; default: - $where = array('in', [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 27, 28, 29, 30]);//17181920 + $where = array('in', [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]);//17181920 } return $where; } @@ -97,8 +97,8 @@ class MessageLogic ]) ->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(); + } 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']; } diff --git a/application/admin/model/ActionRecord.php b/application/admin/model/ActionRecord.php index 29921f8..0826365 100644 --- a/application/admin/model/ActionRecord.php +++ b/application/admin/model/ActionRecord.php @@ -36,6 +36,9 @@ class ActionRecord extends Common if($leads_id){ $leads_dataList = db('admin_action_record')->where(['types' => 'crm_leads','action_id' => $leads_id])->order('id','desc')->select(); $dataList = array_merge($leads_dataList, $dataList); + # 对线索和客户的合并数据进行排序 + $sortData = array_column($dataList, 'create_time'); + array_multisort($sortData,SORT_DESC , $dataList); } } $userModel = model('User'); diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index 6b4c294..14b4f66 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -28,11 +28,11 @@ class Admin extends Common $structure_id = $apiCommon->userInfo['structure_id']; //员工IDS $user_ids = []; - if ($param['userId']) { - $user_ids = array($param['userId']); + if ($param['user_id']) { + $user_ids = array($param['user_id']); } - if ($param['deptId']) { - $userModel->getSubUserByStr($param['deptId'], 2); + if ($param['structure_id']) { + $userModel->getSubUserByStr($param['structure_id'], 2); } if ($param['dataType']) { switch ($param['dataType']) { @@ -65,8 +65,8 @@ class Admin extends Common } } } - if (!$user_ids) $user_ids = getSubUserId(true); } + if (!$user_ids) $user_ids = getSubUserId(true,0, $apiCommon->userInfo['id']); $perUserIds = $perUserIds ? : getSubUserId(); //权限范围内userIds $userIds = []; if ($user_ids) { diff --git a/application/admin/model/Common.php b/application/admin/model/Common.php index ac0e38e..ab6c4a4 100644 --- a/application/admin/model/Common.php +++ b/application/admin/model/Common.php @@ -295,38 +295,43 @@ class Common extends Model */ public function exportHandle($list, $field_list, $type = '') { - + foreach ($list as &$val) { foreach ($field_list as $field) { switch ($field['form_type']) { case 'user': - if (isset($val[$field['field'] . '_info']['realname'])) { - $val[$field['field']] = $val[$field['field'] . '_info']['realname']; - } else { - $val[$field['field']] = implode(',', array_column($val[$field['field'] . '_info'], 'realname')); + if (isset($val[$field['field'] . 'name'])) { + $val[$field['field']] = $val[$field['field'] . 'name']; } +// else { +// $val[$field['field']] = implode(',', array_column($val[$field['field'] . '_info'], 'realname')); +// } break; case 'structure': - $temp = array_map(function ($val) { return $val->toarray(); }, $val[$field['field'] . '_info']); - $val[$field['field']] = implode(',', array_column($temp, 'name')); +// $temp = array_map(function ($val) { return $val->toarray(); }, $val[$field['field'] . '_name']); +// $val[$field['field']] = implode(',', array_column($temp, 'name')); +// $val[$field['field']] = implode(',', array_column($temp, 'name')); break; case 'datetime': $val[$field['field']] = strtotime($val[$field['field']]) ? $val[$field['field']] : ''; break; - case 'customer': - case 'business': - case 'contacts': + case 'customer':break; + case 'business':break; + case 'contacts':break; $val[$field['field']] = $val[$field['field'] . '_info']['name']; break; - case 'contacts': - $val[$field['field']] = $val[$field['field'] . '_info']['name']; - break; default : switch ($field['field']) { // 商机销售阶段、商机状态组 case 'status_id': - case 'type_id': - $val[$field['field']] = $val[$field['field'] . '_info']; + if($val['is_end']!=0){ + $val[$field['field']]= $val['is_end']; + } + break; + case 'type_id':break; +// $val[$field['field']] = $val[$field['field'] . '_info']; + case 'check_status' : + $val[$field['field']] = $val[$field['field'] . '_info']; break; } } diff --git a/application/admin/model/ExamineRecord.php b/application/admin/model/ExamineRecord.php index 9339a3a..b43cb6a 100644 --- a/application/admin/model/ExamineRecord.php +++ b/application/admin/model/ExamineRecord.php @@ -56,7 +56,28 @@ class ExamineRecord extends Common $result = []; - # 获取创建者信息 + # 获取创建者信息(办公审批) + if ($param['types'] == 'oa_examine' && !empty($param['is_record'])) { + $info = db('oa_examine')->field(['create_time', 'create_user_id'])->where('examine_id', $param['types_id'])->find(); + $userInfo = $userModel->getUserById($info['create_user_id']); + + $result[] = [ + 'check_date' => date('Y-m-d H:i:s', $info['create_time']), + 'check_time' => $info['create_time'], + 'check_user_id' => $info['create_user_id'], + 'check_user_id_info' => $userInfo, + 'content' => '', + 'flow_id' => 0, + 'is_end' => 0, + 'order_id' => 1, + 'record_id' => 0, + 'status' => 3, + 'types' => $param['types'], + 'types_id' => $param['types_id'] + ]; + } + + # 获取创建者信息(业务审批) if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice']) && !empty($param['is_record'])) { $model = db($param['types']); $primaryKey = null; @@ -75,7 +96,7 @@ class ExamineRecord extends Common 'content' => '', 'flow_id' => 0, 'is_end' => 0, - 'order_id' => 0, + 'order_id' => 1, 'record_id' => 0, 'status' => 3, 'types' => $param['types'], @@ -88,6 +109,7 @@ class ExamineRecord extends Common foreach ($list as $k=>$v) { $list[$k]['check_user_id_info'] = $userModel->getUserById($v['check_user_id']); $list[$k]['check_date'] = date('Y-m-d H:i:s', $v['check_time']); + $list[$k]['order_id'] = $k + 2; $result[] = $list[$k]; } diff --git a/application/admin/model/ExamineStep.php b/application/admin/model/ExamineStep.php index 084f425..1bb1e63 100644 --- a/application/admin/model/ExamineStep.php +++ b/application/admin/model/ExamineStep.php @@ -332,17 +332,35 @@ class ExamineStep extends Common $createUserInfo = $userModel->getUserById($dataInfo['create_user_id']); $createUserInfo['check_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; - if ($dataInfo['check_status'] == 4) { + if ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']!=trim( $dataInfo['check_status'], ',')) { $createUserInfo['check_type'] = 2; - $newlist[0]['type'] = '2'; //撤销 + $newlist[1]['type'] = '2'; //撤销 + $newlist[1]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5 + $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; + $newlist[1]['user_id_info'] = array($createUserInfo); + $newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; + } elseif ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']==trim( $dataInfo['check_status'], ',')){ + $createUserInfo['check_type'] = 3; + $newlist[0]['type'] = '3'; //创建 + $newlist[0]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5 + $createUserInfo['check_type'] = 2; + $newlist[1]['type'] = '2'; //撤销 + $newlist[1]['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; + $newlist[1]['user_id_info'] = array($createUserInfo); + $newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; } else { - $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; } - $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; } $stepList = []; if ($dataInfo['check_status'] !== 4 || $action !== 'view') { @@ -368,6 +386,10 @@ class ExamineStep extends Common $check_type = 1; $type = !empty($dataInfo['check_user_id']) ? 4 : 1; } + if(in_array($val, $check_user_ids) && $dataInfo['check_status'] == 2){ + $check_type = 1; + $type = 1; + } $re_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 2); //撤销人员 if ($dataInfo['check_status'] == 4) { if ($re_check_user_ids) { @@ -484,7 +506,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','5'])) { + if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4','5'])) { $is_check = 1; } diff --git a/application/admin/model/Excel.php b/application/admin/model/Excel.php index 64139d8..81fca30 100644 --- a/application/admin/model/Excel.php +++ b/application/admin/model/Excel.php @@ -85,7 +85,7 @@ class Excel extends Common $objProps->setCategory("5kcrm"); //种类 $objPHPExcel->setActiveSheetIndex(0); //设置当前的sheet $objActSheet = $objPHPExcel->getActiveSheet(); - $objActSheet->setTitle('悟空软件导入模板' . date('Y-m-d', time())); //设置sheet的标题 + $objActSheet->setTitle('导入模板' . date('Y-m-d', time())); //设置sheet的标题 //存储Excel数据源到其他工作薄 $objPHPExcel->createSheet(); @@ -237,6 +237,10 @@ class Excel extends Common $types_name = '员工信息'; $type_name = 'user'; break; + case 'work_task' : + $types_name = '任务信息'; + $type_name = 'task'; + break; default : $types_name = '悟空软件'; $type_name = 'WuKong'; @@ -250,7 +254,7 @@ class Excel extends Common $objWriter->save($save_path); } else { header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - header("Content-Disposition:attachment;filename=" . $type_name .'_'. date('Y-m-d') . ".xls"); + header("Content-Disposition:attachment;filename=" . $type_name . '_' . date('Y-m-d') . ".xls"); header("Pragma:no-cache"); header("Expires:0"); $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xls'); @@ -297,7 +301,7 @@ class Excel extends Common fputcsv($fp, $title_cell); // $export_data = $callback(0); $round = round(1000, 9999); - cache($file_name . $round, $callback['list']); + Cache::set($file_name . $round, $callback['list'], config('export_cache_time')); $sheetContent = cache($file_name . $round); $sheetCount = $callback['dataCount']; $forCount = 1000; //每次取出1000个 @@ -422,14 +426,11 @@ 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') { $address_arr = explode(chr(10), $val['address']); + $rows[] = $address_arr[0] ?: ''; $rows[] = $address_arr[1] ?: ''; $rows[] = $address_arr[2] ?: ''; @@ -488,7 +489,7 @@ class Excel extends Common $user_id = $param['owner_user_id']; // 采用伪队列 允许三人同时导入数据 - $queue = new Queue(self::IMPORT_QUEUE, 5); + $queue = new Queue(self::IMPORT_QUEUE, 50000000); $import_queue_index = input('import_queue_index'); // 队列任务ID @@ -718,27 +719,27 @@ class Excel extends Common if ($end_row > $max_row) { $end_row = $max_row; } - + // 读取数据 $dataList = $sheet->rangeToArray("A{$start_row}:{$max_col}{$end_row}"); // 数据重复时的处理方式 0跳过 1覆盖 - $config = $param['config'] ? : 0; - + $config = $param['config'] ?: 0; // 默认数据 + $default_data = [ 'create_user_id' => $param['create_user_id'], 'owner_user_id' => $param['owner_user_id'], 'create_time' => time(), 'update_time' => time(), ]; + if ($temp !== count($field_list)) { // $this->error = '请使用最新导入模板'; @unlink($save_path); $queue->dequeue(); foreach ($dataList as $val) { - $error_data_func($val,'请使用最新导入模板'); + $error_data_func($val, '请使用最新导入模板'); } - // 错误数据文件保存 $objWriter = \PHPExcel_IOFactory::createWriter($err_PHPExcel, 'Excel5'); $objWriter->save($error_path); $error = [ @@ -750,7 +751,7 @@ class Excel extends Common 'cover' => 0, // 错误数据写入行号 'error' => $total, - 'error_file_path' =>'temp/' . $error_data_file_name + 'error_file_path' => 'temp/' . $error_data_file_name ]; $queue->cache('last_import_cache', [ 'total' => $total, @@ -765,14 +766,15 @@ class Excel extends Common 'cover' => 0, 'error' => $total, 'user_id' => $user_id, - 'error_data_file_path' =>'temp/' . $error_data_file_name + '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)); + Cache::set('item', 1, config('import_cache_time')); + Cache::set('excel_item', serialize($error), config('import_cache_time')); return true; - }else{ + } else { + // 开始导入数据 foreach ($dataList as $val) { $data = []; @@ -793,13 +795,13 @@ class Excel extends Common } else { $temp_value = trim($val[$fk]); } - - + + if ($field['field'] == 'category_id' && $types == 'crm_product') { - $data['category_id'] = $productCategoryArr[$temp_value] ? : 0; + $data['category_id'] = $productCategoryArr[$temp_value] ?: 0; $data['category_str'] = $dataModel->getPidStr($productCategoryArr[$temp_value], '', 1); } - + // 特殊字段特殊处理 $temp_value = $this->handleData($temp_value, $field); $data[$field['field']] = $temp_value; @@ -825,9 +827,9 @@ class Excel extends Common } $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{ + 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); } } @@ -839,17 +841,14 @@ class Excel extends Common $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'){ + 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'] .' '. '公海数据,无覆盖权限'; + $temp_error = $owner['name'] . ' ' . '公海数据,无覆盖权限'; $error_data_func($val, $temp_error); break; } @@ -889,28 +888,25 @@ class Excel extends Common } } else { $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()); } } } - + // 完成数(已导入数) $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, @@ -929,7 +925,7 @@ class Excel extends Common // 导入任务ID 'import_queue_index' => $import_queue_index ]; - + $queue->cache('last_import_cache', [ 'total' => $total, 'done' => $done, @@ -944,12 +940,12 @@ class Excel extends Common $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, @@ -959,25 +955,25 @@ class Excel extends Common '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); + Cache::set('item', 1, config('import_cache_time')); + Cache::set('excel_item', serialize($this->error), config('import_cache_time')); + } else { + $queue->dequeue(); + $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, config('import_cache_time')); + Cache::set('excel', $excelData, config('import_cache_time')); } return true; } - } else { $this->error = '请选择导入文件'; $queue->dequeue(); @@ -1436,20 +1432,20 @@ class Excel extends Common $queue->dequeue(); $this->error['error_file_path'] = 'temp/' . $error_data_file_name; - Cache::set('item', 1); - Cache::set('excel_item', serialize($this->error)); + Cache::set('item', 1, config('import_cache_time')); + Cache::set('excel_item', serialize($this->error), config('import_cache_time')); } 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); + $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, config('import_cache_time')); + Cache::set('excel', $excelData, config('import_cache_time')); } return true; } else { @@ -1705,8 +1701,8 @@ class Excel extends Common } // 将标题名称通过fputcsv写到文件句柄 fputcsv($fp, $title_cell); -// $export_data = $callback(0); - foreach ($callback as $item) { + $export_data = $callback(0); + foreach ($export_data as $item) { $rows = []; foreach ($field_list as $rule) { $rows[] = $item[$rule['field']]; @@ -1731,7 +1727,7 @@ class Excel extends Common * * @author Ymob */ - public function batchTaskImportData($file, $param, $controller = null) + public function batchTaskImportData($file,$field_list, $param, $controller = null) { // 导入模块 $types = $param['types']; @@ -1742,7 +1738,7 @@ class Excel extends Common } $user_id = $param['owner_user_id']; // 采用伪队列 允许三人同时导入数据 - $queue = new Queue(self::IMPORT_QUEUE, 3); + $queue = new Queue(self::IMPORT_QUEUE, 30000); $import_queue_index = input('import_queue_index'); // 队列任务ID @@ -1865,17 +1861,6 @@ class Excel extends Common $error_row++; }; - $field_list = [ - '0' => ['name' => '任务名称', 'field' => 'name'], - '1' => ['name' => '任务描述', 'field' => 'description'], - '2' => ['name' => '开始时间', 'field' => 'start_time'], - '3' => ['name' => '结束时间', 'field' => 'stop_time'], - '4' => ['name' => '负责人', 'field' => 'create_user_id'], - '5' => ['name' => '参与人', 'field' => 'owner_user_id'], - '6' => ['name' => '所属任务列表', 'field' => 'class_id'], - ]; - $field_key_name_list = array_column($field_list, 'name'); - // 加载导入数据文件 $objRender = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls'); $objRender->setReadDataOnly(true); @@ -1889,34 +1874,6 @@ class Excel extends Common $max_col_num += 3 * array_count_values(array_column($field_list, 'form_type'))['map_address']; $max_col = \PHPExcel_Cell::stringFromColumnIndex($max_col_num); - // 检测导入文件是否使用最新模板 - $header = $sheet->rangeToArray("A2:{$max_col}2")[0]; - $temp = 0; - for ($i = 0; $i < count($field_list); $i++) { - if ( - $header[$i] == $field_list[$i]['name'] - || $header[$i] == $field_list[$i]['name'] . '(*)' - ) { - $temp++; - // 字段为地址时,占四列 - } elseif ($field_list[$i]['form_type'] == 'map_address') { - if ( - $header[$i] == $this->map_address[0] - && $header[$i + 1] == $this->map_address[1] - && $header[$i + 2] == $this->map_address[2] - && $header[$i + 3] == $this->map_address[3] - ) { - $temp++; - } - } - } - if ($temp !== count($field_list)) { - $this->error = '请使用最新导入模板'; - @unlink($save_path); - $queue->dequeue(); - return false; - } - // 每次导入条数 $page_size = 100; @@ -1951,9 +1908,31 @@ class Excel extends Common 'create_user_id' => $param['create_user_id'], 'create_time' => time(), 'update_time' => time(), + 'work_id' => $param['work_id'], ]; // 开始导入数据 foreach ($dataList as $val) { + foreach ($field_list as $field) { + $temp_value = trim($val[$fk]); + // 特殊字段特殊处理 + $temp_value = $this->handleData($temp_value, $field); + $data[$field['field']] = $temp_value; + if ($temp_value == '') { + if ($field['is_null']) { + $not_null_field[] = $field['name']; + } + $empty_count++; + } + $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; + } $data = []; $fk = 0; $classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select(); @@ -1972,15 +1951,7 @@ class Excel extends Common $data['class_id'] = db('work_task_class')->insertGetId($item); } $dataModel = new \app\work\model\Task(); - foreach ($field_list as $field) { - $temp_value = trim($val[$fk]); - // 特殊字段特殊处理 - $temp_value = $this->handleData($temp_value, $field); - $data[$field['field']] = $temp_value; - - $fk++; - } - // 数据重复时 + $data = array_merge($data, $default_data); if (!$resData = $dataModel->createTask($data)) { $error_data_func($val, $dataModel->getError()); @@ -2047,20 +2018,23 @@ class Excel extends Common '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)); + Cache::set('item', 1, config('import_cache_time')); + Cache::set('excel_item', serialize($this->error), config('import_cache_time')); } 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); + $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['total'] = $total; + $excelData['done'] = $done; + $excelData['error'] = $error; + $excelData['base'] = 'batchTaskImportData'; + Cache::set('item', 0, config('import_cache_time')); + Cache::set('excel', $excelData, config('import_cache_time')); } return true; } else { @@ -2325,7 +2299,6 @@ class Excel extends Common $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //excel5为xls格式,excel2007为xlsx格式 $objWriter->save('php://output'); } - /** * 运行中 * @param $param @@ -2333,11 +2306,15 @@ class Excel extends Common */ public function importNum() { - $param = Cache::get('item'); - $excelData=Cache::get('excel'); - $base=$excelData['base']; + $param = Cache::pull('item'); + $excelData = Cache::pull('excel'); + $base = $excelData['base']; if ($param == 0) { - $this->$base('',$excelData); + if($base=='batchTaskImportData'){ + $this->batchTaskImportData('', $excelData); + }else{ + $this->batchImportData('', $excelData); + } $data = 0; } elseif ($param == 1) { $data = ''; @@ -2353,7 +2330,7 @@ class Excel extends Common */ public function importInfo() { - $param = Cache::get('excel_item'); + $param = Cache::pull('excel_item'); $param = unserialize($param); return $param; } @@ -2367,19 +2344,19 @@ 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']) + ->where(['i.type' => $param['type'], 'i.user_id' => $param['user_id']])->page($param['page'], $param['limit']) ->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) { - $week = strtotime("+7 day",$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']==''){ + if ($v['error_data_file_path'] == '') { $list[$k]['valid'] = -1; } $list[$k]['create_time'] = date('Y-m-d', $v['create_time']); diff --git a/application/admin/model/Field.php b/application/admin/model/Field.php index 57310bd..2f5fd79 100644 --- a/application/admin/model/Field.php +++ b/application/admin/model/Field.php @@ -681,6 +681,10 @@ class Field extends Model 'value' => [] ]; } + # 产品基本信息增加负责人信息 + if ($param['action'] == 'read' && $param['types'] == 'crm_product') { + $new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find(); + } if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list); foreach ($field_list as $k => $v) { # 处理字段授权 @@ -698,6 +702,11 @@ class Field extends Model $field_list[$k]['writeStatus'] = $status['write']; } + # (联系人,商机,合同,回款,回访)关联其他模块的字段在详情页面不允许修改;创建人、负责人不允许修改 + if ($param['action'] == 'read' && in_array($v['field'], ['customer_id', 'business_id', 'contacts_id', 'contract_id', 'create_user_id', 'owner_user_id'])) { + $field_list[$k]['writeStatus'] = 0; + } + //处理setting内容 $setting = []; $default_value = $v['default_value']; @@ -915,6 +924,14 @@ class Field extends Model ] ]; } + if ($param['types'] == 'crm_customer') { + $field_arr[] = [ + 'field' => 'detail_address', + 'name' => '详细地址', + 'form_type' => 'text', + 'setting' => [] + ]; + } if ($field_arr) $field_list = array_merge($field_list, $field_arr); foreach ($field_list as $k => $v) { //处理setting内容 @@ -947,7 +964,7 @@ class Field extends Model $businessStatusModel = new \app\crm\model\BusinessStatus(); $userInfo = $userModel->getUserById($user_id); $setting = db('crm_business_type') - ->where(['structure_id' => $userInfo['structure_id'], 'status' => 1]) + ->where(['structure_id' => ['like', ',%' . $userInfo['structure_id'] . '%,'], 'status' => 1]) ->whereOr('structure_id', '') ->select(); foreach ($setting as $key => $val) { @@ -1387,22 +1404,25 @@ class Field extends Model $userModel = new \app\admin\model\User(); $structureModel = new \app\admin\model\Structure(); switch ($form_type) { - case 'datetime' : - $val = $val > 0 ? date('Y-m-d H:i:s', $val) : ''; - break; +// case 'datetime' : +// $val = $val > 0 ? date('Y-m-d H:i:s', $val) : ''; +// break; case 'user' : - $val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr($val)); + $val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr(stringToArray($val))); break; case 'userStr' : $val = explode(',', $val); $val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr($val)); break; case 'structure' : - $val = ArrayToString($structureModel->getStructureNameByArr($val)); + $val = implode(',', $structureModel->getStructureNameByArr(stringToArray($val))); break; case 'customer' : $val = db('crm_customer')->where(['customer_id' => $val])->value('name'); break; + case 'contract' : + $val = db('crm_contract')->where(['customer_id' => $val])->value('num'); + break; case 'business' : $val = db('crm_business')->where(['business_id' => $val])->value('name'); break; @@ -1530,177 +1550,223 @@ class Field extends Model public function resetField($types, $data) { - # 线索 - if ($types == 'crm_leads') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } + foreach ($data AS $key => $value) { + switch ($value['field']) { + case 'create_user_id' : + $data[$key]['fieldName'] = 'create_user_name'; + break; + case 'owner_user_id' : + $data[$key]['fieldName'] = 'owner_user_name'; + break; + case 'customer_id' : + $data[$key]['fieldName'] = 'customer_name'; + break; + case 'type_id' : + $data[$key]['fieldName'] = 'type_id_info'; + break; + case 'status_id' : + $data[$key]['fieldName'] = 'status_id_info'; + break; + case 'business_id' : + $data[$key]['fieldName'] = 'business_name'; + break; + case 'contacts_id' : + $data[$key]['fieldName'] = 'contacts_name'; + break; + case 'order_user_id' : + $data[$key]['fieldName'] = 'order_user_name'; + break; + case 'contract_id' : + $data[$key]['fieldName'] = 'contract_num'; + break; + case 'plan_id' : + $data[$key]['fieldName'] = 'plan_id_info'; + break; + case 'category_id' : + $data[$key]['fieldName'] = 'category_name'; + break; + default : + $data[$key]['fieldName'] = $value['field']; } - } - # 客户 - if ($types == 'crm_customer') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } + if (in_array($value['form_type'], ['user', 'structure']) && !in_array($value['field'], ['create_user_id', 'owner_user_id'])) { + $data[$key]['fieldName'] = $value['field'] . '_name'; } } + # 线索 +// if ($types == 'crm_leads') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } + + # 客户 +// if ($types == 'crm_customer') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } + # 联系人 - if ($types == 'crm_contacts') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'customer_id' : - $data[$key]['fieldName'] = 'customer_name'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } - } - } +// if ($types == 'crm_contacts') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'customer_id' : +// $data[$key]['fieldName'] = 'customer_name'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } # 商机 - if ($types == 'crm_business') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'customer_id' : - $data[$key]['fieldName'] = 'customer_name'; - break; - case 'type_id' : - $data[$key]['fieldName'] = 'type_id_info'; - break; - case 'status_id' : - $data[$key]['fieldName'] = 'status_id_info'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } - } - } +// if ($types == 'crm_business') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'customer_id' : +// $data[$key]['fieldName'] = 'customer_name'; +// break; +// case 'type_id' : +// $data[$key]['fieldName'] = 'type_id_info'; +// break; +// case 'status_id' : +// $data[$key]['fieldName'] = 'status_id_info'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } # 合同 - if ($types == 'crm_contract') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'customer_id' : - $data[$key]['fieldName'] = 'customer_name'; - break; - case 'business_id' : - $data[$key]['fieldName'] = 'business_name'; - break; - case 'contacts_id' : - $data[$key]['fieldName'] = 'contacts_name'; - break; - case 'order_user_id' : - $data[$key]['fieldName'] = 'order_user_name'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - } - } - } +// if ($types == 'crm_contract') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'customer_id' : +// $data[$key]['fieldName'] = 'customer_name'; +// break; +// case 'business_id' : +// $data[$key]['fieldName'] = 'business_name'; +// break; +// case 'contacts_id' : +// $data[$key]['fieldName'] = 'contacts_name'; +// break; +// case 'order_user_id' : +// $data[$key]['fieldName'] = 'order_user_name'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } # 回款 - if ($types == 'crm_receivables') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'customer_id' : - $data[$key]['fieldName'] = 'customer_name'; - break; - case 'contract_id' : - $data[$key]['fieldName'] = 'contract_num'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - case 'plan_id' : - $data[$key]['fieldName'] = 'plan_id_info'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } - } - } +// if ($types == 'crm_receivables') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'customer_id' : +// $data[$key]['fieldName'] = 'customer_name'; +// break; +// case 'contract_id' : +// $data[$key]['fieldName'] = 'contract_num'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// case 'plan_id' : +// $data[$key]['fieldName'] = 'plan_id_info'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } # 回访 - if ($types == 'crm_visit') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'customer_id' : - $data[$key]['fieldName'] = 'customer_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - $data[$key]['name'] = '回访人'; - break; - case 'contacts_id' : - $data[$key]['fieldName'] = 'contacts_name'; - break; - case 'contract_id' : - $data[$key]['fieldName'] = 'contract_number'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } - } - } +// if ($types == 'crm_visit') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'customer_id' : +// $data[$key]['fieldName'] = 'customer_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// $data[$key]['name'] = '回访人'; +// break; +// case 'contacts_id' : +// $data[$key]['fieldName'] = 'contacts_name'; +// break; +// case 'contract_id' : +// $data[$key]['fieldName'] = 'contract_number'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } # 产品 - if ($types == 'crm_product') { - foreach ($data as $key => $value) { - switch ($value['field']) { - case 'category_id' : - $data[$key]['fieldName'] = 'category_name'; - break; - case 'create_user_id' : - $data[$key]['fieldName'] = 'create_user_name'; - break; - case 'owner_user_id' : - $data[$key]['fieldName'] = 'owner_user_name'; - break; - default : - $data[$key]['fieldName'] = $value['field']; - } - } - } +// if ($types == 'crm_product') { +// foreach ($data as $key => $value) { +// switch ($value['field']) { +// case 'category_id' : +// $data[$key]['fieldName'] = 'category_name'; +// break; +// case 'create_user_id' : +// $data[$key]['fieldName'] = 'create_user_name'; +// break; +// case 'owner_user_id' : +// $data[$key]['fieldName'] = 'owner_user_name'; +// break; +// default : +// $data[$key]['fieldName'] = $value['field']; +// } +// } +// } return $data; } diff --git a/application/admin/model/File.php b/application/admin/model/File.php index 41380f3..6a0ac34 100644 --- a/application/admin/model/File.php +++ b/application/admin/model/File.php @@ -272,6 +272,7 @@ class File extends Common if (!is_array($request['module_id'])) { $module_ids = array($request['module_id']); } + $moduleName = $request['module']; switch ($request['module']) { case 'crm_leads' : $r = db('crm_leads_file'); $module = db('crm_leads'); break; @@ -302,6 +303,17 @@ class File extends Common unset($request['module_id']); unset($request['by']); + # 查询活动附件,用于判断是否可以删除附件(活动添加的附件只能在活动中删除) + $activityFileIds = []; + $activityType = ['crm_leads' => 1, 'crm_customer' => 2, 'crm_contacts' => 3, 'crm_business' => 5, 'crm_contract' => 6]; + if (!empty($activityType[$moduleName])) { + $activityFileIds = db('crm_activity')->alias('activity') + ->join('__CRM_ACTIVITY_FILE__ file', 'file.activity_id = activity.activity_id', 'LEFT') + ->where(['type' => 1, 'activity_type' => $activityType[$moduleName], 'activity_type_id' => ['in', $module_ids]]) + ->column('file.file_id'); + $activityFileIds = array_filter($activityFileIds); + } + $userModel = new \app\admin\model\User(); $request = $this->fmtRequest( $request ); $map = $request['map']; @@ -321,6 +333,7 @@ class File extends Common $list[$k]['ext'] = getExtension($v['save_name']); $list[$k]['file_path'] = getFullPath($v['file_path']); $list[$k]['file_path_thumb'] = getFullPath($v['file_path_thumb']); + $list[$k]['readOnly'] = !empty($activityType[$moduleName]) && in_array($v['file_id'], $activityFileIds) ? 1 : 0; # 活动中上次的附件,只能在活动中删除 } $data = []; $data['list'] = $list ? : []; diff --git a/application/admin/model/Group.php b/application/admin/model/Group.php index ef2c51e..df36a5a 100644 --- a/application/admin/model/Group.php +++ b/application/admin/model/Group.php @@ -117,7 +117,9 @@ class Group extends Common } $param['rules'] = arrayToString(array_unique($rulesParam)); } - + if($param['title']){ + unset($param['rules']); + } $flag = $this->where('id = '.$group_id)->update($param); if ($flag) { return true; diff --git a/application/admin/model/User.php b/application/admin/model/User.php index 1ac1ae7..b1e5e48 100644 --- a/application/admin/model/User.php +++ b/application/admin/model/User.php @@ -185,6 +185,8 @@ class User extends Common $list[$k]['img'] = $v['img'] ? getFullPath($v['img']) : ''; $list[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : ''; $list[$k]['create_time'] = $v['create_time'] ? date('Y-m-d H:i:s', $v['create_time']) : ''; + $list[$k]['s_name'] = !empty($v['s_name']) ? $v['s_name'] : ''; + $list[$k]['structure_id'] = !empty($v['structure_id']) ? $v['structure_id'] : ''; } $data = []; $data['list'] = $list; @@ -516,7 +518,7 @@ class User extends Common //登录有效时间 $cacheConfig = config('cache'); - $loginExpire = $cacheConfig['expire'] ? : 86400*3; + $loginExpire = !empty($cacheConfig['expire']) ? $cacheConfig['expire'] : 86400 * 30; // 保存缓存 session_start(); @@ -528,10 +530,10 @@ class User extends Common $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding) //删除旧缓存 - if (cache('Auth_'.$userInfo['authkey'].$platform)) { - cache('Auth_'.$userInfo['authkey'].$platform, NULL); + if (Cache::get('Auth_'.$userInfo['authkey'].$platform)) { + Cache::rm('Auth_'.$userInfo['authkey'].$platform); } - cache('Auth_'.$authKey.$platform, $info, $loginExpire, 'UserToken'); + Cache::set('Auth_'.$authKey.$platform, $info, $loginExpire); unset($userInfo['authkey']); // 返回信息 @@ -574,7 +576,7 @@ class User extends Common //登录有效时间 $cacheConfig = config('cache'); - $loginExpire = $cacheConfig['expire'] ? : '86400*3'; + $loginExpire = $cacheConfig['expire'] ? : 86400 * 3; $password = $this->where('id', $userInfo['id'])->value('password'); if (user_md5($old_pwd, $userInfo['salt'], $userInfo['username']) != $password) { @@ -598,7 +600,7 @@ class User extends Common session_start(); $cache['userInfo'] = $userInfo; $cache['authKey'] = user_md5($userInfo['username'].$userInfo['password'].session_id(), $userInfo['salt']); - cache('Auth_'.$auth_key, null); + cache('Auth_'.$cache['authKey'], null); cache('Auth_'.$cache['authKey'], $cache, $loginExpire); return $cache['authKey'];//把auth_key传回给前端 } @@ -713,20 +715,15 @@ class User extends Common unset($authList['bi']); } # 任务审批 - if (in_array('taskExamine', $adminConfig) && !$authList['oa']) { - $oaAuth = ['announcement' => ['read' => true]]; - $authList['oa'] = $oaAuth; - $authList['oa']['taskExamine'] = (Object)[]; - } else { - $authList['oa'] = $authList['oa']; + if (in_array('taskExamine', $adminConfig) ) { $authList['oa']['taskExamine'] = (Object)[]; } # 项目 - if (in_array('work', $adminConfig) && !$authList['work']) { - $oaAuth = ['work' => 'read']; - $authList['work'] = $oaAuth; - } else { - $authList['work'] = $authList['work']; + if (in_array('work', $adminConfig)) { + $authList['project']['projectLabelManage']['projectLabelAdd'] = !empty($authList['work']['work']['save']); + $authList['project']['projectLabelManage']['projectLabelDelete'] = !empty($authList['work']['work']['save']); + $authList['project']['projectLabelManage']['projectLabelUpdate'] = !empty($authList['work']['work']['save']); + $authList['project']['projectManage']['save'] = !empty($authList['work']['work']['save']); } # 日志 if (in_array('log', $adminConfig)) { @@ -789,29 +786,6 @@ class User extends Common if (!empty($authList['crm']['invoice']['index'])) { $authList['crm']['invoiceTitle']['index'] = true; } -// else { -// $authList['crm']['invoice']['updateInvoiceStatus'] = false; -// } - # project - if (!empty($authList['work']['work']['update']) || !empty($authList['work']['work']['save'])) { - $authList['project']['projectLabelManage']['projectLabelAdd'] = true; - $authList['project']['projectLabelManage']['projectLabelDelete'] = true; - $authList['project']['projectLabelManage']['projectLabelUpdate'] = true; - $authList['project']['projectManage']['save'] = true; - } -// else { -// $authList['project']['projectLabelManage']['projectLabelAdd'] = false; -// $authList['project']['projectLabelManage']['projectLabelDelete'] = false; -// $authList['project']['projectLabelManage']['projectLabelUpdate'] = false; -// $authList['project']['projectManage']['save'] = false; -// } - # 项目 - $projectRules = Db::name('admin_rule')->where(['types' => 3, 'level' => 4, 'status' => 0])->column('name'); - if (!empty($authList['project']['projectManage']['save'])) { - foreach ($projectRules AS $key => $value) $authList['work']['project'][$value] = true; - } else { - $authList['work'] = []; - } unset($authList['work']['work']); unset($authList['work']['task']); unset($authList['work']['taskclass']); diff --git a/application/admin/view/install/step2.html b/application/admin/view/install/step2.html index b36bced..e32c962 100644 --- a/application/admin/view/install/step2.html +++ b/application/admin/view/install/step2.html @@ -79,7 +79,7 @@
表前缀:
- +
diff --git a/application/admin/view/install/step5.html b/application/admin/view/install/step5.html index e119ef0..d4af304 100644 --- a/application/admin/view/install/step5.html +++ b/application/admin/view/install/step5.html @@ -44,7 +44,7 @@

恭喜您,已成功安装悟空CRM

-

您已经成功安装开源PHP悟空CRM,您可以尽情享用悟空CRM开源版算有功能及服务.

+

您已经成功安装开源PHP悟空CRM,您可以尽情享用悟空CRM开源版所有功能及服务.

使用管理员账号即可登录

diff --git a/application/admin/view/install/step6.html b/application/admin/view/install/step6.html new file mode 100644 index 0000000..465b95f --- /dev/null +++ b/application/admin/view/install/step6.html @@ -0,0 +1,97 @@ + + + + + + 悟空CRM安装向导 + + + + + + +
+ {include file="public/header"} +
+
+
+
+
+ +
+
检查安装环境
+
+
+
+
+ +
+
创建数据库
+
+
+
+
+ +
+
安装失败
+
+
+
+
+
+

安装悟空CRM数据库超时,请手动导入SQL文件!

+
+

1、SQL文件位置:public/sql/5kcrm.sql、public/sql/install.sql

+

2、在config目录下创建database.php文件

+

3、database.php文件内容:

+

return [

+

// 数据库类型

+

'type' => 'mysql',

+

// 服务器地址

+

'hostname' => '127.0.0.1',

+

// 数据库名

+

'database' => '',

+

// 用户名

+

'username' => '',

+

// 密码

+

'password' => '',

+

// 端口

+

'hostport' => '3306',

+

// 连接dsn

+

'dsn' => '',

+

// 数据库连接参数

+

'params' => [],

+

// 数据库编码默认采用utf8

+

'charset' => 'utf8',

+

// 数据库表前缀

+

'prefix' => '5kcrm_',

+

// 数据库调试模式

+

'debug' => true,

+

// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)

+

'deploy' => 0,

+

// 数据库读写是否分离 主从式有效

+

'rw_separate' => false,

+

// 读写分离后 主服务器数量

+

'master_num' => 1,

+

// 指定从服务器序号

+

'slave_no' => '',

+

// 自动读取主库数据

+

'read_master' => false,

+

// 是否严格检查字段是否存在

+

'fields_strict' => true,

+

// 数据集返回类型

+

'resultset_type' => 'array',

+

];

+
+
+
+ + + + \ No newline at end of file diff --git a/application/bi/controller/Achievement.php b/application/bi/controller/Achievement.php index b50e90f..c308eec 100644 --- a/application/bi/controller/Achievement.php +++ b/application/bi/controller/Achievement.php @@ -38,7 +38,7 @@ class Achievement extends ApiCommon exit(json_encode(['code' => 102, 'error' => '无权操作'])); } } - + /** * 业绩目标完成情况 * @@ -49,21 +49,20 @@ class Achievement extends ApiCommon */ public function statistics($param = '') { - if($param['excel_type']!=1){ + if ($param['excel_type'] != 1) { $param = $this->param; } -// $achievementModel = new \app\crm\model\Achievement(); -// $list = $achievementModel->getList($param) ? : []; + $list = $this->getAchievementStatistics($param) ?: []; //导出使用 if (!empty($param['excel_type'])) { $list = $this->excelStatistics($param) ?: []; return $list; } - + return resultArray(['data' => $list]); } - + /** * 业绩目标完成情况列表 * @@ -77,26 +76,26 @@ class Achievement extends ApiCommon { # 结果数据 $result = []; - + # 参数 - $status = !empty($param['status']) ? $param['status'] : 1; # 类型:1合同目标;2回款目标; - $year = !empty($param['year']) ? $param['year'] : 0; # 年份 + $status = !empty($param['status']) ? $param['status'] : 1; # 类型:1合同目标;2回款目标; + $year = !empty($param['year']) ? $param['year'] : 0; # 年份 $structureId = !empty($param['structure_id']) ? $param['structure_id'] : 0; # 部门 - $userId = !empty($param['user_id']) ? $param['user_id'] : 0; # 员工 - $type = !empty($param['type']) ? $param['type'] : 1; # 类型:1部门;2员工 - + $userId = !empty($param['user_id']) ? $param['user_id'] : 0; # 员工 + $type = !empty($param['type']) ? $param['type'] : 1; # 类型:1部门;2员工 + # 设置业绩目标条件 $achievementWhere['year'] = $year; $achievementWhere['status'] = $status; $achievementWhere['type'] = !empty($type) && $type == 1 ? 2 : 3; if (!empty($userId)) $achievementWhere['obj_id'] = $userId; if (!empty($structureId)) $achievementWhere['obj_id'] = $structureId; - + # 查询业绩目标数据 $achievementList = Db::name('crm_achievement')->where($achievementWhere)->select(); - + if (empty($achievementList)) return []; - + # 部门 if ($type == 1) { foreach ($achievementList as $key => $value) { @@ -118,50 +117,50 @@ class Achievement extends ApiCommon '12' => ['achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'] ] ]; - + # 获取部门下的员工ID $userIds = Db::name('admin_user')->where('structure_id', $value['obj_id'])->column('id'); - + # 业绩完成字段 $finishField = ["DATE_FORMAT(FROM_UNIXTIME(`create_time`,'%Y-%m-%d'),'%m') AS time", 'sum(money) AS money']; - + # 业绩完成条件 $finishWhere['check_status'] = 2; $finishWhere['owner_user_id'] = ['in', $userIds]; - + # 合同 if ($status == 1) { $finishArray = Db::name('crm_contract')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 回款 if ($status == 2) { $finishArray = Db::name('crm_receivables')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 计算完成情况 foreach ($finishArray as $k => $v) { if (!empty($result[$value['obj_id']]['list'][$v['time']])) { $achievement = $result[$value['obj_id']]['list'][$v['time']]['achievement']; - + $result[$value['obj_id']]['list'][$v['time']]['money'] = (int)$v['money']; $result[$value['obj_id']]['list'][$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); - + } } - + $result[$value['obj_id']]['list'] = array_values($result[$value['obj_id']]['list']); } } - + # 员工 if ($type == 2) { $userData = []; $userList = db('admin_user')->field(['id', 'realname'])->select(); - foreach ($userList AS $key => $value) { + foreach ($userList as $key => $value) { $userData[$value['id']] = $value['realname']; } - + foreach ($achievementList as $key => $value) { # 组装结果数据 $result[$value['obj_id']] = [ @@ -181,225 +180,221 @@ class Achievement extends ApiCommon '12' => ['achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'] ] ]; - # 业绩完成字段 $finishField = ["DATE_FORMAT(FROM_UNIXTIME(`create_time`,'%Y-%m-%d'),'%m') AS time", 'sum(money) AS money']; - + # 业绩完成条件 $finishWhere = ['check_status' => 2, 'owner_user_id' => $value['obj_id']]; - + # 合同 if ($status == 1) { $finishArray = Db::name('crm_contract')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 回款 if ($status == 2) { $finishArray = Db::name('crm_receivables')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 计算完成情况 foreach ($finishArray as $k => $v) { if (!empty($result[$value['obj_id']]['list'][$v['time']])) { $achievement = $result[$value['obj_id']]['list'][$v['time']]['achievement']; - + $result[$value['obj_id']]['list'][$v['time']]['money'] = (int)$v['money']; $result[$value['obj_id']]['list'][$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); } } - + $result[$value['obj_id']]['list'] = array_values($result[$value['obj_id']]['list']); } } - + return array_values($result); } - + public function excelStatistics($param) { # 结果数据 $result = []; - + # 参数 $status = !empty($param['status']) ? $param['status'] : 1; # 类型:1合同目标;2回款目标; $year = !empty($param['year']) ? $param['year'] : 0; # 年份 $structureId = !empty($param['structure_id']) ? $param['structure_id'] : 0; # 部门 $userId = !empty($param['user_id']) ? $param['user_id'] : 0; # 员工 $type = !empty($param['type']) ? $param['type'] : 1; # 类型:1部门;2员工 - + # 设置业绩目标条件 $achievementWhere['year'] = $year; $achievementWhere['status'] = $status; $achievementWhere['type'] = !empty($type) && $type == 1 ? 2 : 3; if (!empty($userId)) $achievementWhere['obj_id'] = $userId; if (!empty($structureId)) $achievementWhere['obj_id'] = $structureId; - + # 查询业绩目标数据 $achievementList = Db::name('crm_achievement')->where($achievementWhere)->select(); - + if (empty($achievementList)) return []; - + # 部门 if ($type == 1) { foreach ($achievementList as $key => $value) { # 组装结果数据 - $result[] = [ - ['name' => $value['name'], 'achievement' => (int)$value['january'], 'money' => 0, 'rate' => 0, 'month' => '一月'], - ['name' => $value['name'], 'achievement' => (int)$value['february'], 'money' => 0, 'rate' => 0, 'month' => '二月'], - ['name' => $value['name'], 'achievement' => (int)$value['march'], 'money' => 0, 'rate' => 0, 'month' => '三月'], - - ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第一季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '四月'], - ['name' => $value['name'], 'achievement' => (int)$value['may'], 'money' => 0, 'rate' => 0, 'month' => '五月'], - ['name' => $value['name'], 'achievement' => (int)$value['june'], 'money' => 0, 'rate' => 0, 'month' => '六月'], - - ['name' => $value['name'], 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '第二季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['july'], 'money' => 0, 'rate' => 0, 'month' => '七月'], - ['name' => $value['name'], 'achievement' => (int)$value['august'], 'money' => 0, 'rate' => 0, 'month' => '八月'], - ['name' => $value['name'], 'achievement' => (int)$value['september'], 'money' => 0, 'rate' => 0, 'month' => '九月'], - - ['name' => $value['name'], 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第三季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['october'], 'money' => 0, 'rate' => 0, 'month' => '十月'], - ['name' => $value['name'], 'achievement' => (int)$value['november'], 'money' => 0, 'rate' => 0, 'month' => '十一月'], - ['name' => $value['name'], 'achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'], - - ['name' => $value['name'], 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第四季度'], - ['name' => $value['name'], 'achievement' => (int)$value['yeartarget'], 'money' => 0, 'rate' => 0, 'month' => '全年'], + $result[$value['obj_id']] = [ + 'list' => [ + + '01' => ['name' => $value['name'] ,'achievement' => (int)$value['january'], 'money' => 0, 'rate' => 0, 'month' => '一月'], + '02' => ['name' => $value['name'] ,'achievement' => (int)$value['february'], 'money' => 0, 'rate' => 0, 'month' => '二月'], + '03' => ['name' => $value['name'] ,'achievement' => (int)$value['march'], 'money' => 0, 'rate' => 0, 'month' => '三月'], + + '04' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第一季度'], + + '05' => ['name' => $value['name'] ,'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '四月'], + '06' => ['name' => $value['name'] ,'achievement' => (int)$value['may'], 'money' => 0, 'rate' => 0, 'month' => '五月'], + '07' => ['name' => $value['name'] ,'achievement' => (int)$value['june'], 'money' => 0, 'rate' => 0, 'month' => '六月'], + + '08' => ['name' => '', 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '第二季度'], + + '09' => ['name' => $value['name'] ,'achievement' => (int)$value['july'], 'money' => 0, 'rate' => 0, 'month' => '七月'], + '10' => ['name' => $value['name'] ,'achievement' => (int)$value['august'], 'money' => 0, 'rate' => 0, 'month' => '八月'], + '11' => ['name' => $value['name'] ,'achievement' => (int)$value['september'], 'money' => 0, 'rate' => 0, 'month' => '九月'], + + '12' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第三季度'], + + '13' => ['name' => $value['name'] ,'achievement' => (int)$value['october'], 'money' => 0, 'rate' => 0, 'month' => '十月'], + '14' => ['name' => $value['name'] ,'achievement' => (int)$value['november'], 'money' => 0, 'rate' => 0, 'month' => '十一月'], + '15' => ['name' => $value['name'] ,'achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'], + + '16' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第四季度'], + '17' => ['name' => '', 'achievement' => (int)$value['yeartarget'], 'money' => 0, 'rate' => 0, 'month' => '全年'], + ] ]; - + # 获取部门下的员工ID $userIds = Db::name('admin_user')->where('structure_id', $value['obj_id'])->column('id'); - + # 业绩完成字段 $finishField = ["DATE_FORMAT(FROM_UNIXTIME(`create_time`,'%Y-%m-%d'),'%m') AS time", 'sum(money) AS money']; - + # 业绩完成条件 $finishWhere['check_status'] = 2; $finishWhere['owner_user_id'] = ['in', $userIds]; - + # 合同 if ($status == 1) { $finishArray = Db::name('crm_contract')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 回款 if ($status == 2) { $finishArray = Db::name('crm_receivables')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 计算完成情况 foreach ($finishArray as $k => $v) { - if (!empty($result[$v['time']])) { - $achievement = $result[$v['time']]['achievement']; - $result[$v['time']]['money'] = (int)$v['money']; - $result[$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); + if (!empty($result[$value['obj_id']]['list'][$v['time']])) { + $achievement = $result[$value['obj_id']]['list'][$v['time']]['achievement']; + + $result[$value['obj_id']]['list'][$v['time']]['money'] = (int)$v['money']; + $result[$value['obj_id']]['list'][$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); + } - - } - foreach ($result as &$val){ - $val[3]['money']=$val[0]['money']+$val[1]['money']+$val[2]['money']; - $val[3]['rate']=$val[0]['rate']+$val[1]['rate']+$val[2]['rate']; - $val[7]['money']=$val[4]['money']+$val[5]['money']+$val[6]['money']; - $val[7]['rate']=$val[4]['rate']+$val[5]['rate']+$val[6]['rate']; - $val[11]['money']=$val[7]['money']+$val[9]['money']+$val[10]['money']; - $val[11]['rate']=$val[8]['rate']+$val[9]['rate']+$val[10]['rate']; - $val[15]['money']=$val[12]['money']+$val[13]['money']+$val[14]['money']; - $val[15]['rate']=$val[12]['rate']+$val[13]['rate']+$val[14]['rate']; - $val[15]['money']=$val[12]['money']+$val[13]['money']+$val[14]['money']; - $val[15]['rate']=$val[12]['rate']+$val[13]['rate']+$val[14]['rate']; - $val[16]['money']=$val[3]['money']+$val[7]['money']+$val[11]['money']+$val[15]['money']; - $val[16]['rate']=$val[3]['rate']+$val[7]['rate']+$val[11]['rate']+$val[15]['rate']; } - - $result = array_values($result); + + $result[$value['obj_id']]['list'] = array_values($result[$value['obj_id']]['list']); + $item[]=$result[$value['obj_id']]['list']; } } # 员工 if ($type == 2) { - foreach ($achievementList AS $key => $value) { + $userData = []; + $userList = db('admin_user')->field(['id', 'realname'])->select(); + foreach ($userList as $key => $value) { + $userData[$value['id']] = $value['realname']; + } + + foreach ($achievementList as $key => $value) { # 组装结果数据 - - - $result[] = [ - ['name' => $value['name'], 'achievement' => (int)$value['january'], 'money' => 0, 'rate' => 0, 'month' => '一月'], - ['name' => $value['name'], 'achievement' => (int)$value['february'], 'money' => 0, 'rate' => 0, 'month' => '二月'], - ['name' => $value['name'], 'achievement' => (int)$value['march'], 'money' => 0, 'rate' => 0, 'month' => '三月'], - - ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第一季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '四月'], - ['name' => $value['name'], 'achievement' => (int)$value['may'], 'money' => 0, 'rate' => 0, 'month' => '五月'], - ['name' => $value['name'], 'achievement' => (int)$value['june'], 'money' => 0, 'rate' => 0, 'month' => '六月'], - - ['name' => $value['name'], 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '第二季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['july'], 'money' => 0, 'rate' => 0, 'month' => '七月'], - ['name' => $value['name'], 'achievement' => (int)$value['august'], 'money' => 0, 'rate' => 0, 'month' => '八月'], - ['name' => $value['name'], 'achievement' => (int)$value['september'], 'money' => 0, 'rate' => 0, 'month' => '九月'], - - ['name' => $value['name'], 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第三季度'], - - ['name' => $value['name'], 'achievement' => (int)$value['october'], 'money' => 0, 'rate' => 0, 'month' => '十月'], - ['name' => $value['name'], 'achievement' => (int)$value['november'], 'money' => 0, 'rate' => 0, 'month' => '十一月'], - ['name' => $value['name'], 'achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'], - - ['name' => $value['name'], 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第四季度'], - ['name' => $value['name'], 'achievement' => (int)$value['yeartarget'], 'money' => 0, 'rate' => 0, 'month' => '全年'], + $result[$value['obj_id']] = [ + 'list' => [ + '01' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['january'], 'money' => 0, 'rate' => 0, 'month' => '一月'], + '02' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['february'], 'money' => 0, 'rate' => 0, 'month' => '二月'], + '03' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['march'], 'money' => 0, 'rate' => 0, 'month' => '三月'], + + '04' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第一季度'], + + '05' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '四月'], + '06' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['may'], 'money' => 0, 'rate' => 0, 'month' => '五月'], + '07' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['june'], 'money' => 0, 'rate' => 0, 'month' => '六月'], + + '08' => ['name' => '', 'achievement' => (int)$value['april'], 'money' => 0, 'rate' => 0, 'month' => '第二季度'], + + '09' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['july'], 'money' => 0, 'rate' => 0, 'month' => '七月'], + '10' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['august'], 'money' => 0, 'rate' => 0, 'month' => '八月'], + '11' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['september'], 'money' => 0, 'rate' => 0, 'month' => '九月'], + + '12' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第三季度'], + + '13' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['october'], 'money' => 0, 'rate' => 0, 'month' => '十月'], + '14' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['november'], 'money' => 0, 'rate' => 0, 'month' => '十一月'], + '15' => ['name' =>!empty($value['name']) ? $value['name'] : $userData[$value['obj_id']],'achievement' => (int)$value['december'], 'money' => 0, 'rate' => 0, 'month' => '十二月'], + + '16' => ['name' => '', 'achievement' => 0, 'money' => 0, 'rate' => 0, 'month' => '第四季度'], + '17' => ['name' => '', 'achievement' => (int)$value['yeartarget'], 'money' => 0, 'rate' => 0, 'month' => '全年'], + ] ]; - - - # 业绩完成字段 $finishField = ["DATE_FORMAT(FROM_UNIXTIME(`create_time`,'%Y-%m-%d'),'%m') AS time", 'sum(money) AS money']; - + # 业绩完成条件 $finishWhere = ['check_status' => 2, 'owner_user_id' => $value['obj_id']]; - + # 合同 if ($status == 1) { $finishArray = Db::name('crm_contract')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 回款 if ($status == 2) { $finishArray = Db::name('crm_receivables')->field($finishField)->where($finishWhere)->group('time')->select(); } - + # 计算完成情况 - foreach ($finishArray AS $k => $v) { - if (!empty($result[$v['time']])) { - $achievement = $result[$v['time']]['achievement']; - - $result[$v['time']]['money'] = (int)$v['money']; - $result[$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); + foreach ($finishArray as $k => $v) { + if (!empty($result[$value['obj_id']]['list'][$v['time']])) { + $achievement = $result[$value['obj_id']]['list'][$v['time']]['achievement']; + + $result[$value['obj_id']]['list'][$v['time']]['money'] = (int)$v['money']; + $result[$value['obj_id']]['list'][$v['time']]['rate'] = (int)(($v['money'] / $achievement) * 100); } } - - foreach ($result as &$val){ - $val[3]['money']=$val[0]['money']+$val[1]['money']+$val[2]['money']; - $val[3]['rate']=$val[0]['rate']+$val[1]['rate']+$val[2]['rate']; - $val[7]['money']=$val[4]['money']+$val[5]['money']+$val[6]['money']; - $val[7]['rate']=$val[4]['rate']+$val[5]['rate']+$val[6]['rate']; - $val[11]['money']=$val[7]['money']+$val[9]['money']+$val[10]['money']; - $val[11]['rate']=$val[8]['rate']+$val[9]['rate']+$val[10]['rate']; - $val[15]['money']=$val[12]['money']+$val[13]['money']+$val[14]['money']; - $val[15]['rate']=$val[12]['rate']+$val[13]['rate']+$val[14]['rate']; - $val[15]['money']=$val[12]['money']+$val[13]['money']+$val[14]['money']; - $val[15]['rate']=$val[12]['rate']+$val[13]['rate']+$val[14]['rate']; - $val[16]['money']=$val[3]['money']+$val[7]['money']+$val[11]['money']+$val[15]['money']; - $val[16]['rate']=$val[3]['rate']+$val[7]['rate']+$val[11]['rate']+$val[15]['rate']; - } - $result = array_values($result); + + $result[$value['obj_id']]['list'] = array_values($result[$value['obj_id']]['list']); + $item[]=$result[$value['obj_id']]['list']; } } - - return array_values($result); + + foreach ($item as &$val){ + $val[3]['money']=$val[0]['money']+$val[1]['money']+$val[2]['money']; + $val[3]['rate']=$val[0]['rate']+$val[1]['rate']+$val[2]['rate']; + $val[3]['achievement']=$val[0]['achievement']+$val[1]['achievement']+$val[2]['achievement']; + $val[7]['money']=$val[4]['money']+$val[5]['money']+$val[6]['money']; + $val[7]['rate']=$val[4]['rate']+$val[5]['rate']+$val[6]['rate']; + $val[7]['achievement']=$val[4]['achievement']+$val[5]['achievement']+$val[6]['achievement']; + $val[11]['money']=$val[7]['money']+$val[9]['money']+$val[10]['money']; + $val[11]['rate']=$val[8]['rate']+$val[9]['rate']+$val[10]['rate']; + $val[11]['achievement']=$val[8]['achievement']+$val[9]['achievement']+$val[10]['achievement']; + $val[15]['money']=$val[12]['money']+$val[13]['money']+$val[14]['money']; + $val[15]['rate']=$val[12]['rate']+$val[13]['rate']+$val[14]['rate']; + $val[15]['achievement']=$val[12]['achievement']+$val[13]['achievement']+$val[14]['achievement']; + $val[16]['money']=$val[3]['money']+$val[7]['money']+$val[11]['money']+$val[15]['money']; + $val[16]['rate']=$val[3]['rate']+$val[7]['rate']+$val[11]['rate']+$val[15]['rate']; + } + return $item; } - + /** * 导出 * @param $type @@ -409,11 +404,11 @@ class Achievement extends ApiCommon { $param = $this->param; $list = $this->statistics($param); - if(empty($list)){ - return resultArray(['data'=>'数据不存在']); + if (empty($list)) { + return resultArray(['data' => '数据不存在']); } $excelLogic = new ExcelLogic(); - $data = $excelLogic->achienementExcel($param, $list); + $data = $excelLogic->achienementExcel($list); return $data; } } diff --git a/application/bi/controller/Business.php b/application/bi/controller/Business.php index 283657c..3d42d89 100644 --- a/application/bi/controller/Business.php +++ b/application/bi/controller/Business.php @@ -58,16 +58,14 @@ class Business extends ApiCommon if (empty($this->param['type_id'])) return resultArray(['error' => '请选择商机组!']); $businessModel = new \app\crm\model\Business(); - $param = $this->param; - $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; unset($param['sort_field']); unset($param['sort_value']); - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $data = $businessModel->getFunnel($param); foreach ($data['list'] AS $key => $value) { @@ -93,7 +91,6 @@ class Business extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'business', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -109,7 +106,6 @@ class Business extends ApiCommon 'owner_user_id' => !empty($userIds) ? implode(',',$userIds) : '9999999999' ]; $sql = []; - foreach ($time['list'] as $val) { $whereArr = $where; $whereArr['type'] = $val['type']; @@ -136,9 +132,9 @@ class Business extends ApiCommon $businessModel = new \app\bi\model\Business(); $crmBusinessModel = new \app\crm\model\Business(); $userModel = new \app\admin\model\User(); + $adminModel = new \app\admin\model\Admin(); $param = $this->param; unset($param['types']); - # 日期条件 if (!empty($param['type'])) { $param['start_time'] = strtotime($param['type'] . '-01 00:00:00'); @@ -166,8 +162,13 @@ class Business extends ApiCommon $dataList['list'][$k]['create_user_name'] = $create_user_id_info['realname']; $owner_user_id_info = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $dataList['list'][$k]['owner_user_name'] = $owner_user_id_info['realname']; - $dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段 + if($v['is_end']!=0){ + $dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['is_end'])->value('name');//销售阶段 + }else{ + $dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段 + } $dataList['list'][$k]['business_type'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组 + } # 排序 @@ -190,7 +191,6 @@ class Business extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -203,21 +203,21 @@ class Business extends ApiCommon if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); $time = getTimeArray($param['start_time'], $param['end_time']); $sql = db('crm_business')->alias('business')->field([ - "FROM_UNIXTIME(business.create_time, '{$time['time_format']}')" => 'type', - 'COUNT(business.business_id)' => 'business_num', - 'SUM( + "FROM_UNIXTIME(business.create_time, '{$time['time_format']}')" => 'type', + 'COUNT(business.business_id)' => 'business_num', + 'COUNT( CASE WHEN - `check_status` = 2 - THEN 1 ELSE 0 END + `is_end` = 1 + THEN 1 ELSE NULL END )' => 'business_end' - ])->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left') - ->where([ - 'business.owner_user_id' => ['IN', $userIds], - 'business.create_time' => ['BETWEEN', $time['between']] - ]) - ->group('type') - ->fetchSql() - ->select(); + ])->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left') + ->where([ + 'business.owner_user_id' => ['IN', $userIds], + 'business.create_time' => ['BETWEEN', $time['between']] + ]) + ->group('type') + ->fetchSql() + ->select(); $res = queryCache($sql); $res = array_column($res, null, 'type'); foreach ($time['list'] as $key =>$val) { @@ -246,42 +246,51 @@ class Business extends ApiCommon $businessModel = new \app\bi\model\Business(); $crmBusinessModel = new \app\crm\model\Business(); $userModel = new \app\admin\model\User(); + $adminModel = new \app\admin\model\Admin(); $param = $this->param; - + unset($param['types']); # 日期条件 - if (!empty($param['date'])) { - $param['start_time'] = strtotime($param['date'] . '-01 00:00:00'); + if (!empty($param['type'])) { + $param['start_time'] = strtotime($param['type'] . '-01 00:00:00'); $endMonth = strtotime(date('Y-m-d', $param['start_time']) . " +1 month -1 day"); - $param['end_time'] = strtotime(date('Y-m-d 23:59:59', $endMonth)) ; + $param['end_time'] = strtotime(date('Y-m-d 23:59:59', $endMonth)); unset($param['type']); + } else { + if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); + if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); } - + # 排序参数 $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; - + # 赢单条件 $param['is_end'] = 1; $dataList = $businessModel->getDataList($param); - foreach ($dataList as $k => $v) { + foreach ($dataList['list'] as $k => $v) { $business_info = $crmBusinessModel->getDataById($v['business_id']); - $dataList[$k]['business_name'] = $business_info['name']; - $dataList[$k]['create_time'] = date('Y-m-d',strtotime($business_info['create_time'])); - $dataList[$k]['customer_id'] = $v['customer_id']; + $dataList['list'][$k]['business_name'] = $business_info['name']; + $dataList['list'][$k]['create_time'] = date('Y-m-d',strtotime($business_info['create_time'])); + $dataList['list'][$k]['customer_id'] = $v['customer_id']; $customer = db('crm_customer')->field('name')->where('customer_id',$v['customer_id'])->find(); - $dataList[$k]['customer_name'] = $customer['name']; + $dataList['list'][$k]['customer_name'] = $customer['name']; $create_user_id_info = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; - $dataList[$k]['create_user_name'] = $create_user_id_info['realname']; + $dataList['list'][$k]['create_user_name'] = $create_user_id_info['realname']; $owner_user_id_info = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; - $dataList[$k]['owner_user_name'] = $owner_user_id_info['realname']; - $dataList[$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段 - $dataList[$k]['business_type'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组 + $dataList['list'][$k]['owner_user_name'] = $owner_user_id_info['realname']; + if($v['is_end']!=0){ + $dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['is_end'])->value('name');//销售阶段 + }else{ + $dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段 + } + $dataList['list'][$k]['business_type'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组 + } - + # 排序 if (!empty($dataList)) $dataList = $this->sortCommon($dataList, $sortField, $sortValue); - + return resultArray(['data' => $dataList]); } } diff --git a/application/bi/controller/Contract.php b/application/bi/controller/Contract.php index f43bb96..6028a98 100644 --- a/application/bi/controller/Contract.php +++ b/application/bi/controller/Contract.php @@ -64,7 +64,6 @@ class Contract extends ApiCommon if ($param['excel_type'] != 1) { $param = $this->param; } - $perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); // 权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); // 统计条件 $userIds = $whereArr['userIds']; @@ -140,7 +139,7 @@ class Contract extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - + $perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -233,7 +232,6 @@ class Contract extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - $perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -341,10 +339,12 @@ class Contract extends ApiCommon break; case 'summary': $list = $this->summary($excel_type); + $list=$list['list']; $type['type'] = '合同汇总表'; break; case 'invoice': $list = $this->invoice($excel_type); + $list=$list['list']; $type['type'] = '发票统计分析表'; break; } diff --git a/application/bi/controller/Customer.php b/application/bi/controller/Customer.php index 505c8f1..2fd4f3e 100644 --- a/application/bi/controller/Customer.php +++ b/application/bi/controller/Customer.php @@ -76,7 +76,6 @@ class Customer extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - # 排序参数 $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; @@ -88,10 +87,10 @@ class Customer extends ApiCommon $param['start_time'] = $timeArr[0]; $param['end_time'] = $timeArr[1]; } else { - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] =$param['end_time'] . ' 23:59:59'; } - + $data = $customerModel->getStatistics($param); # 排序 @@ -113,18 +112,15 @@ class Customer extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; - # 处理无员工的情况 if (empty($userIds)) return resultArray(['data' => []]); if (empty($param['type']) && empty($param['start_time'])) { $param['type'] = 'month'; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); $time = getTimeArray($param['start_time'], $param['end_time']); @@ -141,7 +137,6 @@ class Customer extends ApiCommon $whereArr['end_time'] = $val['end_time']; $sql[] = $customerModel->getAddDealSql($whereArr); } - $sql = implode(' UNION ALL ', $sql); $list = queryCache($sql); @@ -161,7 +156,6 @@ class Customer extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -213,7 +207,6 @@ class Customer extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - # 排序参数 $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; @@ -273,7 +266,9 @@ class Customer extends ApiCommon # 排序 if (!empty($result['list'])) $result['list'] = $this->sortCommon($result['list'], $sortField, $sortValue); //导出使用 - if (!empty($param['excel_type'])) return $recordData; + if (!empty($param['excel_type'])) { + return $result; + } return resultArray(['data' => $result]); } @@ -374,7 +369,7 @@ class Customer extends ApiCommon # 排序 if (!empty($result['list'])) $result['list'] = $this->sortCommon($result['list'], $sortField, $sortValue); //导出使用 - if (!empty($param['excel_type'])) return $result['list']; + if (!empty($param['excel_type'])) return $result; return resultArray(['data' => $result]); } @@ -391,7 +386,6 @@ class Customer extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 if (empty($whereArr['userIds'])) resultArray(['data' => []]); @@ -492,7 +486,6 @@ class Customer extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereArr['userIds']; @@ -542,25 +535,25 @@ class Customer extends ApiCommon { $userModel = new \app\admin\model\User(); $actionRecordModel = new \app\bi\model\ActionRecord(); + $CustomerModel = new \app\crm\model\Customer(); $adminModel = new \app\admin\model\Admin(); - if($param['excel_type']!=1){ + if ($param['excel_type'] != 1) { $param = $this->param; } - + # 排序参数 $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; unset($param['sort_field']); unset($param['sort_value']); - + if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); - - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds - $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 - $userIds = $whereArr['userIds']; + if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + + $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds + $whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件 + $userIds = $whereArr['userIds']; $between_time = $whereArr['between_time']; - $sql = CustomerModel::field([ 'COUNT(*)' => 'customer_num', 'owner_user_id' @@ -575,6 +568,33 @@ class Customer extends ApiCommon $customer_num_list = queryCache($sql); $customer_num_list = array_column($customer_num_list, null, 'owner_user_id'); + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $paramPool = []; + $paramPool['config'] = $configInfo['config'] ? : 0; + $paramPool['follow_day'] = $configInfo['follow_day'] ? : 0; + $paramPool['deal_day'] = $configInfo['deal_day'] ? : 0; + $paramPool['remind_config'] = $configInfo['remind_config'] ? : 0; + $customer_list=''; + $action_record_list=''; + if($paramPool['config']==1){ + $sql = $CustomerModel + ->alias('customer') + ->field([ + 'customer.create_user_id as user_id' , + 'COUNT(customer.customer_id) as put_in' + ]) + ->group('user_id') + ->where($CustomerModel->getWhereByPool()) + ->where([ + 'create_time' => ['BETWEEN', $between_time], + 'create_user_id' => ['IN', $userIds], + ]) + ->fetchSql() + ->select(); + $customer_list = queryCache($sql); + $customer_list = array_column($customer_list, null, 'user_id'); + } $sql = $actionRecordModel ->field([ 'user_id', @@ -592,12 +612,13 @@ class Customer extends ApiCommon ->select(); $action_record_list = queryCache($sql); $action_record_list = array_column($action_record_list, null, 'user_id'); - + $res = []; $receiveCount = 0; # 领取公海客户总数 $putInCount = 0; # 进入公海客户总数 foreach ($userIds as $val) { - $item['put_in'] = !empty($action_record_list[$val]['put_in']) ? (int)$action_record_list[$val]['put_in'] : 0; + $item['put'] = !empty($customer_list[$val]['put_in'])?(int)$customer_list[$val]['put_in']:0; + $item['put_in'] = !empty($customer_list[$val]['put_in']) ? $item['put'] : (int)$action_record_list[$val]['put_in'] + $item['put']; $item['receive'] = !empty($action_record_list[$val]['receive']) ? (int)$action_record_list[$val]['receive'] : 0; $item['customer_num'] = !empty($customer_num_list[$val]['customer_num']) ? (int)$customer_num_list[$val]['customer_num'] : 0; $user_info = $userModel->getUserById($val); @@ -634,7 +655,6 @@ class Customer extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereData['userIds']; @@ -701,12 +721,13 @@ class Customer extends ApiCommon * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function userCycleList() + public function userCycleList($param='') { $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); - $param = $this->param; - + if($param['excel_type']!=1){ + $param = $this->param; + } # 排序参数 $sortField = !empty($param['sort_field']) ? $param['sort_field'] : ''; $sortValue = !empty($param['sort_value']) ? $param['sort_value'] : ''; @@ -787,7 +808,7 @@ class Customer extends ApiCommon # 排序 if (!empty($datas['users'])) $datas['users'] = $this->sortCommon($datas['users'], $sortField, $sortValue); //导出使用 - if (!empty($param['excel_type'])) return $datas['list']; + if (!empty($param['excel_type'])) return $datas; return resultArray(['data' => $datas]); } @@ -801,7 +822,9 @@ class Customer extends ApiCommon { $biCustomerModel = new \app\bi\model\Customer(); $productModel = new \app\bi\model\Product(); - $param = $this->param; + if($param['excel_type']!=1){ + $param = $this->param; + } $list = $productModel->getDealByProduct($param); $datas = array(); $cycleCount = 0; @@ -823,7 +846,8 @@ class Customer extends ApiCommon } $datas['total'] = ['product_name' => '总计', 'cycle' => $cycleCount, 'customer_num' => $customerCount]; - + //导出使用 + if (!empty($param['excel_type'])) return $datas; return resultArray(['data' => $datas]); } @@ -833,13 +857,15 @@ class Customer extends ApiCommon * @return * @author zhi */ - public function addressCycle() + public function addressCycle($param='') { $userModel = new \app\admin\model\User(); $customerModel = new \app\crm\model\Customer(); $biCustomerModel = new \app\bi\model\Customer(); $address_arr = \app\crm\model\Customer::$address; - $param = $this->param; + if($param['excel_type']!=1){ + $param = $this->param; + } if (empty($param['type']) && empty($param['start_time'])) { $param['type'] = 'month'; } @@ -907,7 +933,9 @@ class Customer extends ApiCommon } $res['total'] = ['address' => '总计', 'cycle' => $cycleCount, 'customer_num' => $customerCount]; + //导出使用 + if (!empty($param['excel_type'])) return $res; return resultArray(['data' => $res]); } @@ -919,9 +947,11 @@ class Customer extends ApiCommon * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function addressAnalyse() + public function addressAnalyse($param='') { - $param = $this->param; + if($param['excel_type']!=1){ + $param = $this->param; + } // $customerModel = new \app\crm\model\Customer(); $userModel = new \app\admin\model\User(); $address_arr = \app\crm\model\Customer::$address; @@ -936,7 +966,7 @@ class Customer extends ApiCommon $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $userIds = $map_user_ids ? array_intersect($map_user_ids, $perUserIds) : $perUserIds; //数组交集 - + if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); $time = getTimeArray($param['start_time'], $param['end_time']); @@ -966,6 +996,8 @@ class Customer extends ApiCommon $item['dealCustomer'] = !empty($list[$val]['dealCustomer']) ? (int)$list[$val]['dealCustomer'] : 0; $data[] = $item; } + //导出使用 + if (!empty($param['excel_type'])) return $res; return resultArray(['data' => $data]); } @@ -983,7 +1015,6 @@ class Customer extends ApiCommon $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $param = $this->param; - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds $whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereData['userIds']; @@ -1099,21 +1130,22 @@ class Customer extends ApiCommon * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function customerSatisfaction(BiCustomerLogic $biCustomerLogic, $param='') + public function customerSatisfaction($param='') { + $adminModel = new \app\admin\model\Admin(); + $userModel = new \app\admin\model\User(); $param = $this->param; - $param['start_time'] = !empty($param['start_time']) ? strtotime($param['start_time']) : ''; $param['end_time'] = !empty($param['end_time']) ? strtotime($param['end_time']) : ''; if (!empty($param['type'])) { # 日期工具类 $timeArr = getTimeByType($param['type']); - # 设置日期参数 + # 设置日期参数pool $param['start_time'] = $timeArr[0]; $param['end_time'] = $timeArr[1]; } - + $biCustomerLogic=new BiCustomerLogic(); $data = $biCustomerLogic->getCustomerSatisfaction($param); //导出使用 if (!empty($param['excel_type'])) return $data; @@ -1130,13 +1162,12 @@ class Customer extends ApiCommon * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function productSatisfaction(BiCustomerLogic $biCustomerLogic, $param='') + public function productSatisfaction($param='') { $param = $this->param; - + $userInfo=$this->userInfo; $param['start_time'] = !empty($param['start_time']) ? strtotime($param['start_time']) : ''; $param['end_time'] = !empty($param['end_time']) ? strtotime($param['end_time']) : ''; - if (!empty($param['type'])) { # 日期工具类 $timeArr = getTimeByType($param['type']); @@ -1144,7 +1175,8 @@ class Customer extends ApiCommon $param['start_time'] = $timeArr[0]; $param['end_time'] = $timeArr[1]; } - + + $biCustomerLogic= new BiCustomerLogic(); $data = $biCustomerLogic->getProductSatisfaction($param); //导出使用 if (!empty($param['excel_type'])) return $data; @@ -1182,6 +1214,7 @@ class Customer extends ApiCommon break; case 'recordMode': $list = $this->recordMode($param); + $list=$list['list']; $type['type'] = '客户跟进方式分析'; break; case 'poolList': @@ -1195,14 +1228,28 @@ class Customer extends ApiCommon break; case 'customerSatisfaction': $list = $this->customerSatisfaction($param); - $list=$list['list']; $type['type'] = '员工客户满意度分析'; break; case 'productSatisfaction': $list = $this->productSatisfaction($param); - $list=$list['list']; $type['type'] = '产品满意度分析'; break; + case 'userCycleList': + $list = $this->userCycleList($param); + $list=$list['list']; + $type['type'] = '成交周期'; + break; + case 'productCycle': + $list = $this->addressCycle($param); + + $list=$list['list']; + $type['type'] = '地区成交周期'; + break; + case 'addressCycle': + $list = $this->productCycle($param); + $list=$list['list']; + $type['type'] = '地区成交周期'; + break; } if(empty($list)){ diff --git a/application/bi/controller/Log.php b/application/bi/controller/Log.php index 5abd37d..1ef3f36 100644 --- a/application/bi/controller/Log.php +++ b/application/bi/controller/Log.php @@ -45,7 +45,6 @@ class Log extends ApiCommon public function statistics() { $param = $this->param; - if ($param['type']) { $timeArr = getTimeByType($param['type']); $param['start_time'] = $timeArr[0]; diff --git a/application/bi/controller/Product.php b/application/bi/controller/Product.php index b26cbfd..3d55216 100644 --- a/application/bi/controller/Product.php +++ b/application/bi/controller/Product.php @@ -54,9 +54,8 @@ class Product extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $list = $productModel->getStatistics($param); @@ -78,11 +77,10 @@ class Product extends ApiCommon public function productCategory() { $param = $this->param; - $productModel = new \app\bi\model\Product(); - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] =$param['end_time'] . ' 23:59:59'; $list = $productModel->getStatistics($param); @@ -105,28 +103,28 @@ class Product extends ApiCommon $subtotalCount = []; $sumCount = []; $item = []; - $unm = 0; - $subtotal = 0; $res = []; - foreach ($list as $val) { + foreach ($list as &$val) { $res[] = $val['product_id']; $data[$val['product_id']][] = $val; } $res = array_unique($res); foreach ($res as $e) { + $unm = 0; + $subtotal = 0; foreach ($list as $v) { if ($e == $v['product_id']) { $unm += $v['num']; $subtotal += $v['subtotal']; - $sumCount[$e] = $unm + $v['num']; - $subtotalCount[$e] = (float)$subtotal + $v['subtotal']; + $sumCount[$e] = $unm; + $subtotalCount[$e] = (float)$subtotal; } } $item[$e][] = [ 'type' => '', 'category_id_info' => '', 'product_name' => '', - 'contract_name' => '', + 'contract_num' => '', 'realname' => '', 'name' => '', 'price' => '合计', diff --git a/application/bi/controller/Ranking.php b/application/bi/controller/Ranking.php index 4953b54..63fa75c 100644 --- a/application/bi/controller/Ranking.php +++ b/application/bi/controller/Ranking.php @@ -67,19 +67,24 @@ class Ranking extends ApiCommon $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] =$param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'contract'); $whereArr['check_status'] = 2; //导出使用 - if (!empty($param['excel_type'])) return $this->handel( - new \app\bi\model\Contract, - $whereArr, - ['field' => 'SUM(`money`)', 'alias' => 'money', 'default' => '0.00'], - $param['excel_type'] - ); + if (!empty($param['excel_type'])) { + $data=$this->handel( + new \app\bi\model\Contract, + $whereArr, + ['field' => 'SUM(`money`)', 'alias' => 'money', 'default' => '0.00'], + $param['excel_type'] + ); + return $data; +} + + return $this->handel( new \app\bi\model\Contract, $whereArr, @@ -96,18 +101,20 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'receivables'); $whereArr['check_status'] = 2; - //导出使用 - if (!empty($param['excel_type'])) return $this->handel( - new \app\bi\model\Receivables, - $whereArr, - ['field' => 'SUM(`money`)', 'alias' => 'money', 'default' => '0.00'], - $param['excel_type'] - ); + if (!empty($param['excel_type'])) { + $data=$this->handel( + new \app\bi\model\Receivables, + $whereArr, + ['field' => 'SUM(`money`)', 'alias' => 'money', 'default' => '0.00'], + $param['excel_type'] + ); + return $data; +} return $this->handel( new \app\bi\model\Receivables, $whereArr, @@ -124,18 +131,22 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'contract'); $whereArr['check_status'] = 2; //导出使用 - if (!empty($param['excel_type'])) $this->handel( - new ContractModel, - $whereArr, - ['field' => 'COUNT(*)', 'alias' => 'count', 'default' => 0], - $param['excel_type'] - ); + if (!empty($param['excel_type'])) { + $data= $this->handel( + new ContractModel, + $whereArr, + ['field' => 'COUNT(*)', 'alias' => 'count', 'default' => 0], + $param['excel_type'] + ); + return $data; +} + return $this->handel( new ContractModel, $whereArr, @@ -152,8 +163,8 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'customer'); $poolWhere = $this->getWhereByPool(); @@ -181,8 +192,8 @@ class Ranking extends ApiCommon public function addContacts() { $param = $this->param; - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'contacts'); //导出使用 @@ -213,8 +224,8 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'record'); # 权限内的员工列表 @@ -265,8 +276,8 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] =$param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'record'); # 权限内的员工列表 @@ -316,8 +327,8 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $whereArr = $this->com($param, 'record'); $whereArr['category_id'] = 3; // 审批类型,3出差 $whereArr['check_status'] = 2; @@ -351,8 +362,8 @@ class Ranking extends ApiCommon if($param['excel_type']!=1){ $param = $this->param; } - if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00'); - if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59'); + if (!empty($param['start_time'])) $param['start_time'] = $param['start_time'] . ' 00:00:00'; + if (!empty($param['end_time'])) $param['end_time'] = $param['end_time'] . ' 23:59:59'; $list = $productModel->getSortByProduct($param); $list = array_column($list, null, 'owner_user_id'); @@ -466,49 +477,48 @@ class Ranking extends ApiCommon switch ($param['excel_types']) { case 'contract': $list = $this->contract($param); - - foreach ($list as $key => $v) { - $list[$key]['id'] = $key + 1; - } - $type['type'] = '合同金额排行'; + $param['type'] = '合同金额排行'; break; - case'receivables': + case 'receivablesRanKingExport': $list = $this->receivables($param); - $type['type'] = '回款金额排行'; + $param['type'] = '回款金额排行'; break; case 'signing': $list = $this->signing($param); - $type['type'] = '签约合同排行'; + $param['type'] = '签约合同排行'; break; case 'product': $list = $this->product($param); - $type['type'] = '产品销量排行'; + $param['type'] = '产品销量排行'; break; case 'addCustomer': $list = $this->addCustomer($param); - $type['type'] = '新增客户数排行'; + $param['type'] = '新增客户数排行'; break; case 'addContacts': $list = $this->addContacts($param); - $type['type'] = '新增联系人数排行'; + $param['type'] = '新增联系人数排行'; break; case 'recordNun': $list = $this->recordNun($param); - $type['type'] = '跟进次数排行'; + $param['type'] = '跟进次数排行'; break; case 'recordCustomer': $list = $this->recordCustomer($param); - $type['type'] = '跟进客户数排行'; + $param['type'] = '跟进客户数排行'; break; case 'examine': $list = $this->examine($param); - $type['type'] = '出差次数排行'; + $param['type'] = '出差次数排行'; break; } if(empty($list)){ return resultArray(['data'=>'数据不存在']); } $excelLogic = new ExcelLogic(); + foreach ($list as $key => $v) { + $list[$key]['id'] = $key + 1; + } $data = $excelLogic->rankingExcle($param, $list); return $data; } diff --git a/application/bi/logic/BiCustomerLogic.php b/application/bi/logic/BiCustomerLogic.php index 24b4117..113c200 100644 --- a/application/bi/logic/BiCustomerLogic.php +++ b/application/bi/logic/BiCustomerLogic.php @@ -29,11 +29,23 @@ class BiCustomerLogic $result = []; $userModel = new \app\admin\model\User(); - + $adminModel = new \app\admin\model\Admin(); $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); # 权限范围内userIds - $userIds = $perUserIds; # 数组交集 - if (empty($userIds)) return []; - + $whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件 + $userIds = $whereData['userIds']; + if (empty($userIds)) { + # 普通员工没有查看权限,返回固定数据(根据员工筛选) + $result[] = [ + 'realname' => db('admin_user')->where('id', $param['user_id'])->value('realname'), + 'visitContractNum' => 0, + '很满意' => 0, + '满意' => 0, + '一般' => 0, + '不满意' => 0, + '很不满意' => 0, + ]; + return $result; + } # 员工信息 $userList = db('admin_user')->field(['id', 'realname'])->whereIn('id', $userIds)->select(); foreach ($userList AS $key => $value) { @@ -94,10 +106,9 @@ class BiCustomerLogic $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); # 权限范围内userIds $userIds = !empty($param['user_id']) ? array_intersect([$param['user_id']], $perUserIds) : $perUserIds; # 数组交集 - if (empty($userIds)) return []; # 产品列表(上架中) - $productList = db('crm_product')->field(['product_id', 'name'])->where('status', '上架')->select(); + $productList = db('crm_product')->field(['product_id', 'name'])->where( 'delete_user_id',0)->select(); foreach ($productList AS $key => $value) { $productData[$value['product_id']] = [ 'productName' => $value['name'], @@ -110,6 +121,9 @@ class BiCustomerLogic ]; } + # 普通员工没有查询权限,返回固定数据(根据员工筛选) + if (empty($userIds)) array_values($productData); + # 回访条件 $where['visit.owner_user_id'] = ['in', $userIds]; $where['visit.create_time'] = ['between', [$param['start_time'], $param['end_time']]]; diff --git a/application/bi/logic/ExcelLogic.php b/application/bi/logic/ExcelLogic.php index d2a5fbe..0d6d001 100644 --- a/application/bi/logic/ExcelLogic.php +++ b/application/bi/logic/ExcelLogic.php @@ -38,9 +38,9 @@ class ExcelLogic case 'recordMode': $file_name = 'customerRecordCategoryStats'; $field_list = [ - '0' => ['name' => '员工姓名', 'field' => 'realname'], - '1' => ['name' => '跟进次数', 'field' => 'record_num'], - '2' => ['name' => '跟进客户数', 'field' => 'customer_num'], + '0' => ['name' => '跟进方式', 'field' => 'category'], + '1' => ['name' => '个数', 'field' => 'recordNum'], + '2' => ['name' => '占比', 'field' => 'proportion'], ]; break; case 'poolList': @@ -52,7 +52,7 @@ class ExcelLogic '3' => ['name' => '进入公海客户数', 'field' => 'put_in'], ]; break; - case 'userCycle': + case 'userCycleList': $file_name = 'employeeCycleInfo'; $field_list = [ '0' => ['name' => '员工姓名', 'field' => 'realname'], @@ -60,28 +60,44 @@ class ExcelLogic '2' => ['name' => '成交客户数', 'field' => 'customer_num'], ]; break; + case 'productCycle': + $file_name = 'addressCycleInfo'; + $field_list = [ + '0' => ['name' => '地区', 'field' => 'address'], + '1' => ['name' => '成交周期(天)', 'field' => 'cycle'], + '2' => ['name' => '成交客户数', 'field' => 'customer_num'], + ]; + break; + case 'addressCycle': + $file_name = 'productCycleInfo'; + $field_list = [ + '0' => ['name' => '产品名称', 'field' => 'product_name'], + '1' => ['name' => '成交周期(天)', 'field' => 'cycle'], + '2' => ['name' => '成交客户数', 'field' => 'customer_num'], + ]; + break; case 'customerSatisfaction': $file_name = 'customerSatisfaction'; $field_list = [ '0' => ['name' => '员工姓名', 'field' => 'realname'], - '1' => ['name' => '回访合同总数', 'field' => 'visit'], - '2' => ['name' => '很满意', 'field' => 'satisfaction1'], - '3' => ['name' => '满意', 'field' => 'satisfaction2'], - '4' => ['name' => '一般', 'field' => 'satisfaction3'], - '5' => ['name' => '不满意', 'field' => 'satisfaction4'], - '6' => ['name' => '很不满意', 'field' => 'satisfaction5'], + '1' => ['name' => '回访合同总数', 'field' => 'visitContractNum'], + '2' => ['name' => '很满意', 'field' => '很满意'], + '3' => ['name' => '满意', 'field' => '满意'], + '4' => ['name' => '一般', 'field' => '一般'], + '5' => ['name' => '不满意', 'field' => '不满意'], + '6' => ['name' => '很不满意', 'field' => '很不满意'], ]; break; case 'productSatisfaction': $file_name = 'productSatisfaction'; $field_list = [ - '0' => ['name' => '员工姓名', 'field' => 'realname'], - '1' => ['name' => '回访合同总数', 'field' => 'visit'], - '2' => ['name' => '很满意', 'field' => 'satisfaction1'], - '3' => ['name' => '满意', 'field' => 'satisfaction2'], - '4' => ['name' => '一般', 'field' => 'satisfaction3'], - '5' => ['name' => '不满意', 'field' => 'satisfaction4'], - '6' => ['name' => '很不满意', 'field' => 'satisfaction5'], + '0' => ['name' => '产品名称', 'field' => 'productName'], + '1' => ['name' => '回访次数', 'field' => 'visitNum'], + '2' => ['name' => '很满意', 'field' => '很满意'], + '3' => ['name' => '满意', 'field' => '满意'], + '4' => ['name' => '一般', 'field' => '一般'], + '5' => ['name' => '不满意', 'field' => '不满意'], + '6' => ['name' => '很不满意', 'field' => '很不满意'], ]; break; } @@ -101,7 +117,7 @@ class ExcelLogic if($type['excel_types']=='analysis'){ $file_name = 'contractNumStats'; $field_list = []; - p($excelModel->template_download($file_name, $field_list, $type['type'], $param)); + return $excelModel->template_download($file_name, $field_list, $type['type'], $param); }elseif ($type['excel_types']=='summary'){ $file_name = 'totalContract'; @@ -111,7 +127,7 @@ class ExcelLogic '2' => ['name' => '签约合同金额(元)', 'field' => 'money'], '3' => ['name' => '回款金额(元)', 'field' => 'back'], ]; - return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param['items']); + return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param); }elseif ($type['excel_types']=='invoice'){ $file_name = 'invoiceStats'; $field_list = [ @@ -164,15 +180,14 @@ class ExcelLogic { $file_name = 'contractNumStats'; $field_list = [ - '0' => ['name' => '日期', 'field' => 'type'], - '1' => ['name' => '产品分类', 'field' => 'category_id_info'], - '2' => ['name' => '产品名称', 'field' => 'product_name'], - '3' => ['name' => '合同编号', 'field' => 'contract_name'], - '4' => ['name' => '负责人', 'field' => 'realname'], - '5' => ['name' => '客户名称', 'field' => 'name'], - '6' => ['name' => '销售单价', 'field' => 'price'], - '7' => ['name' => '数量', 'field' => 'num'], - '8' => ['name' => '订单产品小计', 'field' => 'subtotal'], + '0' => ['name' => '产品分类', 'field' => 'category_id_info'], + '1' => ['name' => '产品名称', 'field' => 'product_name'], + '2' => ['name' => '合同编号', 'field' => 'contract_num'], + '3' => ['name' => '负责人', 'field' => 'realname'], + '4' => ['name' => '客户名称', 'field' => 'contract_name'], + '5' => ['name' => '销售单价', 'field' => 'price'], + '6' => ['name' => '数量', 'field' => 'num'], + '7' => ['name' => '订单产品小计', 'field' => 'subtotal'], ]; $type = '产品销售情况统计'; $excelModel = new \app\admin\model\Excel(); @@ -199,7 +214,7 @@ class ExcelLogic '3' => ['name' => '合同金额(元)', 'field' => 'money'], ]; break; - case 'receivables': + case 'receivablesRanKingExport': $file_name = 'receivablesRanKing'; $field_list = [ '0' => ['name' => '公司总排名', 'field' => 'id'], @@ -281,7 +296,7 @@ class ExcelLogic * @param $param * @return mixed */ - public function achienementExcel($type, $param) + public function achienementExcel($param) { $file_name = 'contractNumStats'; $field_list = [ @@ -289,11 +304,17 @@ class ExcelLogic '1' => ['name' => '月份', 'field' => 'month'], '2' => ['name' => '目标', 'field' => 'achievement'], '3' => ['name' => '完成', 'field' => 'money'], - '4' => ['name' => 'rate', 'field' => 'realname'], + '4' => ['name' => '完成率', 'field' => 'rate'], ]; $type = '业绩目标完成情况'; $excelModel = new \app\admin\model\Excel(); - return $excelModel->biExportExcel($file_name, $field_list, $type, $param); + $item=[]; + foreach ($param as $value) { + foreach ($value as $v) { + $item[] = $v; + } + } + return $excelModel->biExportExcel($file_name, $field_list, $type, $item); } diff --git a/application/bi/model/Business.php b/application/bi/model/Business.php index 5f99429..428589b 100644 --- a/application/bi/model/Business.php +++ b/application/bi/model/Business.php @@ -67,27 +67,23 @@ class Business extends Common $perUserIds = $userModel->getUserByPer('bi', 'business', 'read'); //权限范围内userIds $whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereData['userIds']; - - if (!empty($whereData['between_time']['last_time'])) unset($whereData['between_time']['last_time']); + if (!empty($whereData['between_time'][0])) unset($whereData['between_time'][1]); $between_time = $whereData['between_time']; $where['business.owner_user_id'] = array('in',$userIds); - $where['business.create_time'] = ['between', $between_time]; - $where['check_status'] = 2; + $where['business.create_time'] = ['between', [$param['start_time'],$param['end_time']]]; if (!empty($param['is_end']) && $param['is_end'] == 1) $where['is_end'] = 1; $count = db('crm_business')->alias('business') ->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left') ->where($where)->group('business.business_id')->count(); $sql = db('crm_business')->alias('business') - ->field('business.business_id,business.customer_id,business.money,business.type_id,business.status_id,business.deal_date,business.create_user_id,business.owner_user_id') + ->field('business.business_id,business.customer_id,business.money,business.type_id,business.status_id,business.deal_date,business.create_user_id,business.owner_user_id,business.is_end') ->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left') ->where($where) - ->fetchSql() ->limit(($page - 1) * $limit, $limit) ->order(['money' => 'DESC']) ->group('business.business_id') ->select(); - - return ['dataCount' => $count, 'list' => queryCache($sql)]; + return ['dataCount' => $count, 'list' => $sql]; } } \ No newline at end of file diff --git a/application/bi/model/Examine.php b/application/bi/model/Examine.php index acfa928..1ffd5a9 100644 --- a/application/bi/model/Examine.php +++ b/application/bi/model/Examine.php @@ -59,8 +59,7 @@ class Examine extends Common $userIds = $whereData['userIds']; //时间 - $time_array = getTimeArray(); - + $category_list = db('oa_examine_category') ->where(['status' => 1,'is_deleted' => ['neq',1]]) ->field('category_id,title') @@ -75,7 +74,7 @@ class Examine extends Common $sql = OaExamineModel::field($fields) ->where([ - 'create_time' => ['BETWEEN', $time_array['between']], + 'create_time' => ['BETWEEN', $whereData['between_time']], 'create_user_id' => ['IN', $userIds], 'check_status' => ['neq', 4] ]) diff --git a/application/common.php b/application/common.php index cf58b4c..6a65e51 100644 --- a/application/common.php +++ b/application/common.php @@ -166,14 +166,14 @@ function where_arr($array = [], $m = '', $c = '', $a = '') if (!empty($v['end'])) $v['end'] = date('Y-m-d', $v['end']); } # 创建人、负责人、回访人(非自定义字段) - if ($v['form_type'] == 'user' && in_array($k, ['create_user_id', 'owner_user_id'])) { - if ($v['condition'] == 'is') $v['condition'] = 'contains'; - } +// if ($v['form_type'] == 'user' && in_array($k, ['create_user_id', 'owner_user_id'])) { +// if ($v['condition'] == 'is') $v['condition'] = 'contains'; +// } # 自定义字段的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)"; + return "(".$c.$k." not like ',%".$v['value'][0]."%,' OR ".$c.$k." is null)"; } } # 处理多选字段的精确搜索 @@ -182,7 +182,7 @@ function where_arr($array = [], $m = '', $c = '', $a = '') if ($v['condition'] == 'is' && count($v['value']) > 1) { $checkboxLike = ''; foreach ($v['value'] AS $kk => $vv) { - $checkboxLike .= $c.$k." like "."'%".$vv."%' AND "; + $checkboxLike .= $c.$k." like "."',%".$vv."%,' AND "; } return "(".$checkboxLike."LENGTH(".$c.$k.") = LENGTH('".arrayToString($v['value'])."'))"; } @@ -779,7 +779,6 @@ function updateActionLog($user_id, $types, $action_id, $oldData = [], $newData = { if (is_array($oldData) && is_array($newData) && $user_id) { $differentData = array_diff_assoc($newData, $oldData); - $fieldModel = new FieldModel(); $userModel = new UserModel(); $structureModel = new \app\admin\model\Structure(); @@ -791,6 +790,7 @@ function updateActionLog($user_id, $types, $action_id, $oldData = [], $newData = $unField = ['update_time','create_time']; //定义过滤字段 $message = []; $un_form_type = ['file', 'form']; + foreach ($differentData as $k => $v) { if ($newFieldArr[$k] && !in_array($newFieldArr[$k]['form_type'], $un_form_type)) { $field_name = ''; @@ -829,6 +829,11 @@ function updateActionLog($user_id, $types, $action_id, $oldData = [], $newData = } elseif ($newFieldArr[$k]['form_type'] == 'visit') { $new_value = $v ? db('crm_visit')->where(['visit_id' => $v])->value('number') : ''; $old_value = $v ? db('crm_visit')->where(['visit_id' => $oldData[$k]])->value('number') : ''; + } elseif ($newFieldArr[$k]['form_type'] == 'single_user'){ + $new_value = $v ? db('admin_user')->where(['id' => $v])->value('realname') : ''; + $old_value = $v ? db('admin_user')->where(['id' => $oldData['owner_user_id']])->value('realname') : ''; + }elseif($newFieldArr[$k]['form_type'] == 'floatnumber'){ + $new_value = $v ? number_format($v,2) : ''; } $message[] = '将 ' . "'" . $field_name . "'" . ' 由 ' . $old_value . ' 修改为 ' . $new_value; } diff --git a/application/common/behavior/AuthenticateBehavior.php b/application/common/behavior/AuthenticateBehavior.php index 5c1af1e..c3c6fac 100644 --- a/application/common/behavior/AuthenticateBehavior.php +++ b/application/common/behavior/AuthenticateBehavior.php @@ -6,6 +6,7 @@ // +---------------------------------------------------------------------- namespace app\common\behavior; +use think\Cache; use think\Request; use think\Db; @@ -30,18 +31,18 @@ class AuthenticateBehavior $permission = $params['permission']; //无限制 /*获取头部信息*/ $header = $request->header(); - $authKey = $header['authkey']; + $authKey = trim($header['authkey']); $paramArr = $request->param(); $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求分类(mobile,ding) - $cache = cache('Auth_'.$authKey.$platform); + $cache = Cache::get('Auth_'.$authKey.$platform); $userInfo = $cache['userInfo']; if (in_array($a, $permission)) { return true; } - if (empty($userInfo)) { + if (empty($userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code'=>101,'error'=>'请先登录'])); } diff --git a/application/common/controller/Common.php b/application/common/controller/Common.php index b888660..88305c8 100644 --- a/application/common/controller/Common.php +++ b/application/common/controller/Common.php @@ -7,6 +7,7 @@ namespace app\common\controller; +use think\Cache; use think\Controller; use think\Request; @@ -30,8 +31,8 @@ class Common extends Controller $this->param = $param; $request = request(); $header = $request->header(); - $authKey = $header['authkey']; - $cache = cache('Auth_'.$authKey.$platform); + $authKey = trim($header['authkey']); + $cache = Cache::get('Auth_'.$authKey.$platform); if ($cache) $this->userInfo = $cache['userInfo']; $m = strtolower($request->module()); diff --git a/application/crm/controller/Achievement.php b/application/crm/controller/Achievement.php index 2cadbf8..8a24512 100644 --- a/application/crm/controller/Achievement.php +++ b/application/crm/controller/Achievement.php @@ -65,19 +65,23 @@ class Achievement extends ApiCommon //员工业绩目标列表 public function indexForuser(AchievementLogic $achievementLogic) { -// $model = model('Achievement'); -// $param = $this->param; -// $data = $model->getDataListForUser($param); -// return resultArray(['data' => $data]); - if (empty($this->param['year'])) return resultArray(['error' => '请选择年份!']); - if (empty($this->param['type'])) return resultArray(['error' => '请选择业绩类型']); - if (empty($this->param['structure_id']) && empty($this->param['user_id'])) { - return resultArray(['error' => '请选择部门或员工!']); + $model = model('Achievement'); + $param = $this->param; + $data = $model->getDataListForUser($param); + # 剔除没有业绩目标的员工 + foreach ($data AS $key => $value) { + if (empty((int)$value['yeartarget'])) unset($data[(int)$key]); } - - $data = $achievementLogic->getEmployeeList($this->param); - - return resultArray(['data' => $data]); + return resultArray(['data' => array_values($data)]); +// if (empty($this->param['year'])) return resultArray(['error' => '请选择年份!']); +// if (empty($this->param['type'])) return resultArray(['error' => '请选择业绩类型']); +// if (empty($this->param['structure_id']) && empty($this->param['user_id'])) { +// return resultArray(['error' => '请选择部门或员工!']); +// } +// +// $data = $achievementLogic->getEmployeeList($this->param); +// +// return resultArray(['data' => $data]); } /** diff --git a/application/crm/controller/Business.php b/application/crm/controller/Business.php index ed3f1cb..4d1c91a 100644 --- a/application/crm/controller/Business.php +++ b/application/crm/controller/Business.php @@ -8,6 +8,7 @@ namespace app\crm\controller; use app\admin\controller\ApiCommon; +use app\crm\traits\SearchConditionTrait; use app\crm\traits\StarTrait; use think\Hook; use think\Request; @@ -15,7 +16,7 @@ use think\Db; class Business extends ApiCommon { - use StarTrait; + use StarTrait, SearchConditionTrait; /** * 用于判断权限 @@ -93,7 +94,7 @@ class Business extends ApiCommon $roPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'read'); $rwPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'update'); if (!in_array($data['owner_user_id'],$auth_user_ids) && !$rwPre && !$roPre) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } //商机状态组 @@ -212,7 +213,7 @@ class Business extends ApiCommon public function statusList() { $businessStatusModel = model('BusinessStatus'); - $key = 'BI_queryCache_StatusList_Data1'; + $key = 'BI_queryCache_StatusList_Data'; $list = cache($key); if (!$list) { $userInfo = $this->userInfo; @@ -225,7 +226,7 @@ class Business extends ApiCommon foreach ($list as $k=>$v) { $list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']); } - cache($key, $list, true); + cache($key, $list, config('business_status_cache_time')); } return resultArray(['data' => $list]); @@ -415,7 +416,7 @@ class Business extends ApiCommon 'create_user_id' => $businessInfo['owner_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => $businessInfo['customer_id'] + 'customer_ids' => ',' . $businessInfo['customer_id'] . ',' ]); //推进记录添加 @@ -426,7 +427,18 @@ class Business extends ApiCommon $temp['owner_user_id'] = $userInfo['id']; $temp['remark'] = $param['remark'] ? : ''; Db::name('CrmBusinessLog')->insert($temp); - return resultArray(['data' => '推进成功']); + + # 返回商机阶段数据 + $typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id'); + $businessStatus = db('crm_business_status')->where('type_id', $typeId)->select(); + $result = [ + 'business_id' => $param['business_id'], + 'type_id' => $typeId, + 'status_id' => $param['status_id'], + 'status_list' => $businessStatus + ]; + + return resultArray(['data' => $result]); } } @@ -523,17 +535,25 @@ class Business extends ApiCommon $businessId = $this->param['business_id']; + $userInfo = $this->userInfo; + + # 查询联系人和商机关联数据 + $contactsIds = Db::name('crm_contacts_business')->where('business_id', $businessId)->column('contacts_id'); + # 联系人 - $contactsCount = Db::name('crm_contacts_business')->alias('business') - ->join('__CRM_CONTACTS__ contacts', 'contacts.contacts_id = business.contacts_id') - ->join('__CRM_CUSTOMER__ customer', 'customer.customer_id = contacts.customer_id') - ->where('business_id', $businessId)->count(); + $contactsAuth = $this->getContactsSearchWhere($userInfo['id']); + $contactsCount = Db::name('crm_contacts')->whereIn('contacts_id', $contactsIds)->where($contactsAuth)->count(); # 合同 - $contractCount = Db::name('crm_contract')->where('business_id', $businessId)->count(); + $contractAuth = $this->getContractSearchWhere($userInfo['id']); + $contractCount = Db::name('crm_contract')->where('business_id', $businessId)->where($contractAuth)->count(); + + # 查询商机和产品的关联表 + $productIds = Db::name('crm_business_product')->where('business_id', $businessId)->column('product_id'); # 产品 - $productCount = Db::name('crm_business_product')->where('business_id', $businessId)->count(); + $productAuth = $this->getProductSearchWhere(); + $productCount = Db::name('crm_product')->whereIn('product_id', $productIds)->whereIn('owner_user_id', $productAuth)->count(); # 附件 $fileCount = Db::name('crm_business_file')->alias('business')->join('__ADMIN_FILE__ file', 'file.file_id = business.file_id', 'LEFT')->where('business_id', $businessId)->count(); diff --git a/application/crm/controller/Contacts.php b/application/crm/controller/Contacts.php index 70f7a66..4ff188d 100644 --- a/application/crm/controller/Contacts.php +++ b/application/crm/controller/Contacts.php @@ -8,6 +8,7 @@ namespace app\crm\controller; use app\admin\controller\ApiCommon; +use app\crm\traits\SearchConditionTrait; use app\crm\traits\StarTrait; use think\Hook; use think\Request; @@ -15,7 +16,7 @@ use think\Db; class Contacts extends ApiCommon { - use StarTrait; + use StarTrait, SearchConditionTrait; /** * 用于判断权限 @@ -67,12 +68,11 @@ class Contacts extends ApiCommon $param['owner_user_id'] = $userInfo['id']; if ($data = $contactsModel->createData($param)) { - //关联 联系人与商机 客户添加与商机添加联系人可共用此接口 - $business_id = $param['business_id']?$param['business_id']:0; - if($business_id != 0){ - $data['cancel_or_relation'] = 1;// 1:关联 0取消 + # 商机管理联系人 + $business_id = $param['business_id'] ? $param['business_id'] : 0; + if (!empty($business_id)) { $data['business_id'] = $business_id; - if ($res = Db::name('crm_contacts_business')->data($data)->insert()) { + if ($res = Db::name('crm_contacts_business')->data($data)->insert()) { return resultArray(['data' => '添加成功']); } else { return resultArray(['error' => Db::name('crm_contacts_business')->getError()]); @@ -99,7 +99,7 @@ class Contacts extends ApiCommon //判断权限 $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'read'); if (!in_array($data['owner_user_id'],$auth_user_ids)) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { @@ -494,8 +494,16 @@ class Contacts extends ApiCommon $contactsId = $this->param['contacts_id']; + $userInfo = $this->userInfo; + + # 查询联系人和商机的关联表 + $businessIds = Db::name('crm_contacts_business')->where('contacts_id', $contactsId)->column('business_id'); + + # 商机权限条件 + $businessAuth = $this->getBusinessSearchWhere($userInfo['id']); + # 商机 - $businessCount = Db::name('crm_business')->where('contacts_id', $contactsId)->count(); + $businessCount = Db::name('crm_business')->whereIn('business_id', $businessIds)->where($businessAuth)->count(); # 附件 $fileCount = Db::name('crm_contacts_file')->alias('contacts')->join('__ADMIN_FILE__ file', 'file.file_id = contacts.file_id', 'LEFT')->where('contacts_id', $contactsId)->count(); diff --git a/application/crm/controller/Contract.php b/application/crm/controller/Contract.php index bd63218..3bea21a 100644 --- a/application/crm/controller/Contract.php +++ b/application/crm/controller/Contract.php @@ -12,13 +12,14 @@ use app\admin\model\Message; use app\admin\model\User; use app\crm\model\NumberSequence; use app\crm\traits\AutoNumberTrait; +use app\crm\traits\SearchConditionTrait; use think\Db; use think\Hook; use think\Request; class Contract extends ApiCommon { - use AutoNumberTrait; + use AutoNumberTrait, SearchConditionTrait; /** * 用于判断权限 @@ -149,7 +150,7 @@ class Contract extends ApiCommon $roPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'read'); $rwPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'update'); if (!in_array($data['owner_user_id'],$auth_user_ids) && !$roPre && !$rwPre) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { @@ -771,6 +772,8 @@ class Contract extends ApiCommon $contractId = $this->param['contract_id']; + $userInfo = $this->userInfo; + $contract = Db::name('crm_contract')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('contract_id', $contractId)->find(); # 团队 @@ -779,14 +782,20 @@ class Contract extends ApiCommon $contract['owner_user_id'] = [$contract['owner_user_id']]; $teamCount = array_filter(array_unique(array_merge($contract['ro_user_id'], $contract['rw_user_id'], $contract['owner_user_id']))); + # 查询合同和产品的关联数据 + $productIds = Db::name('crm_contract_product')->where('contract_id', $contractId)->column('product_id'); + # 产品 - $productCount = Db::name('crm_contract_product')->where('contract_id', $contractId)->count(); + $productAuth = $this->getProductSearchWhere(); + $productCount = Db::name('crm_product')->whereIn('product_id', $productIds)->whereIn('owner_user_id', $productAuth)->count(); # 回款 - $receivablesCount = Db::name('crm_receivables')->where('contract_id', $contractId)->count(); + $receivablesAuth = $this->getReceivablesSearchWhere(); + $receivablesCount = Db::name('crm_receivables')->where('contract_id', $contractId)->whereIn('owner_user_id', $receivablesAuth)->count(); # 回访 - $visitCount = Db::name('crm_visit')->where('contract_id', $contractId)->count(); + $visitAuth = $this->getVisitSearchWhere($userInfo['id']); + $visitCount = Db::name('crm_visit')->where('contract_id', $contractId)->where($visitAuth)->count(); # 附件 $fileCount = Db::name('crm_contract_file')->alias('contract')->join('__ADMIN_FILE__ file', 'file.file_id = contract.file_id', 'LEFT')->where('contract_id', $contractId)->count(); diff --git a/application/crm/controller/Customer.php b/application/crm/controller/Customer.php index 8506476..273d8f6 100644 --- a/application/crm/controller/Customer.php +++ b/application/crm/controller/Customer.php @@ -9,6 +9,7 @@ namespace app\crm\controller; use app\admin\controller\ApiCommon; use app\crm\logic\CustomerLogic; +use app\crm\traits\SearchConditionTrait; use app\crm\traits\StarTrait; use think\Hook; use think\Request; @@ -16,64 +17,65 @@ use think\Db; class Customer extends ApiCommon { - use StarTrait; - + use StarTrait, SearchConditionTrait; + /** * 用于判断权限 * @permission 无限制 * @allow 登录用户可访问 * @other 其他根据系统设置 - **/ + **/ public function _initialize() { $action = [ - 'permission'=>['exceldownload','setfollow', 'delete'], - 'allow'=>['read', 'system', 'count', 'poolauthority'] + 'permission' => ['exceldownload', 'setfollow', 'delete'], + 'allow' => ['read', 'system', 'count', 'poolauthority'] ]; - Hook::listen('check_auth',$action); + Hook::listen('check_auth', $action); $request = Request::instance(); - $a = strtolower($request->action()); + $a = strtolower($request->action()); if (!in_array($a, $action['permission'])) { parent::_initialize(); } else { - $param = Request::instance()->param(); - $this->param = $param; + $param = Request::instance()->param(); + $this->param = $param; } - } - + } + /** * 客户列表 - * @author Michael_xu * @return + * @author Michael_xu */ public function index() { $customerModel = model('Customer'); $param = $this->param; $userInfo = $this->userInfo; - $param['user_id'] = $userInfo['id']; + $param['user_id'] = $userInfo['id']; $data = $customerModel->getDataList($param); return resultArray(['data' => $data]); } - + /** * 客户公海(没有负责人或已经到期) - * @author Michael_xu * @return + * @author Michael_xu */ public function pool() { $param = $this->param; $param['action'] = 'pool'; + unset($param['poolId']); # todo uniApp传来的参数,临时删除掉 fanqi。 $data = model('Customer')->getDataList($param); return resultArray(['data' => $data]); - } - + } + /** * 添加客户 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function save() { @@ -88,12 +90,12 @@ class Customer extends ApiCommon return resultArray(['error' => $customerModel->getError()]); } } - + /** * 客户详情 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function read() { @@ -113,18 +115,18 @@ class Customer extends ApiCommon //判断是否客户池数据 $wherePool = $customerModel->getWhereByPool(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find(); - if (!$resPool && !in_array($data['owner_user_id'],$auth_user_ids) && !$roPre && !$rwPre) { - $authData['dataAuth'] = 0; + if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) { + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } return resultArray(['data' => $data]); } - + /** * 编辑客户 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function update() { @@ -135,21 +137,21 @@ class Customer extends ApiCommon $data = $customerModel->getDataById($param['id']); if (!$data) { return resultArray(['error' => $customerModel->getError()]); - } - + } + $param['user_id'] = $userInfo['id']; if ($customerModel->updateDataById($param, $param['id'])) { return resultArray(['data' => '编辑成功']); } else { return resultArray(['error' => $customerModel->getError()]); - } + } } - + /** * 删除客户 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function delete() { @@ -175,24 +177,24 @@ class Customer extends ApiCommon } $delIds = []; $errorMessage = []; - + //数据权限判断 $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'delete'); //判断是否客户池数据(客户池数据只有管理员可以删) $adminId = $userModel->getAdminId(); $wherePool = $customerModel->getWhereByPool(); - foreach ($customer_id as $k=>$v) { + foreach ($customer_id as $k => $v) { $isDel = true; //数据详情 $data = db('crm_customer')->where(['customer_id' => $v])->find(); if (!$data) { $isDel = false; - $errorMessage[] = 'id为'.$v.'的客户删除失败,错误原因:'.$customerModel->getError(); + $errorMessage[] = 'id为' . $v . '的客户删除失败,错误原因:' . $customerModel->getError(); } $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $v])->where($wherePool)->find(); - if (!$resPool && !in_array($data['owner_user_id'],$auth_user_ids) && $isDel) { + if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && $isDel) { $isDel = false; - $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:无权操作'; + $errorMessage[] = '名称为' . $data['name'] . '的客户删除失败,错误原因:无权操作'; } // 公海 (原逻辑,公海仅允许管理员删除,修改为授权,不再限制) // if ($resPool && !in_array($data['owner_user_id'],$adminId)) { @@ -204,26 +206,26 @@ class Customer extends ApiCommon $resBusiness = db('crm_business')->where(['customer_id' => $v])->find(); if ($resBusiness) { $isDel = false; - $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:客户下存在商机,不能删除'; + $errorMessage[] = '名称为' . $data['name'] . '的客户删除失败,错误原因:客户下存在商机,不能删除'; } } if ($isDel) { $resContacts = db('crm_contacts')->where(['customer_id' => $v])->find(); if ($resContacts) { $isDel = false; - $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:客户下存在联系人,不能删除'; - } - } + $errorMessage[] = '名称为' . $data['name'] . '的客户删除失败,错误原因:客户下存在联系人,不能删除'; + } + } if ($isDel) { - $resContract = db('crm_contract')->where(['customer_id' => $v])->find(); + $resContract = db('crm_contract')->where(['customer_id' => $v])->find(); if ($resContract) { $isDel = false; - $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:客户下存在合同,不能删除'; - } - } + $errorMessage[] = '名称为' . $data['name'] . '的客户删除失败,错误原因:客户下存在合同,不能删除'; + } + } if ($isDel) { $delIds[] = $v; - } + } } if ($delIds) { $delRes = $customerModel->delDatas($delIds); @@ -231,12 +233,12 @@ class Customer extends ApiCommon return resultArray(['error' => $customerModel->getError()]); } //删除跟进记录 - $recordModel->delDataByTypes(2,$delIds); + $recordModel->delDataByTypes(2, $delIds); //删除关联附件 - $fileModel->delRFileByModule('crm_customer',$delIds); + $fileModel->delRFileByModule('crm_customer', $delIds); //删除关联操作记录 - $actionRecordModel->delDataById(['types'=>'crm_customer','action_id'=>$delIds]); - actionLog($delIds,'','',''); + $actionRecordModel->delDataById(['types' => 'crm_customer', 'action_id' => $delIds]); + actionLog($delIds, '', '', ''); } if ($errorMessage) { return resultArray(['error' => $errorMessage]); @@ -244,16 +246,16 @@ class Customer extends ApiCommon return resultArray(['data' => '删除成功']); } } - + /** * 客户转移 - * @author Michael_xu * @param owner_user_id 变更负责人 * @param is_remove 1移出,2转为团队成员 * @param types business,contract 相关模块 * @param type 权限 1只读2读写 * @return - */ + * @author Michael_xu + */ public function transfer() { $param = $this->param; @@ -262,19 +264,19 @@ class Customer extends ApiCommon $businessModel = model('Business'); $contractModel = model('Contract'); $contactsModel = model('Contacts'); - $settingModel = model('Setting'); - $customerConfigModel = model('CustomerConfig'); - $userModel = new \app\admin\model\User(); - + $settingModel = model('Setting'); + $customerConfigModel = model('CustomerConfig'); + $userModel = new \app\admin\model\User(); + if (!$param['owner_user_id']) { return resultArray(['error' => '变更负责人不能为空']); } if (!$param['customer_id'] || !is_array($param['customer_id'])) { - return resultArray(['error' => '请选择需要转移的客户']); - } + return resultArray(['error' => '请选择需要转移的客户']); + } $is_remove = ($param['is_remove'] == 2) ? 2 : 1; - $type = $param['type'] == 2 ? : 1; - $types = $param['types'] ? : []; + $type = $param['type'] == 2 ?: 1; + $types = $param['types'] ?: []; $data = []; $data['owner_user_id'] = $param['owner_user_id']; @@ -282,27 +284,27 @@ class Customer extends ApiCommon $data['follow'] = '待跟进'; # 获取客户的时间 $data['obtain_time'] = time(); - + $ownerUserName = $userModel->getUserNameById($param['owner_user_id']); $errorMessage = []; foreach ($param['customer_id'] as $customer_id) { $customerInfo = db('crm_customer')->where(['customer_id' => $customer_id])->find(); if (!$customerInfo) { - $errorMessage[] = '名称:为《'.$customerInfo['name'].'》的客户转移失败,错误原因:数据不存在;'; + $errorMessage[] = '名称:为《' . $customerInfo['name'] . '》的客户转移失败,错误原因:数据不存在;'; continue; } $resCustomer = true; //权限判断 if (!$customerModel->checkData($customer_id)) { - $errorMessage[] = $customerInfo['name'].'转移失败,错误原因:无权限;'; + $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:无权限;'; continue; } //拥有客户数上限检测 - if (!$customerConfigModel->checkData($param['owner_user_id'],1)) { - $errorMessage[] = $customerInfo['name'].'转移失败,错误原因:'.$customerConfigModel->getError(); + if (!$customerConfigModel->checkData($param['owner_user_id'], 1)) { + $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:' . $customerConfigModel->getError(); continue; } - + //团队成员 $teamData = []; $teamData['type'] = $type; //权限 1只读2读写 @@ -310,11 +312,14 @@ class Customer extends ApiCommon $teamData['types'] = 'crm_customer'; //类型 $teamData['types_id'] = $customer_id; //类型ID $teamData['is_del'] = ($is_remove == 1) ? 1 : ''; - $res = $settingModel->createTeamData($teamData); + $res = $settingModel->createTeamData($teamData); + # 处理分配标识,待办事项专用 + $data['is_allocation'] = 1; + $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); if (!$resCustomer) { - $errorMessage[] = $customerInfo['name'].'转移失败,错误原因:数据出错;'; + $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:数据出错;'; continue; } else { # 处理转移时,负责人出现在只读和读写成员列表中 @@ -331,58 +336,58 @@ class Customer extends ApiCommon db('crm_customer')->where('customer_id', $customer_id)->update($customerArray); } - if (in_array('crm_contacts',$types)) { + if (in_array('crm_contacts', $types)) { $contactsIds = []; $contactsIds = db('crm_contacts')->where(['customer_id' => $customer_id])->column('contacts_id'); if ($contactsIds) { $resContacts = $contactsModel->transferDataById($contactsIds, $param['owner_user_id'], $type, $is_remove); if ($resContacts !== true) { $errorMessage[] = $resContacts; - continue; + continue; } - } - } - + } + } + //商机、合同转移 - if (in_array('crm_business',$types)) { + if (in_array('crm_business', $types)) { $businessIds = []; $businessIds = db('crm_business')->where(['customer_id' => $customer_id])->column('business_id'); if ($businessIds) { $resBusiness = $businessModel->transferDataById($businessIds, $param['owner_user_id'], $type, $is_remove); if ($resBusiness !== true) { - $errorMessage = $errorMessage ? array_merge($errorMessage,$resBusiness) : $resBusiness; - continue; + $errorMessage = $errorMessage ? array_merge($errorMessage, $resBusiness) : $resBusiness; + continue; } } } - - if (in_array('crm_contract',$types)) { + + if (in_array('crm_contract', $types)) { $contractIds = []; $contractIds = db('crm_contract')->where(['customer_id' => $customer_id])->column('contract_id'); if ($contractIds) { $resContract = $contractModel->transferDataById($contractIds, $param['owner_user_id'], $type, $is_remove); if ($resContract !== true) { - $errorMessage = $errorMessage ? array_merge($errorMessage,$resContract) : $resContract; - continue; + $errorMessage = $errorMessage ? array_merge($errorMessage, $resContract) : $resContract; + continue; } - } - } + } + } //修改记录 - updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:'.$ownerUserName); + updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:' . $ownerUserName); } if (!$errorMessage) { return resultArray(['data' => '转移成功']); } else { return resultArray(['error' => $errorMessage]); } - } - + } + /** * 客户放入公海(负责人置为0) - * @author Michael_xu - * @param + * @param * @return - */ + * @author Michael_xu + */ public function putInPool() { $param = $this->param; @@ -390,7 +395,7 @@ class Customer extends ApiCommon $customerModel = model('Customer'); $settingModel = new \app\crm\model\Setting(); if (!$param['customer_id'] || !is_array($param['customer_id'])) { - return resultArray(['error' => '请选择需要放入公海的客户']); + return resultArray(['error' => '请选择需要放入公海的客户']); } $data = []; $data['owner_user_id'] = 0; @@ -401,12 +406,12 @@ class Customer extends ApiCommon $customerInfo = []; $customerInfo = db('crm_customer')->where(['customer_id' => $customer_id])->find(); if (!$customerInfo) { - $errorMessage[] = '名称:为《'.$customerInfo['name'].'》的客户放入公海失败,错误原因:数据不存在;'; + $errorMessage[] = '名称:为《' . $customerInfo['name'] . '》的客户放入公海失败,错误原因:数据不存在;'; continue; } //权限判断 if (!$customerModel->checkData($customer_id)) { - $errorMessage[] = '"'.$customerInfo['name'].'"放入公海失败,错误原因:无权限'; + $errorMessage[] = '"' . $customerInfo['name'] . '"放入公海失败,错误原因:无权限'; continue; } //将团队成员全部清除 @@ -414,13 +419,13 @@ class Customer extends ApiCommon $data['rw_user_id'] = ''; $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); if (!$resCustomer) { - $errorMessage[] = '"'.$customerInfo['name'].'"放入公海失败,错误原因:数据出错;'; + $errorMessage[] = '"' . $customerInfo['name'] . '"放入公海失败,错误原因:数据出错;'; continue; } //联系人负责人清除 db('crm_contacts')->where(['customer_id' => $customer_id])->update(['owner_user_id' => 0]); //修改记录 - updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户放入公海'); + updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户放入公海'); } if (!$errorMessage) { return resultArray(['data' => '操作成功']); @@ -428,45 +433,45 @@ class Customer extends ApiCommon return resultArray(['error' => $errorMessage]); } } - + /** * 客户锁定,解锁 - * @author Michael_xu * @param is_lock 1锁定,2解锁 * @return - */ + * @author Michael_xu + */ public function lock() { $param = $this->param; $userInfo = $this->userInfo; $customerModel = model('Customer'); - $customerConfigModel = model('CustomerConfig'); + $customerConfigModel = model('CustomerConfig'); $is_lock = ((int)$param['is_lock'] == 2) ? (int)$param['is_lock'] : 1; $lock_name = ($is_lock == 2) ? '解锁' : '锁定'; if (!$param['customer_id'] || !is_array($param['customer_id'])) { - return resultArray(['error' => '请选择需要'.$lock_name.'的客户']); + return resultArray(['error' => '请选择需要' . $lock_name . '的客户']); } $data = []; $data['is_lock'] = ($is_lock == 1) ? $is_lock : 0; - $data['update_time'] = time(); + $data['update_time'] = time(); $errorMessage = []; foreach ($param['customer_id'] as $customer_id) { $customerInfo = []; $customerInfo = $customerModel->getDataById($customer_id); if (!$customerInfo) { - $errorMessage[] = '名称:为《'.$customerInfo['name'].'》的客户'.$lock_name.'失败,错误原因:数据不存在;'; + $errorMessage[] = '名称:为《' . $customerInfo['name'] . '》的客户' . $lock_name . '失败,错误原因:数据不存在;'; continue; } //权限判断 if (!$customerModel->checkData($customer_id)) { - $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:无权限'; + $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:无权限'; continue; } //锁定上限检测 - if ($is_lock == 1 && !$customerConfigModel->checkData($customerInfo['owner_user_id'],2)) { - $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:'.$customerConfigModel->getError(); - continue; - } + if ($is_lock == 1 && !$customerConfigModel->checkData($customerInfo['owner_user_id'], 2)) { + $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:' . $customerConfigModel->getError(); + continue; + } //已成交客户,锁定,提示无需锁定 // if ($customerInfo['deal_status'] == '已成交' && $is_lock == 1) { // $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:已成交状态,无需锁定'; @@ -474,23 +479,23 @@ class Customer extends ApiCommon // } $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); if (!$resCustomer) { - $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:数据出错;'; + $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:数据出错;'; } //修改记录 - updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户'.$lock_name); + updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户' . $lock_name); } if (!$errorMessage) { return resultArray(['data' => '操作成功']); } else { return resultArray(['error' => $errorMessage]); - } + } } - + /** * 客户领取 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function receive() { @@ -498,26 +503,26 @@ class Customer extends ApiCommon $userInfo = $this->userInfo; $customerModel = model('Customer'); $customerConfigModel = model('CustomerConfig'); - - $customer_ids = $param['customer_id']; + + $customer_ids = $param['customer_id'] ?: $userInfo['id']; if (!$customer_ids || !is_array($customer_ids)) { - return resultArray(['error' => '请选择需要领取的客户']); + return resultArray(['error' => '请选择需要领取的客户']); } $errorMessage = []; $wherePool = $customerModel->getWhereByPool(); - foreach ($customer_ids as $k=>$v) { + foreach ($customer_ids as $k => $v) { $dataName = db('crm_customer')->where(['customer_id' => $v])->value('name'); //判断是否是客户池数据 $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $v])->where($wherePool)->find(); if (!$resPool) { - $errorMessage[] = '客户《'.$dataName.'》领取失败,错误原因:非公海数据无权操作;'; + $errorMessage[] = '客户《' . $dataName . '》领取失败,错误原因:非公海数据无权操作;'; continue; } //拥有客户数上限检测 - if (!$customerConfigModel->checkData($userInfo['id'],1)) { - $errorMessage[] = '客户《'.$dataName.'》领取失败,错误原因:'.$customerConfigModel->getError(); + if (!$customerConfigModel->checkData($userInfo['id'], 1)) { + $errorMessage[] = '客户《' . $dataName . '》领取失败,错误原因:' . $customerConfigModel->getError(); continue; - } + } $data = []; $data['owner_user_id'] = $userInfo['id']; $data['update_time'] = time(); @@ -530,26 +535,26 @@ class Customer extends ApiCommon $data['obtain_time'] = time(); $resCustomer = db('crm_customer')->where(['customer_id' => $v])->update($data); if (!$resCustomer) { - $errorMessage[] = '客户《'.$dataName.'》领取失败,错误原因:数据出错;'; + $errorMessage[] = '客户《' . $dataName . '》领取失败,错误原因:数据出错;'; continue; } //联系人领取 db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $userInfo['id']]); //修改记录 - updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户'); + updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户'); } if (!$errorMessage) { return resultArray(['data' => '领取成功']); } else { return resultArray(['error' => $errorMessage]); - } - } - + } + } + /** * 客户分配 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function distribute() { @@ -558,31 +563,31 @@ class Customer extends ApiCommon $customerModel = model('Customer'); $userModel = new \app\admin\model\User(); $customerConfigModel = model('CustomerConfig'); - + $customer_ids = $param['customer_id']; $owner_user_id = $param['owner_user_id']; if (!$customer_ids || !is_array($customer_ids)) { - return resultArray(['error' => '请选择需要分配的客户']); + return resultArray(['error' => '请选择需要分配的客户']); } if (!$owner_user_id) { - return resultArray(['error' => '请选择分配人']); + return resultArray(['error' => '请选择分配人']); } $ownerUserName = $userModel->getUserNameById($owner_user_id); - + $errorMessage = []; $wherePool = $customerModel->getWhereByPool(); - foreach ($customer_ids as $k=>$v) { + foreach ($customer_ids as $k => $v) { $dataName = db('crm_customer')->where(['customer_id' => $v])->value('name'); //判断是否是客户池数据 $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $v])->where($wherePool)->find(); if (!$resPool) { - $errorMessage[] = '客户《'.$dataName.'》分配失败,错误原因:非公海数据无权操作;'; + $errorMessage[] = '客户《' . $dataName . '》分配失败,错误原因:非公海数据无权操作;'; continue; } //拥有客户数上限检测 - if (!$customerConfigModel->checkData($owner_user_id,1)) { - $errorMessage[] = '客户《'.$dataName.'》分配失败,错误原因:'.$customerConfigModel->getError(); - continue; + if (!$customerConfigModel->checkData($owner_user_id, 1)) { + $errorMessage[] = '客户《' . $dataName . '》分配失败,错误原因:' . $customerConfigModel->getError(); + continue; } $data = []; $data['owner_user_id'] = $owner_user_id; @@ -591,33 +596,35 @@ class Customer extends ApiCommon $data['follow'] = '待跟进'; //将团队成员全部清除 $data['ro_user_id'] = ''; - $data['rw_user_id'] = ''; + $data['rw_user_id'] = ''; + # 处理分配标识,待办事项专用 + $data['is_allocation'] = 1; $resCustomer = db('crm_customer')->where(['customer_id' => $v])->update($data); if (!$resCustomer) { - $errorMessage[] = '客户《'.$dataName.'》分配失败,错误原因:数据出错;'; + $errorMessage[] = '客户《' . $dataName . '》分配失败,错误原因:数据出错;'; } db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $owner_user_id]); //修改记录 - updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:'.$ownerUserName); + updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:' . $ownerUserName); //站内信 $send_user_id[] = $owner_user_id; - $sendContent = $userInfo['realname'].'将客户《'.$dataName.'》,分配给您'; + $sendContent = $userInfo['realname'] . '将客户《' . $dataName . '》,分配给您'; if ($send_user_id) { sendMessage($send_user_id, $sendContent, $v, 1); - } + } } if (!$errorMessage) { return resultArray(['data' => '分配成功']); } else { return resultArray(['error' => $errorMessage]); - } - } - + } + } + /** * 客户导出 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function excelExport() { @@ -625,7 +632,7 @@ class Customer extends ApiCommon $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; if ($param['customer_id']) { - $param['customer_id'] = ['condition' => 'in','value' => $param['customer_id'],'form_type' => 'text','name' => '']; + $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => '']; } $param['is_excel'] = 1; $excelModel = new \app\admin\model\Excel(); @@ -633,15 +640,15 @@ class Customer extends ApiCommon $fieldModel = new \app\admin\model\Field(); $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id']); // 文件名 - $file_name = '5kcrm_customer_'.date('Ymd'); - + $file_name = '5kcrm_customer_' . date('Ymd'); + $model = model('Customer'); $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) { + 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); @@ -649,33 +656,33 @@ class Customer extends ApiCommon return $data; }); } - + /** * 客户导入模板下载 - * @author Michael_xu * @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用 * @return + * @author Michael_xu */ public function excelDownload($save_path = '') { $param = $this->param; $userInfo = $this->userInfo; $excelModel = new \app\admin\model\Excel(); - + // 导入的字段列表 $fieldModel = new \app\admin\model\Field(); - $fieldParam['types'] = 'crm_customer'; - $fieldParam['action'] = 'excel'; + $fieldParam['types'] = 'crm_customer'; + $fieldParam['action'] = 'excel'; $field_list = $fieldModel->field($fieldParam); $excelModel->excelImportDownload($field_list, 'crm_customer', $save_path); } - + /** * 客户数据导入 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function excelImport() { @@ -683,7 +690,7 @@ class Customer extends ApiCommon $userInfo = $this->userInfo; $excelModel = new \app\admin\model\Excel(); $param['create_user_id'] = $userInfo['id']; - $param['owner_user_id'] = $param['owner_user_id'] ? : 0; + $param['owner_user_id'] = $param['owner_user_id'] ?: 0; $param['deal_time'] = time(); $param['deal_status'] = '未成交'; $param['types'] = 'crm_customer'; @@ -692,28 +699,29 @@ class Customer extends ApiCommon $res = $excelModel->batchImportData($file, $param, $this); return resultArray(['data' => $excelModel->getError()]); } - + /** * 客户标记为已跟进 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ - public function setFollow(){ + public function setFollow() + { $param = $this->param; - $customerIds = $param['id'] ? : []; + $customerIds = $param['id'] ?: []; if (!$customerIds || !is_array($customerIds)) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } $data['follow'] = '已跟进'; $data['update_time'] = time(); - $res = db('crm_customer')->where(['customer_id' => ['in',$customerIds]])->update($data); + $res = db('crm_customer')->where(['customer_id' => ['in', $customerIds]])->update($data); if (!$res) { - return resultArray(['error'=>'操作失败,请重试']); + return resultArray(['error' => '操作失败,请重试']); } - return resultArray(['data'=>'跟进成功']); + return resultArray(['data' => '跟进成功']); } - + /** * 置顶 / 取消置顶 * @return [type] [description] @@ -724,28 +732,28 @@ class Customer extends ApiCommon $userInfo = $this->userInfo; $param['create_role_id'] = $userInfo['id']; $param['top_time'] = time(); - - $top_id = Db::name('crm_top')->where(['module' => ['eq',$param['module']],'create_role_id' => ['eq',$userInfo['id']],'module_id' => ['eq',$param['module_id']]])->column('top_id'); + + $top_id = Db::name('crm_top')->where(['module' => ['eq', $param['module']], 'create_role_id' => ['eq', $userInfo['id']], 'module_id' => ['eq', $param['module_id']]])->column('top_id'); if ($top_id) { - if ($res = Db::name('crm_top')->where('top_id',$top_id[0])->update($param)) { + if ($res = Db::name('crm_top')->where('top_id', $top_id[0])->update($param)) { return resultArray(['data' => $res]); } else { return resultArray(['error' => Db::name('crm_top')->getError()]); } } else { - if ($res = Db::name('crm_top')->data($param)->insert()) { + if ($res = Db::name('crm_top')->data($param)->insert()) { return resultArray(['data' => $res]); } else { return resultArray(['error' => $customerModel->getError()]); } } } - + /** * 客户公海导出 - * @author Michael_xu - * @param + * @param * @return + * @author Michael_xu */ public function poolExcelExport() { @@ -753,7 +761,7 @@ class Customer extends ApiCommon $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; if ($param['customer_id']) { - $param['customer_id'] = ['condition' => 'in','value' => $param['customer_id'],'form_type' => 'text','name' => '']; + $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => '']; } $param['is_excel'] = 1; $excelModel = new \app\admin\model\Excel(); @@ -764,7 +772,7 @@ class Customer extends ApiCommon return $val['field'] != 'owner_user_id'; }); // 文件名 - $file_name = '5kcrm_customer_pool_'.date('Ymd'); + $file_name = '5kcrm_customer_pool_' . date('Ymd'); $param['action'] = 'pool'; $model = model('Customer'); @@ -773,29 +781,28 @@ class Customer extends ApiCommon $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) { + return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param) { $param['page'] = $page; $param['limit'] = $limit; $data = $model->getDataList($param); - $data['list'] = $model->exportHandle($data['list'], $field_list, 'crm_customer'); + $data['list'] = $model->exportHandle($data['list'], $field_list,'crm_customer'); return $data; }); - } - + } + /** * 客户成交状态 - * @author Michael_xu * @param status 1已成交,2未成交 * @return - */ + * @author Michael_xu + */ public function deal_status() { $param = $this->param; $userInfo = $this->userInfo; - $statusArr = ['1' => '已成交','2' => '未成交']; - $statusList = ['1','2']; - if (!$param['customer_id'] || !in_array($param['status'],$statusList)) { + $statusArr = ['1' => '已成交', '2' => '未成交']; + $statusList = ['1', '2']; + if (!$param['customer_id'] || !in_array($param['status'], $statusList)) { return resultArray(['error' => '参数错误']); } $customerModel = model('Customer'); @@ -808,46 +815,46 @@ class Customer extends ApiCommon $data = []; $data['update_time'] = time(); $data['deal_time'] = time(); - $data['deal_status'] = $statusArr[$param['status']]; + $data['deal_status'] = $statusArr[$param['status']]; $errorMessage = []; foreach ($customer_ids as $customer_id) { $dataInfo = []; $dataInfo = db('crm_customer')->where(['customer_id' => $customer_id])->field('owner_user_id,deal_status,name')->find(); //权限判断 if (!$customerModel->checkData($customer_id, 1)) { - $errorMessage[] = '名称:为《'.$dataInfo['name'].'》的客户更改失败,错误原因:'.$customerModel->getError(); + $errorMessage[] = '名称:为《' . $dataInfo['name'] . '》的客户更改失败,错误原因:' . $customerModel->getError(); continue; } $owner_user_id = $dataInfo['owner_user_id'];; if (!$owner_user_id) { - $errorMessage[] = '名称:为《'.$dataInfo['name'].'》的客户更改失败,错误原因:公海数据无权操作'; - continue; + $errorMessage[] = '名称:为《' . $dataInfo['name'] . '》的客户更改失败,错误原因:公海数据无权操作'; + continue; } //拥有客户数上限检测 if ($statusArr[$param['status']] == '未成交' && $dataInfo['deal_status'] == '已成交') { - if (!$customerConfigModel->checkData($owner_user_id,1,1)) { - $errorMessage[] = '名称:为《'.$dataInfo['name'].'》的客户更改失败,错误原因:'.$customerConfigModel->getError(); + if (!$customerConfigModel->checkData($owner_user_id, 1, 1)) { + $errorMessage[] = '名称:为《' . $dataInfo['name'] . '》的客户更改失败,错误原因:' . $customerConfigModel->getError(); continue; - } + } } if ($statusArr[$param['status']] == '已成交') { - $data['is_lock'] = 0; + $data['is_lock'] = 0; } $res = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); if (!$res) { - $errorMessage[] = '名称:为《'.$dataInfo['name'].'》的客户更改失败,错误原因:操作失败,请重试!'; + $errorMessage[] = '名称:为《' . $dataInfo['name'] . '》的客户更改失败,错误原因:操作失败,请重试!'; continue; } //修改记录 updateActionLog($userInfo['id'], 'crm_customer', $customer_id, ['deal_status' => $dataInfo['deal_status']], ['deal_status' => $data['deal_status']]); } - if (!$errorMessage) { + if (!$errorMessage) { return resultArray(['data' => '操作成功']); } else { return resultArray(['error' => $errorMessage]); - } + } } - + /** * 设置关注 * @@ -857,19 +864,19 @@ class Customer extends ApiCommon */ public function star() { - $userId = $this->userInfo['id']; + $userId = $this->userInfo['id']; $targetId = $this->param['target_id']; - $type = $this->param['type']; - + $type = $this->param['type']; + if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']); - + if (!$this->setStar($type, $userId, $targetId)) { return resultArray(['error' => '设置关注失败!']); } - + return resultArray(['data' => '设置关注成功!']); } - + /** * 附近客户 * @@ -877,17 +884,17 @@ class Customer extends ApiCommon */ public function nearby() { - if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']); - if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']); + if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']); + if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']); if (empty($this->param['distance'])) return resultArray(['error' => '请选择距离!']); - + $customerModel = model('Customer'); - + $data = $customerModel->getNearbyList($this->param); - + return resultArray(['data' => $data]); } - + /** * 系统信息 * @@ -899,14 +906,14 @@ class Customer extends ApiCommon public function system() { if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']); - + $customerModel = new \app\crm\model\Customer(); - + $data = $customerModel->getSystemInfo($this->param['id']); - + return resultArray(['data' => $data]); } - + /** * table标签栏数量 * @@ -920,30 +927,43 @@ class Customer extends ApiCommon if (empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']); $userInfo = $this->userInfo; - + $customerId = $this->param['customer_id']; - + # 联系人 - $contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where('owner_user_id', '<>', 0)->count(); + $contactsAuth = $this->getContactsSearchWhere($userInfo['id']); + $contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where($contactsAuth)->count(); + # 团队成员 $customer = Db::name('crm_customer')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('customer_id', $customerId)->find(); - $customer['ro_user_id'] = explode(',', trim($customer['ro_user_id'], ',')); - $customer['rw_user_id'] = explode(',', trim($customer['rw_user_id'], ',')); + $customer['ro_user_id'] = explode(',', trim($customer['ro_user_id'], ',')); + $customer['rw_user_id'] = explode(',', trim($customer['rw_user_id'], ',')); $customer['owner_user_id'] = [$customer['owner_user_id']]; $teamCount = array_filter(array_unique(array_merge($customer['ro_user_id'], $customer['rw_user_id'], $customer['owner_user_id']))); + # 商机 - $businessCount = Db::name('crm_business')->where('customer_id', $customerId)->count(); + $businessAuth = $this->getBusinessSearchWhere($userInfo['id']); + $businessCount = Db::name('crm_business')->where('customer_id', $customerId)->where($businessAuth)->count(); + # 合同 - $contractCount = Db::name('crm_contract')->where('customer_id', $customerId)->count(); + $contractAuth = $this->getContractSearchWhere($userInfo['id']); + $contractCount = Db::name('crm_contract')->where('customer_id', $customerId)->where($contractAuth)->count(); + # 回款 - $receivablesCount = Db::name('crm_receivables')->where('customer_id', $customerId)->count(); + $receivablesAuth = $this->getReceivablesSearchWhere(); + $receivablesCount = Db::name('crm_receivables')->where('customer_id', $customerId)->whereIn('owner_user_id', $receivablesAuth)->count(); + # 回访 - $visitCount = Db::name('crm_visit')->where(['customer_id' => $customerId, 'deleted_state' => 0, 'owner_user_id' => $userInfo['id']])->count(); + $visitAuth = $this->getVisitSearchWhere($userInfo['id']); + $visitCount = Db::name('crm_visit')->where(['customer_id' => $customerId, 'deleted_state' => 0])->where($visitAuth)->count(); + # 发票 - $invoiceCount = Db::name('crm_invoice')->where('customer_id', $customerId)->count(); + $invoiceAuth = $this->getInvoiceSearchWhere(); + $invoiceCount = Db::name('crm_invoice')->where('customer_id', $customerId)->whereIn('owner_user_id', $invoiceAuth)->count(); + # 附件 $fileCount = Db::name('crm_customer_file')->alias('customer')->join('__ADMIN_FILE__ file', 'file.file_id = customer.file_id')->where('customer_id', $customerId)->count(); - + $data = [ 'businessCount' => $businessCount, 'contactCount' => $contactsCount, @@ -954,10 +974,10 @@ class Customer extends ApiCommon 'receivablesCount' => $receivablesCount, 'returnVisitCount' => $visitCount ]; - + return resultArray(['data' => $data]); } - + /** * 公海权限 * @@ -970,45 +990,45 @@ class Customer extends ApiCommon public function poolAuthority(CustomerLogic $customerLogic) { $authority = [ - 'delete' => false, # 删除 - 'distribute' => false, # 分配 + 'delete' => false, # 删除 + 'distribute' => false, # 分配 'excelexport' => false, # 导出 - 'index' => false, # 列表 - 'receive' => false, # 领取 + 'index' => false, # 列表 + 'receive' => false, # 领取 ]; - + $userId = $this->userInfo['id']; - + if (empty($userId)) return resultArray(['data' => $authority]); - + # 员工角色数据 $groupIds = $customerLogic->getEmployeeGroups($userId); # 员工角色下的规则数据 $ruleIds = $customerLogic->getEmployeeRules($groupIds); # 公海规则数据 $poolRules = $customerLogic->getPoolRules(); - + # 整理员工规则数据 $rules = []; - $ruleIds = implode(',',$ruleIds); + $ruleIds = implode(',', $ruleIds); $rules = array_filter(array_unique(explode(',', $ruleIds))); # 整理公海规则数据 $deleteId = $distributeId = $exportId = $indexId = $receiveId = 0; - foreach ($poolRules AS $key => $value) { - if ($value['name'] == 'pool') $indexId = $value['id']; - if ($value['name'] == 'distribute') $distributeId = $value['id']; - if ($value['name'] == 'receive') $receiveId = $value['id']; - if ($value['name'] == 'poolExcelExport') $exportId = $value['id']; - if ($value['name'] == 'poolDelete') $deleteId = $value['id']; + foreach ($poolRules as $key => $value) { + if ($value['name'] == 'pool') $indexId = $value['id']; + if ($value['name'] == 'distribute') $distributeId = $value['id']; + if ($value['name'] == 'receive') $receiveId = $value['id']; + if ($value['name'] == 'poolExcelExport') $exportId = $value['id']; + if ($value['name'] == 'poolDelete') $deleteId = $value['id']; } - + # 权限判断 - $authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false; - $authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false; - $authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false; - $authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false; - $authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false; - + $authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false; + $authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false; + $authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false; + $authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false; + $authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false; + return resultArray(['data' => $authority]); } } \ No newline at end of file diff --git a/application/crm/controller/Index.php b/application/crm/controller/Index.php index 2ffcb3c..130db6e 100644 --- a/application/crm/controller/Index.php +++ b/application/crm/controller/Index.php @@ -128,8 +128,8 @@ class Index extends ApiCommon $end_time = $between_time[1]; } else { //自定义时间 - $start_time = $param['start_time'] ?: strtotime(date('Y-01-01', time())); - $end_time = $param['end_time'] ? strtotime(date('Y-m-01', $param['end_time']) . ' +1 month -1 day') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day'); + $start_time = $param['start_time'] ?strtotime($param['start_time'].'00:00:00'): strtotime(date('Y-01-01', time())); + $end_time = $param['end_time'] ? strtotime($param['end_time'].'23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day'); $between_time = array($start_time, $end_time); } @@ -214,13 +214,9 @@ class Index extends ApiCommon $param['user_id'] = $param['user_id'] ?: $userInfo['id'];; $businessModel = new \app\crm\model\Business(); $param['merge'] = 1; - if($param['dataType']==1){ - $userIds[] = $param['user_id']; - }elseif($param['dataType']==2){ - $param['perUserIds'] = getSubUserId(true,0,$param['user_id']); - } - if ($param['dataType'] == 3 || $param['dataType'] == 4) { - $param['structure_id'] = $userInfo['structure_id']; + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].' 00:00:00'; + $param['end_time']=$param['end_time'].' 23:59:59'; } $list = $businessModel->getFunnel($param); return resultArray(['data' => $list]); @@ -238,12 +234,21 @@ class Index extends ApiCommon //统计条件 $param = $this->param; $userInfo = $this->userInfo; - $userWhere['type']=3; $userWhere['status']=$param['label']; - $userIds = []; if ($param['dataType'] == 3 || $param['dataType'] == 4) { - $param['structure_id'] = $userInfo['structure_id']; $userWhere['type']=2; + }else{ + $userWhere['type']=3; + } + if ($param['type']) { + $last_where_contract = getTimeByType($param['type']); + $userWhere['year']=date('Y',$last_where_contract[0]); + $time = getTimeArray(); + } else { + //自定义时间 + $param['start_time']=$param['start_time']?$param['start_time'].' 00:00:00':0; + $param['end_time']=$param['end_time'].' 23:59:59'; + $time = getTimeArray(strtotime($param['start_time']),strtotime($param['end_time'])); } $whereArr = $adminModel->getWhere($param, 1, ''); if($param['user_id']){ @@ -251,26 +256,13 @@ class Index extends ApiCommon }elseif ($param['structure_id']){ $userWhere['type']=2; } - $param['user_id'] = $param['user_id'] ?: $userInfo['id']; - if ($param['dataType'] == 1) { - $userIds[] = $param['user_id']; - } else { - $userIds = $whereArr['userIds']; - } - if (!isset($param['user_id'])) { + $userIds = $whereArr['userIds']; + if (!empty($param['user_id'])) { $userWhere['obj_id'] = $param['user_id']; } else { $userWhere['obj_id'] = ['in', $userIds]; } - if (!empty($param['type'])) { - $last_where_contract = getTimeByType($param['type']); - $userWhere['year']=date('Y',$last_where_contract[0]); - } else { - //自定义时间 - $userWhere['year']=$param['start_time'] ?date('Y',$param['start_time']): strtotime(date('Y', time())); - } //时间 - $time = getTimeArray(); $ax = 7; if ($time['time_format'] == '%Y-%m-%d') { $ax = 10; @@ -314,6 +306,7 @@ class Index extends ApiCommon } $list = array(); $money = '0.00'; + foreach ($time['list'] as $val) { $item = []; $item['type'] = $val['type']; @@ -322,8 +315,10 @@ class Index extends ApiCommon $achievement=Db::name('crm_achievement')->where($userWhere)->select(); $data_time=date('m',strtotime($val['type'])); + $num=''; foreach ($achievement as $val){ - $item['achievement']=$val[$this->monthName[$data_time]]; + $num+=(int)$val[$this->monthName[$data_time]]; + $item['achievement']=$num; } $list[] = $item; } @@ -342,6 +337,10 @@ class Index extends ApiCommon { $param = $this->param; $adminModel = new \app\admin\model\Admin(); + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, '', ''); //统计条件 $userIds = $whereArr['userIds']; $where = []; @@ -367,6 +366,7 @@ class Index extends ApiCommon { $param = $this->param; $adminModel = new \app\admin\model\Admin(); + $whereArr = $adminModel->getWhere($param, '', ''); //统计条件 $userIds = $whereArr['userIds']; $where = []; @@ -537,7 +537,10 @@ class Index extends ApiCommon $types = $param['types']; $userInfo = $this->userInfo; $user_id = $param['user_id'] ? : $userInfo['id']; - + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].' 00:00:00'; + $param['end_time']=$param['end_time'].' 23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $userIds = $whereArr['userIds']; $between_time = $whereArr['between_time']; @@ -664,7 +667,7 @@ class Index extends ApiCommon // Db::query('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;'); $param = $this->param; $userInfo = $this->userInfo; - $param['user_id'] = $userInfo['id']; + $param['user_id'] = $param['user_id']?:$userInfo['id']; $indexModel = new IndexLogic; $data = $indexModel->ranking($param); return resultArray(['data' => $data]); @@ -678,7 +681,7 @@ class Index extends ApiCommon { $param = $this->param; $userInfo = $this->userInfo; - $param['user_id'] = $userInfo['id']; + $param['user_id'] = $param['user_id']?:$userInfo['id']; $indexModel = new IndexLogic; $data = $indexModel->queryDataInfo($param); return resultArray(['data' => $data]); @@ -692,10 +695,6 @@ class Index extends ApiCommon $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $param['user_id'] ?: $userInfo['id']; - - if ($param['dataType'] == 3 || $param['dataType'] == 4) { - $param['structure_id'] = $userInfo['structure_id']; - } $indexModel = new IndexLogic; $data = $indexModel->businessList($param); return resultArray(['data' => $data]); @@ -752,14 +751,7 @@ class Index extends ApiCommon public function activityList(){ $param = $this->param; $userInfo = $this->userInfo; - $param['user']=$param['user_id']; $param['id']=$userInfo['id']; - if ($param['dataType'] == 1) { - $param['user_id']=$param['user_id']?:$userInfo['id']; - } - if ($param['dataType'] == 3 || $param['dataType'] == 4) { - $param['structure_id'] = $userInfo['structure_id']; - } $indexLogic=new IndexLogic(); $data=$indexLogic->activityList($param); return resultArray(['data'=>$data]); diff --git a/application/crm/controller/Invoice.php b/application/crm/controller/Invoice.php index ee77c45..49582c5 100644 --- a/application/crm/controller/Invoice.php +++ b/application/crm/controller/Invoice.php @@ -100,7 +100,6 @@ class Invoice extends ApiCommon if (empty($numberInfo['number'])) return resultArray(['error' => '请填写发票编号!']); $param['invoice_apple_number'] = $numberInfo['number']; } - # 检查发票编号是否重复 if ($invoiceLogic->getInvoiceId(['invoice_apple_number' => $param['invoice_apple_number']])) { return resultArray(['error' => '发票编号重复!']); @@ -142,10 +141,32 @@ class Invoice extends ApiCommon if (!$invoice_id = $invoiceLogic->save($param)) { return resultArray(['error' => '创建失败!']); } - + $send_user_id = stringToArray($param['check_user_id']); + (new Message())->send( + Message::INVOICE_TO_DO, + [ + 'title' => $param['invoice_apple_number'], + 'action_id' => $invoice_id + ], + $send_user_id + ); # 更新crm_number_sequence表中的last_date、create_time字段 if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']); updateActionLog($param['create_user_id'], 'crm_invoice', $invoice_id, '', '', '创建了发票'); + + # 创建待办事项的关联数据 + $checkUserIds = db('crm_invoice')->where('invoice_id', $invoice_id)->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_invoice', + 'types_id' => $invoice_id, + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + return resultArray(['data' => '创建成功!']); } @@ -182,7 +203,7 @@ class Invoice extends ApiCommon } if (!isSuperAdministrators($userInfo['id']) && $readStatus === false) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } @@ -299,7 +320,22 @@ class Invoice extends ApiCommon # 更新crm_number_sequence表中的last_date、create_time字段 if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']); //修改记录 - // updateActionLog($param['user_id'], 'crm_invoice', $param['invoice_id'], $dataInfo, $param); + // updateActionLog($param['user_id'], 'crm_invoice', $param['invoice_id'], $dataInfo, $param); + + # 删除待办事项的关联数据 + db('crm_dealt_relation')->where(['types' => ['eq', 'crm_invoice'], 'types_id' => ['eq', $param['invoice_id']]])->delete(); + # 创建待办事项的关联数据 + $checkUserIds = db('crm_invoice')->where('invoice_id', $param['invoice_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_invoice', + 'types_id' => $param['invoice_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); return resultArray(['data' => '编辑成功!']); } @@ -490,7 +526,7 @@ class Invoice extends ApiCommon 'title' => $dataInfo['invoice_apple_number'], 'action_id' => $param['id'] ], - $dataInfo['owner_user_id'] + stringToArray($dataInfo['owner_user_id']) ); } else { if (!empty($status)) { @@ -512,7 +548,7 @@ class Invoice extends ApiCommon 'title' => $dataInfo['invoice_apple_number'], 'action_id' => $param['id'] ], - $dataInfo['owner_user_id'] + stringToArray($dataInfo['owner_user_id']) ); } } diff --git a/application/crm/controller/Leads.php b/application/crm/controller/Leads.php index 6314ed9..d8cbb99 100644 --- a/application/crm/controller/Leads.php +++ b/application/crm/controller/Leads.php @@ -107,7 +107,7 @@ class Leads extends ApiCommon $auth_user_ids = $userModel->getUserByPer('crm', 'leads', 'read'); if (!in_array($data['owner_user_id'], $auth_user_ids)) { //无权限 - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { @@ -312,6 +312,10 @@ class Leads extends ApiCommon $errorMessage[] = '"' . $leadsInfo['name'] . '"转移失败,错误原因:无权限;'; continue; } + + # 处理分配标识,待办事项专用 + $data['is_allocation'] = 1; + $resLeads = db('crm_leads')->where(['leads_id' => $leads_id])->update($data); if (!$resLeads) { $errorMessage[] = '"' . $leadsInfo['name'] . '"转移失败,错误原因:数据出错;'; diff --git a/application/crm/controller/Message.php b/application/crm/controller/Message.php index 3505b42..68b2687 100644 --- a/application/crm/controller/Message.php +++ b/application/crm/controller/Message.php @@ -180,16 +180,18 @@ class Message extends ApiCommon cache('remindReceivablesPlanCount'.$userInfo['id'], $data['remindReceivablesPlan']); cache('remindReceivablesPlanTime'.$userInfo['id'], time() + 180); } - # 待回访合同 - $visitContractTime = cache('visitContractTime'.$userInfo['id']); - $visitContractCount = cache('visitContractCount'.$userInfo['id']); - if (time() <= $visitContractTime) { - $data['returnVisitRemind'] = (int)$visitContractCount; - } else { - $visitContract = $this->visitContract(true); - $data['returnVisitRemind'] = $visitContract['dataCount'] ? : 0; - cache('visitContractCount'.$userInfo['id'], $data['returnVisitRemind']); - cache('visitContractTime'.$userInfo['id'], time() + 180); + if ($configData['visit_config'] == 1) { + # 待回访合同 + $visitContractTime = cache('visitContractTime'.$userInfo['id']); + $visitContractCount = cache('visitContractCount'.$userInfo['id']); + if (time() <= $visitContractTime) { + $data['returnVisitRemind'] = (int)$visitContractCount; + } else { + $visitContract = $this->visitContract(true); + $data['returnVisitRemind'] = $visitContract['dataCount'] ? : 0; + cache('visitContractCount'.$userInfo['id'], $data['returnVisitRemind']); + cache('visitContractTime'.$userInfo['id'], time() + 180); + } } # 即将到期合同 if ($configData['contract_config'] == 1) { @@ -249,13 +251,15 @@ class Message extends ApiCommon switch ($type) { case '1' : $param['next_time'] = ['between', [$todayTime[0], $todayTime[1]]]; + $param['is_dealt'] = ['neq', 1]; break; case '2' : $param['next_time'] = ['between', [1, time()]]; + $param['is_dealt'] = ['neq', 1]; break; case '3' : $param['last_time'] = ['between', [$todayTime[0], $todayTime[1]]]; - $param['follow'] = ['eq', '已跟进']; + $param['is_dealt'] = ['eq', 1]; break; } @@ -293,16 +297,16 @@ class Message extends ApiCommon switch ($type) { case '1' : - $param['next_time'] = ['between',array($todayTime[0],$todayTime[1])]; - // $param['follow'] = ['neq','已跟进']; + $param['next_time'] = ['between',array($todayTime[0],$todayTime[1])]; + $param['is_dealt'] = ['neq', 1]; break; case '2' : - $param['next_time'] = ['between',array(1,time())]; - // $param['today_param'] = 'customer.next_time>record.update_time'; + $param['next_time'] = ['between',array(1,time())]; + $param['is_dealt'] = ['neq', 1]; break; case '3' : $param['last_time'] = ['between',array($todayTime[0],$todayTime[1])]; - $param['follow'] = ['eq','已跟进']; + $param['is_dealt'] = ['eq', 1]; break; } $data = $customerModel->getDataList($param); @@ -343,12 +347,15 @@ class Message extends ApiCommon switch ($type) { case '1' : $param['next_time'] = ['between', [$todayTime[0], $todayTime[1]]]; + $param['is_dealt'] = ['neq', 1]; break; case '2' : $param['next_time'] = ['between', [1, time()]]; + $param['is_dealt'] = ['neq', 1]; break; case '3' : $param['last_time'] = ['between', [$todayTime[0], $todayTime[1]]]; + $param['is_dealt'] = ['eq', 1]; break; } @@ -361,7 +368,7 @@ class Message extends ApiCommon } /** - * 待跟进线索 + * 分配给我的线索 * @author Michael_xu * @return */ @@ -382,8 +389,14 @@ class Message extends ApiCommon $param['owner_user_id'] = $userInfo['id']; switch ($type) { - case '1' : $param['follow'] = ['neq','已跟进']; break; - case '2' : $param['follow'] = ['eq','已跟进']; break; + case '1' : + $param['follow'] = [['neq','已跟进'], null, 'or']; + $param['is_allocation'] = 1; + break; + case '2' : + $param['follow'] = ['eq','已跟进']; + $param['is_allocation'] = 1; + break; } $param['user_id'] = $userInfo['id']; $data = $leadsModel->getDataList($param); @@ -394,7 +407,7 @@ class Message extends ApiCommon } /** - * 待跟进客户 + * 分配给我的客户 * @author Michael_xu * @return */ @@ -416,8 +429,14 @@ class Message extends ApiCommon $param['owner_user_id'] = $userInfo['id']; switch ($type) { - case '1' : $param['follow'] = ['eq','待跟进']; break; - case '2' : $param['follow'] = ['eq','已跟进']; break; + case '1' : + $param['follow'] = [['eq','待跟进'], null, 'or']; + $param['is_allocation'] = 1; + break; + case '2' : + $param['follow'] = ['eq','已跟进']; + $param['is_allocation'] = 1; + break; } $data = $customerModel->getDataList($param); if ($types == 'list') { @@ -450,15 +469,18 @@ class Message extends ApiCommon switch ($type) { case '1' : $param['check_status'] = ['lt','2']; - $param['check_user_id'] = ['like','%,'.$userInfo['id'].',%']; + $param['check_user_id'] = ['like',',%'.$userInfo['id'].'%,']; + # 要提醒的合同ID + $contractIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_contract'], 'user_id' => ['eq', $userInfo['id']]])->column('types_id'); + $param['contractIdArray'] = !empty($contractIdArray) ? $contractIdArray : -1; break; - case '2' : - // $param['check_status'] = ['egt','2']; - $param['flow_user_id'] = ['like','%,'.$userInfo['id'].',%']; + case '2' : + $param['flow_user_id'] = ['like',',%'.$userInfo['id'].'%,']; break; } $param['user_id'] = $userInfo['id']; $data = $contractModel->getDataList($param); + if ($types == 'list') { return resultArray(['data' => $data]); } @@ -487,11 +509,14 @@ class Message extends ApiCommon case '1' : # 待审核、审核中 $param['check_status'] = ['lt','2']; - $param['check_user_id'] = ['like','%,'.$userInfo['id'].',%']; + $param['check_user_id'] = ['like',',%'.$userInfo['id'].'%,']; + # 要提醒的回款ID + $receivablesIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'user_id' => ['eq', $userInfo['id']]])->column('types_id'); + $param['receivablesIdArray'] = !empty($receivablesIdArray) ? $receivablesIdArray : -1; break; case '2' : # 全部 - $param['flow_user_id'] = ['like','%,'.$userInfo['id'].',%']; + $param['flow_user_id'] = ['like',',%'.$userInfo['id'].'%,']; break; } $param['user_id'] = $userInfo['id']; @@ -527,11 +552,16 @@ class Message extends ApiCommon case '1' : # 待审核、审核中 $param['check_status'] = ['lt', 2]; - $param['check_user_id'] = ['like', '%,'. $userId .',%']; + $param['check_user_id'] = ['like', ',%'. $userId .'%,']; + # 要提醒的发票ID + $invoiceIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_invoice'], 'user_id' => ['eq', $userId]])->column('types_id'); + $param['invoiceIdArray'] = !empty($invoiceIdArray) ? $invoiceIdArray : -1; + $param['dealt'] = 1; break; case '2' : # 全部 - $param['flow_user_id'] = ['like', '%,'. $userId .',%']; + $param['flow_user_id'] = ['like', ',%'. $userId .'%,']; + $param['dealt'] = 1; break; } @@ -566,18 +596,23 @@ class Message extends ApiCommon $param['owner_user_id'] = array('in',getSubUserId(false)); } switch ($type) { - case '1' : $param['receivables_id'] = 0; - $param['check_status'] = array('lt',2); - $param['remind_date'] = array('elt',date('Y-m-d',time())); - $param['return_date'] = array('egt',date('Y-m-d',time())); - $param['types'] = 1; - break; - case '2' : $param['receivables_id'] = array('gt',0); - $param['check_status'] = 2; - break; - case '3' : $param['receivables_id'] = 0; - $param['remind_date'] = array('lt',date('Y-m-d',time())); - break; + case '1' : + $param['receivables_id'] = 0; + $param['check_status'] = array('lt',2); + $param['remind_date'] = array('elt',date('Y-m-d',time())); + $param['return_date'] = array('egt',date('Y-m-d',time())); + $param['types'] = 1; + $param['is_dealt'] = 0; + break; + case '2' : + $param['receivables_id'] = ['gt', 0]; + $param['check_status'] = 2; + $param['dealt'] = 1; + break; + case '3' : + $param['receivables_id'] = 0; + $param['remind_date'] = array('lt',date('Y-m-d',time())); + break; } $data = $receivablesPlanModel->getDataList($param); if ($types == 'list') { @@ -725,13 +760,15 @@ class Message extends ApiCommon $where['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false)] : $userId; # 下次联系时间 $where['next_time'] = ['between', [$todayTime[0], $todayTime[1]]]; + # 是否已处理(联系) + $where['is_dealt'] = 0; # 线索 if ($type == 'todayLeads') { $leadsId = !empty($typeId) ? $typeId : Db::name('crm_leads')->where($where)->column('leads_id'); Db::name('crm_leads')->whereIn('leads_id', $leadsId)->update([ - 'next_time' => 0, 'last_time' => time(), + 'is_dealt' => 1, 'follow' => '已跟进' ]); } @@ -739,8 +776,8 @@ class Message extends ApiCommon if ($type == 'todayCustomer') { $customerId = !empty($typeId) ? $typeId : Db::name('crm_customer')->where($where)->column('customer_id'); Db::name('crm_customer')->whereIn('customer_id', $customerId)->update([ - 'next_time' => 0, 'last_time' => time(), + 'is_dealt' => 1, 'follow' => '已跟进' ]); } @@ -748,8 +785,8 @@ class Message extends ApiCommon if ($type == 'todayBusiness') { $businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); Db::name('crm_business')->whereIn('business_id', $businessId)->update([ - 'next_time' => 0, - 'last_time' => time() + 'last_time' => time(), + 'is_dealt' => 1 ]); } } @@ -757,7 +794,8 @@ class Message extends ApiCommon # 处理分配给我的线索、客户 if (in_array($type, ['followLeads', 'followCustomer'])) { $where['owner_user_id'] = $userId; - $where['follow'] = ['neq','已跟进']; + $where['follow'] = [['neq','已跟进'], null, 'or']; + $where['is_allocation'] = 1; # 线索 if ($type == 'followLeads') { @@ -774,31 +812,24 @@ class Message extends ApiCommon # 处理待审核合同、回款、发票 if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice'])) { $where['check_status'] = ['lt','2']; - $where['check_user_id'] = ['like','%,' . $userId . ',%']; - - $update = [ - 'check_status' => 2, - 'flow_id' => 0, - 'order_id' => 0, - 'check_user_id' => '', - 'flow_user_id' => ',' . $userId . ',' - ]; + $where['check_user_id'] = ['like',',%' . $userId . '%,']; # 合同 if ($type == 'checkContract') { $contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id'); - Db::name('crm_contract')->whereIn('contract_id', $contractId)->update($update); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_contract')->whereIn('types_id', $contractId)->delete(); } # 回款 if ($type == 'checkReceivables') { $receivablesId = !empty($typeId) ? $typeId : Db::name('crm_receivables')->where($where)->column('receivables_id'); - Db::name('crm_receivables')->whereIn('receivables_id', $receivablesId)->update($update); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_receivables')->whereIn('types_id', $receivablesId)->delete(); } # 发票 if ($type == 'checkInvoice') { $invoiceId = !empty($typeId) ? $typeId : Db::name('crm_invoice')->where($where)->column('invoice_id'); - Db::name('crm_invoice')->whereIn('invoice_id', $invoiceId)->update($update); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_invoice')->whereIn('types_id', $invoiceId)->delete(); } + } # 处理到期合同 @@ -831,14 +862,16 @@ class Message extends ApiCommon Db::name('crm_customer')->whereIn('customer_id', $typeId)->update([ 'follow' => '已跟进', 'last_time' => time(), - 'update_time' => time() + 'deal_time' => time(), + 'update_time' => time(), ]); } else { $whereData['page'] = 1; - $whereData['limit'] = 30; + $whereData['limit'] = 100; $whereData['is_remind'] = db('crm_config')->where('name', 'remind_config')->value('value');; $whereData['user_id'] = $userId; $whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer','bydata' => empty($isSub) ? 'me' : 'sub'])->value('scene_id'); + $whereData['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userId)] : $userId; $poolCustomers = (new \app\crm\model\Customer())->getDataList($whereData); $ids = []; foreach ($poolCustomers['list'] AS $key => $value) { @@ -847,11 +880,35 @@ class Message extends ApiCommon if (!empty($ids)) Db::name('crm_customer')->whereIn('customer_id', $ids)->update([ 'follow' => '已跟进', 'last_time' => time(), - 'update_time' => time() + 'deal_time' => time(), + 'update_time' => time(), ]); } } + # 带回款提醒 + if ($type == 'remindReceivablesPlan') { + $planId = []; + if (!empty($typeId)) { + $planId = $typeId; + } else { + $param['owner_user_id'] = $isSub ? ['in',getSubUserId(false)] : $userId; + $param['receivables_id'] = 0; + $param['check_status'] = ['lt', 2]; + $param['remind_date'] = ['elt', date('Y-m-d',time())]; + $param['return_date'] = ['egt', date('Y-m-d',time())]; + $param['types'] = 1; + $param['page'] = 1; + $param['limit'] = 1000; + $receivablesPlanModel = model('ReceivablesPlan'); + $data = $receivablesPlanModel->getDataList($param); + foreach ($data['list'] AS $key => $value) { + $planId[] = $value['plan_id']; + } + } + if (!empty($planId)) db('crm_receivables_plan')->whereIn('plan_id', $planId)->update(['is_dealt' => 1]); + } + return resultArray(['data' => '操作成功!']); } diff --git a/application/crm/controller/Product.php b/application/crm/controller/Product.php index 8cd4c32..94b9885 100644 --- a/application/crm/controller/Product.php +++ b/application/crm/controller/Product.php @@ -99,7 +99,7 @@ class Product extends ApiCommon $auth_user_ids = $userModel->getUserByPer('crm', 'product', 'read'); if (!in_array($data['owner_user_id'], $auth_user_ids)) { //无权限 - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { diff --git a/application/crm/controller/Receivables.php b/application/crm/controller/Receivables.php index 07d5f49..a1f99c1 100644 --- a/application/crm/controller/Receivables.php +++ b/application/crm/controller/Receivables.php @@ -68,7 +68,6 @@ class Receivables extends ApiCommon $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(); // 导出的字段列表 @@ -76,7 +75,6 @@ class Receivables extends ApiCommon $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']); @@ -181,7 +179,7 @@ class Receivables extends ApiCommon //判断权限 $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'read'); if (!in_array($data['owner_user_id'], $auth_user_ids)) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { diff --git a/application/crm/controller/Visit.php b/application/crm/controller/Visit.php index 41f9801..0f4a08e 100644 --- a/application/crm/controller/Visit.php +++ b/application/crm/controller/Visit.php @@ -70,6 +70,7 @@ class Visit extends ApiCommon } $param['owner_user_id'] = $param['owner_user_id'] ? : $userInfo['id']; $param['create_user_id'] = $userInfo['id']; + $param['create_time'] = time(); $param['update_time'] = time(); $res = $Visit->createData($param); if ($res) { @@ -98,7 +99,7 @@ class Visit extends ApiCommon $roPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'read'); $rwPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'update'); if (!in_array($data['owner_user_id'], $auth_user_ids) && !$rwPre && !$roPre) { - $authData['dataAuth'] = 0; + $authData['dataAuth'] = (int)0; return resultArray(['data' => $authData]); } if (!$data) { @@ -129,6 +130,7 @@ class Visit extends ApiCommon //判断权限 $data = $Visit->getDataById($param['id']); $auth_user_ids = $userModel->getUserByPer('crm', 'visit', 'update'); + $param['update_time'] = time(); if ($Visit->updateDataById($param, $param['id'])) { # 更新crm_number_sequence表中的last_date、create_time字段 if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']); diff --git a/application/crm/logic/ActivityLogic.php b/application/crm/logic/ActivityLogic.php index 080b71f..fc4e5c5 100644 --- a/application/crm/logic/ActivityLogic.php +++ b/application/crm/logic/ActivityLogic.php @@ -8,6 +8,7 @@ namespace app\crm\logic; +use app\admin\model\Group; use app\crm\model\Activity; use think\Db; @@ -86,11 +87,11 @@ class ActivityLogic $query->where('activity_type_id', $param['activity_type_id']); $query->where('activity_type', $this->moduleToNumber[$param['module']]); }); - $query->whereOr('customer_ids', 'like', '%'.$param['activity_type_id'].'%'); - $query->whereOr('contacts_ids', 'like', '%'.$param['activity_type_id'].'%'); - $query->whereOr('contract_ids', 'like', '%'.$param['activity_type_id'].'%'); - $query->whereOr('business_ids', 'like', '%'.$param['activity_type_id'].'%'); - $query->whereOr('leads_ids', 'like', '%'.$param['activity_type_id'].'%'); + $query->whereOr('customer_ids', 'like', ',%'.$param['activity_type_id'].'%,'); + $query->whereOr('contacts_ids', 'like', ',%'.$param['activity_type_id'].'%,'); + $query->whereOr('contract_ids', 'like', ',%'.$param['activity_type_id'].'%,'); + $query->whereOr('business_ids', 'like', ',%'.$param['activity_type_id'].'%,'); + $query->whereOr('leads_ids', 'like', ',%'.$param['activity_type_id'].'%,'); }) ->order('update_time', 'desc') ->group('update_time') @@ -190,7 +191,8 @@ class ActivityLogic $query->where('activity_type_id', $param['activity_type_id']); }); $query->whereOr(function ($query) use ($param) { - $query->where('customer_ids', 'like', '%' . $param['activity_type_id'] . '%'); + $query->where('customer_ids', 'like', '%,' . $param['activity_type_id'] . ',%'); + $query->whereIn('activity_type', [8, 9, 11]); }); if (!empty($contactsData)) { $query->whereOr(function ($query) use ($contactsData) { @@ -220,111 +222,43 @@ class ActivityLogic break; case 'contacts' : - $customerId = Db::name('crm_contacts')->where('contacts_id', $param['activity_type_id'])->value('customer_id'); - - $businessData = []; - $contractData = []; - - # 商机ID串 - $business = Db::name('crm_business')->field(['business_id'])->where('customer_id', $customerId)->select(); - if (!empty($business)) { - $businessData['activity_type'] = 5; - $businessData['activity_type_id'] = array_reduce($business, function ($result, $value) { - return array_merge($result, array_values($value)); - }, []); - } - - # 合同ID串 - $contract = Db::name('crm_contract')->field(['contract_id'])->where('contacts_id', $customerId)->select(); - if (!empty($contract)) { - $contractData['activity_type'] = 6; - $contractData['activity_type_id'] = array_reduce($contract, function ($result, $value) { - return array_merge($result, array_values($value)); - }, []); - } - - # 联系人模块查询条件 - $contactsWhere = function ($query) use ($param, $businessData, $contractData) { + $contactsWhere = function ($query) use ($param) { $query->whereOr(function ($query) use ($param) { $query->where('activity_type', 3); $query->where('activity_type_id', $param['activity_type_id']); }); $query->whereOr(function ($query) use ($param) { - $query->where('contacts_ids', 'like', '%' . $param['activity_type_id'] . '%'); + $query->where('contacts_ids', 'like', '%,' . $param['activity_type_id'] . ',%'); + $query->whereIn('activity_type', [8, 9, 11]); }); - if (!empty($businessData)) { - $query->whereOr(function ($query) use ($businessData) { - $query->where('activity_type', $businessData['activity_type']); - $query->whereIn('activity_type_id', $businessData['activity_type_id']); - }); - } - if (!empty($contractData)) { - $query->whereOr(function ($query) use ($contractData) { - $query->where('activity_type', $contractData['activity_type']); - $query->whereIn('activity_type_id', $contractData['activity_type_id']); - }); - } }; break; case 'business' : - $contractData = []; - # 合同ID串 - $contract = Db::name('crm_contract')->field(['contract_id'])->where('business_id', $param['activity_type_id'])->select(); - if (!empty($contract)) { - $contractData['activity_type'] = 6; - $contractData['activity_type_id'] = array_reduce($contract, function ($result, $value) { - return array_merge($result, array_values($value)); - }, []); - } - # 商机模块查询条件 - $businessWhere = function ($query) use ($param, $contractData) { + $businessWhere = function ($query) use ($param) { $query->whereOr(function ($query) use ($param) { $query->where('activity_type', 5); $query->where('activity_type_id', $param['activity_type_id']); }); $query->whereOr(function ($query) use ($param) { - $query->where('business_ids', 'like', '%' . $param['activity_type_id'] . '%'); - $query->where(['activity_type' => ['neq', 2]]); + $query->where('business_ids', 'like', '%,' . $param['activity_type_id'] . ',%'); + $query->whereIn('activity_type', [8, 9, 11]); }); - if (!empty($contractData)) { - $query->whereOr(function ($query) use ($contractData) { - $query->where('activity_type', $contractData['activity_type']); - $query->whereIn('activity_type_id', $contractData['activity_type_id']); - }); - } }; - break; case 'contract' : - $receivablesData = []; - - # 回款ID串 - $receivables = Db::name('crm_receivables')->field(['receivables_id'])->where('contract_id', $param['activity_type_id'])->select(); - if (!empty($receivables)) { - $receivablesData['activity_type'] = 7; - $receivablesData['activity_type_id'] = array_reduce($receivables, function ($result, $value) { - return array_merge($result, array_values($value)); - }, []); - } - # 合同模块查询条件 - $contractWhere = function ($query) use ($param, $receivables) { + $contractWhere = function ($query) use ($param) { $query->whereOr(function ($query) use ($param) { $query->where('activity_type', 6); $query->where('activity_type_id', $param['activity_type_id']); }); $query->whereOr(function ($query) use ($param) { - $query->where('contract_ids', 'like', '%' . $param['activity_type_id'] . '%'); + $query->where('contract_ids', 'like', '%,' . $param['activity_type_id'] . ',%'); + $query->whereIn('activity_type', [8, 9, 11]); }); - if (!empty($receivablesData)) { - $query->whereOr(function ($query) use ($receivablesData) { - $query->where('activity_type', $receivablesData['activity_type']); - $query->whereIn('activity_type_id', $receivablesData['activity_type_id']); - }); - } }; break; @@ -355,7 +289,7 @@ class ActivityLogic ->where('status', 1) ->order('update_time', 'desc') ->select(); - + $fileModel = new \app\admin\model\File(); foreach ($dataArray AS $key => $value) { # 用户信息 todo 有模型文件,时间问题,暂时将查询写在循环中 @@ -388,9 +322,13 @@ class ActivityLogic } # 查询联系人信息 - $dataArray[$key]['contacts_name'] = ''; + $dataArray[$key]['contacts_list'] = []; if ($dataArray[$key]['type'] == 1 && !empty($dataArray[$key]['contacts_ids'])) { - $dataArray[$key]['contacts_name'] = Db::name('crm_contacts')->where('contacts_id', $dataArray[$key]['contacts_ids'])->value('name'); + $res = Db::name('crm_contacts')->where('contacts_id', trim($dataArray[$key]['contacts_ids'], ','))->value('name'); + $dataArray[$key]['contacts_list'][] = [ + 'contacts_id' => (int)trim($dataArray[$key]['contacts_ids'], ','), + 'name' =>empty($res)? null : $res, + ]; } # 时间格式处理 @@ -403,6 +341,11 @@ class ActivityLogic # 客户模块跟进记录关联的商机 $dataArray[$key]['business_list'] = $value['activity_type'] == 2 ? $this->getBusinessInfo($value['business_ids']) : []; + + # 去掉客户模块跟进记录联系人ID两端的逗号 + if ($value['type'] == 1 && $value['activity_type'] == 2) { + $dataArray[$key]['contacts_ids'] = !empty($value['contacts_ids']) ? trim($value['contacts_ids'], ',') : ''; + } } # 是否是最后一页 @@ -470,10 +413,11 @@ class ActivityLogic $param['create_user_id'] = $userId; $param['type'] = 1; - $param['next_time'] = !empty($param['next_time']) ? strtotime($param['next_time']) : 0; - $param['business_ids'] = !empty($param['business_ids']) ? implode(',', $param['business_ids']) : ''; + $param['next_time'] = !empty($param['next_time']) ? strtotime($param['next_time']) : 0; + $param['business_ids'] = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : ''; $param['create_time'] = time(); $param['update_time'] = time(); + if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ','; $activityJson = Activity::create($param); if (empty($activityJson)) return false; @@ -531,7 +475,7 @@ class ActivityLogic $param['type'] = 1; $param['next_time'] = strtotime($param['next_time']); - $param['business_ids'] = !empty($param['business_ids']) ? implode(',', $param['business_ids']) : ''; + $param['business_ids'] = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : ''; $param['update_time'] = time(); if (!Activity::update($param)) return false; @@ -585,6 +529,15 @@ class ActivityLogic $activityInfo = Db::name('crm_activity')->where(['activity_id' => $activityId])->find(); if (Activity::update(['activity_id' => $activityId, 'status' => 0])) { $this->updateNextTime($this->activityType[$activityInfo['activity_type']]['en'], $activityInfo['activity_type_id'], '', true); + # 删除附件 + $fileIds = db('crm_activity_file')->where('activity_id', $activityId)->column('file_id'); + if (!empty($fileIds)) { + db('crm_activity_file')->where('activity_id', $activityId)->delete(); + db('admin_file')->whereIn('file_id', $fileIds)->delete(); + } + if ($activityInfo['activity_type'] == 3) db('crm_contacts_file')->whereIn('file_id', $fileIds)->delete(); + if ($activityInfo['activity_type'] == 5) db('crm_business_file')->whereIn('file_id', $fileIds)->delete(); + if ($activityInfo['activity_type'] == 6) db('crm_contract_file')->whereIn('file_id', $fileIds)->delete(); return true; } else { return false; @@ -635,6 +588,10 @@ class ActivityLogic if (!$is_del && in_array($types, ['crm_customer', 'crm_leads'])) { $data['follow'] = '已跟进'; } + # 设置今日需联系线索、客户、商机 + if (!$is_del && in_array($types, ['crm_customer', 'crm_leads', 'crm_business'])) { + if (!empty($next_time) && $next_time >= strtotime('Y-m-d 00:00:00')) $data['is_dealt'] = 0; + } $dbName->where([$dbId => $types_id])->update($data); return true; } diff --git a/application/crm/logic/CommonLogic.php b/application/crm/logic/CommonLogic.php index 61773a6..41f3bbb 100644 --- a/application/crm/logic/CommonLogic.php +++ b/application/crm/logic/CommonLogic.php @@ -193,7 +193,6 @@ class CommonLogic # 编辑参数 $data = []; - $item=[]; if (!empty($param['list'])) { foreach ($param['list'] as $key => $value) { foreach ($value as $k => $v) { @@ -204,48 +203,29 @@ class CommonLogic # 处理产品类别 $categorys = explode(',', $v); $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 (in_array($k, $fileField) || in_array($k, $checkboxField) || in_array($k, $userField) || in_array($k, $structureField)) { + # 处理附件、多选、人员、部门类型数据 + $data[$k] = !empty($v) ? arrayToString($v) : ''; } elseif ($types == 'crm_visit' && $k == 'contract_id') { # 处理回访提交过来的合同编号 if (!empty($v[0]['contract_id'])) $data[$k] = $v[0]['contract_id']; - }else { + } else { $data[$k] = $v; } + $item[$k]=$v; } - $item=$value; } $data[$primaryKey] = $actionId; $data['update_time'] = time(); } $res = $model->update($data); + unset($data[$primaryKey]); + unset($data['update_time']); //详细信息修改新增操作记录 if ($res) { //修改记录 $user_id = $apiCommon->userInfo; - updateActionLog($user_id['id'], $types, $actionId, $info, $item); + updateActionLog($user_id['id'], $types, $actionId, $info, $data); } return $res; } diff --git a/application/crm/logic/IndexLogic.php b/application/crm/logic/IndexLogic.php index e815490..f000ff5 100644 --- a/application/crm/logic/IndexLogic.php +++ b/application/crm/logic/IndexLogic.php @@ -37,13 +37,17 @@ class IndexLogic extends Common $contractModel = new \app\crm\model\Contract(); $receivablesModel = new \app\crm\model\Receivables(); $activityModel = new \app\crm\model\Activity(); - + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $lastArr = $adminModel->getWhere($param, 1, '', true); //统计条件 $userIds = $whereArr['userIds']; $between_time = $whereArr['between_time']; $last_between_time = $lastArr['between_time']; - + + $customerNum = 0; //新增客户 $customerLastNum = 0; //上期对比 $contactsNum = 0; //新增联系人 @@ -146,19 +150,30 @@ class IndexLogic extends Common public function getCountSql($param) { + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $follow_day = $configInfo['follow_day'] ? : 0; + $deal_day = $configInfo['deal_day'] ? : 0; + //默认公海条件(没有负责人或已经到期) + $data['follow_time'] = time()-$follow_day*86400; + $data['deal_time'] = time()-$deal_day*86400; + $data['deal_status'] = '未成交'; $countSql = "SELECT count(1) count1, 0 count2 FROM 5kcrm_crm_customer WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " and owner_user_id IN (" . implode(',', $param['customer_auth_user_ids']) . ") + and (( ( deal_time > ".$data['deal_time']." ) or (update_time > ".$data['follow_time']." and deal_time > ".$data['deal_time']."))or deal_status = '已成交' or is_lock = 1 ) UNION ALL SELECT count(1) AS count1, 0 count2 - FROM 5kcrm_crm_contacts - WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " - and owner_user_id IN (" . implode(',', $param['contacts_auth_user_ids']) . ") + FROM 5kcrm_crm_contacts contacts + LEFT JOIN 5kcrm_crm_customer customer ON contacts.customer_id=customer.customer_id + WHERE contacts.create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " + and contacts.owner_user_id IN (" . implode(',', $param['contacts_auth_user_ids']) . ") + and (( ( customer.deal_time > ".$data['deal_time']." ) or (customer.update_time > ".$data['follow_time']." and customer.deal_time > ".$data['deal_time']."))or customer.deal_status = '已成交' or customer. is_lock = 1 ) UNION ALL SELECT count(1) AS count1, @@ -180,7 +195,7 @@ class IndexLogic extends Common FROM 5kcrm_crm_receivables WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " AND check_status = 2 - and owner_user_id IN (" . implode(',', $param['receivables_auth_user_ids']) . ") + and owner_user_id IN (" . implode(',', $param['receivables_auth_user_ids']) . ") UNION ALL SELECT count(1) AS count, @@ -221,6 +236,10 @@ class IndexLogic extends Common $adminModel = new \app\admin\model\Admin(); $customerModel = new \app\crm\model\Customer(); $dateTime = date('Y-m-d H:i:s'); + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $userIds = $whereArr['userIds']; //权限控制 @@ -235,13 +254,12 @@ class IndexLogic extends Common $customerParam['getCount'] = 1; $customerParam['owner_user_id'] = $owner_user_ids; - $sevenDaysParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-1 week') . ") "; - $fifteenDaysParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('15 day') . ") "; - $oneMonthParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-30 day') . ") "; - $threeMonthParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-3 month') . ") "; - $sixMonthParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-6 month') . ") "; - $unContactParam['otherMap'] = " ( last_time < next_time AND next_time < now()) "; - + $sevenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") "; + $fifteenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") "; + $oneMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") "; + $threeMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-3 month') . ") "; + $sixMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-6 month') . ") "; + $unContactParam['otherMap'] = " ( next_time < " . strtotime(date('Y-m-d 00:00:00')) . " AND (next_time) >0) "; $data['sevenDays'] = $customerModel->getDataList(array_merge($customerParam, $sevenDaysParam))['dataCount'] ?: 0; $data['fifteenDays'] = $customerModel->getDataList(array_merge($customerParam, $fifteenDaysParam))['dataCount'] ?: 0; $data['oneMonth'] = $customerModel->getDataList(array_merge($customerParam, $oneMonthParam))['dataCount'] ?: 0; @@ -264,6 +282,10 @@ class IndexLogic extends Common $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $customerModel = new \app\crm\model\Customer(); + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $userIds = $whereArr['userIds']; //权限控制 @@ -286,20 +308,24 @@ class IndexLogic extends Common $customerParam['owner_user_id'] = $owner_user_ids; switch ($label) { + case 1 : +// ((( next_time < " . strtotime(date('Y-m-d 00:00:00')).") AND (last_time IS NOT NULL)) AND (IFNULL(last_time,next_time) >0)) + $customerParam['otherMap'] = " (next_time < " . strtotime(date('Y-m-d 00:00:00')) . " AND (next_time) >0) "; + break; case 2 : - $customerParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-1 week') . ") "; + $customerParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") "; break; case 3 : - $customerParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('15 day') . ") "; + $customerParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") "; break; case 4 : - $customerParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-30 day') . ") "; + $customerParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") "; break; case 5 : - $customerParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-3 month') . ") "; + $customerParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-3 month') . ") "; break; case 6 : - $customerParam['otherMap'] = " ( IFNULL('last_time','create_time') < " . strtotime('-6 month') . ") "; + $customerParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-6 month') . ") "; break; } return $customerModel->getDataList($customerParam); @@ -318,7 +344,10 @@ class IndexLogic extends Common $adminModel = new \app\admin\model\Admin(); $user_id = $param['user_id'] ?: [-1]; $status = $param['label'] ?: 1; //1合同目标 2回款目标 3合同数 4新增客户数 5新增联系人数 6新增跟进记录数 - + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $userIds = $whereArr['userIds']; $between_time = $whereArr['between_time']; @@ -508,9 +537,9 @@ class IndexLogic extends Common $achievementMoney = db('crm_achievement')->where($where_achievement)->find(); $v['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : ''; if ($achievementMoney[$achievement] == 0.00) { - $v['rate'] = 0.00; + $v['rate'] = 0; } else { - $v['rate'] = (int)$v['money'] / $achievementMoney[$achievement]; + $v['rate'] = round($v['money'] / $achievementMoney[$achievement]*100,2); } if ($userName['realname'] == $v['realname']) { $list['self']['sort'] = $k + 1; @@ -543,6 +572,10 @@ class IndexLogic extends Common { $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $user_id = $param['user_id'] ?: [-1]; $userIds = $whereArr['userIds']; @@ -572,7 +605,6 @@ class IndexLogic extends Common ); $resDataArr = array_merge($resDataArr, $resData[0]); } - return $resDataArr; } @@ -583,6 +615,14 @@ class IndexLogic extends Common */ public function getQueryDataSql($param) { + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $follow_day = $configInfo['follow_day'] ? : 0; + $deal_day = $configInfo['deal_day'] ? : 0; + //默认公海条件(没有负责人或已经到期) + $data['follow_time'] = time()-$follow_day*86400; + $data['deal_time'] = time()-$deal_day*86400; + $data['deal_status'] = '未成交'; switch ($param['type']) { case 1 : $countSql = "SELECT @@ -590,20 +630,21 @@ class IndexLogic extends Common COUNT(CASE WHEN deal_status = '已成交' THEN 1 ELSE NULL END) AS dealCustomer FROM 5kcrm_crm_customer WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " - AND owner_user_id IN (" . implode(',', $param['customer_auth_user_ids']) . ")"; + AND owner_user_id IN (" . implode(',', $param['customer_auth_user_ids']) . ") + and (( ( deal_time > ".$data['deal_time']." ) or (update_time > ".$data['follow_time']." and deal_time > ".$data['deal_time']."))or deal_status = '已成交' or is_lock = 1 ) + "; break; case 2 : $countSql = "SELECT - count(1) activityNum, - COUNT(CASE WHEN b.activity_type_id in (SELECT customer_id FROM 5kcrm_crm_customer + COUNT(distinct CASE WHEN b.activity_type_id in (SELECT customer_id FROM 5kcrm_crm_customer WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " - AND owner_user_id IN (" . implode(',', $param['customer_auth_user_ids']) . ") - ) THEN 1 ELSE NULL END ) as activityRealNum + AND owner_user_id IN (" . implode(',', $param['customer_auth_user_ids']) . ") AND next_time is not null + ) THEN b.activity_type_id ELSE NULL END) as activityNum FROM 5kcrm_crm_activity AS b WHERE create_time BETWEEN " . $param['start_time'] . " AND " . $param['end_time'] . " AND b.type = '1' - AND b.activity_type = '2' - AND b.status = '1' + AND b.activity_type = '2' + AND b.status = '1' AND b.create_user_id IN (" . implode(',', $param['record_auth_user_ids']) . ")"; break; case 3 : @@ -643,6 +684,10 @@ class IndexLogic extends Common { $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); + if($param['start_time'] && $param['end_time']){ + $param['start_time']=$param['start_time'].'00:00:00'; + $param['end_time']=$param['end_time'].'23:59:59'; + } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $user_id = $param['user_id'] ?: [-1]; $userIds = $whereArr['userIds']; @@ -731,13 +776,7 @@ class IndexLogic extends Common $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 - if ($param['dataType'] == 1) { - $userIds = []; - $userIds[] = $param['user_id']; - } else { - $userIds = $whereArr['userIds']; - } - + $userIds = $whereArr['userIds']; //权限控制 if (!empty($param['type'])) { $last_where_contract = getTimeByType($param['type']); @@ -745,8 +784,8 @@ class IndexLogic extends Common $where_activity['t.create_time'] = array('between', $between_time); } else { //自定义时间 - $start_time = $param['start_time'] ?: strtotime(date('Y-01-01', time())); - $end_time = $param['end_time'] ? strtotime(date('Y-m-01', $param['end_time']) . ' +1 month -1 day') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day'); + $start_time = $param['start_time'] ?strtotime($param['start_time'].'00:00:00'): strtotime(date('Y-01-01', time())); + $end_time = $param['end_time'] ? strtotime($param['end_time'].'23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day'); $where_activity['t.create_time'] = ['between', [$start_time, $end_time]]; } $auth_customer_user_ids = $userModel->getUserByPer('crm', 'activity', 'index'); @@ -782,7 +821,7 @@ class IndexLogic extends Common } else { $type['t.type'] = $param['queryType']; } - if ($param['user'] == '') { + if ($param['user_id'] == '') { if ($param['subUser'] == '0') { $type['t.create_user_id'] = $param['id']; //下属创建 @@ -796,7 +835,7 @@ class IndexLogic extends Common $type['t.create_user_id'] = array('in', $subStr); } } else { - $type['t.create_user_id'] = $param['user']; + $type['t.create_user_id'] = $param['user_id']; } $type['t.status'] = 1; $list = db('crm_activity') diff --git a/application/crm/logic/InvoiceLogic.php b/application/crm/logic/InvoiceLogic.php index f4cd51e..2b8d666 100644 --- a/application/crm/logic/InvoiceLogic.php +++ b/application/crm/logic/InvoiceLogic.php @@ -46,22 +46,23 @@ class InvoiceLogic $limit = $param['limit']; $getCount = $param['getCount']; + $userId = $param['user_id']; + $invoiceIdArray = $param['invoiceIdArray']; // 待办事项提醒参数 + $dealt = $param['dealt']; unset($param['getCount']); unset($param['limit']); unset($param['page']); + unset($param['user_id']); + unset($param['invoiceIdArray']); + unset($param['dealt']); $where = []; if ($search) { # 处理基本参数 - $userId = $param['user_id']; + $scene_id = $param['scene_id']; - unset($param['user_id']); unset($param['scene_id']); -// unset($param['owner_user_id']); -// unset($param['check_status']); -// unset($param['check_user_id']); -// unset($param['flow_user_id']); $common = new Common(); @@ -97,9 +98,21 @@ class InvoiceLogic if ($where) $param = $where; } + # 待办事项查询参数 + $dealtWhere = []; + if (!empty($invoiceIdArray)) $dealtWhere['invoice_id'] = ['in', $invoiceIdArray]; + + # 权限,不是待办事项,则加上列表权限 + $auth = []; + if (empty($dealt)) { + $userModel = new \app\admin\model\User(); + $authUserIds = $userModel->getUserByPer('crm', 'invoice', 'index'); + $auth['owner_user_id'] = ['in', $authUserIds]; + } + # 查询数据 - $list = Invoice::with(['toCustomer', 'toContract', 'toAdminUser'])->field($field)->where($param) - ->limit($limit)->order('update_time', 'desc')->paginate($limit)->toArray(); + $list = Invoice::with(['toCustomer', 'toContract', 'toAdminUser'])->field($field)->where($auth) + ->where($param)->where($dealtWhere)->limit($limit)->order('update_time', 'desc')->paginate($limit)->toArray(); # 处理发票类型 // foreach ($list['data'] AS $key => $value) { diff --git a/application/crm/logic/VisitLogic.php b/application/crm/logic/VisitLogic.php index 8289023..758ab1b 100644 --- a/application/crm/logic/VisitLogic.php +++ b/application/crm/logic/VisitLogic.php @@ -92,7 +92,11 @@ class VisitLogic extends Common $userField = $fieldModel->getFieldByFormType('crm_visit', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_visit', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型 - + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_visit', 'visit', $order_field, $order_type); @@ -130,17 +134,18 @@ class VisitLogic extends Common ->where($map)->where($partMap)->where($authMap)->group('visit.visit_id')->count('visit.visit_id'); foreach ($list as $k => $v) { + $list[$k]['contract_num'] = $v['contract_number']; $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) { - $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -237,7 +242,6 @@ class VisitLogic extends Common if ($v == 'visit_user_id') continue; $param[$v] = arrayToString($param[$v]); } - $param['update_time'] = ''; $visitModel = new Visit(); if ($visitModel->data($param)->allowField(true)->save()) { $visit_id = $visitModel->visit_id; diff --git a/application/crm/model/Achievement.php b/application/crm/model/Achievement.php index ab27ec6..89ed144 100644 --- a/application/crm/model/Achievement.php +++ b/application/crm/model/Achievement.php @@ -83,8 +83,8 @@ class Achievement extends Common if ($request['year']) { $map['year'] = $request['year']; } - if ($request['status']) { - $map['status'] = $request['status']; + if ($request['type']) { + $map['status'] = $request['type']; } if ($request['user_id']) { //员工 $map['obj_id'] = $request['user_id']; @@ -101,7 +101,11 @@ class Achievement extends Common } elseif ($request['structure_id']) { $map['type'] = 3; $result = array(); - $userlist = Db::name('AdminUser')->field('id,realname as name')->where('structure_id = '.$request['structure_id'].'')->select(); + if ($request['structure_id'] == 1) { + $userlist = Db::name('AdminUser')->field('id,realname as name')->whereIn('status', [1, 2])->select(); + } else { + $userlist = Db::name('AdminUser')->field('id,realname as name')->where('structure_id = '.$request['structure_id'].'')->select(); + } if (!$userlist) { return array(); } @@ -273,8 +277,8 @@ class Achievement extends Common foreach ($temp_user_ids as $k =>$v) { $data2['type'] = 3; $data2['obj_id'] = $v; + $data2['status'] = $param['status']; $data2['year'] = $param['year']; - $data2['status'] = !empty($param['status']) ? $param['status'] : 1; # 员工名称 $param['name'] = Db::name('admin_user')->where('id', $v)->value('realname'); $ret = $this->where($data2)->find(); diff --git a/application/crm/model/Business.php b/application/crm/model/Business.php index abf7845..4ddd033 100644 --- a/application/crm/model/Business.php +++ b/application/crm/model/Business.php @@ -45,6 +45,8 @@ class Business extends Common $order_type = $request['order_type']; $is_excel = $request['is_excel']; //导出 $getCount = $request['getCount']; + $businessTypeId = $request['typeId']; // 针对mobile + $businessStatusId = $request['statusId']; // 针对mobile unset($request['scene_id']); unset($request['search']); unset($request['user_id']); @@ -53,6 +55,8 @@ class Business extends Common unset($request['order_type']); unset($request['is_excel']); unset($request['getCount']); + unset($request['typeId']); + unset($request['statusId']); $request = $this->fmtRequest($request); $requestMap = $request['map'] ?: []; @@ -68,7 +72,7 @@ class Business extends Common $sceneMap = $sceneModel->getDefaultData('crm_business', $user_id) ?: []; } } - if ($search) { + if ($search || $search == '0') { //普通筛选 $sceneMap['name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '商机名称']; } @@ -142,12 +146,20 @@ class Business extends Common $userField = $fieldModel->getFieldByFormType('crm_business', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_business', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_business', 'datetime'); //日期时间类型 + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_business', 'business', $order_field, $order_type); } else { $order = 'business.update_time desc'; } + # 商机组和商机状态搜索 + if (!empty($businessTypeId)) $map['business.type_id'] = ['eq', $businessTypeId]; + if (!empty($businessStatusId)) $map['business.status_id'] = ['eq', $businessStatusId]; $readAuthIds = $userModel->getUserByPer('crm', 'business', 'read'); $updateAuthIds = $userModel->getUserByPer('crm', 'business', 'update'); @@ -184,11 +196,11 @@ class Business 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) { $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -267,18 +279,19 @@ class Business extends Common 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]); } + # 设置今日需联系商机 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + $param['money'] = $param['money'] ?: '0.00'; $param['discount_rate'] = $param['discount_rate'] ?: '0.00'; if ($this->data($param)->allowField(true)->save()) { + updateActionLog($param['create_user_id'], 'crm_business', $this->business_id, '', '', '创建了商机'); $business_id = $this->business_id; if ($param['product']) { //产品数据处理 @@ -310,7 +323,7 @@ class Business 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'] . ',' ]); return $data; @@ -352,8 +365,10 @@ class Business extends Common return false; } - # 处理下次联系时间 - if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']); + # 商机金额小数处理 + if (!empty($param['money']) && is_numeric($param['money']) && strpos($param['money'], ".") === false) { + $param['money'] .= '.00'; + } //处理部门、员工、附件、多选类型字段 $arrFieldAtt = $fieldModel->getArrayField('crm_business'); @@ -361,6 +376,9 @@ class Business extends Common $param[$v] = arrayToString($param[$v]); } + # 设置今日需联系商机 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + $param['money'] = $param['money'] ?: '0.00'; $param['discount_rate'] = $param['discount_rate'] ?: '0.00'; //商机状态改变 @@ -464,19 +482,22 @@ class Business extends Common $map = []; $map['create_time'] = $where['create_time']; $map['owner_user_id'] = ['in', $userIds]; - + $map['type_id'] = $type_id; + $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' + 'SUM(CASE WHEN is_end = 1 THEN money ELSE 0 END) AS sum_ying', + 'SUM(CASE WHEN is_end = 2 THEN money ELSE 0 END) AS sum_shu', + 'type_id' ]) ->where($map) ->fetchSql() - ->select(); + ->find(); $res_a = queryCache($sql_a, 200); $sql = CrmBusinessModel::field([ "status_id", 'COUNT(*)' => 'count', - 'SUM(`money`)' => 'sum' + 'SUM(`money`)' => 'sum', + 'type_id' ]) ->where($where) ->whereNotIn('is_end', '1,2,3') @@ -485,7 +506,7 @@ class Business extends Common ->select(); $res = queryCache($sql, 200); $res = array_column($res, null, 'status_id'); - + $sum_money = 0; $count = 0; # 商机数总和 $moneyCount = 0; # 金额总和 @@ -493,20 +514,20 @@ class Business extends Common $v['count'] = $res[$v['status_id']]['count'] ?: 0; $v['money'] = $res[$v['status_id']]['sum'] ?: 0; $v['status_name'] = $v['name']; - + $statusList[$k] = $v; - + $sum_money += $v['money']; $moneyCount += $v['money']; $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]; - + return $data ?: []; } diff --git a/application/crm/model/BusinessStatus.php b/application/crm/model/BusinessStatus.php index 224b474..bd79e15 100644 --- a/application/crm/model/BusinessStatus.php +++ b/application/crm/model/BusinessStatus.php @@ -44,8 +44,11 @@ class BusinessStatus extends Common * @return [array] [description] */ public function getTypeList($request) - { - + { + # H5不传page和limit(查全部),商机组不会有太多,把limit设置大一些就行。 + if (empty($request['limit'])) $request['limit'] = 100; + if (empty($request['page'])) $request['page'] = 1; + $userModel = new \app\admin\model\User(); $structureModel = new \app\admin\model\Structure(); $request = $this->fmtRequest( $request ); @@ -54,6 +57,7 @@ class BusinessStatus extends Common //普通筛选 $map['name'] = ['like', '%'.$map['search'].'%']; } + $map['is_display'] = ['eq', 1]; unset($map['search']); $list = db('crm_business_type') @@ -67,6 +71,7 @@ class BusinessStatus extends Common $list[$k]['structure_id_info'] = $structureModel->getListByStr($v['structure_id']) ? : []; $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]['status_list'] = db('crm_business_status')->where('type_id', $v['type_id'])->order('order_id', 'asc')->select(); } $data = []; $data['list'] = $list; diff --git a/application/crm/model/Contacts.php b/application/crm/model/Contacts.php index 7708eb7..b691ad5 100644 --- a/application/crm/model/Contacts.php +++ b/application/crm/model/Contacts.php @@ -63,7 +63,7 @@ class Contacts extends Common $sceneMap = $sceneModel->getDefaultData('crm_contacts', $user_id) ? : []; } $searchMap = []; - if ($search) { + if ($search || $search == '0') { //普通筛选 $searchMap = function($query) use ($search){ $query->where('contacts.name',array('like','%'.$search.'%')) @@ -109,7 +109,11 @@ class Contacts extends Common $userField = $fieldModel->getFieldByFormType('crm_contacts', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型 - + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_contacts','contacts',$order_field,$order_type); @@ -147,7 +151,6 @@ class Contacts extends Common ->field('contacts.*,customer.name as customer_name') ->orderRaw($order) ->select(); - foreach ($list as $k=>$v) { $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']) : []; @@ -155,11 +158,11 @@ class Contacts extends Common $list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : ''; foreach ($userField as $key => $val) { $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -194,7 +197,6 @@ class Contacts extends Common $data = []; $data['list'] = $list; $data['dataCount'] = $dataCount ? : 0; - return $data; } @@ -248,7 +250,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'] . ',' ]); # 处理商机首要联系人 @@ -376,7 +378,7 @@ class Contacts extends Common $starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_contacts'])->value('star_id'); $dataInfo['star'] = !empty($starId) ? 1 : 0; # 处理决策人显示问题 - $dataInfo['decision'] = !empty($dataInfo['decision']) && $dataInfo['decision'] == '是' ? '是' : ''; + $dataInfo['decision'] = !empty($dataInfo['decision']) && $dataInfo['decision'] == '是' ? '是' : '否'; # 处理时间格式 $fieldModel = new \app\admin\model\Field(); $datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型 diff --git a/application/crm/model/Contract.php b/application/crm/model/Contract.php index 888ade3..2515f59 100644 --- a/application/crm/model/Contract.php +++ b/application/crm/model/Contract.php @@ -47,6 +47,7 @@ class Contract extends Common $order_type = $request['order_type']; $is_excel = $request['is_excel']; //导出 $getCount = $request['getCount']; + $contractIdArray = $request['contractIdArray']; // 待办事项提醒参数 unset($request['scene_id']); unset($request['search']); @@ -55,6 +56,7 @@ class Contract extends Common unset($request['order_type']); unset($request['is_excel']); unset($request['getCount']); + unset($request['contractIdArray']); $request = $this->fmtRequest( $request ); @@ -71,9 +73,25 @@ class Contract extends Common $sceneMap = $sceneModel->getDefaultData('crm_contract', $user_id) ? : []; } } - if ($search) { - //普通筛选 - $sceneMap['name'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '合同名称']; + $searchWhere = []; + if ($search || $search == '0') { + //普通筛选 + $searchWhere = function ($query) use ($search) { + $query->where(function ($query) use ($search){ + $query->whereLike('customer.name', '%' . $search . '%'); + })->whereOr(function ($query) use ($search) { + $query->whereLike('contract.num', '%' . $search . '%'); + })->whereOr(function ($query) use ($search) { + $query->whereLike('contract.name', '%' . $search . '%'); + }); + }; +// if (db('crm_customer')->whereLike('name', '%' . $search . '%')->value('customer_id')) { +// $sceneMap['customer_name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '客户名称']; +// } elseif (db('crm_contract')->whereLike('num', '%' . $search . '%')->value('contract_id')) { +// $sceneMap['num'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '合同编号']; +// } else { +// $sceneMap['name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '合同名称']; +// } } $partMap = []; //优先级:普通筛选>高级筛选>场景 @@ -128,12 +146,21 @@ class Contract extends Common $userField = $fieldModel->getFieldByFormType('crm_contract', 'user'); $structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型 + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_contract','contract',$order_field,$order_type); } else { $order = 'contract.update_time desc'; } + + # 待办事项查询参数 + $dealtWhere = []; + if (!empty($contractIdArray)) $dealtWhere['contract.contract_id'] = ['in', $contractIdArray]; $readAuthIds = $userModel->getUserByPer('crm', 'contract', 'read'); $updateAuthIds = $userModel->getUserByPer('crm', 'contract', 'update'); @@ -144,15 +171,14 @@ class Contract extends Common ->join('__CRM_BUSINESS__ business','contract.business_id = business.business_id','LEFT') ->join('__CRM_CONTACTS__ contacts','contract.contacts_id = contacts.contacts_id','LEFT') // ->join('__CRM_RECEIVABLES_PLAN__ plan','contract.contract_id = plan.contract_id','LEFT') - ->where($map)->where($partMap)->where($authMap)->group('contract.contract_id')->count('contract.contract_id'); + ->where($searchWhere)->where($map)->where($partMap)->where($authMap)->where($dealtWhere)->group('contract.contract_id')->count('contract.contract_id'); if (!empty($getCount) && $getCount == 1) { $data['dataCount'] = !empty($dataCount) ? $dataCount : 0; $contractMoney = $this->getContractMoney($map, $partMap, $authMap); - $receivedMoney = $this->getReceivablesMoney($map, $partMap, $authMap); $data['extraData']['money'] = [ - 'contractMoney' => $this->getContractMoney($map, $partMap, $authMap), # 合同总金额 - 'receivedMoney' => $this->getReceivablesMoney($map, $partMap, $authMap), # 回款总金额 - 'unReceivedMoney' => sprintf("%.2f", $contractMoney - $receivedMoney) # 未回款 + 'contractMoney' => $contractMoney['contractMoney'], # 合同总金额 + 'receivedMoney' => $contractMoney['receivablesMoney'], # 回款总金额 + 'unReceivedMoney' => $contractMoney['arrearsMoney'] # 未回款总金额 ]; return $data; } @@ -167,9 +193,11 @@ class Contract extends Common ->join('__CRM_CONTACTS__ contacts','contract.contacts_id = contacts.contacts_id','LEFT') // ->join('__CRM_RECEIVABLES_PLAN__ plan','contract.contract_id = plan.contract_id','LEFT') ->join('CrmReceivables receivables','receivables.contract_id = contract.contract_id AND receivables.check_status = 2','LEFT') - ->where($map) + ->where($searchWhere) + ->where($map) ->where($partMap) ->where($authMap) + ->where($dealtWhere) ->limit($request['offset'], $request['length']) ->field(array_merge($indexField, [ 'customer.name' => 'customer_name', @@ -188,11 +216,11 @@ class Contract 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) { $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -243,58 +271,78 @@ class Contract extends Common $data['list'] = $list; $data['dataCount'] = $dataCount ? : 0; $contractMoney = $this->getContractMoney($map, $partMap, $authMap); - $receivedMoney = $this->getReceivablesMoney($map, $partMap, $authMap); $data['extraData']['money'] = [ - 'contractMoney' => $this->getContractMoney($map, $partMap, $authMap), # 合同总金额 - 'receivedMoney' => $this->getReceivablesMoney($map, $partMap, $authMap), # 回款总金额 - 'unReceivedMoney' => sprintf("%.2f", $contractMoney - $receivedMoney) # 未回款 + 'contractMoney' => $contractMoney['contractMoney'], # 合同总金额 + 'receivedMoney' => $contractMoney['receivablesMoney'], # 回款总金额 + 'unReceivedMoney' => $contractMoney['arrearsMoney'] # 未回款 ]; return $data; } /** - * 获取回款总金额 + * 获取合同相关金额 * * @param $map * @param $partMap * @param $authMap - * @return float|string + * @author fanqi + * @date 2021-03-03 + * @return array */ - private function getReceivablesMoney($map, $partMap, $authMap) + private function getContractMoney($map, $partMap, $authMap) { - $contractIds = db('crm_contract') + $contractMoney = 0.00; # 合同总金额 + $receivablesMoney = 0.00; # 回款总金额 + $arrearsMoney = 0.00; # 未回款总金额 + + # 过滤审核状态参数,只查询审核成功的数据。 + foreach ($map AS $key => $value) { + if ($key === 'contract.check_status') unset($map[$key]); + } + + $data = db('crm_contract') ->alias('contract') ->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT') ->join('__CRM_BUSINESS__ business','contract.business_id = business.business_id','LEFT') ->join('__CRM_CONTACTS__ contacts','contract.contacts_id = contacts.contacts_id','LEFT') - ->where('check_status', 2)->where($map)->where($partMap)->where($authMap)->column('contract.contract_id'); - $contractIds = array_unique($contractIds); - - $money = db('crm_receivables')->where('check_status', 2)->whereIn('contract_id', $contractIds)->sum('money'); + ->join('__CRM_RECEIVABLES__ receivables','receivables.contract_id = contract.contract_id','LEFT') + ->where('contract.check_status', 2) + ->where($map) + ->where($partMap) + ->where($authMap) + ->field(['contract.contract_id', 'contract.money AS contractMoney', 'receivables.money AS receivablesMoney', 'receivables.check_status AS receivablesStatus']) + ->select(); + + # 将同一合同下的回款进行整合 + $result = []; + foreach ($data AS $key => $value) { + # 同属于一个合同下的回款 + if (!empty($result[$value['contract_id']])) { + if ($value['receivablesStatus'] == 2) $result[$value['contract_id']]['receivablesMoney'] += $value['receivablesMoney']; + continue; + } - return !empty($money) ? sprintf("%.2f", $money) : 0.00; - } + $result[$value['contract_id']] = [ + 'contractMoney' => $value['contractMoney'], + 'receivablesMoney' => $value['receivablesStatus'] == 2 ? $value['receivablesMoney'] : 0, + ]; + } + # 统计各金额总和 + foreach ($result AS $key => $value) { + $contractMoney += $value['contractMoney']; # 合同金额 + $receivablesMoney += $value['receivablesMoney']; # 回款金额 - /** - * 获取合同总金额 - * - * @param $map - * @param $partMap - * @param $authMap - * @return float|string - */ - private function getContractMoney($map, $partMap, $authMap) - { - $money = db('crm_contract') - ->alias('contract') - ->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT') - ->join('__CRM_BUSINESS__ business','contract.business_id = business.business_id','LEFT') - ->join('__CRM_CONTACTS__ contacts','contract.contacts_id = contacts.contacts_id','LEFT') - ->where('check_status', 2)->where($map)->where($partMap)->where($authMap)->sum('contract.money'); + # 未回款金额 + if ($value['contractMoney'] > $value['receivablesMoney']) $arrearsMoney += $value['contractMoney'] - $value['receivablesMoney']; + } - return !empty($money) ? sprintf("%.2f", $money) : 0.00; + return [ + 'contractMoney' => sprintf("%.2f", $contractMoney), + 'receivablesMoney' => sprintf("%.2f", $receivablesMoney), + 'arrearsMoney' => sprintf("%.2f", $arrearsMoney) + ]; } //根据IDs获取数组 @@ -383,11 +431,24 @@ class Contract extends Common 'create_user_id' => $param['create_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => $param['customer_id'], - 'contacts_ids' => $param['contacts_id'], - 'business_ids' => $param['business_id'] + 'customer_ids' => ',' . $param['customer_id'] . ',', + 'contacts_ids' => ',' . $param['contacts_id'] . ',', + 'business_ids' => ',' . $param['business_id'] . ',' ]); + # 创建待办事项的关联数据 + $checkUserIds = db('crm_contract')->where('contract_id', $data['contract_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_contract', + 'types_id' => $data['contract_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + return $data; } else { $this->error = '添加失败'; @@ -456,6 +517,22 @@ class Contract extends Common } $data = []; $data['contract_id'] = $contract_id; + + # 删除待办事项的关联数据 + db('crm_dealt_relation')->where(['types' => ['eq', 'crm_contract'], 'types_id' => ['eq', $data['contract_id']]])->delete(); + # 创建待办事项的关联数据 + $checkUserIds = db('crm_contract')->where('contract_id', $data['contract_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_contract', + 'types_id' => $data['contract_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + return $data; } else { $this->error = '编辑失败'; diff --git a/application/crm/model/Customer.php b/application/crm/model/Customer.php index 1796d79..7152c9a 100644 --- a/application/crm/model/Customer.php +++ b/application/crm/model/Customer.php @@ -59,6 +59,7 @@ class Customer extends Common $is_remind = $request['is_remind']; $getCount = $request['getCount']; $otherMap = $request['otherMap']; + unset($request['poolId']); //需要过滤的参数 $unsetRequest = ['scene_id','search','user_id','is_excel','action','order_field','order_type','is_remind','getCount','type','otherMap']; foreach ($unsetRequest as $v) { @@ -79,7 +80,7 @@ class Customer extends Common } } $searchMap = []; - if ($search) { + if ($search || $search == '0') { //普通筛选 $searchMap = function($query) use ($search){ $query->where('customer.name',array('like','%'.$search.'%')) @@ -170,6 +171,11 @@ class Customer extends Common $userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型 + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type); @@ -229,13 +235,13 @@ class Customer extends Common foreach ($userField as $key => $val) { if (in_array($val, $field_list)) { $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $list[$k][$val.'_name'] = implode($usernameField, ','); } } foreach ($structureField as $key => $val) { if (in_array($val, $field_list)) { $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : []; - $list[$k][$val] = implode($structureNameField, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } } foreach ($datetimeField as $key => $val) { @@ -335,7 +341,11 @@ class Customer extends Common foreach ($arrFieldAtt as $k=>$v) { $param[$v] = arrayToString($param[$v]); } - if ($this->data($param)->allowField(true)->isUpdate(false)->save()) { + + # 设置今日需联系客户 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + + if ($this->data($param)->allowField(true)->isUpdate(false)->save()) { //修改记录 updateActionLog($param['create_user_id'], 'crm_customer', $this->customer_id, '', '', '创建了客户'); $data = []; @@ -426,7 +436,10 @@ class Customer extends Common foreach ($arrFieldAtt as $k=>$v) { $param[$v] = arrayToString($param[$v]); } - $param['follow'] = '已跟进'; + + # 设置今日需联系客户 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + if ($this->update($param, ['customer_id' => $customer_id], true)) { //修改记录 updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param); @@ -511,6 +524,12 @@ class Customer extends Common public function getStatistics($request) { $userModel = new \app\admin\model\User(); + $adminModel = new \app\admin\model\Admin(); + $request['start_time']=strtotime($request['start_time']); + $request['end_time']=strtotime($request['end_time']); + $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds + $whereArr = $adminModel->getWhere($request, '', $perUserIds); //统计条件 + $userIds = $whereArr['userIds']; $request = $this->fmtRequest( $request ); $map = $request['map'] ? : []; unset($map['search']); @@ -527,7 +546,7 @@ class Customer extends Common $where_time = " > 0 "; $where_date = " != '' "; } - + //员工IDS $map_user_ids = []; if (!empty($map['user_id'])) { @@ -535,17 +554,19 @@ class Customer extends Common } elseif (!empty($map['structure_id'])) { $map_user_ids = $userModel->getSubUserByStr($map['structure_id'], 2); } - - # 没有传递员工参数并且部门下没员工的情况 - if (empty($map_user_ids)) return []; - - $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds - $userIds = $map_user_ids ? array_intersect($map_user_ids, $perUserIds) : $perUserIds; //数组交集 - $userIds = array_values($userIds); - + $prefix = config('database.prefix'); $count = count($userIds); + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $follow_day = $configInfo['follow_day'] ? : 0; + $deal_day = $configInfo['deal_day'] ? : 0; + //默认公海条件(没有负责人或已经到期) + $data['follow_time'] = time()-$follow_day*86400; + $data['deal_time'] = time()-$deal_day*86400; + $data['deal_status'] = '未成交'; $sql = ''; + foreach ($userIds as $key => $user_id) { $sql .= " SELECT @@ -573,12 +594,13 @@ class Customer extends Common WHERE cu.create_time {$where_time} AND cu.owner_user_id = {$user_id} + AND (( ( deal_time > ".$data['deal_time']." ) OR (update_time > ".$data['follow_time']." AND deal_time > ".$data['deal_time']."))OR deal_status = '已成交' OR is_lock = 1 ) "; if ($count > 1 && $key != $count - 1) { $sql .= " UNION ALL "; } } - + if ($sql == '') { return []; } @@ -587,6 +609,7 @@ class Customer extends Common $dealCustomerCount = 0; # 成交客户总数 $contractMoneyCount = 0; # 合同总金额 $receivablesMoneyCount = 0; # 回款总金额 + $list = queryCache($sql); foreach ($list as &$val) { $val['deal_customer_num'] = Floor($val['deal_customer_num']); @@ -756,7 +779,7 @@ class Customer extends Common $is_lock = $param['is_lock'] ? : 0; $deal_status = $param['deal_status'] ? : '未成交'; $update_time = $param['update_time']; - if (strtotime($param['update_time'])) { + if (strtotime(date('Y-m-d H:i:s', $param['update_time'])) != $param['update_time']) { $update_time = strtotime($param['update_time']); } if (!$is_lock && $deal_status !== '已成交') { @@ -809,7 +832,6 @@ class Customer extends Common //通过提前提醒时间,计算查询时间段 $remind_follow_day = ($follow_day-$remind_day > 0) ? ($follow_day-$remind_day) : $follow_day-1; $remind_deal_day = ($deal_day-$remind_day > 0) ? ($deal_day-$remind_day) : $deal_day-1; - if (($follow_day > 0) && ($deal_day > 0)) { $follow_between = array(time()-$follow_day*86400,time()-$remind_follow_day*86400); $deal_between = array(time()-$deal_day*86400,time()-$remind_deal_day*86400); @@ -825,7 +847,7 @@ class Customer extends Common ->where(['customer.is_lock' => 0]) ->where(['customer.deal_status' => ['neq','已成交']]); }); - }; + }; } else { $whereData = function($query) use ($data){ $query->where(function ($query) use ($data) { @@ -1084,9 +1106,11 @@ class Customer extends Common $poolStatus = checkPerByAction('crm', 'customer', 'pool'); # 客户 + $customerAuth = []; $customerWhere = []; if ((!empty($param['type']) && $param['type'] == 2) || !$poolStatus) { $customerWhere = $this->getWhereByCustomer(); + $customerAuth['owner_user_id'] = ['neq', 0]; } # 公海 @@ -1099,20 +1123,6 @@ class Customer extends Common return []; } - # 基本权限 -// $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index'); -// $authMapData['auth_user_ids'] = $auth_user_ids; -// $authMapData['user_id'] = $apiCommon->userInfo['id']; -// $authMap = function($query) use ($authMapData){ -// $query->where(['customer.owner_user_id' => array('in',$authMapData['auth_user_ids'])]) -// ->whereOr(function ($query) use ($authMapData) { -// $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", customer.ro_user_id)')->where(['customer.owner_user_id' => array('neq','')]); -// }) -// ->whereOr(function ($query) use ($authMapData) { -// $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", customer.rw_user_id)')->where(['customer.owner_user_id' => array('neq','')]); -// }); -// }; - # 附近 $lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']); $lngLatWhere = function ($query) use ($lngLatRange) { @@ -1133,7 +1143,7 @@ class Customer extends Common ->where($customerWhere) ->where($poolWhere) ->where($lngLatWhere) -// ->where($authMap) + ->where($customerAuth) ->field(['customer_id', 'name', 'address', 'detail_address', 'owner_user_id', 'lat', 'lng']) ->order('update_time', 'desc') ->select(); @@ -1143,7 +1153,7 @@ class Customer extends Common # todo 暂时将查询写在循环中 $ownerUserInfo = !empty($value['owner_user_id']) ? $userModel->getUserById($value['owner_user_id']) : []; $ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : ''; - $list[$key]['owner_user_name'] = $ownerUserName; + $list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人'; $list[$key]['distance'] = $this->getLngLatDistance($param['lng'], $param['lat'], $value['lng'], $value['lat'], 1, 0); } diff --git a/application/crm/model/Index.php b/application/crm/model/Index.php index b59c8ff..f7d90df 100644 --- a/application/crm/model/Index.php +++ b/application/crm/model/Index.php @@ -14,88 +14,92 @@ use think\helper\Time; class Index extends Common { - /** - * 销售简报 - * @author Michael_xu - * @param - * @return - */ - public function getSalesData($param) - { - $where = array(); - $start_time = $param['start_time']; - $where['create_time'] = Time::today(); - } - - public function getQueryRepeat($type, $content) + /** + * 销售简报 + * @param + * @return + * @author Michael_xu + */ + public function getSalesData($param) + { + $where = array(); + $start_time = $param['start_time']; + $where['create_time'] = Time::today(); + } + + public function getQueryRepeat($type, $content) { - $result = []; + $result = []; $customerList = []; - $poolList = []; - $leadsList = []; - + $poolList = []; + $leadsList = []; + # 客户列表 $customerList = $this->getCustomerList($type, $content); # 公海列表 if (count($customerList) < 10) $poolList = $this->getPoolList($type, $content); # 线索列表 if (count($customerList) + count($poolList) < 10) $leadsList = $this->getLeadsList($type, $content); - # 处理客户列表数据 - foreach ($customerList AS $key => $value) { + foreach ($customerList as $key => $value) { $ownerUserName = !empty($value['owner_user_id']) ? db('admin_user')->where('id', $value['owner_user_id'])->value('realname') : ''; - - $result[] = [ - 'id' => $value['customer_id'], - 'name' => $value['name'], - 'create_time' => date('Y-m-d H:i:s', $value['create_time']), - 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', - 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', - 'last_time' => !empty($value['deal_time']) ? date('Y-m-d H:i:s', $value['deal_time']) : '', - 'owner_user_name' => $ownerUserName, - 'module' => '客户模块', - 'type' => 2 - ]; + if (!empty($ownerUserName)) { + $result[] = [ + 'id' => $value['customer_id'], + 'name' => $value['name'], + 'create_time' => date('Y-m-d H:i:s', $value['create_time']), + 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', + 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', + 'last_time' => !empty($value['deal_time']) ? date('Y-m-d H:i:s', $value['deal_time']) : '', + 'owner_user_name' => $ownerUserName, + 'module' => '客户模块', + 'type' => 2 + ]; + } } - # 处理公海列表数据 - foreach ($poolList AS $key => $value) { + foreach ($poolList as $key => $value) { $ownerUserName = !empty($value['owner_user_id']) ? db('admin_user')->where('id', $value['owner_user_id'])->value('realname') : ''; - + $result[] = [ - 'id' => $value['customer_id'], - 'name' => $value['name'], - 'create_time' => date('Y-m-d H:i:s', $value['create_time']), - 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', - 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', - 'last_time' => !empty($value['deal_time']) ? date('Y-m-d H:i:s', $value['deal_time']) : '', + 'id' => $value['customer_id'], + 'name' => $value['name'], + 'create_time' => date('Y-m-d H:i:s', $value['create_time']), + 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', + 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', + 'last_time' => !empty($value['deal_time']) ? date('Y-m-d H:i:s', $value['deal_time']) : '', 'owner_user_name' => $ownerUserName, - 'module' => '公海模块', - 'type' => 9 + 'module' => '公海模块', + 'type' => 9, + // guogaobo 公海数据权限 + 'poolAuthList' => [ + 'receive' => true, + 'excelexport' => true, + 'poolId' => $value['customer_id'], // guogaobo 多公海使用 公海类型id + 'index' => true, + 'distribute' => true, + 'delete' => true + ] ]; } - # 处理线索模块数据 - foreach ($leadsList AS $key => $value) { + foreach ($leadsList as $key => $value) { $ownerUserName = !empty($value['owner_user_id']) ? db('admin_user')->where('id', $value['owner_user_id'])->value('realname') : ''; - + $result[] = [ - 'id' => $value['leads_id'], - 'name' => $value['name'], - 'create_time' => date('Y-m-d H:i:s', $value['create_time']), - 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', - 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', - 'last_time' => '', + 'id' => $value['leads_id'], + 'name' => $value['name'], + 'create_time' => date('Y-m-d H:i:s', $value['create_time']), + 'mobile' => !empty($value['mobile']) ? $value['mobile'] : '', + 'telephone' => !empty($value['telephone']) ? $value['telephone'] : '', + 'last_time' => '', 'owner_user_name' => $ownerUserName, - 'module' => '线索模块', - 'type' => 1 - + 'module' => '线索模块', + 'type' => 1 ]; } - return $result; } - /** * 获取客户列表 * @@ -107,19 +111,19 @@ class Index extends Common * @throws \think\exception\DbException */ private function getCustomerList($type, $content) - { - # 默认条件 - $customerWhere = $this->getCustomerWhere(); - - # 查询条件 - $searchWhere = $this->getSearchWhere($type, $content); - - # 查询字段 - $field = ['customer_id', 'name', 'create_time', 'owner_user_id', 'deal_time', 'telephone', 'mobile']; - - return db('crm_customer')->alias('customer')->field($field)->where($customerWhere) - ->where($searchWhere)->limit(10)->order('update_time', 'desc')->select(); - } +{ + # 默认条件 + $customerWhere = $this->getCustomerWhere(); + + # 查询条件 + $searchWhere = $this->getSearchWhere($type, $content); + + # 查询字段 + $field = ['customer_id', 'name', 'create_time', 'owner_user_id', 'deal_time', 'telephone', 'mobile']; + + return db('crm_customer')->alias('customer')->field($field)->where($customerWhere) + ->where($searchWhere)->limit(10)->order('update_time', 'desc')->select(); +} /** * 获取公海客户列表 @@ -132,19 +136,19 @@ class Index extends Common * @throws \think\exception\DbException */ private function getPoolList($type, $content) - { - # 公海条件 - $poolWhere = $this->getPoolWhere(); - - # 查询条件 - $searchWhere = $this->getSearchWhere($type, $content); - - # 查询字段 - $field = ['customer_id', 'name', 'create_time', 'owner_user_id', 'deal_time', 'telephone', 'mobile']; - - return db('crm_customer')->alias('customer')->field($field)->where($poolWhere) - ->where($searchWhere)->limit(10)->order('update_time', 'desc')->select(); - } +{ + # 公海条件 + $poolWhere = $this->getPoolWhere(); + + # 查询条件 + $searchWhere = $this->getSearchWhere($type, $content); + + # 查询字段 + $field = ['customer_id', 'name', 'create_time', 'owner_user_id', 'deal_time', 'telephone', 'mobile']; + + return db('crm_customer')->alias('customer')->field($field)->where($poolWhere) + ->where($searchWhere)->limit(10)->order('update_time', 'desc')->select(); +} /** * 获取线索列表 @@ -157,16 +161,16 @@ class Index extends Common * @throws \think\exception\DbException */ private function getLeadsList($type, $content) - { - # 查询条件 - $searchWhere = $this->getSearchWhere($type, $content); - - # 查询字段 - $field = ['leads_id', 'name', 'telephone', 'mobile', 'owner_user_id', 'create_time', 'is_transform']; - - return db('crm_leads')->field($field)->where($searchWhere)->where('is_transform', 0)->limit(10) - ->order('update_time', 'desc')->select(); - } +{ + # 查询条件 + $searchWhere = $this->getSearchWhere($type, $content); + + # 查询字段 + $field = ['leads_id', 'name', 'telephone', 'mobile', 'owner_user_id', 'create_time', 'is_transform']; + + return db('crm_leads')->field($field)->where($searchWhere)->where('is_transform', 0)->limit(10) + ->order('update_time', 'desc')->select(); +} /** * 获取查询条件 @@ -176,114 +180,114 @@ class Index extends Common * @return array|\Closure */ private function getSearchWhere($type, $content) - { - $searchWhere = []; - - # 查询客户名称 - if ($type == 'name') { - $searchWhere = function ($query) use ($content) { - $query->where('name', 'like', '%' . $content . '%'); - }; - } - - # 查询手机或电话 - if ($type == 'phone') { - $searchWhere = function ($query) use ($content) { - $query->where(function ($query) use ($content) { - $query->whereOr('telephone', $content); - $query->whereOr('mobile', $content); - }); - }; - } - - return $searchWhere; +{ + $searchWhere = []; + + # 查询客户名称 + if ($type == 'name') { + $searchWhere = function ($query) use ($content) { + $query->where('name', 'like', '%' . $content . '%'); + }; } + + # 查询手机或电话 + if ($type == 'phone') { + $searchWhere = function ($query) use ($content) { + $query->where(function ($query) use ($content) { + $query->whereOr('telephone', $content); + $query->whereOr('mobile', $content); + }); + }; + } + + return $searchWhere; +} /** * [客户公海条件] - * @author Michael_xu * @param * @return + * @author Michael_xu */ private function getPoolWhere() - { - $configModel = new \app\crm\model\ConfigData(); - $configInfo = $configModel->getData(); - $config = $configInfo['config'] ? : 0; - $follow_day = $configInfo['follow_day'] ? : 0; - $deal_day = $configInfo['deal_day'] ? : 0; - $whereData = []; - //启用 - if ($config == 1) { - //默认公海条件(没有负责人或已经到期) - $data['follow_time'] = time()-$follow_day*86400; - $data['deal_time'] = time()-$deal_day*86400; - $data['deal_status'] = '未成交'; - if ($follow_day < $deal_day) { - $whereData = function($query) use ($data){ - $query->where(['customer.owner_user_id'=>0]) - ->whereOr(function ($query) use ($data) { - $query->where(function ($query) use ($data) { - $query->where(['customer.update_time' => array('elt',$data['follow_time'])]) - ->whereOr(['customer.deal_time' => array('elt',$data['deal_time'])]); - }) - ->where(['customer.is_lock' => 0]) - ->where(['customer.deal_status' => ['neq','已成交']]); - }); - }; - } else { - $whereData = function($query) use ($data){ - $query->where(['customer.owner_user_id'=>0]) - ->whereOr(function ($query) use ($data) { - $query->where(function ($query) use ($data) { - $query->where(['customer.deal_time' => array('elt',$data['deal_time'])]); - }) - ->where(['customer.is_lock' => 0]) - ->where(['customer.deal_status' => ['neq','已成交']]); - }); - }; - } +{ + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $config = $configInfo['config'] ?: 0; + $follow_day = $configInfo['follow_day'] ?: 0; + $deal_day = $configInfo['deal_day'] ?: 0; + $whereData = []; + //启用 + if ($config == 1) { + //默认公海条件(没有负责人或已经到期) + $data['follow_time'] = time() - $follow_day * 86400; + $data['deal_time'] = time() - $deal_day * 86400; + $data['deal_status'] = '未成交'; + if ($follow_day < $deal_day) { + $whereData = function ($query) use ($data) { + $query->where(['customer.owner_user_id' => 0]) + ->whereOr(function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.update_time' => array('elt', $data['follow_time'])]) + ->whereOr(['customer.deal_time' => array('elt', $data['deal_time'])]); + }) + ->where(['customer.is_lock' => 0]) + ->where(['customer.deal_status' => ['neq', '已成交']]); + }); + }; } else { - $whereData['customer.owner_user_id'] = 0; + $whereData = function ($query) use ($data) { + $query->where(['customer.owner_user_id' => 0]) + ->whereOr(function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.deal_time' => array('elt', $data['deal_time'])]); + }) + ->where(['customer.is_lock' => 0]) + ->where(['customer.deal_status' => ['neq', '已成交']]); + }); + }; } - return $whereData ? : []; + } else { + $whereData['customer.owner_user_id'] = 0; } + return $whereData ?: []; +} /** * [客户默认条件] - * @author Michael_xu * @param * @return + * @author Michael_xu */ private function getCustomerWhere() - { - $configModel = new \app\crm\model\ConfigData(); - $configInfo = $configModel->getData(); - $config = $configInfo['config'] ? : 0; - $follow_day = $configInfo['follow_day'] ? : 0; - $deal_day = $configInfo['deal_day'] ? : 0; - //默认条件(没有到期或已锁定) - $data['follow_time'] = time()-$follow_day*86400; - $data['deal_time'] = time()-$deal_day*86400; - if ($config == 1) { - if ($follow_day < $deal_day) { - $whereData = function($query) use ($data){ - $query->where(function ($query) use ($data) { - $query->where(['customer.update_time' => array('gt',$data['follow_time']),'customer.deal_time' => array('gt',$data['deal_time'])]); - }) - ->whereOr(['customer.deal_status' => '已成交']) - ->whereOr(['customer.is_lock' => 1]); - }; - } else { - $whereData = function($query) use ($data){ - $query->where(function ($query) use ($data) { - $query->where(['customer.deal_time' => array('gt',$data['deal_time'])]); - }) - ->whereOr(['customer.deal_status' => '已成交']) - ->whereOr(['customer.is_lock' => 1]); - }; - } +{ + $configModel = new \app\crm\model\ConfigData(); + $configInfo = $configModel->getData(); + $config = $configInfo['config'] ?: 0; + $follow_day = $configInfo['follow_day'] ?: 0; + $deal_day = $configInfo['deal_day'] ?: 0; + //默认条件(没有到期或已锁定) + $data['follow_time'] = time() - $follow_day * 86400; + $data['deal_time'] = time() - $deal_day * 86400; + if ($config == 1) { + if ($follow_day < $deal_day) { + $whereData = function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.update_time' => array('gt', $data['follow_time']), 'customer.deal_time' => array('gt', $data['deal_time'])]); + }) + ->whereOr(['customer.deal_status' => '已成交']) + ->whereOr(['customer.is_lock' => 1]); + }; + } else { + $whereData = function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.deal_time' => array('gt', $data['deal_time'])]); + }) + ->whereOr(['customer.deal_status' => '已成交']) + ->whereOr(['customer.is_lock' => 1]); + }; } - return $whereData ? : []; } + return $whereData ?: []; +} } \ No newline at end of file diff --git a/application/crm/model/Leads.php b/application/crm/model/Leads.php index cdd7b30..7d641d6 100644 --- a/application/crm/model/Leads.php +++ b/application/crm/model/Leads.php @@ -67,7 +67,7 @@ class Leads extends Common } } $searchMap = []; - if ($search) { + if ($search || $search == '0') { //普通筛选 $searchMap = function ($query) use ($search) { $query->where('leads.name', array('like', '%' . $search . '%')) @@ -105,7 +105,11 @@ class Leads extends Common $userField = $fieldModel->getFieldByFormType('crm_leads', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_leads', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型 - + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_leads', 'leads', $order_field, $order_type); @@ -141,11 +145,11 @@ class Leads 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) { $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -214,6 +218,9 @@ class Leads extends Common $param[$v] = arrayToString($param[$v]); } + # 设置今日需联系线索 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + if ($this->data($param)->allowField(true)->isUpdate(false)->save()) { //修改记录 updateActionLog($param['create_user_id'], 'crm_leads', $this->leads_id, '', '', '创建了线索'); @@ -282,7 +289,10 @@ class Leads extends Common foreach ($arrFieldAtt as $k => $v) { $param[$v] = arrayToString($param[$v]); } - $param['follow'] = '已跟进'; + + # 设置今日需联系线索 + if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; + if ($this->update($param, ['leads_id' => $leads_id], true)) { //修改记录 updateActionLog($param['user_id'], 'crm_leads', $leads_id, $dataInfo, $param); diff --git a/application/crm/model/Product.php b/application/crm/model/Product.php index 7eb8f94..70c89b1 100644 --- a/application/crm/model/Product.php +++ b/application/crm/model/Product.php @@ -64,7 +64,7 @@ class Product extends Common //默认场景 $sceneMap = $sceneModel->getDefaultData('crm_product', $user_id) ? : []; } - if ($search) { + if ($search || $search == '0') { //普通筛选 $sceneMap['name'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '产品名称']; } @@ -103,7 +103,11 @@ class Product extends Common $userField = $fieldModel->getFieldByFormType('crm_product', 'user'); //人员类型 $structureField = $fieldModel->getFieldByFormType('crm_product', 'structure'); //部门类型 $datetimeField = $fieldModel->getFieldByFormType('crm_product', 'datetime'); //日期时间类型 - + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_product','product',$order_field,$order_type); @@ -133,12 +137,12 @@ 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) { - $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; diff --git a/application/crm/model/Receivables.php b/application/crm/model/Receivables.php index 3408058..c528f99 100644 --- a/application/crm/model/Receivables.php +++ b/application/crm/model/Receivables.php @@ -45,12 +45,14 @@ class Receivables extends Common $order_field = $request['order_field']; $order_type = $request['order_type']; $getCount = $request['getCount']; + $receivablesIdArray = $request['receivablesIdArray']; // 待办事项提醒参数 unset($request['scene_id']); unset($request['search']); unset($request['user_id']); unset($request['order_field']); unset($request['order_type']); unset($request['getCount']); + unset($request['receivablesIdArray']); $request = $this->fmtRequest( $request ); $requestMap = $request['map'] ? : []; @@ -67,9 +69,21 @@ class Receivables extends Common $sceneMap = $sceneModel->getDefaultData('crm_receivables', $user_id) ? : []; } } - if ($search) { - //普通筛选 - $sceneMap['number'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '回款编号']; + $searchWhere = []; + if (!empty($search) || $search == '0') { + //普通筛选 + $searchWhere = function ($query) use ($search) { + $query->where(function ($query) use ($search){ + $query->whereLike('customer.name', '%' . $search . '%'); + })->whereOr(function ($query) use ($search) { + $query->whereLike('receivables.number', '%' . $search . '%'); + }); + }; +// if (db('crm_customer')->whereLike('name', '%' . $search . '%')->value('customer_id')) { +// $sceneMap['customer_name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '客户名称']; +// } else { +// $sceneMap['number'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '回款编号']; +// } } //优先级:普通筛选>高级筛选>场景 $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; @@ -99,18 +113,21 @@ 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); - } else { - $order = 'receivables.update_time desc'; - } + # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) + $temporaryField = str_replace('_name', '', $order_field); + if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { + $order_field = $temporaryField; + } //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_receivables','receivables',$order_field, $order_type); } else { $order = 'receivables.update_time desc'; - } + } + + # 待办事项查询参数 + $dealtWhere = []; + if (!empty($receivablesIdArray)) $dealtWhere['receivables.receivables_id'] = ['in', $receivablesIdArray]; $readAuthIds = $userModel->getUserByPer('crm', 'receivables', 'read'); $updateAuthIds = $userModel->getUserByPer('crm', 'receivables', 'update'); @@ -119,7 +136,7 @@ class Receivables extends Common ->alias('receivables') ->join('__CRM_CUSTOMER__ customer','receivables.customer_id = customer.customer_id','LEFT') ->join('__CRM_CONTRACT__ contract','receivables.contract_id = contract.contract_id','LEFT') - ->where($map)->where($authMap)->count('receivables_id'); + ->where($searchWhere)->where($map)->where($authMap)->where($dealtWhere)->count('receivables_id'); if (!empty($getCount) && $getCount == 1) { $data['dataCount'] = !empty($dataCount) ? $dataCount : 0; $data['extraData']['money'] = ['receivablesMoney' => $this->getReceivablesMoney($map, $authMap)]; @@ -131,9 +148,11 @@ class Receivables extends Common $list = db('crm_receivables') ->alias('receivables') ->join('__CRM_CUSTOMER__ customer','receivables.customer_id = customer.customer_id','LEFT') - ->join('__CRM_CONTRACT__ contract','receivables.contract_id = contract.contract_id','LEFT') + ->join('__CRM_CONTRACT__ contract','receivables.contract_id = contract.contract_id','LEFT') + ->where($searchWhere) ->where($map) ->where($authMap) + ->where($dealtWhere) ->limit($request['offset'], $request['length']) ->field('receivables.*,customer.name as customer_name,contract.name as contract_name,contract.num as contract_num,contract.money as contract_money') ->orderRaw($order) @@ -151,12 +170,12 @@ 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) { - $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; - $list[$k][$val] = implode($usernameField, ','); + $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; + $list[$k][$val.'_name'] = 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, ','); + $list[$k][$val.'_name'] = implode($structureNameField, ','); } foreach ($datetimeField as $key => $val) { $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null; @@ -283,10 +302,23 @@ class Receivables extends Common 'create_user_id' => $param['create_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => $param['customer_id'], - 'contract_ids' => $param['contract_id'] + 'customer_ids' => ',' . $param['customer_id'] . ',', + 'contract_ids' => ',' . $param['contract_id'] . ',' ]); + # 创建待办事项的关联数据 + $checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_receivables', + 'types_id' => $data['receivables_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + return $data; } else { $this->error = '添加失败'; @@ -376,6 +408,22 @@ class Receivables extends Common $data = []; $data['receivables_id'] = $receivables_id; + + # 删除待办事项的关联数据 + db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'types_id' => ['eq', $data['receivables_id']]])->delete(); + # 创建待办事项的关联数据 + $checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray AS $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_receivables', + 'types_id' => $data['receivables_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + return $data; } else { $this->error = '编辑失败'; diff --git a/application/crm/model/ReceivablesPlan.php b/application/crm/model/ReceivablesPlan.php index 19ebd6e..645749d 100644 --- a/application/crm/model/ReceivablesPlan.php +++ b/application/crm/model/ReceivablesPlan.php @@ -33,7 +33,7 @@ class ReceivablesPlan extends Common * @return [array] [description] */ public function getDataList($request) - { + { $userModel = new \app\admin\model\User(); $search = $request['search']; $user_id = $request['user_id']; @@ -42,6 +42,7 @@ class ReceivablesPlan extends Common $types = $request['types']; $getCount = $request['getCount']; $status = isset($request['status']) ? $request['status'] : 1; + $dealt = $request['dealt']; # 待办事项 unset($request['scene_id']); unset($request['search']); unset($request['user_id']); @@ -49,6 +50,7 @@ class ReceivablesPlan extends Common unset($request['types']); unset($request['getCount']); unset($request['status']); + unset($request['dealt']); $request = $this->fmtRequest( $request ); $map = $request['map'] ? : []; @@ -81,19 +83,27 @@ class ReceivablesPlan extends Common // @ymob 2019-12-11 17:51:54 // 修改回款时,回款计划选项列表应该包含该回款对应的回款计划 不能过滤 // 将types改为status,status:可用的回款计划 fanqi - if ($request['map']['receivables_id']) { - if (!empty($request['map']['contract_id'])) { - $map = " + if (empty($dealt)) { # 不是待办事项 + if ($request['map']['receivables_id']) { + if (!empty($request['map']['contract_id'])) { + $map = " (`receivables_plan`.`contract_id` = {$request['map']['contract_id']} AND `receivables_plan`.`receivables_id` = {$request['map']['receivables_id']}) OR (`receivables_plan`.`contract_id` = {$request['map']['contract_id']} AND `receivables_plan`.`receivables_id` = 0) "; - } else { - $map = " (`receivables_plan`.`receivables_id` = 0 )"; + } else { + $map = " (`receivables_plan`.`receivables_id` = 0 )"; + } + } elseif ($status == 0) { + $map['receivables_plan.receivables_id'] = 0; } - } elseif ($status == 0) { - $map['receivables_plan.receivables_id'] = 0; - } + } + + # 待办事项-待回款提醒-已回款 + if (!empty($dealt)) { + $map = " (`receivables_plan`.`receivables_id` > ".$request['map']['receivables_id'][1]." )"; + } + $dataCount = db('crm_receivables_plan') ->alias('receivables_plan') diff --git a/application/crm/traits/AutoNumberTrait.php b/application/crm/traits/AutoNumberTrait.php index d09b958..3e07c2e 100644 --- a/application/crm/traits/AutoNumberTrait.php +++ b/application/crm/traits/AutoNumberTrait.php @@ -29,7 +29,31 @@ trait AutoNumberTrait $number = ''; $data = []; - $info = Db::name('crm_number_sequence')->where('number_type', $type)->where('status', 0)->select(); + # 根据设置重置编号(不想改下面的代码,在这里在写一个,多公海版本出来后,用定时来做) + $list = Db::name('crm_number_sequence')->where('number_type', $type)->where('status', 0)->select(); + foreach ($list AS $key => $value) { + if ($value['type'] == 3 && $value['reset'] != 0) { + # 1:每天;2:每月;3:每年; + $currentDate = [ + 1 => date('Y-m-d'), + 2 => date('Y-m'), + 3 => date('Y') + ]; + $lastDate = [ + 1 => date('Y-m-d', $value['last_date']), + 2 => date('Y-m', $value['last_date']), + 3 => date('Y', $value['last_date']) + ]; + + if ($currentDate[$value['reset']] != $lastDate[$value['reset']]) { + Db::name('crm_number_sequence')->where('number_sequence_id', $value['number_sequence_id'])->update([ + 'last_number' => 1 + ]); + } + } + } + + $info = Db::name('crm_number_sequence')->where('number_type', $type)->order('sort', 'asc')->where('status', 0)->select(); foreach ($info AS $key => $value) { # 文本 diff --git a/application/crm/traits/SearchConditionTrait.php b/application/crm/traits/SearchConditionTrait.php new file mode 100644 index 0000000..29d21f0 --- /dev/null +++ b/application/crm/traits/SearchConditionTrait.php @@ -0,0 +1,153 @@ +getUserByPer('crm', 'contacts', 'index'); + + $authMapData['auth_user_ids'] = $authUserIds; + $authMapData['user_id'] = $userId; + + return $this->getSearchAuthWhere($authMapData); + } + + /** + * 商机tab列表查询条件(权限) + * + * @param $userId 当前登录ID + * @author fanqi + * @date 2021-03-09 + * @return \Closure + */ + public function getBusinessSearchWhere($userId) + { + $userModel = new \app\admin\model\User(); + + $authUserIds = $userModel->getUserByPer('crm', 'business', 'index'); + + $authMapData['auth_user_ids'] = $authUserIds; + $authMapData['user_id'] = $userId; + + return $this->getSearchAuthWhere($authMapData); + } + + /** + * 合同tab列表查询条件(权限) + * + * @param $userId 当前登录ID + * @author fanqi + * @date 2021-03-09 + * @return \Closure + */ + public function getContractSearchWhere($userId) + { + $userModel = new \app\admin\model\User(); + + $authUserIds = $userModel->getUserByPer('crm', 'contract', 'index'); + + $authMapData['auth_user_ids'] = $authUserIds; + $authMapData['user_id'] = $userId; + + return $this->getSearchAuthWhere($authMapData); + } + + /** + * 回访tab列表查询条件(权限) + * + * @param $userId + * @author fanqi + * @date 2021-03-09 + * @return \Closure + */ + public function getVisitSearchWhere($userId) + { + $userModel = new \app\admin\model\User(); + + $authUserIds = $userModel->getUserByPer('crm', 'visit', 'index'); + + $authMapData['auth_user_ids'] = $authUserIds; + $authMapData['user_id'] = $userId; + + return $this->getSearchAuthWhere($authMapData); + } + + /** + * 回款tab列表查询条件(权限) + * + * @author fanqi + * @date 2021-03-10 + * @return array[] + */ + public function getReceivablesSearchWhere() + { + $userModel = new \app\admin\model\User(); + + return $userModel->getUserByPer('crm', 'receivables', 'index'); + } + + /** + * 发票tab列表查询条件 + * + * @author fanqi + * @date 2021-03-11 + * @return array|false|string + */ + public function getInvoiceSearchWhere() + { + $userModel = new \app\admin\model\User(); + + return $userModel->getUserByPer('crm', 'invoice', 'index'); + } + + /** + * 产品tab列表查询条件 + * + * @author fanqi + * @date 2021-03-11 + * @return array|false|string + */ + public function getProductSearchWhere() + { + $userModel = new \app\admin\model\User(); + + return $userModel->getUserByPer('crm', 'product', 'index'); + } + + /** + * 查询权限条件 + * + * @param $authMapData 权限范围内的ID + * @return \Closure + */ + private function getSearchAuthWhere($authMapData) + { + return function($query) use ($authMapData) { + $query->where(['owner_user_id' => ['in', $authMapData['auth_user_ids']]]) + ->whereOr(function ($query) use ($authMapData) { + $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", ro_user_id)')->where(['owner_user_id' => ['neq', '']]); + }) + ->whereOr(function ($query) use ($authMapData) { + $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", rw_user_id)')->where(['owner_user_id' => ['neq', '']]); + }); + }; + } +} \ No newline at end of file diff --git a/application/oa/controller/Task.php b/application/oa/controller/Task.php index 0f86786..db26612 100644 --- a/application/oa/controller/Task.php +++ b/application/oa/controller/Task.php @@ -380,20 +380,39 @@ class Task extends ApiCommon } $taskInfo = Db::name('Task')->where(['task_id' => $param['task_id']])->find(); $det = Db::name('TaskRelation')->where(['task_id' => $param['task_id']])->find(); + $activityUpdate = []; if ($param['type'] == '1') { $newstr = str_replace(',' . $param['id'] . ',', ',', $det['customer_ids']); $newdata['customer_ids'] = $newstr; + # 删除活动关联 + $customerIds = db('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->value('customer_ids'); + $activityUpdate['customer_ids'] = str_replace(',' . $param['id'] . ',', ',', $customerIds); + if ($activityUpdate['customer_ids'] == ',') $activityUpdate['customer_ids'] = ''; } elseif ($param['type'] == '2') { $newstr = str_replace(',' . $param['id'] . ',', ',', $det['contacts_ids']); $newdata['contacts_ids'] = $newstr; + # 删除活动关联 + $contactsIds = db('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->value('contacts_ids'); + $activityUpdate['contacts_ids'] = str_replace(',' . $param['id'] . ',', ',', $contactsIds); + if ($activityUpdate['contacts_ids'] == ',') $activityUpdate['contacts_ids'] = ''; } elseif ($param['type'] == '3') { $newstr = str_replace(',' . $param['id'] . ',', ',', $det['business_ids']); $newdata['business_ids'] = $newstr; + # 删除活动关联 + $businessIds = db('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->value('business_ids'); + $activityUpdate['business_ids'] = str_replace(',' . $param['id'] . ',', ',', $businessIds); + if ($activityUpdate['business_ids'] == ',') $activityUpdate['business_ids'] = ''; } elseif ($param['type'] == '4') { $newstr = str_replace(',' . $param['id'] . ',', ',', $det['contract_ids']); $newdata['contract_ids'] = $newstr; + # 删除活动关联 + $contractIds = db('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->value('contract_ids'); + $activityUpdate['contract_ids'] = str_replace(',' . $param['id'] . ',', ',', $contractIds); + if ($activityUpdate['contract_ids'] == ',') $activityUpdate['contract_ids'] = ''; } $flag = Db::name('TaskRelation')->where(['task_id' => $param['task_id']])->update($newdata); + # 取消活动关联 + db('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->update($activityUpdate); if ($flag) { if (!$taskInfo['pid']) { actionLog($taskInfo['task_id'], $taskInfo['owner_user_id'], $taskInfo['structure_ids'], '编辑关联关系'); diff --git a/application/oa/logic/LogLogic.php b/application/oa/logic/LogLogic.php index d2d023c..758acb5 100644 --- a/application/oa/logic/LogLogic.php +++ b/application/oa/logic/LogLogic.php @@ -242,8 +242,9 @@ class LogLogic extends Common $between_time = [$start_time['start_time'], $start_time['end_time']]; $map['owner_user_id'] = $user_id; $map['create_time'] = array('between', $between_time); + $map1['update_time'] = array('between', $between_time); $customerNum = Db::name('CrmCustomer') - ->where($map) + ->where($map1) ->count(); $businessNum = Db::name('CrmBusiness') ->where($map) @@ -307,7 +308,7 @@ class LogLogic extends Common switch ($type) { case '1': if ($search) $map['customer.name'] = array('like', '%' . $search . '%'); - $map['customer.create_time'] = array('between', $between_time); + $map['customer.update_time'] = array('between', $between_time); $activityData = Db::name('CrmCustomer') ->alias('customer') ->join('__ADMIN_USER__ user', 'user.id = customer.owner_user_id', 'LEFT') @@ -316,6 +317,7 @@ class LogLogic extends Common ->where($customerMap) ->order('customer.customer_id desc') ->field('customer.customer_id,customer.name,customer.deal_status,customer.create_time,user.realname as owner_user_name,customer.last_time') + ->page($param['page'],$param['limit']) ->select(); $dataCount = Db::name('CrmCustomer') ->alias('customer') @@ -335,6 +337,7 @@ class LogLogic extends Common ->where($map) ->where($map2) ->order('business.business_id desc') + ->page($param['page'],$param['limit']) ->field('business.business_id,business.name,status.name as status_name,business.create_time,user.realname as owner_user_name,business.last_time') ->select(); $dataCount = Db::name('CrmBusiness') @@ -354,6 +357,7 @@ class LogLogic extends Common ->where($map) ->where($map3) ->order('contract.contract_id desc') + ->page($param['page'],$param['limit']) ->field('contract.contract_id,contract.name,contract.create_time,contract.check_status,u.realname as order_user_name') ->select(); $dataCount = Db::name('CrmContract') @@ -372,6 +376,7 @@ class LogLogic extends Common ->field('receivables.receivables_id,receivables.number,receivables.return_time,user.realname as owner_user_name') ->where($map) ->where($map4) + ->page($param['page'],$param['limit']) ->order('receivables.receivables_id desc') ->select(); $dataCount = Db::name('CrmReceivables') @@ -929,11 +934,22 @@ class LogLogic extends Common $imgList[] = $val; } } + $is_update = 0; + $is_delete = 0; + //创建人或负责人或管理员有撤销权限 + if ($item['create_user_id'] == $param['user_id']) { + $is_update = 1; + $is_delete = 1; + } $param['type_id'] = $item['log_id']; $param['type'] = 'oa_log'; $item['replyList'] = $commonModel->read($param); $item['fileList'] = $fileList ?: []; $item['imgList'] = $imgList ?: []; + + $permission['is_delete'] = $is_update; + $permission['is_update'] = $is_delete; + $item['permission'] = $permission; //相关业务 $relationArr = $recordModel->getListByRelationId('log', $item['log_id']); $item['businessList'] = $relationArr['businessList']; diff --git a/application/oa/logic/TaskLogic.php b/application/oa/logic/TaskLogic.php index d7851c1..0f689ae 100644 --- a/application/oa/logic/TaskLogic.php +++ b/application/oa/logic/TaskLogic.php @@ -16,7 +16,6 @@ class TaskLogic $taskModel = new TaskModel(); $recordModel = new \app\admin\model\Record(); $str = ',' . $param['user_id'] . ','; - //自定义时间 $map['t.stop_time'] = $param['dueDate'] ? strtotime($param['dueDate'] . ' +1 month -1 day') : ['>=', 0]; $search = $param['search']; @@ -35,30 +34,70 @@ class TaskLogic $where['t.status'] = [['=', 1], ['=', 5], 'OR']; } - if ($param['main_user_id']) { - $where['t.main_user_id'] = $param['main_user_id']; - } //项目id $priority = ($param['priority'] || $param['priority'] == '0') ? $param['priority'] : ['in', [0, 1, 2, 3]]; $where['t.priority'] = $priority; - if ($param['work_id'] != 0) { - $where['t.work_id'] = $param['work_id']; + if (!empty($param['work_id'])) { + $where = []; + $where['ishidden'] = 0; + $where['pid'] = 0; + $where['work_id'] = $param['work_id']; + if (!empty($param['search'])) { + $taskSearch = ' (task.name like "%' . $param['search'] . '%" OR task.description like "%' . $param['search'] . '%")'; + } + # 成员 + if (!empty($param['owner_user_id']) && is_array($param['owner_user_id'])) { + $whereStr = ''; + foreach ($param['owner_user_id'] as $key => $value) { + $whereStr .= '( task.owner_user_id like "%,' . $value . ',%") OR '; + } + if (!empty($whereStr)) $whereStr = '(' . rtrim($whereStr, 'OR ') . ')'; + } + # 截止日期 + $timeWhere = $this->getTimeParam($param['time_type']); + # 标签 + $labelWhere = ''; + if (!empty($param['label_id']) && is_array($param['label_id'])) { + foreach ($param['label_id'] as $key => $value) { + $labelWhere .= '( task.lable_id like "%,' . $value . ',%") OR '; + } + if (!empty($labelWhere)) $labelWhere = '(' . rtrim($labelWhere, 'OR ') . ')'; + } + if ($param['owner_user_id']) { + foreach ($param['owner_user_id'] as $key => $value) { + $logWhere.= '( task.owner_user_id like "%,' . $value . ',%") OR '; + } + if (!empty($logWhere)) $logWhere = '(' . rtrim($logWhere, 'OR ') . ')'; + } $taskList = db('task') - ->alias('t') - ->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.class_id') + ->alias('task') + ->join('AdminUser u', 'u.id = task.main_user_id', 'LEFT') + ->field('task.task_id,task.name as task_name,task.main_user_id,task.description,task.priority,task.stop_time,task.create_time,task.owner_user_id, + task.start_time,task.create_user_id,u.realname as main_user_name,task.class_id,task.work_id,task.lable_id') ->where($where) - ->order('t.task_id desc') + ->where($timeWhere) + ->where($labelWhere) + ->where($whereStr) + ->where($labelWhere) + ->where($taskSearch) + ->order('task.task_id desc') ->select(); } else { - if ($param['is_top'] == 5) { + if ($param['is_top'] > 0 ) { $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'] . ' ) )'; if (!empty($this->param['search'])) { - $where['taskSearch'] = ' and (task.name like "%' . $this->param['search'] . '%" OR task.description like "%' . $this->param['search'] . '%")'; + $taskSearch = ' (task.name like "%' . $this->param['search'] . '%" OR task.description like "%' . $this->param['search'] . '%")'; + } + # 成员 + if (!empty($param['owner_user_id']) && is_array($param['owner_user_id'])) { + $whereStr = ''; + foreach ($param['owner_user_id'] as $key => $value) { + $whereStr .= '( task.owner_user_id like "%,' . $value . ',%") OR '; + } + if (!empty($whereStr)) $whereStr = '(' . rtrim($whereStr, 'OR ') . ')'; } # 截止日期 $timeWhere = $this->getTimeParam($param['time_type']); @@ -70,17 +109,19 @@ class TaskLogic } if (!empty($labelWhere)) $labelWhere = '(' . rtrim($labelWhere, 'OR ') . ')'; } - $where = $this->where($param); $taskList = db('task') - ->alias('t') - ->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') + ->alias('task') + ->join('AdminUser u', 'u.id = task.main_user_id', 'LEFT') + ->field('task.task_id,task.name as task_name,task.main_user_id,task.description,task.priority,task.stop_time,task.create_time,task.owner_user_id, + task.start_time,task.create_user_id,u.realname as main_user_name,task.is_top') ->where($where) ->where($timeWhere) ->where($labelWhere) - ->order('t.task_id desc') + ->where($whereStr) + ->where($taskSearch) + ->where($labelWhere) + ->order('task.task_id desc') ->select(); - } else { ///下属任务 if ($param['mold'] == 1) { @@ -127,7 +168,6 @@ class TaskLogic ->select(); } else { $map['t.pid'] = 0; - // $map['t.work_id'] = 0; if ($type != 0) { switch ($type) { case '1' : @@ -162,7 +202,7 @@ class TaskLogic $taskList[$key]['work'] = ''; if ($param['work_id'] != 0) { $work = db('work_task_class')->where('class_id', $value['class_id'])->find(); - $taskList[$key]['work'] = $work['name']; + $taskList[$key]['work'] = $work['name']?:'未分组'; } if ($param['is_top'] != 0) { switch ($value['is_top']) { @@ -207,11 +247,12 @@ class TaskLogic $relationArr = $recordModel->getListByRelationId('task', $value['task_id']); $lableArr = $recordModel->getListByLableId('task', $value['task_id']); $taskList[$key]['owner_user_name'] = arrayToString(array_column($userModel->getListByStr($value['owner_user_id']), 'realname')); - $taskList[$key]['work_name'] = arrayToString(array_column($lableArr['lable'], 'name')) . ' '; - $taskList[$key]['relation'] = arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' . + $taskList[$key]['owner_user_name'] = trim($taskList[$key]['owner_user_name'],','); + $taskList[$key]['work_name'] = trim(arrayToString(array_column($lableArr['lable'], 'name')),','). ' '; + $taskList[$key]['relation'] = trim(arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' . arrayToString(array_column($relationArr['contactsList'], 'name')) . ' ' . arrayToString(array_column($relationArr['contractList'], 'name')) . ' ' . - arrayToString(array_column($relationArr['customerList'], 'name')); + arrayToString(array_column($relationArr['customerList'], 'name')),','); } return $taskList; } @@ -222,8 +263,8 @@ class TaskLogic */ public function excelExport($param) { - $data = $this->getDataList($param); + p($data); $excelModel = new \app\admin\model\Excel(); if ($param['work_id'] != 0) { $file_name = 'work_task'; @@ -289,19 +330,19 @@ class TaskLogic $work_id = $param['work_id'] ?: ''; if ($param['main_user_id']) { - $map['t.main_user_id'] = ['in', $param['main_user_id']]; + $map['task.main_user_id'] = ['in', $param['main_user_id']]; } - + //截止时间 if ($param['stop_time_type']) { if ($param['stop_time_type'] == '5') { //没有截至日期 - $map['t.stop_time'] = '0'; + $map['task.stop_time'] = '0'; } elseif ($param['stop_time_type'] == '6') { //延期的 - $map['t.stop_time'] = ['between', [1, time()]]; - $map['t.status'] = 1; + $map['task.stop_time'] = ['between', [1, time()]]; + $map['task.status'] = 1; } elseif ($param['stop_time_type'] == '7') { //今日更新 $timeAry = getTimeByType('today'); - $map['t.update_time'] = ['between', [$timeAry[0], $timeAry[1]]]; + $map['task.update_time'] = ['between', [$timeAry[0], $timeAry[1]]]; } else { switch ($param['stop_time_type']) { case '1': //今天到期 @@ -321,7 +362,7 @@ class TaskLogic default: break; } - $map['t.stop_time'] = ['between', [$timeAry[0], $timeAry[1]]]; + $map['task.stop_time'] = ['between', [$timeAry[0], $timeAry[1]]]; } } @@ -345,10 +386,10 @@ class TaskLogic $task_ids = $task_id; } } - $map['t.task_id'] = ['in', $task_ids]; + $map['task.task_id'] = ['in', $task_ids]; } else { - $map['t.task_id'] = $work_id; + $map['task.task_id'] = $work_id; } return $map; } diff --git a/application/oa/model/Announcement.php b/application/oa/model/Announcement.php index e971676..f6d13d8 100644 --- a/application/oa/model/Announcement.php +++ b/application/oa/model/Announcement.php @@ -203,6 +203,7 @@ class Announcement extends Common } $userModel = new \app\admin\model\User(); $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']); + $dataInfo['create_time'] = $dataInfo['create_time']?date('Y-m-d H:i:s',$dataInfo['create_time']):null; $structureModel = new \app\admin\model\Structure(); $dataInfo['structureList'] = $structureModel->getDataByStr($dataInfo['structure_ids'])?:array(); $dataInfo['announcement_id'] = $announcement_id; diff --git a/application/oa/model/Event.php b/application/oa/model/Event.php index e28dbd3..07e9814 100644 --- a/application/oa/model/Event.php +++ b/application/oa/model/Event.php @@ -631,6 +631,7 @@ class Event extends Common foreach ($event_date as $k => $v) { $event_date[$k]['create_time'] = $v['create_time'] ? date('Y-m-d H:i:s', $v['create_time']) : null; $event_date[$k]['last_time'] = $v['last_time'] ? date('Y-m-d H:i:s', $v['last_time']) : null; + $event_date[$k]['next_time'] = $v['next_time'] ? date('Y-m-d H:i:s', $v['next_time']) : null; } $data = []; $data['list'] = $event_date; diff --git a/application/oa/model/Examine.php b/application/oa/model/Examine.php index cd7d764..f6e168c 100644 --- a/application/oa/model/Examine.php +++ b/application/oa/model/Examine.php @@ -68,6 +68,7 @@ class Examine extends Common 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 . " ) )"; } + $map['examine.create_user_id'] = ['<>',$user_id]; break; case '1' : $map['check_user_id'] = [['like', '%,' . $user_id . ',%']]; @@ -356,10 +357,10 @@ class Examine extends Common 'create_user_id' => $param['create_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '', + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '', ]); } @@ -447,14 +448,18 @@ class Examine extends Common $send_user_id ); } - + //相关业务 + Db::name('OaExamineRelation')->where('examine_id', $examine_id)->delete(); // 先删除在添加 $rdata = []; - $rdata['customer_ids'] = $param['oaExamineRelation']['customer_ids'] ? arrayToString($param['oaExamineRelation']['customer_ids']) : []; - $rdata['contacts_ids'] = $param['oaExamineRelation']['contacts_ids'] ? arrayToString($param['oaExamineRelation']['contacts_ids']) : []; - $rdata['business_ids'] = $param['oaExamineRelation']['business_ids'] ? arrayToString($param['oaExamineRelation']['business_ids']) : []; - $rdata['contract_ids'] = $param['oaExamineRelation']['contract_ids'] ? arrayToString($param['oaExamineRelation']['contract_ids']) : []; - Db::name('OaExamineRelation')->where('examine_id = ' . $examine_id)->update($rdata); + $rdata['examine_id'] = $examine_id; + $rdata['status'] = 1; + $rdata['create_time'] = time(); + $rdata['customer_ids'] = $param['oaExamineRelation']['customer_ids'] ? arrayToString($param['oaExamineRelation']['customer_ids']) : ''; + $rdata['contacts_ids'] = $param['oaExamineRelation']['contacts_ids'] ? arrayToString($param['oaExamineRelation']['contacts_ids']) : ''; + $rdata['business_ids'] = $param['oaExamineRelation']['business_ids'] ? arrayToString($param['oaExamineRelation']['business_ids']) : ''; + $rdata['contract_ids'] = $param['oaExamineRelation']['contract_ids'] ? arrayToString($param['oaExamineRelation']['contract_ids']) : ''; + Db::name('OaExamineRelation')->insert($rdata); //处理差旅相关 $resTravel = true; @@ -493,10 +498,10 @@ class Examine extends Common 'create_user_id' => $create_user_id, 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '', + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '', ]); } @@ -581,6 +586,7 @@ class Examine extends Common } $travelList[$k]['start_time'] = date('Y-m-d H:i:s', $v['start_time']); $travelList[$k]['end_time'] = date('Y-m-d H:i:s', $v['end_time']); + $travelList[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']); $travelList[$k]['fileList'] = $fileList ?: []; $travelList[$k]['imgList'] = $imgList ?: []; } diff --git a/application/oa/model/Log.php b/application/oa/model/Log.php index ff15ff1..c3c7243 100644 --- a/application/oa/model/Log.php +++ b/application/oa/model/Log.php @@ -73,8 +73,8 @@ class Log extends Common $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']), ',')]; + if ($request['create_user_id'] != '') { + $map['log.create_user_id'] = ['in', trim(arrayToString($request['create_user_id']), ',')]; } switch ($by) { case 'me' : @@ -282,10 +282,10 @@ class Log extends Common 'create_user_id' => $param['create_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '', + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '', ]); } @@ -361,10 +361,10 @@ class Log extends Common 'create_user_id' => $param['user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '' + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '' ]); } return $data; diff --git a/application/work/controller/Task.php b/application/work/controller/Task.php index 4c25364..0f6ff8e 100644 --- a/application/work/controller/Task.php +++ b/application/work/controller/Task.php @@ -20,27 +20,27 @@ use think\Db; class Task extends ApiCommon { use WorkAuthTrait; - + /** * 用于判断权限 * @permission 无限制 * @allow 登录用户可访问 * @other 其他根据系统设置 - **/ + **/ public function _initialize() { $action = [ - 'permission'=>[''], - 'allow'=>[ + 'permission' => [''], + 'allow' => [ 'index', 'mytask', 'updatetop', 'updateorder', 'read', 'update', 'readloglist', 'updatepriority', 'updateowner', 'delownerbyid', 'delstruceurebyid', 'updatestoptime', 'updatelable', 'updatename', - 'taskover', 'datelist','save','delmainuserid','rename','delete','archive','recover','archlist', - 'archivetask','setover','updateclassorder','excelimport','excelexport','taskusers','ownertasklist'] - + 'taskover', 'datelist', 'save', 'delmainuserid', 'rename', 'delete', 'archive', 'recover', 'archlist', + 'archivetask', 'setover', 'updateclassorder', 'excelimport', 'excelexport', 'taskusers', 'ownertasklist'] + ]; - Hook::listen('check_auth',$action); + Hook::listen('check_auth', $action); $request = Request::instance(); - $a = strtolower($request->action()); + $a = strtolower($request->action()); if (!in_array($a, $action['permission'])) { parent::_initialize(); } @@ -48,19 +48,19 @@ class Task extends ApiCommon $param = $this->param; if ($param['task_id']) { $userInfo = $this->userInfo; - $taskModel = model('Task'); + $taskModel = model('Task'); if (!$taskModel->checkTask($param['task_id'], $userInfo)) { header('Content-Type:application/json; charset=utf-8'); - exit(json_encode(['code'=>102,'error'=>'没有权限'])); + exit(json_encode(['code' => 102, 'error' => '没有权限'])); } } } - + /** * 项目下任务列表 + * @return * @author yykun - * @return - */ + */ public function index() { $param = $this->param; @@ -69,10 +69,10 @@ class Task extends ApiCommon if (!$param['work_id']) { return resultArray(['error' => '参数错误']); } - $list = $taskModel->getDataList($param, $userInfo['id']); + $list = $taskModel->getDataList($param, $userInfo['id']); return resultArray(['data' => $list]); } - + public function ownerTaskList() { $param = $this->param; @@ -84,7 +84,7 @@ class Task extends ApiCommon $list = $taskModel->getOwnerTaskList($param, $userInfo['id']); return resultArray(['data' => $list]); } - + /** * 任务列表导出 * @@ -92,7 +92,8 @@ class Task extends ApiCommon * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function excelExport(){ + public function excelExport() + { $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; @@ -105,30 +106,74 @@ class Task extends ApiCommon $data = $TaskLogic->excelExport($param); return $data; } + /** - * 客户导入模板下载 - * @author Michael_xu + * 导入模板下载 * @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用 * @return + * @author Michael_xu */ public function excelDownload($save_path = '') { - $param = $this->param; - $userInfo = $this->userInfo; $excelModel = new \app\admin\model\Excel(); $field_list = [ - '0' => ['name' => '任务名称', 'field' => 'name'], - '1' => ['name' => '任务描述', 'field' => 'description'], - '2' => ['name' => '开始时间', 'field' => 'start_time'], - '3' => ['name' => '结束时间', 'field' => 'stop_time'], - '4' => ['name' => '创建人', 'field' => 'create_user_id'], - '5' => ['name' => '参与人', 'field' => 'owner_user_id'], - '6' => ['name' => '所在任务列表', 'field' => 'class_id'], + '0' => [ + 'name' => '任务名称', + 'field' => 'name', + 'types' => 'task', + 'form_type' => 'text', + 'default_value' => '', + 'is_unique' => 1, + 'is_null' => 1, + 'input_tips' => '', + 'setting' => array(), + 'is_hidden' => 0, + 'writeStatus' => 1, + 'value' => '', + ], + '1' => [ + 'name' => '任务描述', + 'field' => 'description', + 'types' => 'task', + 'form_type' => 'textarea', + ], + '2' => [ + 'name' => '开始时间', + 'field' => 'start_time', + 'types' => 'task', + 'form_type' => 'datetime', + ], + '3' => [ + 'name' => '结束时间', + 'field' => 'stop_time', + 'types' => 'task', + 'form_type' => 'datetime', + ], + '4' => [ + 'name' => '创建人', + 'field' => 'create_user_id', + 'types' => 'task', + 'form_type' => 'user', + ], + '5' => [ + 'name' => '参与人', + 'field' => 'owner_user_id', + 'types' => 'task', + 'form_type' => 'user', + ], + '6' => [ + 'name' => '所在任务列表', + 'field' => 'class_id', + 'types' => 'task', + 'form_type' => 'text', + 'is_unique' => 1, + 'is_null' => 1, + ], ]; // 导入的字段列表 - $excelModel->excelImportDownload($field_list, 'task', $save_path); + $excelModel->excelImportDownload($field_list, 'work_task', $save_path); } - + /** * 客户数据导入 * @@ -146,20 +191,74 @@ class Task extends ApiCommon header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } + $field_list = [ + '0' => [ + 'name' => '任务名称', + 'field' => 'name', + 'types' => 'task', + 'form_type' => 'text', + 'default_value' => '', + 'is_unique' => 1, + 'is_null' => 1, + 'input_tips' => '', + 'setting' => array(), + 'is_hidden' => 0, + 'writeStatus' => 1, + 'value' => '', + ], + '1' => [ + 'name' => '任务描述', + 'field' => 'description', + 'types' => 'task', + 'form_type' => 'textarea', + ], + '2' => [ + 'name' => '开始时间', + 'field' => 'start_time', + 'types' => 'task', + 'form_type' => 'datetime', + ], + '3' => [ + 'name' => '结束时间', + 'field' => 'stop_time', + 'types' => 'task', + 'form_type' => 'datetime', + ], + '4' => [ + 'name' => '创建人', + 'field' => 'create_user_id', + 'types' => 'task', + 'form_type' => 'user', + ], + '5' => [ + 'name' => '参与人', + 'field' => 'owner_user_id', + 'types' => 'task', + 'form_type' => 'user', + ], + '6' => [ + 'name' => '所在任务列表', + 'field' => 'class_id', + 'types' => 'task', + 'form_type' => 'text', + 'is_unique' => 1, + 'is_null' => 1, + ], + ]; $excelModel = new \app\admin\model\Excel(); $param['create_user_id'] = $userInfo['id']; - $param['owner_user_id'] = $param['owner_user_id'] ? : 0; + $param['owner_user_id'] = $param['owner_user_id'] ?: 0; $file = request()->file('file'); $param['types'] = 'task'; // $res = $excelModel->importExcel($file, $param, $this); - $res = $excelModel->batchTaskImportData($file, $param, $this); + $res = $excelModel->batchTaskImportData($file,$field_list, $param, $this); if (!$res) { return resultArray(['error' => $excelModel->getError()]); } return resultArray(['data' => $excelModel->getError()]); } - - + + /** * 任务搜索 * @@ -169,39 +268,40 @@ class Task extends ApiCommon public function search(TaskLogic $taskLogic) { $data = $taskLogic->getSearchData($this->param); - + return resultArray(['data' => $data]); } + /** * 我的任务 + * @return * @author yykun - * @return */ public function myTask() { - $taskModel = model('Task'); - $userId = $this->userInfo['id']; - - $data = []; + $taskModel = model('Task'); + $userId = $this->userInfo['id']; + + $data = []; $data[0]['title'] = '收件箱'; $data[1]['title'] = '今天要做'; $data[2]['title'] = '下一步要做'; $data[3]['title'] = '以后要做'; for ($k = 0; $k < 4; $k++) { $where = []; - $where['ishidden'] = 0; - $where['is_top'] = $k; - $where['pid'] = 0; - $where['whereStr'] = ' ( task.create_user_id ='.$userId.' or ( task.owner_user_id like "%,'.$userId.',%") or ( task.main_user_id = '.$userId.' ) )'; + $where['ishidden'] = 0; + $where['is_top'] = $k; + $where['pid'] = 0; + $where['whereStr'] = ' ( task.create_user_id =' . $userId . ' or ( task.owner_user_id like "%,' . $userId . ',%") or ( task.main_user_id = ' . $userId . ' ) )'; if (!empty($this->param['search'])) $where['taskSearch'] = '(task.name like "%' . $this->param['search'] . '%" OR task.description like "%' . $this->param['search'] . '%")'; - $resData = $taskModel->getProjectTaskList($where, $this->param); + $resData = $taskModel->getProjectTaskList($where, $this->param); $data[$k]['is_top'] = $k; - $data[$k]['list'] = $resData['list'] ? : []; - $data[$k]['count'] = $resData['count'] ? : 0; + $data[$k]['list'] = $resData['list'] ?: []; + $data[$k]['count'] = $resData['count'] ?: 0; } return resultArray(['data' => $data]); } - + /** * 我的任务 拖拽改变分类 * @@ -210,23 +310,23 @@ class Task extends ApiCommon * @throws \think\exception\PDOException */ public function updateTop() - { - $param = $this->param; - $tolist = $param['tolist']; + { + $param = $this->param; + $tolist = $param['tolist']; $fromlist = $param['fromlist']; - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskOrder', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + if ($param['to_top_id'] || $param['to_top_id'] == 0) { if ($tolist) { foreach ($tolist as $k1 => $v1) { $toData = []; $toData['is_top'] = $param['to_top_id']; - $toData['top_order_id'] = $k1+1; + $toData['top_order_id'] = $k1 + 1; Db::name('Task')->where(['task_id' => $v1])->update($toData); } } @@ -236,37 +336,37 @@ class Task extends ApiCommon foreach ($fromlist as $k2 => $v2) { $fromData = []; $fromData['is_top'] = $param['from_top_id']; - $fromData['top_order_id'] = $k2+1; + $fromData['top_order_id'] = $k2 + 1; Db::name('Task')->where(['task_id' => $v2])->update($fromData); } } } else { - return resultArray(['error' => '参数错误' ]); + return resultArray(['error' => '参数错误']); } - return resultArray(['data' => true ]); + return resultArray(['data' => true]); } - + /** * 项目 拖拽改变分类并排序 - * @author yykun * @return + * @author yykun */ public function updateOrder() { $param = $this->param; - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskOrder', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + if ($param['tolist']) { $tolist = $param['tolist']; foreach ($tolist as $k1 => $v1) { $toData = []; $toData['class_id'] = $param['toid']; - $toData['order_id'] = $k1+1; + $toData['order_id'] = $k1 + 1; Db::name('Task')->where(['task_id' => $v1])->update($toData); } } @@ -275,13 +375,13 @@ class Task extends ApiCommon foreach ($fromlist as $k2 => $v2) { $fromData = []; $fromData['class_id'] = $param['fromid']; - $fromData['order_id'] = $k2+1; + $fromData['order_id'] = $k2 + 1; Db::name('Task')->where(['task_id' => $v2])->update($fromData); } } - return resultArray(['data' => true ]); + return resultArray(['data' => true]); } - + /** * 项目下 拖拽整个分类排序 * @@ -292,59 +392,59 @@ class Task extends ApiCommon * @throws \think\exception\DbException * @throws \think\exception\PDOException */ - public function updateClassOrder() - { - $param = $this->param; + public function updateClassOrder() + { + $param = $this->param; $classlist = $param['class_ids']; - if (!$param['work_id'] || !$param['class_ids']) { - return resultArray(['error'=>'参数错误']); + if (!$param['work_id'] || !$param['class_ids']) { + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('updateClassOrder', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + foreach ($classlist as $k => $v) { $temp = []; - $temp['order_id'] = $k+1; - Db::name('WorkTaskClass')->where(['work_id' => $param['work_id'],'class_id' => $v])->update($temp); - } - + $temp['order_id'] = $k + 1; + Db::name('WorkTaskClass')->where(['work_id' => $param['work_id'], 'class_id' => $v])->update($temp); + } + return resultArray(['data' => '操作成功!']); - } - + } + /** * 任务详情 - * @author yykun * @return + * @author yykun */ public function read() - { + { $param = $this->param; $userInfo = $this->userInfo; if (!$param['task_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } $taskModel = model('Task'); $taskData = $taskModel->getDataById($param['task_id'], $userInfo); - + # 获取任务的项目信息 $workInfo = Db::name('work')->field(['work_id', 'group_id', 'is_open'])->where('work_id', $taskData['work_id'])->find(); # 是否是公开项目 - $userId = $userInfo['id']; + $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) : []; - + if ($taskData) { - return resultArray(['data'=>$taskData]); + return resultArray(['data' => $taskData]); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 任务编辑 * @@ -357,9 +457,9 @@ class Task extends ApiCommon { $taskModel = model('Task'); $param = $this->param; - $userInfo = $this->userInfo; + $userInfo = $this->userInfo; $param['create_user_id'] = $userInfo['id']; - + # 权限判断 $action = 'updateChildTask'; # 修改子任务 if (!empty($param['customer_ids']) || !empty($param['customer_ids']) || !empty($param['customer_ids']) || !empty($param['customer_ids'])) { @@ -371,82 +471,82 @@ class Task extends ApiCommon header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - - $ary = array('owner_userid_del','owner_userid_add','stop_time','lable_id_add','lable_id_del','name','structure_id_del','structure_id_add'); - if ((in_array($param['type'],$ary))) { - return resultArray(['error'=>'参数错误']); + + $ary = array('owner_userid_del', 'owner_userid_add', 'stop_time', 'lable_id_add', 'lable_id_del', 'name', 'structure_id_del', 'structure_id_add'); + if ((in_array($param['type'], $ary))) { + return resultArray(['error' => '参数错误']); } if ($taskModel->updateDetTask($param)) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } /** * 任务操作记录 - * @author yykun * @return - */ + * @author yykun + */ public function readLoglist() { $param = $this->param; $taskModel = model('Task'); - if (!$param['task_id']) return resultArray(['error'=>'参数错误']); + if (!$param['task_id']) return resultArray(['error' => '参数错误']); $list = $taskModel->getTaskLogList($param); - return resultArray(['data'=>$list]); + return resultArray(['data' => $list]); } - + /** * 优先级设置 - * @author yykun * @return + * @author yykun */ public function updatePriority() { $param = $this->param; $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $param['create_user_id'] = $userInfo['id']; if (!isset($param['priority_id']) || !$param['task_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskPriority', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - - $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->setField('priority',$param['priority_id']); + + $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->setField('priority', $param['priority_id']); if ($flag) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>'操作失败']); + return resultArray(['error' => '操作失败']); } } - + /** - * 参与人/参与部门编辑 - * @author yykun + * 参与人/参与部门编辑 * @return + * @author yykun */ public function updateOwner() { $param = $this->param; $userInfo = $this->userInfo; - $task_id = $param['task_id'] ? : ''; + $task_id = $param['task_id'] ?: ''; $param['create_user_id'] = $userInfo['id']; $taskInfo = db('task')->where(['task_id' => $param['task_id']])->find(); if (!$taskInfo) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskOwnerUser', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $data = []; //部门编辑 $structure_ids = ''; @@ -457,18 +557,18 @@ class Task extends ApiCommon $sendUserArr = []; if ($param['owner_userids']) { $owner_user_id = arrayToString($param['owner_userids']); - foreach ($param['owner_userids'] as $k=>$v) { - if (!in_array($v,stringToArray($taskInfo['owner_user_id']))) { + foreach ($param['owner_userids'] as $k => $v) { + if (!in_array($v, stringToArray($taskInfo['owner_user_id']))) { $sendUserArr[] = $v; - } + } } // $content = $userInfo['realname'].'邀请您参与《'.$taskInfo['name'].'》项目,请及时查看'; // if ($sendUserArr) sendMessage($sendUserArr,$content,1); - actionLog($param['task_id'],$param['owner_user_id'],$param['structure_ids'],'修改了参与人'); - } + actionLog($param['task_id'], $param['owner_user_id'], $param['structure_ids'], '修改了参与人'); + } $data['structure_ids'] = $structure_ids; $data['owner_user_id'] = $owner_user_id; - $resUpdate = db('task')->where(['task_id' => $param['task_id']])->update($data); + $resUpdate = db('task')->where(['task_id' => $param['task_id']])->update($data); if ($resUpdate) { //站内信 if ($sendUserArr) { @@ -481,68 +581,68 @@ class Task extends ApiCommon $sendUserArr ); } - return resultArray(['data'=>'修改成功']); + return resultArray(['data' => '修改成功']); } - return resultArray(['error'=>'修改失败或数据无变化']); + return resultArray(['error' => '修改失败或数据无变化']); } - + /** * 单独删除参与人 - * @author yykun * @return + * @author yykun */ public function delOwnerById() { $taskModel = model('Task'); $userInfo = $this->userInfo; $param = $this->param; - $param['create_user_id'] = $userInfo['id']; - $ary = array('owner_userid_del','owner_userid_add'); + $param['create_user_id'] = $userInfo['id']; + $ary = array('owner_userid_del', 'owner_userid_add'); if (!in_array($param['type'], $ary)) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskOwnerUser', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $ret = $taskModel->updateDetTask($param); if ($ret) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 单独删除参与部门 - * @author yykun * @return + * @author yykun */ public function delStruceureById() { $taskModel = model('Task'); $param = $this->param; $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; - $ary = array('structure_id_del','structure_id_add'); + $param['create_user_id'] = $userInfo['id']; + $ary = array('structure_id_del', 'structure_id_add'); if (!in_array($param['type'], $ary)) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } $res = $taskModel->updateDetTask($param); if ($res) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 设置任务截止时间 - * @author yykun * @return + * @author yykun */ public function updateStoptime() { @@ -553,42 +653,42 @@ class Task extends ApiCommon // if (!$param['stop_time']) { // return resultArray(['error'=>'参数错误']); // } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskTime', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + if ($taskModel->updateDetTask($param)) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 修改任务标签 - * @author yykun * @return + * @author yykun */ public function updateLable() { $taskModel = model('Task'); $param = $this->param; $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; - $ary = array('lable_id_add','lable_id_del'); + $param['create_user_id'] = $userInfo['id']; + $ary = array('lable_id_add', 'lable_id_del'); if (!in_array($param['type'], $ary)) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskLabel', $param['work_id'], $userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + if (isset($param['lable_id_add']) && !is_array($param['lable_id_add'])) { $label_id_arr[] = $param['lable_id_add']; $param['lable_id_add'] = $label_id_arr; @@ -596,43 +696,43 @@ class Task extends ApiCommon if (isset($param['lable_id_del']) && !is_array($param['lable_id_del'])) { $label_id_arr[] = $param['lable_id_del']; $param['lable_id_del'] = $label_id_arr; - } + } if ($taskModel->updateDetTask($param)) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 修改任务名称 - * @author yykun * @return + * @author yykun */ public function updateName() { $taskModel = model('Task'); $param = $this->param; $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $param['create_user_id'] = $userInfo['id']; if ($param['type'] !== 'name') { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('setTaskTitle', $param['work_id'], $userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $res = $taskModel->updateDetTask($param); if ($res) { - return resultArray(['data'=>'操作成功']); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 任务标记结束 * @@ -646,28 +746,28 @@ class Task extends ApiCommon $taskModel = model('Task'); $param = $this->param; $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; - if (!$param['task_id'] || !$param['status'] ){ - return resultArray(['error'=>'参数错误']); + $param['create_user_id'] = $userInfo['id']; + if (!$param['task_id'] || !$param['status']) { + return resultArray(['error' => '参数错误']); } - + # 权限判断 $pid = Db::name('task')->where('task_id', $param['task_id'])->value('pid'); if (!empty($param['work_id']) && !$this->checkWorkOperationAuth(empty($pid) ? 'setTaskStatus' : 'setChildTaskStatus', $param['work_id'], $userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - - $taskInfo = Db::name('Task')->where(['task_id' => $param['task_id']])->find(); + + $taskInfo = Db::name('Task')->where(['task_id' => $param['task_id']])->find(); if ($param['status'] == '5') { - $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->setField('status',5); - if ($flag && !$taskInfo['pid']) { - $temp['user_id'] = $userInfo['id']; - $temp['content'] = '任务标记结束'; - $temp['create_time'] = time(); - $temp['task_id'] = $param['task_id']; - Db::name('WorkTaskLog')->insert($temp); - actionLog($taskInfo['task_id'],$taskInfo['owner_user_id'],$taskInfo['structure_ids'],'任务标记结束'); + $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->setField('status', 5); + if ($flag && !$taskInfo['pid']) { + $temp['user_id'] = $userInfo['id']; + $temp['content'] = '任务标记结束'; + $temp['create_time'] = time(); + $temp['task_id'] = $param['task_id']; + Db::name('WorkTaskLog')->insert($temp); + actionLog($taskInfo['task_id'], $taskInfo['owner_user_id'], $taskInfo['structure_ids'], '任务标记结束'); //抄送站内信 $sendUserArr = []; $sendUserArr[] = $taskInfo['create_user_id']; @@ -675,7 +775,7 @@ class Task extends ApiCommon $sendUserArr[] = $taskInfo['main_user_id']; } if ($taskInfo['owner_user_id']) { - $sendUserArr = $sendUserArr ? array_merge($sendUserArr,stringToArray($taskInfo['owner_user_id'])) : stringToArray($taskInfo['owner_user_id']); + $sendUserArr = $sendUserArr ? array_merge($sendUserArr, stringToArray($taskInfo['owner_user_id'])) : stringToArray($taskInfo['owner_user_id']); } if ($sendUserArr) { (new Message())->send( @@ -687,44 +787,44 @@ class Task extends ApiCommon $sendUserArr ); } - } + } } else { - $flag = Db::name('Task')->where('task_id ='.$param['task_id'])->setField('status',1); - if ($flag && !$taskInfo['pid']) { - $temp['user_id'] = $userInfo['id']; - $temp['content'] = '任务标记开始'; - $temp['create_time'] = time(); - $temp['task_id'] = $param['task_id']; - Db::name('WorkTaskLog')->insert($temp); - actionLog($taskInfo['task_id'],$taskInfo['owner_user_id'],$taskInfo['structure_ids'],'任务标记开始'); - } + $flag = Db::name('Task')->where('task_id =' . $param['task_id'])->setField('status', 1); + if ($flag && !$taskInfo['pid']) { + $temp['user_id'] = $userInfo['id']; + $temp['content'] = '任务标记开始'; + $temp['create_time'] = time(); + $temp['task_id'] = $param['task_id']; + Db::name('WorkTaskLog')->insert($temp); + actionLog($taskInfo['task_id'], $taskInfo['owner_user_id'], $taskInfo['structure_ids'], '任务标记开始'); + } } if ($flag) { - return resultArray(['data' => true ]); + return resultArray(['data' => true]); } else { - return resultArray(['error' => '标记失败' ]); + return resultArray(['error' => '标记失败']); } } - + /** * 日历任务展示/月份 - * @author yykun * @return + * @author yykun */ - public function dateList() + public function dateList() { $param = $this->param; $taskModel = model('Task'); $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; $data = $taskModel->getDateList($param); - return resultArray(['data'=>$data]); + return resultArray(['data' => $data]); } - + /** * 添加任务 - * @author Michael_xu * @return + * @author Michael_xu */ public function save() { @@ -732,11 +832,11 @@ class Task extends ApiCommon $taskModel = model('Task'); $workModel = model('Work'); if (!$param['name']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; - $param['create_user_name'] = $userInfo['realname']; + $userInfo = $this->userInfo; + $param['create_user_id'] = $userInfo['id']; + $param['create_user_name'] = $userInfo['realname']; # 任务权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth(empty($param['pid']) ? 'addChildTask' : 'saveTask', $param['work_id'], $userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); @@ -748,16 +848,16 @@ class Task extends ApiCommon // } $res = $taskModel->createTask($param); if ($res) { - return resultArray(['data'=>$res]); + return resultArray(['data' => $res]); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 删除主负责人 - * @author yykun * @return + * @author yykun */ public function delMainUserId() { @@ -765,180 +865,180 @@ class Task extends ApiCommon $workModel = model('Task'); if ($param['task_id']) { $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; - $taskInfo = Db::name('Task')->where(['task_id' => $param['task_id']])->find(); + $param['create_user_id'] = $userInfo['id']; + $taskInfo = Db::name('Task')->where(['task_id' => $param['task_id']])->find(); $data = []; $data['main_user_id'] = ''; $data['status'] = 1; - $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->update($data); - if ($flag && !$taskInfo['pid']) { - actionLog($taskInfo['task_id'],$taskInfo['owner_user_id'],$taskInfo['structure_ids'],'删除负责人'); - return resultArray(['data'=>'操作成功']); - } - return resultArray(['error'=>'操作失败']); + $flag = Db::name('Task')->where(['task_id' => $param['task_id']])->update($data); + if ($flag && !$taskInfo['pid']) { + actionLog($taskInfo['task_id'], $taskInfo['owner_user_id'], $taskInfo['structure_ids'], '删除负责人'); + return resultArray(['data' => '操作成功']); + } + return resultArray(['error' => '操作失败']); } else { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } } - + /** * 重命名任务 - * @author yykun * @return + * @author yykun */ public function rename() { $param = $this->param; $workModel = model('Work'); if (!$param['rename'] || !$param['work_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $userInfo = $this->userInfo; + $param['create_user_id'] = $userInfo['id']; $flag = $workModel->rename($param); if ($flag) { - return resultArray(['data'=>'编辑成功']); + return resultArray(['data' => '编辑成功']); } else { - return resultArray(['error'=>$workModel->getError()]); + return resultArray(['error' => $workModel->getError()]); } } - + /** * 删除任务 - * @author yykun * @return + * @author yykun */ public function delete() { $param = $this->param; $taskModel = model('Task'); if (!$param['task_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 $pid = Db::name('task')->where('task_id', $param['task_id'])->value('pid'); if (!empty($param['work_id']) && !$this->checkWorkOperationAuth(empty($pid) ? 'deleteTask' : 'deleteChildTask', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $param['create_user_id'] = $userInfo['id']; $flag = $taskModel->delTaskById($param); if ($flag) { - return resultArray(['data'=>'删除成功']); + return resultArray(['data' => '删除成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 归档任务 - * @author yykun * @return + * @author yykun */ public function archive() { $param = $this->param; $taskModel = model('Task'); if (!$param['task_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('archiveTask', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $param['create_user_id'] = $userInfo['id']; $flag = $taskModel->archiveData($param); if ($flag) { - $temp['user_id'] = $userInfo['id']; - $temp['content'] = '归档任务'; - $temp['create_time'] = time(); - $temp['task_id'] = $param['task_id']; - Db::name('WorkTaskLog')->insert($temp); - return resultArray(['data'=>'归档成功']); + $temp['user_id'] = $userInfo['id']; + $temp['content'] = '归档任务'; + $temp['create_time'] = time(); + $temp['task_id'] = $param['task_id']; + Db::name('WorkTaskLog')->insert($temp); + return resultArray(['data' => '归档成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 恢复归档任务 - * @author yykun * @return + * @author yykun */ public function recover() { $param = $this->param; $taskModel = model('Task'); if (!$param['task_id']) { - return resultArray(['error'=>'参数错误']); + return resultArray(['error' => '参数错误']); } - + # 权限判断 if (!empty($param['work_id']) && !$this->checkWorkOperationAuth('archiveTask', $param['work_id'], $this->userInfo['id'])) { header('Content-Type:application/json; charset=utf-8'); exit(json_encode(['code' => 102, 'error' => '无权操作!'])); } - + $userInfo = $this->userInfo; - $param['create_user_id'] = $userInfo['id']; + $param['create_user_id'] = $userInfo['id']; $flag = $taskModel->recover($param); if ($flag) { - $temp['user_id'] = $userInfo['id']; - $temp['content'] = '恢复归档任务'; - $temp['create_time'] = time(); - $temp['task_id'] = $param['task_id']; - Db::name('WorkTaskLog')->insert($temp); - return resultArray(['data'=>'操作成功']); + $temp['user_id'] = $userInfo['id']; + $temp['content'] = '恢复归档任务'; + $temp['create_time'] = time(); + $temp['task_id'] = $param['task_id']; + Db::name('WorkTaskLog')->insert($temp); + return resultArray(['data' => '操作成功']); } else { - return resultArray(['error'=>$taskModel->getError()]); + return resultArray(['error' => $taskModel->getError()]); } } - + /** * 归档任务列表 - * @author yykun * @return + * @author yykun */ public function archList() { $param = $this->param; $userInfo = $this->userInfo; $taskModel = model('Task'); - if (!$param['work_id']) return resultArray(['error'=>'参数错误']); + if (!$param['work_id']) return resultArray(['error' => '参数错误']); $request = []; $request['work_id'] = $param['work_id']; $request['is_archive'] = 1; $list = $taskModel->getTaskList($request); - return resultArray(['data'=>$list]); + return resultArray(['data' => $list]); } - + /** * 归档某一类已完成任务 - * @author yykun * @return + * @author yykun */ public function archiveTask() - { + { $param = $this->param; - if (!$param['class_id']) return resultArray(['error'=>'参数错误']); + if (!$param['class_id']) return resultArray(['error' => '参数错误']); $data = array(); $data['is_archive'] = 1; $data['archive_time'] = time(); - $res = db('task')->where(['class_id' => $param['class_id'],'status' => '5'])->update($data); + $res = db('task')->where(['class_id' => $param['class_id'], 'status' => '5'])->update($data); if ($res) { return resultArray(['data' => '操作成功']); } else { return resultArray(['error' => '暂无已完成任务,归档失败!']); } } - + /** * 任务成员列表 * @@ -950,31 +1050,31 @@ class Task extends ApiCommon public function taskUsers() { $userId = $this->userInfo['id']; - + # 查询条件 $where['create_user_id'] = $userId; - $where['main_user_id'] = $userId; - $where['owner_user_id'] = ['like', '%,'.$userId.',%']; - + $where['main_user_id'] = $userId; + $where['owner_user_id'] = ['like', '%,' . $userId . ',%']; + # 查询数据 $data = Db::name('task')->field(['create_user_id', 'main_user_id', 'owner_user_id'])->whereOr($where)->select(); - + # 整理数据 $userIds = []; - foreach ($data AS $key => $value) { + foreach ($data as $key => $value) { if (!empty($value['create_user_id'])) $userIds[] = $value['create_user_id']; - if (!empty($value['main_user_id'])) $userIds[] = $value['main_user_id']; - + if (!empty($value['main_user_id'])) $userIds[] = $value['main_user_id']; + $ownerUserIds = explode(',', $value['owner_user_id']); - foreach ($ownerUserIds AS $k => $v) { + foreach ($ownerUserIds as $k => $v) { if (!empty($v)) $userIds[] = $v; } } $userIds = array_unique($userIds); - + # 查询参与人 $userList = Db::name('admin_user')->field(['id', 'realname'])->whereIn('id', $userIds)->select(); - + return resultArray(['data' => $userList]); } } \ No newline at end of file diff --git a/application/work/controller/Work.php b/application/work/controller/Work.php index 3e64fb9..fcb912a 100644 --- a/application/work/controller/Work.php +++ b/application/work/controller/Work.php @@ -45,7 +45,8 @@ class work extends ApiCommon 'grouplist', 'addusergroup', 'update', - 'follow' + 'follow', + 'updateWorkOrder' ] ]; Hook::listen('check_auth',$action); @@ -632,25 +633,22 @@ class work extends ApiCommon return resultArray(['data' => '操作成功!']); } - + /** - * 项目排序 + * 项目列表排序 * - * @author alvin guogaobo - * @version 1.0 版本号 - * @since 2021/2/23 0023 15:27 + * @author fanqi + * @date 2021-03-11 + * @param WorkLogic $workLogic */ -// 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'=>'操作成功']); -// } + public function updateWorkOrder(WorkLogic $workLogic) + { + $workIds = $this->param['workIds']; + $userInfo = $this->userInfo; + + $workLogic->setWorkOrder($workIds, $userInfo['id']); + + return resultArray(['data' => '操作成功!']); + } } \ No newline at end of file diff --git a/application/work/logic/WorkLogic.php b/application/work/logic/WorkLogic.php index 3f39a0d..e803c44 100644 --- a/application/work/logic/WorkLogic.php +++ b/application/work/logic/WorkLogic.php @@ -18,21 +18,25 @@ class WorkLogic public function index($param) { # 排序 - $orderField = 'work_id'; + $orderField = 'w.work_id'; $orderSort = 'asc'; if (!empty($param['sort_type']) && $param['sort_type'] == 1) { - $orderField = 'work_id'; + $orderField = 'w.work_id'; $orderSort = 'asc'; } if (!empty($param['sort_type']) && $param['sort_type'] == 2) { - $orderField = 'work_id'; + $orderField = 'w.work_id'; $orderSort = 'desc'; } if (!empty($param['sort_type']) && $param['sort_type'] == 3) { - $orderField = 'update_time'; + $orderField = 'w.update_time'; $orderSort = 'desc'; } - + if (!empty($param['sort_type']) && $param['sort_type'] == 4) { + $orderField = 'o.order'; + $orderSort = 'asc'; + } + # 搜索 $searchWhere = ''; $dateWhere = []; @@ -51,59 +55,90 @@ class WorkLogic switch ($type) { case 1 : # 今天 - $dateWhere['update_time'][] = ['egt', strtotime(date('Y-m-d 00:00:00'))]; - $dateWhere['update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59'))]; + $dateWhere['w.update_time'][] = ['egt', strtotime(date('Y-m-d 00:00:00'))]; + $dateWhere['w.update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59'))]; break; case 2 : # 上周 - $dateWhere['update_time'][] = ['egt', strtotime('last week monday')]; - $dateWhere['update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59', strtotime('last week sunday')))]; + $dateWhere['w.update_time'][] = ['egt', strtotime('last week monday')]; + $dateWhere['w.update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59', strtotime('last week sunday')))]; break; case 3 : # 上月 - $dateWhere['update_time'][] = ['egt', strtotime(date('Y-m-01 00:00:00', strtotime('last month')))]; - $dateWhere['update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59', strtotime('Last day of last month')))]; + $dateWhere['w.update_time'][] = ['egt', strtotime(date('Y-m-01 00:00:00', strtotime('last month')))]; + $dateWhere['w.update_time'][] = ['elt', strtotime(date('Y-m-d 23:59:59', strtotime('Last day of last month')))]; break; case 4 : # 去年 - $dateWhere['update_time'][] = ['egt', strtotime(date('Y-01-01 00:00:00', strtotime('last year')))]; - $dateWhere['update_time'][] = ['elt', strtotime(date('Y-12-31 23:59:59', strtotime('last year')))]; + $dateWhere['w.update_time'][] = ['egt', strtotime(date('Y-01-01 00:00:00', strtotime('last year')))]; + $dateWhere['w.update_time'][] = ['elt', strtotime(date('Y-12-31 23:59:59', strtotime('last year')))]; } # 时间区间 - 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($startTime)) $dateWhere['w.update_time'] = ['egt', strtotime($startTime . '00:00:00')]; + if (!empty($endTime)) $dateWhere['w.update_time'] = ['elt', strtotime($endTime . '23:59:59')]; # 搜索内容 - if ($search) $searchWhere = '(name like "%' . $search . '%") OR (description like "%' . $search . '%")'; + if ($search) $searchWhere = '(w.name like "%' . $search . '%") OR (w.description like "%' . $search . '%")'; # 成员 if (!empty($ownerUserId)) { $userIds = Db::name('work_user')->whereIn('user_id', $ownerUserId)->column('work_id'); - $userWhere['work_id'] = ['in', $userIds]; + $userWhere['w.work_id'] = ['in', $userIds]; } $userModel = new \app\admin\model\User(); $perUserIds = $userModel->getUserByPer('work', 'work', 'index'); $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(); + + if ($param['sort_type'] == 4 && db('work_order')->where('user_id', $param['user_id'])->count() > 0) { + # 选择了按手动拖动排序,并且手动排过序。 + $data = Db::name('work')->alias('w') + ->field('w.*') + ->join('__WORK_ORDER__ o', 'o.work_id = w.work_id', 'left') + ->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('o.user_id', $param['user_id']) + ->where($searchWhere) + ->where($dateWhere) + ->where($userWhere) + ->order($orderField, $orderSort)->select(); + } else { + # 未手动排过序,如果选择了手动排序选项 + if ($param['sort_type'] == 4) { + $orderField = 'w.work_id'; + $orderSort = 'asc'; + } + + $data = Db::name('work')->alias('w') + ->field('w.*') + ->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) { $data[$key]['authList']['project'] = $this->getRuleList($value['work_id'], $param['user_id'], $value['group_id']); @@ -111,94 +146,33 @@ class WorkLogic return $data; } - + /** - * @param $param work 排序数组值 user_id用户 + * 手动设置项目顺序 * - * @author alvin guogaobo - * @version 1.0 版本号 - * @since 2021/2/23 15:42 + * @param $workIds 项目ID数组 + * @param $userId 当前用户ID + * @author fanqi + * @date 2021-03-11 + * @return bool */ -// 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; -// } + public function setWorkOrder($workIds, $userId) + { + $data = []; + + foreach ($workIds AS $key => $value) { + $data[] = [ + 'work_id' => $value, + 'user_id' => $userId, + 'order' => $key + 1 + ]; + } + + if (!empty($data)) { + if (db('work_order')->where('user_id', $userId)->delete() === false) return false; + if (db('work_order')->insertAll($data) === false) return false; + } + + return true; + } } \ No newline at end of file diff --git a/application/work/model/Task.php b/application/work/model/Task.php index 398c633..3564e09 100644 --- a/application/work/model/Task.php +++ b/application/work/model/Task.php @@ -138,6 +138,7 @@ class Task extends Common $map['is_archive'] = 0; $map['main_user_id']=$request['main_user_id']; $taskList = []; + $map['search']=$request['search']; $resTaskList = $this->getTaskList($map); $data[$key]['count'] = $resTaskList['count']; $data[$key]['list'] = $resTaskList['list']; @@ -449,7 +450,7 @@ class Task extends Common 'title' => $param['name'], 'action_id' => $task_id ], - trim(',',$param['owner_user_id']) + stringToArray($param['owner_user_id']) ); } @@ -463,10 +464,10 @@ class Task extends Common 'create_user_id' => $param['create_user_id'], 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '' + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '' ]); } @@ -679,7 +680,7 @@ class Task extends Common } } # 删除活动记录 - Db::name('crm_activity')->where(['activity_type' => 8, 'activity_type_id' => $param['task_id']])->delete(); + Db::name('crm_activity')->where(['activity_type' => 11, 'activity_type_id' => $param['task_id']])->delete(); # 添加活动记录 if (!empty($rdata['customer_ids']) || !empty($rdata['contacts_ids']) || !empty($rdata['business_ids']) || !empty($rdata['contract_ids'])) { Db::name('crm_activity')->insert([ @@ -690,10 +691,10 @@ class Task extends Common 'create_user_id' => $createUserId, 'update_time' => time(), 'create_time' => time(), - 'customer_ids' => !empty($rdata['customer_ids']) ? trim($rdata['customer_ids'], ',') : '', - 'contacts_ids' => !empty($rdata['contacts_ids']) ? trim($rdata['contacts_ids'], ',') : '', - 'business_ids' => !empty($rdata['business_ids']) ? trim($rdata['business_ids'], ',') : '', - 'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '' + 'customer_ids' => !empty($rdata['customer_ids']) ? $rdata['customer_ids'] : '', + 'contacts_ids' => !empty($rdata['contacts_ids']) ? $rdata['contacts_ids'] : '', + 'business_ids' => !empty($rdata['business_ids']) ? $rdata['business_ids'] : '', + 'contract_ids' => !empty($rdata['contract_ids']) ? $rdata['contract_ids'] : '' ]); } return true; @@ -785,6 +786,8 @@ class Task extends Common if (!$taskInfo['pid']) { actionLog($taskInfo['task_id'], $taskInfo['owner_user_id'], $taskInfo['structure_ids'], '删除了任务'); } + # 删除任务的活动记录 + db('crm_activity')->where(['type' => 2, 'activity_type' => 11, 'activity_type_id' => $param['task_id']])->delete(); return true; } else { $this->error = '删除失败'; @@ -906,9 +909,9 @@ class Task extends Common $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['search']); + unset($request['whereStr']); + unset($request['lable_id']); unset($request['main_user_id']); $request = $this->fmtRequest($request); $requestMap = $request['map'] ?: []; @@ -916,11 +919,11 @@ class Task extends Common $lableModel = new \app\work\model\WorkLable(); $map = $requestMap; $map['ishidden'] = $requestMap['ishidden'] ?: 0; + $map = where_arr($map, 'work', 'task', 'index'); if ($search) { //普通筛选 - $map['name'] = ['like', '%' . $search . '%']; + $map['task.name'] = ['like', '%' . $search . '%']; } - $map = where_arr($map, 'work', 'task', 'index'); if ($lable_id) { $map['task.lable_id'] = array('like', '%' . $lable_id . '%'); } diff --git a/config/config.php b/config/config.php index 22b465c..0083508 100644 --- a/config/config.php +++ b/config/config.php @@ -14,7 +14,7 @@ return [ // 应用命名空间 'app_namespace' => 'app', // 应用调试模式 - 'app_debug' => false, + 'app_debug' => true, // 应用Trace 'app_trace' => false, // 应用模式状态 @@ -181,7 +181,7 @@ return [ 'cache' => [ // 驱动方式 - 'type' => 'File', + 'type' => 'redis', // 缓存保存目录 'path' => CACHE_PATH, // 缓存前缀 @@ -190,14 +190,8 @@ return [ 'expire' => 86400*30, // 禁用缓存子目录 'cache_subdir' => false, - 'redis' => [ - 'type' => 'redis', - 'host' => '127.0.0.1', // 全局缓存有效期(0为永久有效) - 'expire'=> 0, - // 缓存前缀 - 'prefix'=> 'think', - - ], + // 密码 + 'password' => '' ], // +---------------------------------------------------------------------- @@ -266,5 +260,12 @@ return [ 'bi_cache_time' => 1800, // 商业智能慢查询查询时间(查询超过该时间进行数据缓存)(毫秒) 'bi_slow_query_time' => 500, - 'public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkqKFcAQtIp4rlkB5LOMnViyVY/hhA6x0R9ftwtEXsAFu4hBZrm9txdEvxSrDCUsx3Zwv/gdimeOzTtfSKffdoE/DwllNP9Zu6nsr2kGRgPrRwjtlO+j2FOM0b9UY1SQ/bWE+a9oQL2jL9xMSbtX1xG/+HcMo1bT+pa6FNQzs3egmvMt75/jaxINPSraj4kgNFawSBk7qDBEqDYiQwtPTuaNW1YZIs++/gZHsCRgGs/JrAbxNpl7+v/+Z503I3I2rs/8eUM5d16NXR8M7vtobUDCTIiQOgRahO8WMadgFlwavyVCYhy/TBXyj5RUfWaS26LrEN3vkj4TjoJu5m9LQ5QIDAQAB', + // 导入缓存时间(秒) + 'import_cache_time' => 1800, + // 导出缓存时间(秒) + 'export_cache_time' => 1800, + // 商机状态组列表缓存时间(秒) + 'business_status_cache_time' => 1800, + + 'public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkqKFcAQtIp4rlkB5LOMnViyVY/hhA6x0R9ftwtEXsAFu4hBZrm9txdEvxSrDCUsx3Zwv/gdimeOzTtfSKffdoE/DwllNP9Zu6nsr2kGRgPrRwjtlO+j2FOM0b9UY1SQ/bWE+a9oQL2jL9xMSbtX1xG/+HcMo1bT+pa6FNQzs3egmvMt75/jaxINPSraj4kgNFawSBk7qDBEqDYiQwtPTuaNW1YZIs++/gZHsCRgGs/JrAbxNpl7+v/+Z503I3I2rs/8eUM5d16NXR8M7vtobUDCTIiQOgRahO8WMadgFlwavyVCYhy/TBXyj5RUfWaS26LrEN3vkj4TjoJu5m9LQ5QIDAQAB', ]; diff --git a/config/route_admin.php b/config/route_admin.php index 4c45a03..f15ea20 100644 --- a/config/route_admin.php +++ b/config/route_admin.php @@ -16,7 +16,11 @@ return [ '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']], + 'admin/install/step6' => ['admin/install/step6', ['method' => 'GET']], + 'admin/install/progress' => ['admin/install/progress', ['method' => 'POST']], + + // 升级公告 + 'admin/adminUser/readNotice' => ['admin/index/readNotice', ['method' => 'POST']], //子部门列表 'admin/structures/subIndex' => ['admin/structures/subIndex', ['method' => 'POST']], diff --git a/config/route_work.php b/config/route_work.php index 0861c16..d195f42 100644 --- a/config/route_work.php +++ b/config/route_work.php @@ -47,7 +47,9 @@ return [ //【项目】删除参与人 'work/work/ownerDel' => ['work/work/ownerDel', ['method' => 'POST']], //【项目】参与人列表 - 'work/work/ownerList' => ['work/work/ownerList', ['method' => 'POST']], + 'work/work/ownerList' => ['work/work/ownerList', ['method' => 'POST']], + //【项目】项目列表排序 + 'work/work/updateWorkOrder' => ['work/work/updateWorkOrder', ['method' => 'POST']], //【我的任务】查看我的任务 'work/task/myTask' => ['work/task/myTask', ['method' => 'POST']], @@ -108,7 +110,7 @@ return [ //【任务】导入 'work/task/excelImport' => ['work/task/excelImport', ['method' => 'POST']], // 【任务】导入模板下载 - 'work/task/excelDownload' => ['crm/customer/excelDownload', ['method' => 'GET']], + 'work/task/excelDownload' => ['work/task/excelDownload', ['method' => 'GET']], //【标签】编辑 'work/tasklable/update' => ['work/tasklable/update', ['method' => 'POST']], diff --git a/config/version.php b/config/version.php index dcf4052..98037f5 100644 --- a/config/version.php +++ b/config/version.php @@ -1,5 +1,5 @@ '11.0.1', -'RELEASE'=>'20210227', +'VERSION'=>'11.0.2', +'RELEASE'=>'20210316', ); \ No newline at end of file diff --git a/public/sql/5kcrm.sql b/public/sql/5kcrm.sql index bd2f171..9dd84e1 100644 --- a/public/sql/5kcrm.sql +++ b/public/sql/5kcrm.sql @@ -311,7 +311,7 @@ CREATE TABLE `5kcrm_admin_record` ( `record_id` int(11) NOT NULL AUTO_INCREMENT, `types` varchar(50) NOT NULL COMMENT '关联类型', `types_id` int(11) NOT NULL COMMENT '类型ID', - `content` varchar(1000) NOT NULL COMMENT '跟进内容', + `content` varchar(1024) DEFAULT NULL COMMENT '跟进内容', `category` varchar(30) NOT NULL DEFAULT '' COMMENT '跟进类型', `next_time` int(11) NOT NULL DEFAULT '0' COMMENT '下次联系时间', `business_ids` varchar(255) NOT NULL DEFAULT '' COMMENT '商机ID', @@ -502,6 +502,7 @@ CREATE TABLE `5kcrm_admin_user` ( `authkey` varchar(32) NOT NULL DEFAULT '' COMMENT '验证信息', `authkey_time` int(11) NOT NULL DEFAULT '0' COMMENT '验证失效时间', `type` tinyint(2) NOT NULL COMMENT '1系统用户 0非系统用户', + `is_read_notice` tinyint(1) NOT NULL DEFAULT 0 COMMENT '用户是否已读升级公告:1已读;0未读', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表'; @@ -558,6 +559,7 @@ CREATE TABLE `5kcrm_crm_business` ( `rw_user_id` varchar(500) NOT NULL DEFAULT '' COMMENT '读写权限', `create_time` int(11) NOT NULL COMMENT '创建时间', `update_time` int(11) NOT NULL COMMENT '更新时间', + `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;', PRIMARY KEY (`business_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商机表'; @@ -738,6 +740,8 @@ CREATE TABLE `5kcrm_crm_customer` ( `next_time` int(11) NOT NULL DEFAULT '0' COMMENT '下次联系时间', `create_time` int(11) NOT NULL COMMENT '创建时间', `update_time` int(11) NOT NULL COMMENT '更新时间', + `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;', + `is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的线索:1是;0不是', PRIMARY KEY (`customer_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客户表'; @@ -765,6 +769,8 @@ CREATE TABLE `5kcrm_crm_leads` ( `next_time` int(11) DEFAULT '0' COMMENT '下次联系时间', `create_time` int(11) NOT NULL COMMENT '创建时间', `update_time` int(11) NOT NULL COMMENT '更新时间', + `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;', + `is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的线索:1是;0不是', PRIMARY KEY (`leads_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='线索表'; @@ -848,6 +854,7 @@ CREATE TABLE `5kcrm_crm_receivables_plan` ( `create_time` int(11) NOT NULL COMMENT '创建时间', `update_time` int(11) NOT NULL COMMENT '更新时间', `file` varchar(500) NOT NULL DEFAULT '' COMMENT '附件', + `is_dealt` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已经处理(待办事项):1已处理;0未处理;', PRIMARY KEY (`plan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='回款计划表'; @@ -1674,7 +1681,7 @@ ALTER TABLE `5kcrm_oa_event_notice` drop COLUMN `repeated`; ALTER TABLE `5kcrm_oa_event_notice` MODIFY COLUMN `noticetype` tinyint(4) unsigned DEFAULT NULL COMMENT '1分 2时 3天'; ALTER TABLE `5kcrm_oa_event_notice` ADD COLUMN `number` tinyint(4) NOT NULL DEFAULT 0 COMMENT '根据noticetype来决定提前多久提醒'; ALTER TABLE `5kcrm_admin_field` ADD COLUMN `is_hidden` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否隐藏:1隐藏;0不隐藏'; -INSERT INTO `5kcrm_admin_field` VALUES (NULL, 'crm_customer', 0, 'email', '邮箱', 'text', '', 0, 0, 0, '', '', 9, 1, 1553788800, 1611144298, 2, '', 0); +INSERT INTO `5kcrm_admin_field` VALUES (NULL, 'crm_customer', 0, 'email', '邮箱', 'email', '', 0, 0, 0, '', '', 9, 1, 1553788800, 1611144298, 2, '', 0); ALTER TABLE `5kcrm_crm_leads` ADD COLUMN `last_time` int(10) unsigned DEFAULT NULL COMMENT '最后跟进时间'; ALTER TABLE `5kcrm_crm_leads` ADD COLUMN `last_record` varchar(512) DEFAULT NULL COMMENT '最后跟进记录'; ALTER TABLE `5kcrm_admin_config` MODIFY COLUMN `controller` varchar(50) DEFAULT NULL COMMENT '控制器'; @@ -1713,7 +1720,7 @@ INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_ty 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', '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', 'satisfaction', '客户满意度', 'select', '', '0', '0', '0', '', '很满意\r\n满意\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'); DROP TABLE IF EXISTS `5kcrm_crm_number_sequence`; @@ -1734,18 +1741,18 @@ CREATE TABLE `5kcrm_crm_number_sequence` ( PRIMARY KEY (`number_sequence_id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT=Dynamic COMMENT='编号规则'; -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('1', '0', '1', 'HT', null, null, null, null, '1607356800', '1', null, '0', '1'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('2', '1', '2', 'yyyyMMdd', null, null, null, null, '1607356800', '1', null, '0', '1'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('3', '2', '3', '1', '1', '1', '43', '1612578239', '1607356800', '1', null, '0', '1'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('4', '1', '1', 'HK', null, null, null, null, '1611627355', '7', null, '0', '2'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('5', '1', '2', 'yyyyMMdd', null, null, null, null, '1611627355', '7', null, '0', '2'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('6', '1', '3', '1', '1', '4', '21', '1612578487', '1611627355', '7', null, '0', '2'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('7', '1', '1', 'HF', null, null, null, null, '1611627355', '7', null, '0', '3'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('8', '1', '2', 'yyyyMMdd', null, null, null, null, '1611627355', '7', null, '0', '3'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('9', '1', '3', '1', '1', '4', '13', '1612519628', '1611627355', '7', null, '0', '3'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('10', '1', '2', 'yyyyMMdd', null, null, null, null, '1612505697', '8', null, '0', '4'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('11', '1', '1', 'FP', null, null, null, null, '1612505750', '8', null, '0', '4'); -INSERT INTO `5kcrm_crm_number_sequence` VALUES ('12', '2', '3', '1', '1', '4', '4', '1612581183', '1612505750', '8', null, '0', '4'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('1', '1', '1', 'HT', null, null, null, null, '1615737600', '1', null, '0', '1'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('2', '2', '2', 'yyyyMMdd', null, null, null, null, '1615737600', '1', null, '0', '1'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('3', '3', '3', '1', '1', '1', '1', '1615737600', '1615737600', '1', null, '0', '1'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('4', '1', '1', 'HK', null, null, null, null, '1615737600', '7', null, '0', '2'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('5', '2', '2', 'yyyyMMdd', null, null, null, null, '1615737600', '7', null, '0', '2'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('6', '3', '3', '1', '1', '1', '1', '1615737600', '1615737600', '7', null, '0', '2'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('7', '1', '1', 'HF', null, null, null, null, '1615737600', '7', null, '0', '3'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('8', '2', '2', 'yyyyMMdd', null, null, null, null, '1615737600', '7', null, '0', '3'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('9', '3', '3', '1', '1', '1', '1', '1615737600', '1615737600', '7', null, '0', '3'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('10', '1', '2', 'yyyyMMdd', null, null, null, null, '1615737600', '8', null, '0', '4'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('11', '2', '1', 'FP', null, null, null, null, '1615737600', '8', null, '0', '4'); +INSERT INTO `5kcrm_crm_number_sequence` VALUES ('12', '3', '3', '1', '1', '1', '1', '1615737600', '1615737600', '8', null, '0', '4'); DROP TABLE IF EXISTS `5kcrm_crm_visit`; CREATE TABLE `5kcrm_crm_visit` ( @@ -1926,6 +1933,11 @@ CREATE TABLE `5kcrm_admin_oalog_rule` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '日报规则表' ROW_FORMAT = Dynamic; +INSERT INTO `5kcrm_admin_oalog_rule` VALUES (1, 4, NULL, NULL, NULL, NULL, 1, 'a:3:{i:0;s:27:\"每一天都是崭新的!\";i:1;s:63:\"蓝天是宁静的,空气是清新的,阳光是明媚的!\";i:2;s:93:\"以下内容为系统默认欢迎语,在日志随机展示,可自定义更改欢迎语。\";}'); +INSERT INTO `5kcrm_admin_oalog_rule` VALUES (2, 1, '3,4,10', '1,2,3,4,5,7,6', '08:00', '21:00', 1, NULL); +INSERT INTO `5kcrm_admin_oalog_rule` VALUES (3, 2, '3,4', NULL, '1', '3', 1, NULL); +INSERT INTO `5kcrm_admin_oalog_rule` VALUES (4, 3, '3', NULL, '3', '8', 1, NULL); + ALTER TABLE `5kcrm_crm_business_type` ADD COLUMN `is_display` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT '软删除:1显示0不显示'; DROP TABLE IF EXISTS `5kcrm_admin_operation_log`; @@ -1956,6 +1968,24 @@ CREATE TABLE `5kcrm_crm_receivables_file` ( PRIMARY KEY (`r_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '回款附件表' ROW_FORMAT = Dynamic; -INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('activity_phrase', 'a:5:{i:0;s:18:\\\"电话无人接听\\\";i:1;s:15:\\\"客户无意向\\\";i:2;s:42:\\\"客户意向度适中,后续继续跟进\\\";i:3;s:42:\\\"客户意向度较强,成交几率较大\\\";i:4;s:3:\\\"312\\\";}', '跟进记录常用语'); +INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('activity_phrase', 'a:4:{i:0;s:18:"电话无人接听";i:1;s:15:"客户无意向";i:2;s:42:"客户意向度适中,后续继续跟进";i:3;s:42:"客户意向度较强,成交几率较大";}', '跟进记录常用语'); INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_config', '1', '是否开启回访提醒:1开启;0不开启'); -INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_day', '10', '客户回访提醒天数'); \ No newline at end of file +INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_day', '10', '客户回访提醒天数'); + +DROP TABLE IF EXISTS `5kcrm_crm_dealt_relation`; +CREATE TABLE `5kcrm_crm_dealt_relation` ( + `dealt_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `types` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '类型:crm_contract;crm_invoice;crm_receivables', + `types_id` int(10) UNSIGNED NOT NULL COMMENT '类型ID', + `user_id` int(10) UNSIGNED NOT NULL COMMENT '用户ID', + PRIMARY KEY (`dealt_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '待办事项关联表' ROW_FORMAT = Dynamic; + +DROP TABLE IF EXISTS `5kcrm_work_order`; +CREATE TABLE `5kcrm_work_order` ( + `order_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `work_id` int(10) UNSIGNED NOT NULL, + `user_id` int(10) UNSIGNED NOT NULL, + `order` int(10) UNSIGNED NOT NULL DEFAULT 1, + PRIMARY KEY (`order_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '项目排序表' ROW_FORMAT = Dynamic; \ No newline at end of file diff --git a/public/sql/update_sql_20210316.sql b/public/sql/update_sql_20210316.sql new file mode 100644 index 0000000..389fd05 --- /dev/null +++ b/public/sql/update_sql_20210316.sql @@ -0,0 +1,31 @@ +ALTER TABLE `5kcrm_crm_leads` ADD COLUMN `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;'; +ALTER TABLE `5kcrm_crm_customer` ADD COLUMN `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;'; +ALTER TABLE `5kcrm_crm_business` ADD COLUMN `is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理(待办事项):1已处理;0未处理;'; +ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `is_dealt` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已经处理(待办事项):1已处理;0未处理;'; + +DROP TABLE IF EXISTS `5kcrm_crm_dealt_relation`; +CREATE TABLE `5kcrm_crm_dealt_relation` ( + `dealt_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `types` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '类型:crm_contract;crm_invoice;crm_receivables', + `types_id` int(10) UNSIGNED NOT NULL COMMENT '类型ID', + `user_id` int(10) UNSIGNED NOT NULL COMMENT '用户ID', + PRIMARY KEY (`dealt_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '待办事项关联表' ROW_FORMAT = Dynamic; + +DROP TABLE IF EXISTS `5kcrm_work_order`; +CREATE TABLE `5kcrm_work_order` ( + `order_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `work_id` int(10) UNSIGNED NOT NULL, + `user_id` int(10) UNSIGNED NOT NULL, + `order` int(10) UNSIGNED NOT NULL DEFAULT 1, + PRIMARY KEY (`order_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '项目排序表' ROW_FORMAT = Dynamic; + +UPDATE `5kcrm_admin_field` SET `form_type`='email' WHERE `types` = 'crm_customer' AND `field` = 'email'; + +ALTER TABLE `5kcrm_crm_leads` ADD COLUMN `is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的线索:1是;0不是'; +ALTER TABLE `5kcrm_crm_customer` ADD COLUMN `is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的线索:1是;0不是'; + +ALTER TABLE `5kcrm_admin_user` ADD COLUMN `is_read_notice` tinyint(1) NOT NULL DEFAULT 0 COMMENT '用户是否已读升级公告:1已读;0未读'; + +ALTER TABLE `5kcrm_crm_activity` MODIFY COLUMN `content` varchar(1024) DEFAULT NULL COMMENT '跟进内容'; diff --git a/public/static/js/step2.js b/public/static/js/step2.js index e54c26c..60a1eb0 100644 --- a/public/static/js/step2.js +++ b/public/static/js/step2.js @@ -70,7 +70,7 @@ $('.next').click(function () { var result = checkForm(); // console.log('result---', result, forms); if (result) { - + $('#cover').css('display', 'block');//显示遮罩层 setTimeout(()=>{ $.ajax({ @@ -81,21 +81,27 @@ $('.next').click(function () { data: { form: forms }, - async: false, + async: true, + timeout: 20000, success: function (result) { if (result.code == '200') { + localStorage.clear(); window.location = 'step5.html'; } else if (result.code == '400') { - $('#cover').css('display', 'none'); - alert(result.error); //失败 - return false; + window.location.href = '/admin/install/step6'; + // $('#cover').css('display', 'none'); + // alert(result.error); //失败 + // return false; // window.location = 'step3.html' } else { - window.location = 'step3.html' - alert('安装失败'); + window.location.href = '/admin/install/step6'; + // window.location = 'step3.html'; + // alert('安装失败'); } + }, + error: function (xhr) { + window.location.href = '/admin/install/step6'; } - // getRes(); }); }) }