diff --git a/application/admin/view/install/step3.html b/application/admin/view/install/step3.html
index 96b813d..d08e8a0 100644
--- a/application/admin/view/install/step3.html
+++ b/application/admin/view/install/step3.html
@@ -16,17 +16,23 @@
-
1
+
+
+
检查安装环境
-
2
+
+
+
创建数据库
-
3
+
+
+
安装成功
diff --git a/application/admin/view/install/step5.html b/application/admin/view/install/step5.html
new file mode 100644
index 0000000..e119ef0
--- /dev/null
+++ b/application/admin/view/install/step5.html
@@ -0,0 +1,64 @@
+
+
+
+
+
+
悟空CRM安装向导
+
+
+
+
+
+
+
+
+
+
+
+
+
+
检查安装环境
+
+
+
+
+
+
+
创建数据库
+
+
+
+
+
+
+
安装成功
+
+
+
+
+
+
+
+
+
恭喜您,已成功安装悟空CRM
+
+
您已经成功安装开源PHP悟空CRM,您可以尽情享用悟空CRM开源版算有功能及服务.
+
使用管理员账号即可登录
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/admin/view/public/footer.html b/application/admin/view/public/footer.html
index ca7601b..283d477 100644
--- a/application/admin/view/public/footer.html
+++ b/application/admin/view/public/footer.html
@@ -1,6 +1,6 @@
diff --git a/application/bi/controller/Examine.php b/application/bi/controller/Examine.php
index 618ec6a..b956eed 100644
--- a/application/bi/controller/Examine.php
+++ b/application/bi/controller/Examine.php
@@ -122,10 +122,11 @@ class Examine extends ApiCommon
unset($where['create_time']);
unset($where['create_user_id']);
unset($where['create_user_id']);
- $where['check_status'] = 'all';
+// $where['check_status'] = 'all';
$where['page'] = $param['page'];
$where['limit'] = $param['limit'];
$where['user_id'] = $user_id;
+ $where['bi_types'] = 'bi';
$where['between_time'] = array($start_time,$end_time);
$list = $examineModel->getDataList($where);
diff --git a/application/common.php b/application/common.php
index da12270..cf58b4c 100644
--- a/application/common.php
+++ b/application/common.php
@@ -165,10 +165,29 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
if (!empty($v['start'])) $v['start'] = date('Y-m-d', $v['start']);
if (!empty($v['end'])) $v['end'] = date('Y-m-d', $v['end']);
}
- if ($v['form_type'] == 'user') {
+ # 创建人、负责人、回访人(非自定义字段)
+ if ($v['form_type'] == 'user' && in_array($k, ['create_user_id', 'owner_user_id'])) {
if ($v['condition'] == 'is') $v['condition'] = 'contains';
}
- if ($types == 'contract') {
+ # 自定义字段的user、structure类型
+ if (($v['form_type'] == 'user' && !in_array($k, ['create_user_id', 'owner_user_id'])) || $v['form_type'] == 'structure') {
+ if ($v['condition'] == 'is') $v['condition'] = 'contains';
+ if ($v['condition'] == 'isNot') {
+ return "(".$c.$k." not like '%".$v['value'][0]."%' OR ".$c.$k." is null)";
+ }
+ }
+ # 处理多选字段的精确搜索
+ if ($v['form_type'] == 'checkbox' && !empty($v['value'])) {
+ if ($v['condition'] == 'is' && count($v['value']) == 1) $v['value'][0] = ',' . $v['value'][0] . ',';
+ if ($v['condition'] == 'is' && count($v['value']) > 1) {
+ $checkboxLike = '';
+ foreach ($v['value'] AS $kk => $vv) {
+ $checkboxLike .= $c.$k." like "."'%".$vv."%' AND ";
+ }
+ return "(".$checkboxLike."LENGTH(".$c.$k.") = LENGTH('".arrayToString($v['value'])."'))";
+ }
+ }
+ if ($types == 'contract' && !empty($v['value'])) {
switch ($k) {
case 'business_id' :
$k = 'name';
@@ -186,11 +205,11 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
break;
}
}
- if ($types == 'receivables' && $v['name'] == '合同编号') {
+ if ($types == 'receivables' && $v['name'] == '合同编号' && !empty($v['value'])) {
$k = 'num';
$c = 'contract.';
}
- if ($types == 'receivables' && $k == 'plan_id') {
+ if ($types == 'receivables' && $k == 'plan_id' && !empty($v['value'])) {
$planIds = [];
foreach ($v['value'] AS $kk => $vv) {
$planIdArray = db('crm_receivables_plan')->whereLike('num', '%' . $vv . '%')->column('plan_id');
@@ -200,17 +219,21 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
}
$v['value'] = array_unique($planIds);
}
- if ($types == 'invoice' && $v['type'] == 'invoice_status') {
+ if ($types == 'invoice' && $v['type'] == 'invoice_status' && !empty($v['value'])) {
foreach ($v['value'] AS $kk => $vv) {
if ($vv == '已开票') $v['value'][$kk] = 1;
if ($vv == '未开票') $v['value'][$kk] = 0;
}
}
- if ($types == 'visit' && $v['type'] == 'contract_name') {
+ if ($types == 'visit' && $v['type'] == 'contract_name' && !empty($v['value'])) {
$k = 'num';
$c = 'contract.';
}
- if ($k == 'check_status' && is_array($v) && in_array($v['value'][0], $checkStatusList)) {
+ if ($types == 'visit' && $v['type'] == 'contacts_name' && !empty($v['value'])) {
+ $k = 'name';
+ $c = 'contacts.';
+ }
+ if ($k == 'check_status' && is_array($v) && in_array($v['value'][0], $checkStatusList) && !empty($v['value'])) {
$v['value'] = $checkStatusArray[$v['value'][0]] ?: '0';
}
if (is_array($v)) {
diff --git a/application/crm/controller/Business.php b/application/crm/controller/Business.php
index 0d3c4a6..ed3f1cb 100644
--- a/application/crm/controller/Business.php
+++ b/application/crm/controller/Business.php
@@ -276,11 +276,6 @@ class Business extends ApiCommon
$errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:无权限;';
continue;
}
- $resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
- if (!$resBusiness) {
- $errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:数据出错;';
- continue;
- }
//团队成员
teamUserId(
@@ -291,7 +286,25 @@ class Business extends ApiCommon
$is_remove,
0
);
-
+
+ $resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
+ if (!$resBusiness) {
+ $errorMessage[] = $businessInfo['name'].'"转移失败,错误原因:数据出错;';
+ continue;
+ } else {
+ $businessArray = [];
+ $teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $business_id)->find();
+ if (!empty($teamBusiness['ro_user_id'])) {
+ $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
+ $businessArray['ro_user_id'] = $businessRo;
+ }
+ if (!empty($teamBusiness['rw_user_id'])) {
+ $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
+ $businessArray['rw_user_id'] = $businessRo;
+ }
+ db('crm_business')->where('business_id', $business_id)->update($businessArray);
+ }
+
//修改记录
updateActionLog($userInfo['id'], 'crm_business', $business_id, '', '', '将商机转移给:'.$ownerUserName);
}
diff --git a/application/crm/controller/Contract.php b/application/crm/controller/Contract.php
index 1f079f2..bd63218 100644
--- a/application/crm/controller/Contract.php
+++ b/application/crm/controller/Contract.php
@@ -214,12 +214,6 @@ class Contract extends ApiCommon
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
}
-
- if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
- //保存为草稿
- $param['check_status'] = 5; //草稿(未提交)
- $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
- } else {
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
//将合同审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流)
@@ -244,7 +238,7 @@ class Contract extends ApiCommon
} else {
$check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
}
- if ($param['is_draft']) {
+ if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿
$param['check_status'] = 5;
$param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
@@ -257,7 +251,7 @@ class Contract extends ApiCommon
}
$param['flow_user_id'] = '';
}
- }
+
if ($contractModel->updateDataById($param, $param['id'])) {
//将审批记录至为无效
@@ -314,7 +308,7 @@ class Contract extends ApiCommon
$isDel = false;
$errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前合同已作废,非超级管理员,不可删除';
}
- if (!in_array($data['check_status'],['0','4','5','6']) && !in_array(1,$adminTypes)) {
+ if (!in_array($data['check_status'], [4, 5]) && !in_array(1,$adminTypes)) {
$isDel = false;
$errorMessage[] = '名称为'.$data['name'].'的合同删除失败,错误原因:当前状态为审批中或已审批通过,不可删除';
}
@@ -335,9 +329,9 @@ class Contract extends ApiCommon
return resultArray(['error' => $contractModel->getError()]);
}
//删除跟进记录
- $recordModel->delDataByTypes('crm_contract',$delIds);
+ $recordModel->delDataByTypes(6,$delIds);
//删除关联附件
- $fileModel->delRFileByModule(6,$delIds);
+ $fileModel->delRFileByModule('crm_contract',$delIds);
//删除关联操作记录
$actionRecordModel->delDataById(['types'=>'crm_contract','action_id'=>$delIds]);
// 删除回款记录
@@ -395,15 +389,10 @@ class Contract extends ApiCommon
$errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:无权限;';
continue;
}
- if (in_array($contractInfo['check_status'],['0','1'])) {
- $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;';
- continue;
- }
- $resContract = db('crm_contract')->where(['contract_id' => $contract_id])->update($data);
- if (!$resContract) {
- $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:数据出错;';
- continue;
- }
+// if (in_array($contractInfo['check_status'],['0','1'])) {
+// $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:待审或审批中,无法转移;';
+// continue;
+// }
//团队成员
teamUserId(
@@ -411,9 +400,29 @@ class Contract extends ApiCommon
$contract_id,
$type,
[$contractInfo['owner_user_id']],
- $is_remove,
+ ($is_remove == 1) ? 1 : '',
0
);
+
+ $resContract = db('crm_contract')->where(['contract_id' => $contract_id])->update($data);
+ if (!$resContract) {
+ $errorMessage[] = $contractInfo['name'].'"转移失败,错误原因:数据出错;';
+ continue;
+ } else {
+ # 处理负责人重复显示在团队成员中的bug
+ $contractArray = [];
+ $teamContract = db('crm_contract')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('contract_id', $contract_id)->find();
+ if (!empty($teamContract['ro_user_id'])) {
+ $contractRo = arrayToString(array_diff(stringToArray($teamContract['ro_user_id']), [$teamContract['owner_user_id']]));
+ $contractArray['ro_user_id'] = $contractRo;
+ }
+ if (!empty($teamContract['rw_user_id'])) {
+ $contractRo = arrayToString(array_diff(stringToArray($teamContract['rw_user_id']), [$teamContract['owner_user_id']]));
+ $contractArray['rw_user_id'] = $contractRo;
+ }
+ db('crm_contract')->where('contract_id', $contract_id)->update($contractArray);
+ }
+
//修改记录
updateActionLog($userInfo['id'], 'crm_contract', $contract_id, '', '', '将合同转移给:'.$ownerUserName);
}
diff --git a/application/crm/controller/Customer.php b/application/crm/controller/Customer.php
index 8e59d91..8506476 100644
--- a/application/crm/controller/Customer.php
+++ b/application/crm/controller/Customer.php
@@ -316,7 +316,20 @@ class Customer extends ApiCommon
if (!$resCustomer) {
$errorMessage[] = $customerInfo['name'].'转移失败,错误原因:数据出错;';
continue;
- }
+ } else {
+ # 处理转移时,负责人出现在只读和读写成员列表中
+ $customerArray = [];
+ $teamCustomer = db('crm_customer')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('customer_id', $customer_id)->find();
+ if (!empty($teamCustomer['ro_user_id'])) {
+ $customerRo = arrayToString(array_diff(stringToArray($teamCustomer['ro_user_id']), [$teamCustomer['owner_user_id']]));
+ $customerArray['ro_user_id'] = $customerRo;
+ }
+ if (!empty($teamCustomer['rw_user_id'])) {
+ $customerRo = arrayToString(array_diff(stringToArray($teamCustomer['rw_user_id']), [$teamCustomer['owner_user_id']]));
+ $customerArray['rw_user_id'] = $customerRo;
+ }
+ db('crm_customer')->where('customer_id', $customer_id)->update($customerArray);
+ }
if (in_array('crm_contacts',$types)) {
$contactsIds = [];
@@ -339,7 +352,7 @@ class Customer extends ApiCommon
if ($resBusiness !== true) {
$errorMessage = $errorMessage ? array_merge($errorMessage,$resBusiness) : $resBusiness;
continue;
- }
+ }
}
}
@@ -677,7 +690,7 @@ class Customer extends ApiCommon
$file = request()->file('file');
// $res = $excelModel->importExcel($file, $param, $this);
$res = $excelModel->batchImportData($file, $param, $this);
- return resultArray(['data' => '导入成功']);
+ return resultArray(['data' => $excelModel->getError()]);
}
/**
diff --git a/application/crm/controller/Invoice.php b/application/crm/controller/Invoice.php
index 8606196..ee77c45 100644
--- a/application/crm/controller/Invoice.php
+++ b/application/crm/controller/Invoice.php
@@ -315,6 +315,8 @@ class Invoice extends ApiCommon
*/
public function delete(InvoiceLogic $invoiceLogic)
{
+ $actionRecordModel = new \app\admin\model\ActionRecord();
+ $fileModel = new \app\admin\model\File();
$idArray = $this->param['id'];
$userinfo = $this->userInfo['id'];
@@ -326,7 +328,7 @@ class Invoice extends ApiCommon
if (!isSuperAdministrators($userinfo['id'])) {
$list = $invoiceLogic->getExamineStatus($idString, true);
foreach ($list AS $key => $value) {
- if (!in_array($value['check_status'], ['3', '4', '5', '6'])) {
+ if (!in_array($value['check_status'], [4, 5])) {
$status = false;
break;
}
@@ -338,8 +340,9 @@ class Invoice extends ApiCommon
if (!$invoiceLogic->delete($idArray)) return resultArray(['error' => '删除失败!']);
# 删除附件
- $fileModel = new \app\admin\model\File();
$fileModel->delRFileByModule('crm_invoice', $idArray);
+ //删除关联操作记录
+ $actionRecordModel->delDataById(['types'=>'crm_invoice','action_id'=>$idArray]);
return resultArray(['data' => '删除成功!']);
}
diff --git a/application/crm/controller/Leads.php b/application/crm/controller/Leads.php
index 407012f..6314ed9 100644
--- a/application/crm/controller/Leads.php
+++ b/application/crm/controller/Leads.php
@@ -226,7 +226,8 @@ class Leads extends ApiCommon
$data['deal_time'] = time();
$data['create_time'] = time();
$data['update_time'] = time();
- $data['next_time'] = $leadsInfo['next_time'] ? date('Y-m-d H:i:s', $leadsInfo['next_time']) : 0;
+ $data['next_time'] = $leadsInfo['next_time'];
+ if (empty($data['telephone'])) $data['telephone'] = 0;
# 获取客户的时间
$data['obtain_time'] = time();
//权限判断
@@ -404,6 +405,9 @@ class Leads extends ApiCommon
$file = request()->file('file');
// $res = $excelModel->importExcel($file, $param);
$res = $excelModel->batchImportData($file, $param, $this);
+ if (!$res) {
+ return resultArray(['error' => $excelModel->getError()]);
+ }
return resultArray(['data' => $excelModel->getError()]);
}
diff --git a/application/crm/controller/Product.php b/application/crm/controller/Product.php
index 2bcb30c..8cd4c32 100644
--- a/application/crm/controller/Product.php
+++ b/application/crm/controller/Product.php
@@ -10,6 +10,7 @@ namespace app\crm\controller;
use app\admin\controller\ApiCommon;
use app\crm\model\Product as ProductModel;
use app\admin\model\File as FileModel;
+use app\admin\model\ActionRecord as ActionRecordModel;
use think\Db;
use think\Hook;
use think\Request;
@@ -294,6 +295,8 @@ class Product extends ApiCommon
ProductModel::commit();
// 删除关联附件
(new FileModel)->delRFileByModule('crm_product', $delIds);
+ // 操作记录
+ (new ActionRecordModel)->delDataById('crm_product', $delIds);
// 添加删除记录
actionLog($delIds, '', '', '');
return resultArray(['data' => '删除成功']);
diff --git a/application/crm/controller/Receivables.php b/application/crm/controller/Receivables.php
index e40e8ad..07d5f49 100644
--- a/application/crm/controller/Receivables.php
+++ b/application/crm/controller/Receivables.php
@@ -19,42 +19,79 @@ use think\Db;
class Receivables extends ApiCommon
{
use AutoNumberTrait;
-
+
/**
* 用于判断权限
* @permission 无限制
* @allow 登录用户可访问
* @other 其他根据系统设置
- **/
+ **/
public function _initialize()
{
$action = [
- 'permission'=>[''],
- 'allow'=>['check','revokecheck','system','count']
+ 'permission' => [''],
+ 'allow' => ['check', 'revokecheck', 'system', 'count']
];
- Hook::listen('check_auth',$action);
+ Hook::listen('check_auth', $action);
$request = Request::instance();
- $a = strtolower($request->action());
+ $a = strtolower($request->action());
if (!in_array($a, $action['permission'])) {
parent::_initialize();
}
- }
-
+ }
+
/**
* 回款列表
+ * @return
* @author Michael_xu
- * @return
*/
public function index()
{
$receivablesModel = model('Receivables');
$param = $this->param;
$userInfo = $this->userInfo;
- $param['user_id'] = $userInfo['id'];
- $data = $receivablesModel->getDataList($param);
+ $param['user_id'] = $userInfo['id'];
+ $data = $receivablesModel->getDataList($param);
return resultArray(['data' => $data]);
}
-
+
+ /**
+ * 导出
+ * @param
+ * @return
+ * @author guogaobo
+ */
+ public function excelExport()
+ {
+ $param = $this->param;
+ $userInfo = $this->userInfo;
+ $param['user_id'] = $userInfo['id'];
+ if ($param['receivables_id']) {
+ $param['receivables_id'] = ['condition' => 'in', 'value' => $param['receivables_id'], 'form_type' => 'text', 'name' => ''];
+ $param['is_excel'] = 1;
+ }
+ $excelModel = new \app\admin\model\Excel();
+ // 导出的字段列表
+ $fieldModel = new \app\admin\model\Field();
+ $field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id']);
+ // 文件名
+ $file_name = '5kcrm_receivables_' . date('Ymd');
+
+ $model = model('Receivables');
+ $temp_file = $param['temp_file'];
+ unset($param['temp_file']);
+ $page = $param['page'] ?: 1;
+ unset($param['page']);
+ unset($param['export_queue_index']);
+ return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
+ $param['page'] = $page;
+ $param['limit'] = $limit;
+ $data = $model->getDataList($param);
+ $data['list'] = $model->exportHandle($data['list'], $field_list, 'Receivables');
+ return $data;
+ });
+ }
+
/**
* 添加回款
*
@@ -69,7 +106,7 @@ class Receivables extends ApiCommon
$param['owner_user_id'] = $userInfo['id'];
$examineStatus = $param['examineStatus']; // 审批是否停用
unset($param['examineStatus']);
-
+
# 自动设置回款编号
$numberInfo = [];
if (empty($param['number'])) {
@@ -80,39 +117,39 @@ class Receivables extends ApiCommon
if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿
$param['check_status'] = 5; //草稿(未提交)
- $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
- } else {
- if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
- //审核判断(是否有符合条件的审批流)
- $examineFlowModel = new \app\admin\model\ExamineFlow();
- if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) {
- return resultArray(['error' => '暂无审批人,无法创建']);
- }
- //添加审批相关信息
- $examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables');
- if (!$examineFlowData) {
- return resultArray(['error' => '无可用审批流,请联系管理员']);
- }
- $param['flow_id'] = $examineFlowData['flow_id'];
- //获取审批人信息
- if ($examineFlowData['config'] == 1) {
- //固定审批流
- $nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
- $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
- $check_user_id = $next_user_ids ? : [];
- $param['order_id'] = 1;
- } else {
- $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
- }
- if (!$check_user_id) {
- return resultArray(['error' => '无可用审批人,请联系管理员']);
- }
- $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
+ $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
+ }
+ if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
+ //审核判断(是否有符合条件的审批流)
+ $examineFlowModel = new \app\admin\model\ExamineFlow();
+ if (!$examineFlowModel->checkExamine($param['owner_user_id'], 'crm_receivables')) {
+ return resultArray(['error' => '暂无审批人,无法创建']);
+ }
+ //添加审批相关信息
+ $examineFlowData = $examineFlowModel->getFlowByTypes($param['owner_user_id'], 'crm_receivables');
+ if (!$examineFlowData) {
+ return resultArray(['error' => '无可用审批流,请联系管理员']);
+ }
+ $param['flow_id'] = $examineFlowData['flow_id'];
+ //获取审批人信息
+ if ($examineFlowData['config'] == 1) {
+ //固定审批流
+ $nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
+ $next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
+ $check_user_id = $next_user_ids ?: [];
+ $param['order_id'] = 1;
} else {
- # 审批流停用,将状态改为审核通过
- $param['check_status'] = 2;
+ $check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
+ if (!$check_user_id) {
+ return resultArray(['error' => '无可用审批人,请联系管理员']);
+ }
+ $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
+ } else {
+ # 审批流停用,将状态改为审核通过
+ $param['check_status'] = 2;
}
+
$res = $receivablesModel->createData($param);
if ($res) {
//回款计划关联
@@ -121,18 +158,18 @@ class Receivables extends ApiCommon
}
# 更新crm_number_sequence表中的last_date、create_time字段
if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
-
+
return resultArray(['data' => '添加成功']);
} else {
return resultArray(['error' => $receivablesModel->getError()]);
}
}
-
+
/**
* 回款详情
+ * @param
+ * @return
* @author Michael_xu
- * @param
- * @return
*/
public function read()
{
@@ -140,27 +177,27 @@ class Receivables extends ApiCommon
$userModel = new \app\admin\model\User();
$param = $this->param;
$data = $receivablesModel->getDataById($param['id']);
-
+
//判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'read');
- if (!in_array($data['owner_user_id'],$auth_user_ids)) {
+ if (!in_array($data['owner_user_id'], $auth_user_ids)) {
$authData['dataAuth'] = 0;
return resultArray(['data' => $authData]);
- }
+ }
if (!$data) {
return resultArray(['error' => $receivablesModel->getError()]);
}
return resultArray(['data' => $data]);
}
-
+
/**
* 编辑回款
+ * @param
+ * @return
* @author Michael_xu
- * @param
- * @return
*/
public function update()
- {
+ {
$receivablesModel = model('Receivables');
$userModel = new \app\admin\model\User();
$param = $this->param;
@@ -171,11 +208,11 @@ class Receivables extends ApiCommon
//判断权限
$dataInfo = $receivablesModel->getDataById($param['id']);
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'update');
- if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
+ if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
header('Content-Type:application/json; charset=utf-8');
- exit(json_encode(['code'=>102,'error'=>'无权操作']));
+ exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
-
+
# 自动设置回款编号
$numberInfo = [];
if (empty($param['number'])) {
@@ -183,22 +220,22 @@ class Receivables extends ApiCommon
if (empty($numberInfo['number'])) return resultArray(['error' => '请填写回款编号!']);
$param['number'] = $numberInfo['number'];
}
-
+
//已进行审批,不能编辑
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) {
return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
}
-
+
if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
//保存为草稿
$param['check_status'] = 5; //草稿(未提交)
- $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
+ $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} else {
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
if ($param['is_draft']) {
//保存为草稿
$param['check_status'] = 5;
- $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
+ $param['check_user_id'] = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
} else {
//将回款审批状态至为待审核,提交后重新进行审批
//审核判断(是否有符合条件的审批流)
@@ -217,47 +254,50 @@ class Receivables extends ApiCommon
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $examineFlowData['flow_id'], 'crm_receivables', 0, 0, 0);
- $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
- $check_user_id = $next_user_ids ? : [];
+ $next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
+ $check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1;
} else {
- $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
+ $check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (!$check_user_id) {
return resultArray(['error' => '无可用审批人,请联系管理员']);
}
- $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
+ $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
$param['check_status'] = 0;
$param['flow_user_id'] = '';
}
}
}
-
+
$res = $receivablesModel->updateDataById($param, $param['id']);
if ($res) {
//将审批记录至为无效
$examineRecordModel = new \app\admin\model\ExamineRecord();
- $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]);
+ $examineRecordModel->setEnd(['types' => 'crm_receivables', 'types_id' => $param['id']]);
# 更新crm_number_sequence表中的last_date、create_time字段
if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
-
+
return resultArray(['data' => '编辑成功']);
} else {
return resultArray(['error' => $receivablesModel->getError()]);
- }
+ }
}
-
+
/**
* 删除回款
+ * @param
+ * @return
* @author Michael_xu
- * @param
- * @return
*/
public function delete()
{
+ $actionRecordModel = new \app\admin\model\ActionRecord();
+ $fileModel = new \app\admin\model\File();
+ $recordModel = new \app\admin\model\Record();
$receivablesModel = model('Receivables');
$param = $this->param;
- $userInfo = $this->userInfo;
+ $userInfo = $this->userInfo;
if (!is_array($param['id'])) {
$receivables_id = [$param['id']];
} else {
@@ -265,61 +305,68 @@ class Receivables extends ApiCommon
}
$delIds = [];
$errorMessage = [];
-
+
//数据权限判断
$userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'delete');
$adminTypes = adminGroupTypes($userInfo['id']);
- foreach ($receivables_id as $k=>$v) {
+ foreach ($receivables_id as $k => $v) {
$isDel = true;
//数据详情
$data = $receivablesModel->getDataById($v);
if (!$data) {
$isDel = false;
- $errorMessage[] = 'id为'.$v.'的回款删除失败,错误原因:'.$receivablesModel->getError();
+ $errorMessage[] = 'id为' . $v . '的回款删除失败,错误原因:' . $receivablesModel->getError();
continue;
}
- if (!in_array($data['owner_user_id'],$auth_user_ids)) {
+ if (!in_array($data['owner_user_id'], $auth_user_ids)) {
$isDel = false;
- $errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:无权操作';
+ $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:无权操作';
continue;
}
- if (!in_array($data['check_status'],['0','4','5']) && !in_array(1,$adminTypes)) {
+ if (!in_array($data['check_status'], [4, 5]) && !in_array(1, $adminTypes)) {
$isDel = false;
- $errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:请先撤销审核';
+ $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:请先撤销审核';
continue;
}
if ($isDel) {
if (db('crm_receivables_plan')->where('receivables_id', $v)->value('plan_id')) {
$isDel = false;
- $errorMessage[] = '名称为'.$data['number'].'的回款删除失败,错误原因:回款已关联回款计划,不能删除!';
+ $errorMessage[] = '名称为' . $data['number'] . '的回款删除失败,错误原因:回款已关联回款计划,不能删除!';
continue;
- }
+ }
}
if ($isDel) {
$delIds[] = $v;
- }
+ }
}
if ($delIds) {
$data = $receivablesModel->delDatas($delIds);
if (!$data) {
return resultArray(['error' => $receivablesModel->getError()]);
- }
- actionLog($delIds,'','','');
+ }
+ //删除跟进记录
+ $recordModel->delDataByTypes(7,$delIds);
+ # 删除附件
+ $fileModel->delRFileByModule('crm_receivables', $delIds);
+ //删除关联操作记录
+ $actionRecordModel->delDataById(['types' => 'crm_receivables', 'action_id' => $delIds]);
+ actionLog($delIds, '', '', '');
}
+
if ($errorMessage) {
return resultArray(['error' => $errorMessage]);
} else {
return resultArray(['data' => '删除成功']);
- }
- }
-
+ }
+ }
+
/**
* 回款审核
- * @author Michael_xu
- * @param
+ * @param
* @return
- */
+ * @author Michael_xu
+ */
public function check()
{
$param = $this->param;
@@ -329,19 +376,19 @@ class Receivables extends ApiCommon
$examineStepModel = new \app\admin\model\ExamineStep();
$examineRecordModel = new \app\admin\model\ExamineRecord();
$examineFlowModel = new \app\admin\model\ExamineFlow();
-
+
$receivablesData = [];
$receivablesData['update_time'] = time();
$receivablesData['check_status'] = 1; //0待审核,1审核通中,2审核通过,3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_receivables', $param['id'])) {
- return resultArray(['error' => $examineStepModel->getError()]);
+ return resultArray(['error' => $examineStepModel->getError()]);
};
//审批主体详情
$dataInfo = $receivablesModel->getDataById($param['id']);
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
$is_end = 0; // 1审批结束
-
+
$status = $param['status'] ? 1 : 0; //1通过,0驳回
$checkData = [];
$checkData['check_user_id'] = $user_id;
@@ -350,7 +397,7 @@ class Receivables extends ApiCommon
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
- $checkData['order_id'] = $dataInfo['order_id'] ? : 1;
+ $checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status;
if ($status == 1) {
@@ -358,8 +405,8 @@ class Receivables extends ApiCommon
//固定流程
//获取下一审批信息
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_receivables', $param['id'], $dataInfo['order_id'], $user_id);
- $next_user_ids = $nextStepData['next_user_ids'] ? : [];
- $receivablesData['order_id'] = $nextStepData['order_id'] ? : '';
+ $next_user_ids = $nextStepData['next_user_ids'] ?: [];
+ $receivablesData['order_id'] = $nextStepData['order_id'] ?: '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
@@ -368,21 +415,21 @@ class Receivables extends ApiCommon
} else {
//修改主体相关审批信息
$receivablesData['check_user_id'] = arrayToString($next_user_ids);
- }
+ }
} else {
//自选流程
$is_end = $param['is_end'] ? 1 : '';
- $check_user_id = $param['check_user_id'] ? : '';
+ $check_user_id = $param['check_user_id'] ?: '';
if ($is_end !== 1 && empty($check_user_id)) {
- return resultArray(['error' => '请选择下一审批人']);
+ return resultArray(['error' => '请选择下一审批人']);
}
$receivablesData['check_user_id'] = arrayToString($param['check_user_id']);
- }
+ }
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$receivablesData['check_user_id'] = '';
$receivablesData['check_status'] = 2;
- }
+ }
} else {
//审批驳回
$is_end = 1;
@@ -391,7 +438,7 @@ class Receivables extends ApiCommon
// $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]);
}
//已审批人ID
- $receivablesData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]);
+ $receivablesData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$resReceivables = db('crm_receivables')->where(['receivables_id' => $param['id']])->update($receivablesData);
if ($resReceivables) {
if ($status) {
@@ -416,33 +463,33 @@ class Receivables extends ApiCommon
$dataInfo['owner_user_id']
);
}
-
+
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
if ($is_end == 1 && !empty($status)) {
//发送站内信 通过
(new Message())->send(
- Message::RECEIVABLES_PASS,
- [
- 'title' => $dataInfo['number'],
- 'action_id' => $param['id']
- ],
- $dataInfo['owner_user_id']
- );
+ Message::RECEIVABLES_PASS,
+ [
+ 'title' => $dataInfo['number'],
+ 'action_id' => $param['id']
+ ],
+ $dataInfo['owner_user_id']
+ );
}
- return resultArray(['data' => '审批成功']);
+ return resultArray(['data' => '审批成功']);
} else {
- return resultArray(['error' => '审批失败,请重试!']);
+ return resultArray(['error' => '审批失败,请重试!']);
}
}
-
+
/**
* 回款撤销审核
- * @author Michael_xu
- * @param
+ * @param
* @return
- */
+ * @author Michael_xu
+ */
public function revokeCheck()
{
$param = $this->param;
@@ -453,23 +500,23 @@ class Receivables extends ApiCommon
$examineRecordModel = new \app\admin\model\ExamineRecord();
$customerModel = model('Customer');
$userModel = new \app\admin\model\User();
-
+
$receivablesData = [];
$receivablesData['update_time'] = time();
$receivablesData['check_status'] = 0; //0待审核,1审核通中,2审核通过,3审核未通过
//审批主体详情
- $dataInfo = $receivablesModel->getDataById($param['id']);
+ $dataInfo = $receivablesModel->getDataById($param['id']);
//权限判断(创建人或负责人或管理员)
if ($dataInfo['check_status'] == 2) {
- return resultArray(['error' => '已审批结束,不能撤销']);
- }
+ return resultArray(['error' => '已审批结束,不能撤销']);
+ }
if ($dataInfo['check_status'] == 4) {
- return resultArray(['error' => '无需撤销']);
- }
- $admin_user_ids = $userModel->getAdminId();
+ return resultArray(['error' => '无需撤销']);
+ }
+ $admin_user_ids = $userModel->getAdminId();
if ($dataInfo['owner_user_id'] !== $user_id && !in_array($user_id, $admin_user_ids)) {
return resultArray(['error' => '没有权限']);
- }
+ }
$is_end = 0; // 1审批结束
$status = 2; //1通过,0驳回, 2撤销
@@ -492,12 +539,12 @@ class Receivables extends ApiCommon
// $examineRecordModel->setEnd(['types' => 'crm_receivables','types_id' => $param['id']]);
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
- return resultArray(['data' => '撤销成功']);
+ return resultArray(['data' => '撤销成功']);
} else {
- return resultArray(['error' => '撤销失败,请重试!']);
+ return resultArray(['error' => '撤销失败,请重试!']);
}
}
-
+
/**
* 转移
*
@@ -505,50 +552,50 @@ class Receivables extends ApiCommon
*/
public function transfer()
{
- $param = $this->param;
- $userInfo = $this->userInfo;
+ $param = $this->param;
+ $userInfo = $this->userInfo;
$receivablesModel = model('Receivables');
-
+
$userModel = new \app\admin\model\User();
- $authIds = $userModel->getUserByPer();
-
+ $authIds = $userModel->getUserByPer();
+
if (empty($param['owner_user_id'])) return resultArray(['error' => '变更负责人不能为空']);
if (empty($param['receivables_id']) || !is_array($param['receivables_id'])) return resultArray(['error' => '请选择需要转移的回款']);
-
+
$owner_user_info = $userModel->getUserById($param['owner_user_id']);
-
+
$data = [
'owner_user_id' => $param['owner_user_id'],
- 'update_time' => time(),
+ 'update_time' => time(),
];
-
+
$errorMessage = [];
foreach ($param['receivables_id'] as $receivables_id) {
$receivables_info = $receivablesModel->getDataById($receivables_id);
if (!$receivables_info) {
- $errorMessage[] = 'id:为《'.$receivables_id.'》的回款转移失败,错误原因:数据不存在;';
+ $errorMessage[] = 'id:为《' . $receivables_id . '》的回款转移失败,错误原因:数据不存在;';
continue;
}
-
+
# 转移至当前负责人的直接跳过
if ($param['owner_user_id'] == $receivables_info['owner_user_id']) continue;
-
+
if (!in_array($receivables_info['owner_user_id'], $authIds)) {
- $errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:无权限;';
+ $errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:无权限;';
continue;
}
-
- if (in_array($receivables_info['check_status'],['0','1'])) {
- $errorMessage[] = $receivables_info['number'].'转移失败,错误原因:待审或审批中,无法转移;';
+
+ if (in_array($receivables_info['check_status'], ['0', '1'])) {
+ $errorMessage[] = $receivables_info['number'] . '转移失败,错误原因:待审或审批中,无法转移;';
continue;
}
-
+
$res = $receivablesModel->where(['receivables_id' => $receivables_id])->update($data);
if (!$res) {
- $errorMessage[] = $receivables_info['number'].'"转移失败,错误原因:数据出错;';
+ $errorMessage[] = $receivables_info['number'] . '"转移失败,错误原因:数据出错;';
continue;
}
- updateActionLog($userInfo['id'], 'crm_receivables', $receivables_id, '', '', '将回款转移给:' . $owner_user_info['realname']);
+ updateActionLog($userInfo['id'], 'crm_receivables', $receivables_id, '', '', '将回款转移给:' . $owner_user_info['realname']);
}
if (!$errorMessage) {
return resultArray(['data' => '转移成功']);
@@ -556,7 +603,7 @@ class Receivables extends ApiCommon
return resultArray(['error' => $errorMessage]);
}
}
-
+
/**
* 系统信息
*
@@ -568,14 +615,14 @@ class Receivables extends ApiCommon
public function system()
{
if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
-
+
$receivablesModel = new \app\crm\model\Receivables();
-
+
$data = $receivablesModel->getSystemInfo($this->param['id']);
-
+
return resultArray(['data' => $data]);
}
-
+
/**
* table标签栏数量
*
@@ -587,10 +634,10 @@ class Receivables extends ApiCommon
public function count()
{
if (empty($this->param['receivables_id'])) return resultArray(['error' => '参数错误!']);
-
+
# 附件
$fileCount = Db::name('crm_receivables_file')->alias('receivables')->join('__ADMIN_FILE__ file', 'file.file_id = receivables.file_id', 'LEFT')->where('receivables_id', $this->param['receivables_id'])->count();
-
+
return resultArray(['data' => ['fileCount' => $fileCount]]);
}
}
diff --git a/application/crm/controller/Visit.php b/application/crm/controller/Visit.php
index 8787cd0..41f9801 100644
--- a/application/crm/controller/Visit.php
+++ b/application/crm/controller/Visit.php
@@ -68,9 +68,8 @@ class Visit extends ApiCommon
if (empty($numberInfo['number'])) return resultArray(['error' => '请填写回访编号!']);
$param['number'] = $numberInfo['number'];
}
- $param['owner_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
+ $param['owner_user_id'] = $param['owner_user_id'] ? : $userInfo['id'];
$param['create_user_id'] = $userInfo['id'];
- $param['visit_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
$param['update_time'] = time();
$res = $Visit->createData($param);
if ($res) {
@@ -119,8 +118,7 @@ class Visit extends ApiCommon
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id'];
- $param['owner_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
- $param['visit_user_id'] = $param['visit_user_id'] ? : $userInfo['id'];
+ $param['owner_user_id'] = $param['owner_user_id'] ? : $userInfo['id'];
# 设置回访编号
$numberInfo = [];
if (empty($param['number'])) {
diff --git a/application/crm/logic/ActivityLogic.php b/application/crm/logic/ActivityLogic.php
index 7c6ab64..080b71f 100644
--- a/application/crm/logic/ActivityLogic.php
+++ b/application/crm/logic/ActivityLogic.php
@@ -359,8 +359,9 @@ class ActivityLogic
$fileModel = new \app\admin\model\File();
foreach ($dataArray AS $key => $value) {
# 用户信息 todo 有模型文件,时间问题,暂时将查询写在循环中
- $realname = Db::name('admin_user')->where('id', $dataArray[$key]['create_user_id'])->value('realname');
- $dataArray[$key]['create_user_name'] = $realname;
+ $realname = Db::name('admin_user')->where('id', $dataArray[$key]['create_user_id'])->find();
+ $dataArray[$key]['create_user_name'] = $realname['realname'];
+ $dataArray[$key]['thumb_img'] = $realname['thumb_img'] ? getFullPath($realname['thumb_img']) : '';;
# 附件信息
if ($value['type'] = 1) {
@@ -785,7 +786,7 @@ class ActivityLogic
# 审批
if ($activityType == 9) {
$categoryId = Db::name('oa_examine')->where('examine_id', $activityTypeId)->value('category_id');
- $activityTypeName = Db::name('oa_examine_category')->where('category_id', $categoryId);
+ $activityTypeName = Db::name('oa_examine_category')->where('category_id', $categoryId)->value('title');
}
# 日程
if ($activityType == 10) {
diff --git a/application/crm/logic/CommonLogic.php b/application/crm/logic/CommonLogic.php
index 9ba4037..61773a6 100644
--- a/application/crm/logic/CommonLogic.php
+++ b/application/crm/logic/CommonLogic.php
@@ -12,11 +12,12 @@ use app\admin\controller\ApiCommon;
use app\admin\model\User;
use app\crm\model\Customer;
use think\Db;
+use think\Validate;
class CommonLogic
{
public $error = '操作失败!';
-
+
/**
* 快捷编辑【线索、客户、联系人、商机、合同、回款、回访、产品】
*
@@ -37,56 +38,113 @@ class CommonLogic
* $param['name'] 字段中文名,用作提示
* $param['value] 字段值
*/
-
+
$actionId = $param['action_id'];
- $types = $param['types'];
+ $types = $param['types'];
unset($param['action_id']);
unset($param['types']);
-
+
# 模型
$model = db($types);
-
+
# 主键
$primaryKey = '';
- if ($types == 'crm_leads') $primaryKey = 'leads_id';
- if ($types == 'crm_customer') $primaryKey = 'customer_id';
- if ($types == 'crm_contacts') $primaryKey = 'contacts_id';
- if ($types == 'crm_business') $primaryKey = 'business_id';
- if ($types == 'crm_contract') $primaryKey = 'contract_id';
- if ($types == 'crm_receivables') $primaryKey = 'receivables_id';
- if ($types == 'crm_visit') $primaryKey = 'visit_id';
- if ($types == 'crm_product') $primaryKey = 'product_id';
-
+ // author guogaobo $item模块
+ $info='';
+ switch ($types) {
+ case 'crm_leads' :
+ $primaryKey = 'leads_id';
+ $dataModel=new \app\crm\model\Leads();
+ $info=$dataModel->getDataById($actionId);
+ break;
+ case 'crm_customer' :
+ $primaryKey = 'customer_id';
+ $info=db('crm_customer')->where('customer_id',$actionId)->find();
+ break;
+ case 'crm_contacts' :
+ $primaryKey = 'contacts_id';
+ $dataModel=new \app\crm\model\Contacts();
+ $info=$dataModel->getDataById($actionId);
+ break;
+ case 'crm_business' :
+ $primaryKey = 'business_id';
+ $dataModel=new \app\crm\model\Business();
+ $info=$dataModel->getDataById($actionId);
+ break;
+ case 'crm_contract' :
+ $primaryKey = 'contract_id';
+ $info=db('crm_contract')->where('customer_id',$actionId)->find();
+ break;
+ case 'crm_receivables' :
+ $primaryKey = 'receivables_id';
+ $info=db('crm_receivables')->where('customer_id',$actionId)->find();
+ break;
+ case 'crm_visit' :
+ $primaryKey = 'visit_id';
+ $dataModel=new \app\crm\logic\VisitLogic();
+ $info=$dataModel->getDataById($actionId);
+ break;
+ case 'crm_product' :
+ $primaryKey = 'product_id';
+ $dataModel=new \app\crm\model\Product();
+ $info=$dataModel->getDataById($actionId);
+ break;
+ }
$apiCommon = new ApiCommon();
$userModel = new User();
+
+ if (in_array($types, ['crm_contract', 'crm_receivables'])) {
+ $checkStatus = $model->where($primaryKey, $actionId)->value('check_status');
+ if (!in_array($checkStatus, [4, 5, 6])) {
+ $this->error = '只能编辑状态为撤销、草稿或作废的信息!';
+ return false;
+ }
+ }
+ # 产品修改验证
+ if($types == 'crm_product'){
+ foreach ($param['list'] as $val){
+ $infoData=db('crm_product')->where(['name'=>$val['name'],'delete_user_id'=>0])->find();
+ if(!empty($infoData)){
+ $fieldModel = new \app\admin\model\Field();
+ $validateArr = $fieldModel->validateField('crm_product'); //获取自定义字段验证规则
+ $validate = new Validate($validateArr['rule'], $validateArr['message']);
+ $result = $validate->check($val);
+ if (!$result) {
+ $this->error = $validate->getError();
+ return false;
+ }
+ }
+ }
+ }
+
# 客户模块快捷编辑权限验证
if ($types == 'crm_customer') {
- $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
+ $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
$wherePool = (new Customer())->getWhereByPool();
$resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['action_id']])->where($wherePool)->find();
- if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) {
+ if ($resPool || (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre)) {
$this->error = '无权操作!';
return false;
}
}
-
+
# 商机模块快捷编辑权限验证
if ($types == 'crm_business') {
- $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
+ $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
- if (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre) {
+ if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
$this->error = '无权操作!';
return false;
}
}
-
+
# 合同模块快捷编辑权限验证
if ($types == 'crm_contract') {
- $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
+ $dataInfo = $model->field(['ro_user_id', 'rw_user_id', 'owner_user_id'])->where($primaryKey, $actionId)->find();
$auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'update');
$rwPre = $userModel->rwPre($apiCommon->userInfo['id'], $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
if (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
@@ -95,51 +153,100 @@ class CommonLogic
}
}
- foreach ($param AS $key => $value) {
- # 查询自定义字段信息
- $fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name'])
- ->where('types', $types)->where('field', $key)->find();
-
- # 字符长度
- if (!empty($fieldInfo['max_length']) && strlen($value) > $fieldInfo['max_length']) {
- $this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!';
- return false;
- }
+ $fieldModel = new \app\admin\model\Field();
+ # 日期时间类型
+ $datetimeField = $fieldModel->getFieldByFormType($types, 'datetime');
+ # 附件类型
+ $fileField = $fieldModel->getFieldByFormType($types, 'file');
+ # 多选类型
+ $checkboxField = $fieldModel->getFieldByFormType($types, 'checkbox');
+ # 人员类型
+ $userField = $fieldModel->getFieldByFormType($types, 'user');
+ # 部门类型
+ $structureField = $fieldModel->getFieldByFormType($types, 'structure');
+
+ foreach ($param['list'] as $key => $value) {
+ foreach ($value as $k => $v) {
+ # 查询自定义字段信息
+ $fieldInfo = Db::name('admin_field')->field(['max_length', 'is_unique', 'is_null', 'name'])
+ ->where('types', $types)->where('field', $k)->find();
+
+ # 字符长度
+ if (!empty($fieldInfo['max_length']) && strlen($v) > $fieldInfo['max_length']) {
+ $this->error = $fieldInfo['name'] . ' 字符长度不能超过 ' . $fieldInfo['max_length'] . ' 个字符!';
+ return false;
+ }
- # 必填
- if (!empty($fieldInfo['is_null']) && empty($value)) {
- $this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!';
- return false;
- }
+ # 必填
+ if (!empty($fieldInfo['is_null']) && empty($v)) {
+ $this->error = $fieldInfo['name'] . ' 是必填信息,不能为空!';
+ return false;
+ }
- # 唯一
- if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($key, $value)->value($primaryKey)) {
- $this->error = $fieldInfo['name'] . ' 内容重复!';
- return false;
+ # 唯一
+ if (!empty($fieldInfo['is_unique']) && $model->where([$primaryKey => ['neq', $actionId]])->where($k, $v)->value($primaryKey)) {
+ $this->error = $fieldInfo['name'] . ' 内容重复!';
+ return false;
+ }
}
}
-
+
# 编辑参数
$data = [];
+ $item=[];
if (!empty($param['list'])) {
- foreach ($param['list'] AS $key => $value) {
- foreach ($value AS $k => $v) {
- # 处理下次联系时间格式
- if ($k == 'next_time') {
+ foreach ($param['list'] as $key => $value) {
+ foreach ($value as $k => $v) {
+ if ($k == 'next_time' || in_array($k, $datetimeField)) {
+ # 处理下次联系时间格式、datetime类型数据
$data[$k] = !empty($v) ? strtotime($v) : '';
- } else {
- $data[$k] = $v;
- }
- # 处理产品类别
- if ($types == 'crm_product' && $k == 'category_id') {
+ } elseif ($types == 'crm_product' && $k == 'category_id') {
+ # 处理产品类别
$categorys = explode(',', $v);
- $data[$k] = $categorys[count($categorys) - 1];
+ $data[$k] = $categorys[count($categorys) - 1];
+ } elseif (in_array($k, $fileField)) {
+ # 处理附件类型数据
+ $fileArray = [];
+ foreach ($v AS $kk => $vv) {
+ if (!empty($vv['file_id'])) $fileArray[] = $vv['file_id'];
+ }
+ if (!empty($fileArray)) $data[$k] = arrayToString($fileArray);
+ } elseif (in_array($k, $checkboxField)) {
+ # 处理多选类型数据
+ $data[$k] = arrayToString($v);
+ } elseif (in_array($k, $userField)) {
+ # 处理人员类型数据
+ $userArray = [];
+ foreach ($v AS $kk => $vv) {
+ if (!empty($vv['id'])) $userArray[] = $vv['id'];
+ }
+ $data[$k] = !empty($userArray) ? arrayToString($userArray) : '';
+ } elseif (in_array($k, $structureField)) {
+ # 处理部门类型数据
+ $structureArray = [];
+ foreach ($v AS $kk => $vv) {
+ if (!empty($vv['id'])) $structureArray[] = $vv['id'];
+ }
+ $data[$k] = !empty($structureArray) ? arrayToString($structureArray) : '';
+ } elseif ($types == 'crm_visit' && $k == 'contract_id') {
+ # 处理回访提交过来的合同编号
+ if (!empty($v[0]['contract_id'])) $data[$k] = $v[0]['contract_id'];
+ }else {
+ $data[$k] = $v;
}
}
+ $item=$value;
}
- $data[$primaryKey] = $actionId;
+ $data[$primaryKey] = $actionId;
+ $data['update_time'] = time();
}
-
- return $model->update($data);
+ $res = $model->update($data);
+ //详细信息修改新增操作记录
+ if ($res) {
+ //修改记录
+ $user_id = $apiCommon->userInfo;
+ updateActionLog($user_id['id'], $types, $actionId, $info, $item);
+ }
+ return $res;
}
}
\ No newline at end of file
diff --git a/application/crm/logic/IndexLogic.php b/application/crm/logic/IndexLogic.php
index eae0f09..e815490 100644
--- a/application/crm/logic/IndexLogic.php
+++ b/application/crm/logic/IndexLogic.php
@@ -23,6 +23,10 @@ class IndexLogic extends Common
'12' => 'december',
];
+ /**
+ * @param $param
+ * @return array
+ */
public function index($param)
{
$adminModel = new \app\admin\model\Admin();
@@ -69,17 +73,16 @@ class IndexLogic extends Common
$contract_auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'index');
$receivables_auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'index');
$record_auth_user_ids = $userModel->getUserByPer('crm', 'activity', 'index');
-
$resCount = queryCache(
$this->getCountSql([
'start_time' => $between_time[0],
'end_time' => $between_time[1],
- 'customer_auth_user_ids' => array_intersect($userIds, $customer_auth_user_ids),
- 'contacts_auth_user_ids' => array_intersect($userIds, $contacts_auth_user_ids),
- 'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids),
- 'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids),
- 'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids),
- 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids),
+ 'customer_auth_user_ids' => array_intersect($userIds, $customer_auth_user_ids) ? :[-1],
+ 'contacts_auth_user_ids' => array_intersect($userIds, $contacts_auth_user_ids) ? :[-1],
+ 'business_auth_user_ids' => array_intersect($userIds, $business_auth_user_ids) ? :[-1],
+ 'contract_auth_user_ids' => array_intersect($userIds, $contract_auth_user_ids) ? :[-1],
+ 'receivables_auth_user_ids' => array_intersect($userIds, $receivables_auth_user_ids) ? :[-1],
+ 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? :[-1],
])
);
diff --git a/application/crm/logic/VisitLogic.php b/application/crm/logic/VisitLogic.php
index 6d486cf..8289023 100644
--- a/application/crm/logic/VisitLogic.php
+++ b/application/crm/logic/VisitLogic.php
@@ -54,12 +54,7 @@ class VisitLogic extends Common
//高级筛选
$map = where_arr($map, 'crm', 'visit', 'index');
- $order = ['visit.update_time desc'];
- if (isset($map['visit.visit_time'])) {
- $map['visit.visit_time'][1][0] = date('Y-m-d', $map['visit.visit_time'][1][0]);
- $map['visit.visit_time'][1][1] = date('Y-m-d', $map['visit.visit_time'][1][1]);
- }
$authMap = [];
if (!$partMap) {
$a = 'index';
@@ -68,20 +63,20 @@ class VisitLogic extends Common
if (!is_array($map['visit.owner_user_id'][1])) {
$map['visit.owner_user_id'][1] = [$map['visit.owner_user_id'][1]];
}
- if ($map['visit.owner_user_id'][0] == 'neq') {
+ if (in_array($map['visit.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['visit.owner_user_id'][1]) ?: []; //取差集
} else {
$auth_user_ids = array_intersect($map['visit.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
}
- unset($map['visit.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['visit.owner_user_id'] = array('in', $auth_user_ids);
+ unset($map['visit.owner_user_id']);
} else {
$authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id;
$authMap = function ($query) use ($authMapData) {
- $query->where('visit.owner_user_id', array('in', $authMapData['auth_user_ids']))
+ $query->where('visit.owner_user_id', ['in', $authMapData['auth_user_ids']])
->whereOr('visit.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'))
->whereOr('visit.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
};
@@ -96,6 +91,7 @@ class VisitLogic extends Common
//人员类型
$userField = $fieldModel->getFieldByFormType('crm_visit', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_visit', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
@@ -118,12 +114,11 @@ class VisitLogic extends Common
->where($partMap)
->where($authMap)
->limit($request['offset'], $request['length'])
- ->field(array_merge($indexField, [
- 'contract.num' => 'contract_number',
- 'customer.name' => 'customer_name',
- 'contacts.name' => 'contacts_name',
-
- ]))
+ ->field('visit.*,
+ contract.num as contract_number,
+ customer.name as customer_name,
+ contacts.name as contacts_name'
+ )
->orderRaw($order)
->group('visit.visit_id')
->select();
@@ -140,10 +135,15 @@ class VisitLogic extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) {
- $list[$k][$val . '_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val . '_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
+ }
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
$list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
$list[$k]['contract_id_info']['name'] = $v['contract_name'];
@@ -161,7 +161,7 @@ class VisitLogic extends Common
$is_update = 0;
$is_delete = 0;
if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
- if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
+ if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
$permission['is_read'] = $is_read;
$permission['is_update'] = $is_update;
@@ -198,6 +198,11 @@ class VisitLogic extends Common
$dataInfo['contacts_id_info'] = db('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->field('contacts_id,name')->find();
$dataInfo['contacts_name'] = !empty($dataInfo['contacts_id_info']['name']) ? $dataInfo['contacts_id_info']['name'] : '';
# 处理日期格式
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo;
@@ -330,7 +335,7 @@ class VisitLogic extends Common
return resultArray(['error' => $this->getError()]);
}
//删除关联附件
- $fileModel->delRFileByModule('crm_business', $delIds);
+ $fileModel->delRFileByModule('crm_visit', $delIds);
//删除关联操作记录
$actionRecordModel->delDataById(['types' => 'crm_visit', 'visit_id' => $delIds]);
actionLog($delIds, '', '', '');
diff --git a/application/crm/model/Business.php b/application/crm/model/Business.php
index 2d75552..abf7845 100644
--- a/application/crm/model/Business.php
+++ b/application/crm/model/Business.php
@@ -14,14 +14,14 @@ use app\crm\model\Business as CrmBusinessModel;
class Business extends Common
{
- /**
+ /**
* 为了数据库的整洁,同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
*/
- protected $name = 'crm_business';
+ protected $name = 'crm_business';
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
- protected $autoWriteTimestamp = true;
+ protected $autoWriteTimestamp = true;
/**
* [getDataList 商机list]
@@ -32,190 +32,196 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
- public function getDataList($request)
- {
- $userModel = new \app\admin\model\User();
- $structureModel = new \app\admin\model\Structure();
- $fieldModel = new \app\admin\model\Field();
- $search = $request['search'];
- $user_id = $request['user_id'];
- $scene_id = (int)$request['scene_id'];
- $contacts_id = $request['contacts_id'];
- $order_field = $request['order_field'];
- $order_type = $request['order_type'];
- $is_excel = $request['is_excel']; //导出
+ public function getDataList($request)
+ {
+ $userModel = new \app\admin\model\User();
+ $structureModel = new \app\admin\model\Structure();
+ $fieldModel = new \app\admin\model\Field();
+ $search = $request['search'];
+ $user_id = $request['user_id'];
+ $scene_id = (int)$request['scene_id'];
+ $contacts_id = $request['contacts_id'];
+ $order_field = $request['order_field'];
+ $order_type = $request['order_type'];
+ $is_excel = $request['is_excel']; //导出
$getCount = $request['getCount'];
- unset($request['scene_id']);
- unset($request['search']);
- unset($request['user_id']);
- unset($request['contacts_id']);
- unset($request['order_field']);
- unset($request['order_type']);
- unset($request['is_excel']);
+ unset($request['scene_id']);
+ unset($request['search']);
+ unset($request['user_id']);
+ unset($request['contacts_id']);
+ unset($request['order_field']);
+ unset($request['order_type']);
+ unset($request['is_excel']);
unset($request['getCount']);
- $request = $this->fmtRequest( $request );
- $requestMap = $request['map'] ? : [];
- $sceneModel = new \app\admin\model\Scene();
+ $request = $this->fmtRequest($request);
+ $requestMap = $request['map'] ?: [];
+ $sceneModel = new \app\admin\model\Scene();
# getCount是代办事项传来的参数,代办事项不需要使用场景
$sceneMap = [];
if (empty($getCount)) {
if ($scene_id) {
//自定义场景
- $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'business') ? : [];
+ $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'business') ?: [];
} else {
//默认场景
- $sceneMap = $sceneModel->getDefaultData('crm_business', $user_id) ? : [];
+ $sceneMap = $sceneModel->getDefaultData('crm_business', $user_id) ?: [];
+ }
+ }
+ if ($search) {
+ //普通筛选
+ $sceneMap['name'] = ['condition' => 'contains', 'value' => $search, 'form_type' => 'text', 'name' => '商机名称'];
+ }
+ if (isset($requestMap['type_id'])) {
+ $requestMap['type_id']['value'] = $requestMap['type_id']['type_id'];
+ if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id'];
+ }
+ if ($sceneMap['type_id']) {
+ $requestMap['type_id']['value'] = $sceneMap['type_id']['type_id'];
+ if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id'];
+ unset($sceneMap['type_id']);
+ }
+ $partMap = [];
+ //优先级:普通筛选>高级筛选>场景
+ if ($sceneMap['ro_user_id'] && $sceneMap['rw_user_id']) {
+ //相关团队查询
+ $map = $requestMap;
+ $partMap = function ($query) use ($sceneMap) {
+ $query->where('business.ro_user_id', array('like', '%,' . $sceneMap['ro_user_id'] . ',%'))
+ ->whereOr('business.rw_user_id', array('like', '%,' . $sceneMap['rw_user_id'] . ',%'));
+ };
+ } else {
+ $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
+ }
+ //高级筛选
+ $map = where_arr($map, 'crm', 'business', 'index');
+ $authMap = [];
+ if (!$partMap) {
+ $a = 'index';
+ if ($is_excel) $a = 'excelExport';
+ $auth_user_ids = $userModel->getUserByPer('crm', 'business', $a);
+ if (isset($map['business.owner_user_id']) && $map['business.owner_user_id'][0] != 'like') {
+ if (!is_array($map['business.owner_user_id'][1])) {
+ $map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]];
+ }
+ if (in_array($map['business.owner_user_id'][0], ['neq', 'notin'])) {
+ $auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ?: []; //取差集
+ } else {
+ $auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
+ }
+ unset($map['business.owner_user_id']);
+ $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
+ $authMap['business.owner_user_id'] = array('in', $auth_user_ids);
+ } else {
+ $authMapData = [];
+ $authMapData['auth_user_ids'] = $auth_user_ids;
+ $authMapData['user_id'] = $user_id;
+ $authMap = function ($query) use ($authMapData) {
+ $query->where('business.owner_user_id', array('in', $authMapData['auth_user_ids']))
+ ->whereOr('business.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'))
+ ->whereOr('business.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
+ };
+ }
+ }
+ //联系人商机
+ if ($contacts_id) {
+ $business_id = Db::name('crm_contacts_business')->where(['contacts_id' => $contacts_id])->column('business_id');
+ if ($business_id) {
+ $map['business.business_id'] = array('in', $business_id);
+ } else {
+ $map['business.business_id'] = array('eq', -1);
}
}
- if ($search) {
- //普通筛选
- $sceneMap['name'] = ['condition' => 'contains','value' => $search,'form_type' => 'text','name' => '商机名称'];
- }
- if (isset($requestMap['type_id'])) {
- $requestMap['type_id']['value'] = $requestMap['type_id']['type_id'];
- if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id'];
- }
- if ($sceneMap['type_id']) {
- $requestMap['type_id']['value'] = $sceneMap['type_id']['type_id'];
- if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id'];
- unset($sceneMap['type_id']);
- }
- $partMap = [];
- //优先级:普通筛选>高级筛选>场景
- if ($sceneMap['ro_user_id'] && $sceneMap['rw_user_id']) {
- //相关团队查询
- $map = $requestMap;
- $partMap = function($query) use ($sceneMap){
- $query->where('business.ro_user_id',array('like','%,'.$sceneMap['ro_user_id'].',%'))
- ->whereOr('business.rw_user_id',array('like','%,'.$sceneMap['rw_user_id'].',%'));
- };
- } else {
- $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
- }
- //高级筛选
- $map = where_arr($map, 'crm', 'business', 'index');
- $authMap = [];
- if (!$partMap) {
- $a = 'index';
- if ($is_excel) $a = 'excelExport';
- $auth_user_ids = $userModel->getUserByPer('crm', 'business', $a);
- if (isset($map['business.owner_user_id']) && $map['business.owner_user_id'][0] != 'like') {
- if (!is_array($map['business.owner_user_id'][1])) {
- $map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]];
- }
- if ($map['business.owner_user_id'][0] == 'neq') {
- $auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ? : []; //取差集
- } else {
- $auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
- }
- unset($map['business.owner_user_id']);
- $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ? : ['-1'];
- $authMap['business.owner_user_id'] = array('in',$auth_user_ids);
- } else {
- $authMapData = [];
- $authMapData['auth_user_ids'] = $auth_user_ids;
- $authMapData['user_id'] = $user_id;
- $authMap = function($query) use ($authMapData){
- $query->where('business.owner_user_id',array('in',$authMapData['auth_user_ids']))
- ->whereOr('business.ro_user_id',array('like','%,'.$authMapData['user_id'].',%'))
- ->whereOr('business.rw_user_id',array('like','%,'.$authMapData['user_id'].',%'));
- };
- }
- }
- //联系人商机
- if ($contacts_id) {
- $business_id = Db::name('crm_contacts_business')->where(['contacts_id' => $contacts_id])->column('business_id');
- if ($business_id) {
- $map['business.business_id'] = array('in',$business_id);
- }else{
- $map['business.business_id'] = array('eq',-1);
- }
- }
- //列表展示字段
- $indexField = $fieldModel->getIndexField('crm_business', $user_id, 1) ? : array('name');
- if (!empty($indexField)) {
- foreach ($indexField AS $key => $value) {
- if ($value == 'business.customer_name') unset($indexField[(int)$key]);
+ //列表展示字段
+ $indexField = $fieldModel->getIndexField('crm_business', $user_id, 1) ?: array('name');
+ if (!empty($indexField)) {
+ foreach ($indexField as $key => $value) {
+ if ($value == 'business.customer_name') unset($indexField[(int)$key]);
}
}
- $userField = $fieldModel->getFieldByFormType('crm_business', 'user'); //人员类型
- $structureField = $fieldModel->getFieldByFormType('crm_business', 'structure'); //部门类型
- //排序
- if ($order_type && $order_field) {
- $order = $fieldModel->getOrderByFormtype('crm_business','business',$order_field,$order_type);
- } else {
- $order = 'business.update_time desc';
- }
-
- $readAuthIds = $userModel->getUserByPer('crm', 'business', 'read');
+ $userField = $fieldModel->getFieldByFormType('crm_business', 'user'); //人员类型
+ $structureField = $fieldModel->getFieldByFormType('crm_business', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_business', 'datetime'); //日期时间类型
+ //排序
+ if ($order_type && $order_field) {
+ $order = $fieldModel->getOrderByFormtype('crm_business', 'business', $order_field, $order_type);
+ } else {
+ $order = 'business.update_time desc';
+ }
+
+ $readAuthIds = $userModel->getUserByPer('crm', 'business', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'business', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'business', 'delete');
$dataCount = db('crm_business')
->alias('business')
- ->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT')
+ ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map)->where($partMap)->where($authMap)->count('business_id');
if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
- # 商机总金额
- $sumMoney = Db::name('crm_business')->alias('business')
- ->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money');
- $data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
+ # 商机总金额
+ $sumMoney = Db::name('crm_business')->alias('business')
+ ->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money');
+ $data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data;
}
- $list = db('crm_business')
- ->alias('business')
- ->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT')
- ->where($map)
- ->where($partMap)
- ->where($authMap)
- ->limit($request['offset'], $request['length'])
- ->field(implode(',',$indexField).',business.is_end,customer.name as customer_name')
- ->orderRaw($order)
- ->select();
- $endStatus = ['1' => '赢单','2' => '输单','3' => '无效'];
- foreach ($list as $k=>$v) {
+ $list = db('crm_business')
+ ->alias('business')
+ ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
+ ->where($map)
+ ->where($partMap)
+ ->where($authMap)
+ ->limit($request['offset'], $request['length'])
+ ->field('business.*,customer.name as customer_name')
+ ->orderRaw($order)
+ ->select();
+ $endStatus = ['1' => '赢单', '2' => '输单', '3' => '无效'];
+ foreach ($list as $k => $v) {
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
$list[$k]['customer_id_info']['name'] = $v['customer_name'];
- $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
- $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
- $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
+ $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
+ $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
+ $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
- foreach ($userField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
- }
- foreach ($structureField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
- }
- $statusInfo = [];
- $status_count = 0;
- if (!$v['is_end']) {
- $statusInfo = db('crm_business_status')->where('status_id',$v['status_id'])->find();
- if ($statusInfo['order_id'] < 99) {
- $status_count = db('crm_business_status')->where('type_id',['eq',$v['type_id']])->count();
- }
- //进度
- $list[$k]['status_progress'] = [$statusInfo['order_id'], $status_count+1];
- } else {
- $statusInfo['name'] = $endStatus[$v['is_end']];
- }
- $list[$k]['status_id_info'] = $statusInfo['name'];//销售阶段
- $list[$k]['type_id_info'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组
-
- //权限
- $roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read');
- $rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update');
- $permission = [];
- $is_read = 0;
- $is_update = 0;
- $is_delete = 0;
- if (in_array($v['owner_user_id'],$readAuthIds) || $roPre || $rwPre) $is_read = 1;
- if (in_array($v['owner_user_id'],$updateAuthIds) || $rwPre) $is_update = 1;
- if (in_array($v['owner_user_id'],$deleteAuthIds)) $is_delete = 1;
- $permission['is_read'] = $is_read;
- $permission['is_update'] = $is_update;
- $permission['is_delete'] = $is_delete;
- $list[$k]['permission'] = $permission;
+ foreach ($userField as $key => $val) {
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
+ }
+ foreach ($structureField as $key => $val) {
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
+ }
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
+ $statusInfo = [];
+ $status_count = 0;
+ if (!$v['is_end']) {
+ $statusInfo = db('crm_business_status')->where('status_id', $v['status_id'])->find();
+ if ($statusInfo['order_id'] < 99) {
+ $status_count = db('crm_business_status')->where('type_id', ['eq', $v['type_id']])->count();
+ }
+ //进度
+ $list[$k]['status_progress'] = [$statusInfo['order_id'], $status_count + 1];
+ } else {
+ $statusInfo['name'] = $endStatus[$v['is_end']];
+ }
+ $list[$k]['status_id_info'] = $statusInfo['name'];//销售阶段
+ $list[$k]['type_id_info'] = db('crm_business_type')->where('type_id', $v['type_id'])->value('name');//商机状态组
+
+ //权限
+ $roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read');
+ $rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update');
+ $permission = [];
+ $is_read = 0;
+ $is_update = 0;
+ $is_delete = 0;
+ if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
+ if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
+ if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
+ $permission['is_read'] = $is_read;
+ $permission['is_update'] = $is_update;
+ $permission['is_delete'] = $is_delete;
+ $list[$k]['permission'] = $permission;
# 下次联系时间
$list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注
@@ -225,159 +231,159 @@ class Business extends Common
# 日期
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
- $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
+ $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
}
$data = [];
- $data['list'] = $list ? : [];
- $data['dataCount'] = $dataCount ? : 0;
+ $data['list'] = $list ?: [];
+ $data['dataCount'] = $dataCount ?: 0;
# 商机总金额
$sumMoney = Db::name('crm_business')->alias('business')
- ->join('__CRM_CUSTOMER__ customer','business.customer_id = customer.customer_id','LEFT')
+ ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->whereIn('is_end', [0, 1])->where($map)->where($partMap)->where($authMap)->sum('money');
$data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data;
}
- /**
- * 创建商机主表信息
- * @author Michael_xu
- * @param
- * @return
- */
- public function createData($param)
- {
- $fieldModel = new \app\admin\model\Field();
- $productModel = new \app\crm\model\Product();
- // 自动验证
- $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
- $validate = new Validate($validateArr['rule'], $validateArr['message']);
- $result = $validate->check($param);
- if (!$result) {
- $this->error = $validate->getError();
- return false;
- }
- if (!$param['customer_id']) {
- $this->error = '请选择相关客户';
- return false;
- }
+ /**
+ * 创建商机主表信息
+ * @param
+ * @return
+ * @author Michael_xu
+ */
+ public function createData($param)
+ {
+ $fieldModel = new \app\admin\model\Field();
+ $productModel = new \app\crm\model\Product();
+ // 自动验证
+ $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
+ $validate = new Validate($validateArr['rule'], $validateArr['message']);
+ $result = $validate->check($param);
+ if (!$result) {
+ $this->error = $validate->getError();
+ return false;
+ }
+ if (!$param['customer_id']) {
+ $this->error = '请选择相关客户';
+ return false;
+ }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
- //处理部门、员工、附件、多选类型字段
- $arrFieldAtt = $fieldModel->getArrayField('crm_business');
- foreach ($arrFieldAtt as $k=>$v) {
- $param[$v] = arrayToString($param[$v]);
- }
-
- $param['money'] = $param['money'] ? : '0.00';
- $param['discount_rate'] = $param['discount_rate'] ? : '0.00';
- if ($this->data($param)->allowField(true)->save()) {
- $business_id = $this->business_id;
- if ($param['product']) {
- //产品数据处理
- $resProduct = $productModel->createObject('crm_business', $param, $business_id);
- if ($resProduct == false) {
- $this->error = '产品添加失败';
- return false;
- }
- }
- //添加商机日志
- $data_log['business_id'] = $business_id;
- $data_log['is_end'] = 0;
- $data_log['status_id'] = $param['status_id'];
- $data_log['create_time'] = time();
- $data_log['owner_user_id'] = $param['owner_user_id'];
- $data_log['remark'] = '新建商机';
- Db::name('CrmBusinessLog')->insert($data_log);
-
- $data = [];
- $data['business_id'] = $business_id;
+ //处理部门、员工、附件、多选类型字段
+ $arrFieldAtt = $fieldModel->getArrayField('crm_business');
+ foreach ($arrFieldAtt as $k => $v) {
+ $param[$v] = arrayToString($param[$v]);
+ }
+
+ $param['money'] = $param['money'] ?: '0.00';
+ $param['discount_rate'] = $param['discount_rate'] ?: '0.00';
+ if ($this->data($param)->allowField(true)->save()) {
+ $business_id = $this->business_id;
+ if ($param['product']) {
+ //产品数据处理
+ $resProduct = $productModel->createObject('crm_business', $param, $business_id);
+ if ($resProduct == false) {
+ $this->error = '产品添加失败';
+ return false;
+ }
+ }
+ //添加商机日志
+ $data_log['business_id'] = $business_id;
+ $data_log['is_end'] = 0;
+ $data_log['status_id'] = $param['status_id'];
+ $data_log['create_time'] = time();
+ $data_log['owner_user_id'] = $param['owner_user_id'];
+ $data_log['remark'] = '新建商机';
+ Db::name('CrmBusinessLog')->insert($data_log);
+
+ $data = [];
+ $data['business_id'] = $business_id;
# 添加活动记录
Db::name('crm_activity')->insert([
- 'type' => 2,
- 'activity_type' => 5,
+ 'type' => 2,
+ 'activity_type' => 5,
'activity_type_id' => $data['business_id'],
- 'content' => $param['name'],
- 'create_user_id' => $param['create_user_id'],
- 'update_time' => time(),
- 'create_time' => time(),
- 'customer_ids' => $param['customer_id']
+ 'content' => $param['name'],
+ 'create_user_id' => $param['create_user_id'],
+ 'update_time' => time(),
+ 'create_time' => time(),
+ 'customer_ids' => $param['customer_id']
]);
- return $data;
- } else {
- $this->error = '添加失败';
- return false;
- }
- }
-
- /**
- * 编辑商机主表信息
- * @author Michael_xu
- * @param
- * @return
- */
- public function updateDataById($param, $business_id = '')
- {
- $productModel = new \app\crm\model\Product();
- $dataInfo = $this->getDataById($business_id);
- if (!$dataInfo) {
- $this->error = '数据不存在或已删除';
- return false;
- }
- $param['business_id'] = $business_id;
- //过滤不能修改的字段
- $unUpdateField = ['create_user_id','is_deleted','delete_time'];
- foreach ($unUpdateField as $v) {
- unset($param[$v]);
- }
-
- $fieldModel = new \app\admin\model\Field();
- // 自动验证
- $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
- $validate = new Validate($validateArr['rule'], $validateArr['message']);
-
- $result = $validate->check($param);
- if (!$result) {
- $this->error = $validate->getError();
- return false;
- }
+ return $data;
+ } else {
+ $this->error = '添加失败';
+ return false;
+ }
+ }
+
+ /**
+ * 编辑商机主表信息
+ * @param
+ * @return
+ * @author Michael_xu
+ */
+ public function updateDataById($param, $business_id = '')
+ {
+ $productModel = new \app\crm\model\Product();
+ $dataInfo = $this->getDataById($business_id);
+ if (!$dataInfo) {
+ $this->error = '数据不存在或已删除';
+ return false;
+ }
+ $param['business_id'] = $business_id;
+ //过滤不能修改的字段
+ $unUpdateField = ['create_user_id', 'is_deleted', 'delete_time'];
+ foreach ($unUpdateField as $v) {
+ unset($param[$v]);
+ }
+
+ $fieldModel = new \app\admin\model\Field();
+ // 自动验证
+ $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
+ $validate = new Validate($validateArr['rule'], $validateArr['message']);
+
+ $result = $validate->check($param);
+ if (!$result) {
+ $this->error = $validate->getError();
+ return false;
+ }
# 处理下次联系时间
if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
- //处理部门、员工、附件、多选类型字段
- $arrFieldAtt = $fieldModel->getArrayField('crm_business');
- foreach ($arrFieldAtt as $k=>$v) {
- $param[$v] = arrayToString($param[$v]);
- }
-
- $param['money'] = $param['money'] ? : '0.00';
- $param['discount_rate'] = $param['discount_rate'] ? : '0.00';
- //商机状态改变
- $statusInfo = db('crm_business_status')->where(['status_id' => $param['status_id']])->find();
- if ($statusInfo['type_id']) {
- $param['is_end'] = 0;
- } else {
- $param['is_end'] = $param['status_id'];
- }
- if ($this->update($param, ['business_id' => $business_id], true)) {
- //产品数据处理
- $resProduct = $productModel->createObject('crm_business', $param, $business_id);
- //修改记录
- updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param);
- $data = [];
- $data['business_id'] = $business_id;
- return $data;
- } else {
- $this->rollback();
- $this->error = '编辑失败';
- return false;
- }
- }
+ //处理部门、员工、附件、多选类型字段
+ $arrFieldAtt = $fieldModel->getArrayField('crm_business');
+ foreach ($arrFieldAtt as $k => $v) {
+ $param[$v] = arrayToString($param[$v]);
+ }
+
+ $param['money'] = $param['money'] ?: '0.00';
+ $param['discount_rate'] = $param['discount_rate'] ?: '0.00';
+ //商机状态改变
+ $statusInfo = db('crm_business_status')->where(['status_id' => $param['status_id']])->find();
+ if ($statusInfo['type_id']) {
+ $param['is_end'] = 0;
+ } else {
+ $param['is_end'] = $param['status_id'];
+ }
+ if ($this->update($param, ['business_id' => $business_id], true)) {
+ //产品数据处理
+ $resProduct = $productModel->createObject('crm_business', $param, $business_id);
+ //修改记录
+ updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param);
+ $data = [];
+ $data['business_id'] = $business_id;
+ return $data;
+ } else {
+ $this->rollback();
+ $this->error = '编辑失败';
+ return false;
+ }
+ }
/**
* 商机数据
@@ -389,84 +395,89 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
- public function getDataById($id = '', $userId = 0)
- {
- $dataInfo = db('crm_business')->where('business_id', $id)->find();
- if (!$dataInfo) {
- $this->error = '暂无此数据';
- return false;
- }
- $userModel = new \app\admin\model\User();
- $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
- $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
- $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
- $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
- $dataInfo['type_id_info'] = db('crm_business_type')->where(['type_id' => $dataInfo['type_id']])->value('name');
- $dataInfo['status_id_info'] = db('crm_business_status')->where(['status_id' => $dataInfo['status_id']])->value('name');
- $dataInfo['customer_id_info'] = db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find();
+ public function getDataById($id = '', $userId = 0)
+ {
+ $dataInfo = db('crm_business')->where('business_id', $id)->find();
+ if (!$dataInfo) {
+ $this->error = '暂无此数据';
+ return false;
+ }
+ $userModel = new \app\admin\model\User();
+ $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
+ $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
+ $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
+ $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
+ $dataInfo['type_id_info'] = db('crm_business_type')->where(['type_id' => $dataInfo['type_id']])->value('name');
+ $dataInfo['status_id_info'] = db('crm_business_status')->where(['status_id' => $dataInfo['status_id']])->value('name');
+ $dataInfo['customer_id_info'] = db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find();
$dataInfo['customer_name'] = !empty($dataInfo['customer_id_info']['name']) ? $dataInfo['customer_id_info']['name'] : '';
- # 关注
+ # 关注
$starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_business'])->value('star_id');
$dataInfo['star'] = !empty($starId) ? 1 : 0;
# 首要联系人
$primaryId = Db::name('crm_contacts')->where(['contacts_id' => $dataInfo['contacts_id']])->value('contacts_id');
$dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0;
# 处理日期格式
- $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_business', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
+ $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
- $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
+ $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
return $dataInfo;
- }
-
- //根据IDs获取数组
- public function getDataByStr($idstr)
- {
- $idArr = stringToArray($idstr);
- if (!$idArr) {
- return [];
- }
- $list = Db::name('CrmBusiness')->where(['business_id' => ['in',$idArr]])->select();
- return $list;
- }
-
- /**
+ }
+
+ //根据IDs获取数组
+ public function getDataByStr($idstr)
+ {
+ $idArr = stringToArray($idstr);
+ if (!$idArr) {
+ return [];
+ }
+ $list = Db::name('CrmBusiness')->where(['business_id' => ['in', $idArr]])->select();
+ return $list;
+ }
+
+ /**
* [商机漏斗]
- * @author Michael_xu
* @param
- * @return
- */
- public function getFunnel($request)
+ * @return
+ * @author Michael_xu
+ */
+ public function getFunnel($request)
{
- $merge = $request['merge'] ? : 0;
- $perUserIds = $request['perUserIds'] ? : [];
- $adminModel = new \app\admin\model\Admin();
+ $merge = $request['merge'] ?: 0;
+ $perUserIds = $request['perUserIds'] ?: [];
+ $adminModel = new \app\admin\model\Admin();
$whereArr = $adminModel->getWhere($request, $merge, $perUserIds); //统计查询
$userIds = $whereArr['userIds'];
$between_time = $whereArr['between_time'];
- $where['owner_user_id'] = array('in',$userIds);
- $where['create_time'] = array('between',$between_time);
- //商机状态组
- $default_type_id = db('crm_business_type')->order('type_id asc')->value('type_id');
- $type_id = $request['type_id'] ? $request['type_id'] : $default_type_id;
- $statusList = db('crm_business_status')->where(['type_id' => $type_id])->select();
- $map = [];
- $map['create_time'] = $where['create_time'];
- $map['owner_user_id'] = ['in',$userIds];
-
- $sql_a = CrmBusinessModel::field([
- 'SUM(CASE WHEN status_id = 1 THEN money ELSE 0 END) AS sum_ying',
- 'SUM(CASE WHEN status_id = 2 THEN money ELSE 0 END) AS sum_shu'
- ])
- ->where($map)
- ->fetchSql()
- ->select();
- $res_a = queryCache($sql_a, 200);
- $sql = CrmBusinessModel::field([
- "status_id",
- 'COUNT(*)' => 'count',
- 'SUM(`money`)' => 'sum'
- ])
+ $where['owner_user_id'] = array('in', $userIds);
+ $where['create_time'] = array('between', $between_time);
+ //商机状态组
+ $default_type_id = db('crm_business_type')->order('type_id asc')->value('type_id');
+ $type_id = $request['type_id'] ? $request['type_id'] : $default_type_id;
+ $statusList = db('crm_business_status')->where(['type_id' => $type_id])->select();
+ $map = [];
+ $map['create_time'] = $where['create_time'];
+ $map['owner_user_id'] = ['in', $userIds];
+
+ $sql_a = CrmBusinessModel::field([
+ 'SUM(CASE WHEN status_id = 1 THEN money ELSE 0 END) AS sum_ying',
+ 'SUM(CASE WHEN status_id = 2 THEN money ELSE 0 END) AS sum_shu'
+ ])
+ ->where($map)
+ ->fetchSql()
+ ->select();
+ $res_a = queryCache($sql_a, 200);
+ $sql = CrmBusinessModel::field([
+ "status_id",
+ 'COUNT(*)' => 'count',
+ 'SUM(`money`)' => 'sum'
+ ])
->where($where)
->whereNotIn('is_end', '1,2,3')
->group('status_id')
@@ -476,76 +487,88 @@ class Business extends Common
$res = array_column($res, null, 'status_id');
$sum_money = 0;
- $count = 0; # 商机数总和
- $moneyCount = 0; # 金额总和
- foreach ($statusList as $k=>$v) {
- $v['count'] = $res[$v['status_id']]['count'] ? : 0;
- $v['money'] = $res[$v['status_id']]['sum'] ? : 0;
- $v['status_name'] = $v['name'];
+ $count = 0; # 商机数总和
+ $moneyCount = 0; # 金额总和
+ foreach ($statusList as $k => $v) {
+ $v['count'] = $res[$v['status_id']]['count'] ?: 0;
+ $v['money'] = $res[$v['status_id']]['sum'] ?: 0;
+ $v['status_name'] = $v['name'];
- $statusList[$k] = $v;
+ $statusList[$k] = $v;
$sum_money += $v['money'];
$moneyCount += $v['money'];
- $count += $v['count'];
- }
- $data['list'] = $statusList;
+ $count += $v['count'];
+ }
+ $data['list'] = $statusList;
$data['list'] = $statusList;
- $data['sum_ying'] = $res_a[0]['sum_ying'] ? : 0;
- $data['sum_shu'] = $res_a[0]['sum_shu'] ? : 0;
- $data['sum_money'] = $sum_money ? : 0;
- $data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count];
+ $data['sum_ying'] = $res_a[0]['sum_ying'] ?: 0;
+ $data['sum_shu'] = $res_a[0]['sum_shu'] ?: 0;
+ $data['sum_money'] = $sum_money ?: 0;
+ $data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count];
- return $data ? : [];
- }
+ return $data ?: [];
+ }
- /**
+ /**
* [商机转移]
- * @author Michael_xu
* @param ids 商机ID数组
* @param owner_user_id 变更负责人
* @param is_remove 1移出,2转为团队成员
- * @return
- */
+ * @return
+ * @author Michael_xu
+ */
public function transferDataById($ids, $owner_user_id, $type = 1, $is_remove)
{
- $settingModel = new \app\crm\model\Setting();
- $errorMessage = [];
- foreach ($ids as $id) {
- $businessInfo = db('crm_business')->where(['business_id' => $id])->find();
- //团队成员
- $teamData = [];
+ $settingModel = new \app\crm\model\Setting();
+ $errorMessage = [];
+ foreach ($ids as $id) {
+ $businessInfo = db('crm_business')->where(['business_id' => $id])->find();
+ //团队成员
+ $teamData = [];
$teamData['type'] = $type; //权限 1只读2读写
$teamData['user_id'] = [$businessInfo['owner_user_id']]; //协作人
$teamData['types'] = 'crm_business'; //类型
$teamData['types_id'] = $id; //类型ID
$teamData['is_del'] = ($is_remove == 1) ? 1 : '';
- $res = $settingModel->createTeamData($teamData);
-
- $data = [];
- $data['owner_user_id'] = $owner_user_id;
- $data['update_time'] = time();
- if (!db('crm_business')->where(['business_id' => $id])->update($data)) {
- $errorMessage[] = '商机:'.$businessInfo['name'].'"转移失败,错误原因:数据出错;';
- continue;
- }
- }
- if ($errorMessage) {
- return $errorMessage;
- } else {
- return true;
- }
- }
+ $res = $settingModel->createTeamData($teamData);
+
+ $data = [];
+ $data['owner_user_id'] = $owner_user_id;
+ $data['update_time'] = time();
+ if (!db('crm_business')->where(['business_id' => $id])->update($data)) {
+ $errorMessage[] = '商机:' . $businessInfo['name'] . '"转移失败,错误原因:数据出错;';
+ continue;
+ } else {
+ $businessArray = [];
+ $teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $id)->find();
+ if (!empty($teamBusiness['ro_user_id'])) {
+ $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
+ $businessArray['ro_user_id'] = $businessRo;
+ }
+ if (!empty($teamBusiness['rw_user_id'])) {
+ $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
+ $businessArray['rw_user_id'] = $businessRo;
+ }
+ db('crm_business')->where('business_id', $id)->update($businessArray);
+ }
+ }
+ if ($errorMessage) {
+ return $errorMessage;
+ } else {
+ return true;
+ }
+ }
/**
* [商机统计]
- * @param
- * @return
- */
- public function getTrendql($map)
- {
- $prefix = config('database.prefix');
- $sql = "SELECT
+ * @param
+ * @return
+ */
+ public function getTrendql($map)
+ {
+ $prefix = config('database.prefix');
+ $sql = "SELECT
'{$map['type']}' AS type,
'{$map['start_time']}' AS start_time,
'{$map['end_time']}' AS end_time,
@@ -570,18 +593,18 @@ class Business extends Common
WHERE
create_time BETWEEN {$map['start_time']} AND {$map['end_time']}
AND owner_user_id IN ({$map['owner_user_id']})";
- return $sql;
- }
+ return $sql;
+ }
- /**
+ /**
* [赢单机会转化率趋势分析]
- * @param
- * @return
- */
- public function getWinSql($map)
- {
- $prefix = config('database.prefix');
- $sql = "SELECT
+ * @param
+ * @return
+ */
+ public function getWinSql($map)
+ {
+ $prefix = config('database.prefix');
+ $sql = "SELECT
'{$map['type']}' AS type,
'{$map['start_time']}' AS start_time,
'{$map['end_time']}' AS end_time,
@@ -607,8 +630,8 @@ class Business extends Common
WHERE
create_time BETWEEN {$map['start_time']} AND {$map['end_time']}
AND owner_user_id IN ({$map['owner_user_id']})";
- return $sql;
- }
+ return $sql;
+ }
/**
* 获取系统信息
@@ -619,7 +642,7 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
- public function getSystemInfo($id)
+ public function getSystemInfo($id)
{
# 商机
$business = Db::name('crm_business')->field(['create_user_id', 'create_time', 'update_time'])->where('business_id', $id)->find();
@@ -630,9 +653,9 @@ class Business extends Common
return [
'create_user_name' => $realname,
- 'create_time' => date('Y-m-d H:i:s', $business['create_time']),
- 'update_time' => date('Y-m-d H:i:s', $business['update_time']),
- 'follow_time' => !empty($followTime) ? date('Y-m-d H:i:s', $followTime) : ''
+ 'create_time' => date('Y-m-d H:i:s', $business['create_time']),
+ 'update_time' => date('Y-m-d H:i:s', $business['update_time']),
+ 'follow_time' => !empty($followTime) ? date('Y-m-d H:i:s', $followTime) : ''
];
}
diff --git a/application/crm/model/Contacts.php b/application/crm/model/Contacts.php
index 53cb8c9..7708eb7 100644
--- a/application/crm/model/Contacts.php
+++ b/application/crm/model/Contacts.php
@@ -85,7 +85,7 @@ class Contacts extends Common
if (!is_array($map['contacts.owner_user_id'][1])) {
$map['contacts.owner_user_id'][1] = [$map['contacts.owner_user_id'][1]];
}
- if ($map['contacts.owner_user_id'][0] == 'neq') {
+ if (in_array($map['contacts.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['contacts.owner_user_id'][1]) ? : []; //取差集
} else {
$auth_user_ids = array_intersect($map['contacts.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@@ -107,7 +107,8 @@ class Contacts extends Common
//列表展示字段
$indexField = $fieldModel->getIndexField('crm_contacts', $user_id, 1) ? : array('name');
$userField = $fieldModel->getFieldByFormType('crm_contacts', 'user'); //人员类型
- $structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型
+ $structureField = $fieldModel->getFieldByFormType('crm_contacts', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
@@ -130,7 +131,7 @@ class Contacts extends Common
->where($searchMap)
->where($authMap)
->where($customerWhere)
- ->count('contacts_id');
+ ->count('contacts_id');
if ($getCount == 1) {
$data['dataCount'] = $dataCount ? : 0;
return $data;
@@ -144,7 +145,6 @@ class Contacts extends Common
->where($customerWhere)
->limit($request['offset'], $request['length'])
->field('contacts.*,customer.name as customer_name')
- ->field(implode(',',$indexField).',customer.name as customer_name')
->orderRaw($order)
->select();
@@ -154,11 +154,16 @@ class Contacts extends Common
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : '';
foreach ($userField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
- }
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
+ }
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
//权限
$permission = [];
@@ -173,9 +178,6 @@ class Contacts extends Common
$permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission;
- # 下次联系时间
- $list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
-
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['contacts_id'], 'type' => 'crm_contacts'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@@ -227,9 +229,6 @@ class Contacts extends Common
$param['primary'] = 1;
}
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) {
@@ -249,7 +248,7 @@ class Contacts extends Common
'create_user_id' => $param['create_user_id'],
'update_time' => time(),
'create_time' => time(),
- 'customer_ids' => $param['customer_id']
+ 'customer_ids' => $param['customer_id']
]);
# 处理商机首要联系人
@@ -319,9 +318,6 @@ class Contacts extends Common
return false;
}
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_contacts');
foreach ($arrFieldAtt as $k=>$v) {
@@ -382,7 +378,11 @@ class Contacts extends Common
# 处理决策人显示问题
$dataInfo['decision'] = !empty($dataInfo['decision']) && $dataInfo['decision'] == '是' ? '是' : '';
# 处理时间格式
- $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_contacts', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
diff --git a/application/crm/model/Contract.php b/application/crm/model/Contract.php
index 39fe105..888ade3 100644
--- a/application/crm/model/Contract.php
+++ b/application/crm/model/Contract.php
@@ -99,7 +99,7 @@ class Contract extends Common
if (!is_array($map['contract.owner_user_id'][1])) {
$map['contract.owner_user_id'][1] = [$map['contract.owner_user_id'][1]];
}
- if ($map['contract.owner_user_id'][0] == 'neq') {
+ if (in_array($map['contract.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['contract.owner_user_id'][1]) ? : []; //取差集
} else {
$auth_user_ids = array_intersect($map['contract.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@@ -127,6 +127,7 @@ class Contract extends Common
//人员类型
$userField = $fieldModel->getFieldByFormType('crm_contract', 'user');
$structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_contract','contract',$order_field,$order_type);
@@ -186,11 +187,16 @@ class Contract extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
}
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
$list[$k]['business_id_info']['business_id'] = $v['business_id'];
$list[$k]['business_id_info']['name'] = $v['business_name'];
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
@@ -226,6 +232,9 @@ class Contract extends Common
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
$list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
+ $list[$k]['order_date'] = ($v['order_date']!='0000-00-00') ? $v['order_date'] : null;
+ $list[$k]['start_time'] = ($v['start_time']!='0000-00-00') ? $v['start_time'] : null;
+ $list[$k]['end_time'] = ($v['end_time']!='0000-00-00') ? $v['end_time'] : null;
# 签约人姓名
$orderNames = Db::name('admin_user')->whereIn('id', trim($v['order_user_id'], ','))->column('realname');
$list[$k]['order_user_name'] = implode(',', $orderNames);
@@ -488,6 +497,11 @@ class Contract extends Common
$orderNames = Db::name('admin_user')->whereIn('id', trim($dataInfo['order_user_id'], ','))->column('realname');
$dataInfo['order_user_name'] = implode(',', $orderNames);
# 处理时间根式
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_contract', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
@@ -510,10 +524,10 @@ class Contract extends Common
foreach ($ids as $id) {
$contractInfo = [];
$contractInfo = db('crm_contract')->where(['contract_id' => $id])->find();
- if (in_array($contractInfo['check_status'],['0','1'])) {
- $errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;';
- continue;
- }
+// if (in_array($contractInfo['check_status'],['0','1'])) {
+// $errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:审批中,无法转移;';
+// continue;
+// }
//团队成员
$teamData = [];
$teamData['type'] = $type; //权限 1只读2读写
@@ -529,7 +543,19 @@ class Contract extends Common
if (!db('crm_contract')->where(['contract_id' => $id])->update($data)) {
$errorMessage[] = '合同:'.$contractInfo['name'].'"转移失败,错误原因:数据出错;';
continue;
- }
+ } else {
+ $contractArray = [];
+ $teamContract = db('crm_contract')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('contract_id', $id)->find();
+ if (!empty($teamContract['ro_user_id'])) {
+ $contractRo = arrayToString(array_diff(stringToArray($teamContract['ro_user_id']), [$teamContract['owner_user_id']]));
+ $contractArray['ro_user_id'] = $contractRo;
+ }
+ if (!empty($teamContract['rw_user_id'])) {
+ $contractRo = arrayToString(array_diff(stringToArray($teamContract['rw_user_id']), [$teamContract['owner_user_id']]));
+ $contractArray['rw_user_id'] = $contractRo;
+ }
+ db('crm_contract')->where('contract_id', $id)->update($contractArray);
+ }
}
if ($errorMessage) {
return $errorMessage;
diff --git a/application/crm/model/Customer.php b/application/crm/model/Customer.php
index fc7d995..1796d79 100644
--- a/application/crm/model/Customer.php
+++ b/application/crm/model/Customer.php
@@ -127,7 +127,7 @@ class Customer extends Common
if (!is_array($map['customer.owner_user_id'][1])) {
$map['customer.owner_user_id'][1] = [$map['customer.owner_user_id'][1]];
}
- if ($map['customer.owner_user_id'][0] == 'neq') {
+ if (in_array($map['customer.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['customer.owner_user_id'][1]) ? : []; //取差集
} else {
$auth_user_ids = array_intersect($map['customer.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@@ -169,6 +169,7 @@ class Customer extends Common
$indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ? : array('name');
$userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
@@ -190,8 +191,7 @@ class Customer extends Common
->where($poolMap)
->where($otherMap)
->limit($request['offset'], $request['length'])
- ->field(implode(',',$indexField))
- ->order($order_t) /*置顶*/
+ ->field('customer.*')
->orderRaw($order)
->select();
//保护规则
@@ -228,14 +228,19 @@ class Customer extends Common
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) {
if (in_array($val, $field_list)) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
}
foreach ($structureField as $key => $val) {
if (in_array($val, $field_list)) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
}
}
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
//商机数
$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
//距进入公海天数
@@ -268,9 +273,6 @@ class Customer extends Common
$permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission;
- # 下次联系时间
- $list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
-
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['customer_id'], 'type' => 'crm_customer'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@@ -327,9 +329,6 @@ class Customer extends Common
return false;
}
unset($param['customer_id']);
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_customer');
@@ -377,71 +376,68 @@ class Customer extends Common
* @author Michael_xu
* @param
* @return
- */
- public function updateDataById($param, $customer_id = '')
- {
- $user_id = $param['user_id'];
- $dataInfo = $this->get($customer_id);
- if (!$dataInfo) {
- $this->error = '数据不存在或已删除';
- return false;
- }
-
- //数据权限判断
+ */
+ public function updateDataById($param, $customer_id = '')
+ {
+ $user_id = $param['user_id'];
+ $dataInfo = $this->get($customer_id);
+ if (!$dataInfo) {
+ $this->error = '数据不存在或已删除';
+ return false;
+ }
+ $id = $param['id']?:$customer_id;
+ //数据权限判断
$userModel = new \app\admin\model\User();
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'update');
//读写权限
- $rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
+ $rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update');
//判断是否客户池数据
$wherePool = $this->getWhereByPool();
- $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find();
+ $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $id])->where($wherePool)->find();
if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) {
$this->error = '无权操作';
return false;
- }
-
- $param['customer_id'] = $customer_id;
- //过滤不能修改的字段
- $unUpdateField = ['create_user_id','is_deleted','delete_time','user_id'];
- foreach ($unUpdateField as $v) {
- unset($param[$v]);
- }
- $param['deal_status'] = $dataInfo['deal_status'];
- $fieldModel = new \app\admin\model\Field();
- // 自动验证
- $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
- $validate = new Validate($validateArr['rule'], $validateArr['message']);
- $result = $validate->check($param);
- if (!$result) {
- $this->error = $validate->getError();
- return false;
- }
- //地址
- $param['address'] = $param['address'] ? implode(chr(10),$param['address']) : '';
- if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') {
+ }
+
+ $param['customer_id'] = $customer_id;
+ //过滤不能修改的字段
+ $unUpdateField = ['create_user_id','is_deleted','delete_time','user_id'];
+ foreach ($unUpdateField as $v) {
+ unset($param[$v]);
+ }
+ $param['deal_status'] = $dataInfo['deal_status'];
+ $fieldModel = new \app\admin\model\Field();
+ // 自动验证
+ $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
+ $validate = new Validate($validateArr['rule'], $validateArr['message']);
+ $result = $validate->check($param);
+ if (!$result) {
+ $this->error = $validate->getError();
+ return false;
+ }
+ //地址
+ $param['address'] = $param['address'] ? implode(chr(10),$param['address']) : '';
+ if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') {
$param['deal_time'] = time();
}
-
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
- //处理部门、员工、附件、多选类型字段
- $arrFieldAtt = $fieldModel->getArrayField('crm_customer');
- foreach ($arrFieldAtt as $k=>$v) {
- $param[$v] = arrayToString($param[$v]);
- }
- $param['follow'] = '已跟进';
- if ($this->update($param, ['customer_id' => $customer_id], true)) {
- //修改记录
- updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param);
- $data = [];
- $data['customer_id'] = $customer_id;
- return $data;
- } else {
- $this->error = '编辑失败';
- return false;
- }
- }
+
+ //处理部门、员工、附件、多选类型字段
+ $arrFieldAtt = $fieldModel->getArrayField('crm_customer');
+ foreach ($arrFieldAtt as $k=>$v) {
+ $param[$v] = arrayToString($param[$v]);
+ }
+ $param['follow'] = '已跟进';
+ if ($this->update($param, ['customer_id' => $customer_id], true)) {
+ //修改记录
+ updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param);
+ $data = [];
+ $data['customer_id'] = $customer_id;
+ return $data;
+ } else {
+ $this->error = '编辑失败';
+ return false;
+ }
+ }
/**
* 客户数据
@@ -495,7 +491,11 @@ class Customer extends Common
$primaryId = Db::name('crm_contacts')->where(['customer_id' => $id, 'primary' => 1])->value('contacts_id');
$dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0;
# 处理时间格式
- $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_customer', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
diff --git a/application/crm/model/Invoice.php b/application/crm/model/Invoice.php
index 4d56192..9a6196b 100644
--- a/application/crm/model/Invoice.php
+++ b/application/crm/model/Invoice.php
@@ -14,6 +14,7 @@ class Invoice extends Common
{
protected $name = 'crm_invoice';
protected $pk = 'invoice_id';
+ protected $dateFormat = "Y-m-d H:i:s";
/**
* 关联用户模型
diff --git a/application/crm/model/Leads.php b/application/crm/model/Leads.php
index 42bf606..cdd7b30 100644
--- a/application/crm/model/Leads.php
+++ b/application/crm/model/Leads.php
@@ -90,7 +90,7 @@ class Leads extends Common
if (!is_array($map['leads.owner_user_id'][1])) {
$map['leads.owner_user_id'][1] = [$map['leads.owner_user_id'][1]];
}
- if ($map['leads.owner_user_id'][0] == 'neq') {
+ if (in_array($map['leads.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['leads.owner_user_id'][1]) ?: []; //取差集
} else {
$auth_user_ids = array_intersect($map['leads.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
@@ -104,6 +104,7 @@ class Leads extends Common
$indexField = $fieldModel->getIndexField('crm_leads', $user_id, 1) ?: array('name');
$userField = $fieldModel->getFieldByFormType('crm_leads', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_leads', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型
//排序
if ($order_type && $order_field) {
@@ -139,10 +140,15 @@ class Leads extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) {
- $list[$k][$val . '_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val . '_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
+ }
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
//权限
$permission = [];
@@ -156,8 +162,6 @@ class Leads extends Common
$permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission;
- # 下次联系时间
- $list[$k]['next_time'] = !empty($v['next_time']) ? date('Y-m-d H:i:s', $v['next_time']) : null;
# 关注
$starWhere = ['user_id' => $user_id, 'target_id' => $v['leads_id'], 'type' => 'crm_leads'];
$star = Db::name('crm_star')->where($starWhere)->value('star_id');
@@ -210,9 +214,6 @@ class Leads extends Common
$param[$v] = arrayToString($param[$v]);
}
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
//修改记录
updateActionLog($param['create_user_id'], 'crm_leads', $this->leads_id, '', '', '创建了线索');
@@ -276,9 +277,6 @@ class Leads extends Common
return false;
}
- # 处理下次联系时间
- if (!empty($param['next_time'])) $param['next_time'] = strtotime($param['next_time']);
-
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_leads');
foreach ($arrFieldAtt as $k => $v) {
@@ -323,7 +321,11 @@ class Leads extends Common
$starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_leads'])->value('star_id');
$dataInfo['star'] = !empty($starId) ? 1 : 0;
# 处理时间格式处理
- $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_leads', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null;
diff --git a/application/crm/model/Product.php b/application/crm/model/Product.php
index 26d9609..7eb8f94 100644
--- a/application/crm/model/Product.php
+++ b/application/crm/model/Product.php
@@ -35,7 +35,7 @@ class Product extends Common
* @return array
*/
public function getDataList($request)
- {
+ {
$userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure();
$fieldModel = new \app\admin\model\Field();
@@ -48,8 +48,8 @@ class Product extends Common
$isStatus = !empty($request['is_status']) ? $request['is_status'] : 0;
unset($request['scene_id']);
unset($request['search']);
- unset($request['user_id']);
- unset($request['order_field']);
+ unset($request['user_id']);
+ unset($request['order_field']);
unset($request['order_type']);
unset($request['is_status']);
@@ -87,7 +87,7 @@ class Product extends Common
if (!is_array($map['product.owner_user_id'][1])) {
$map['product.owner_user_id'][1] = [$map['product.owner_user_id'][1]];
}
- if ($map['product.owner_user_id'][0] == 'neq') {
+ if (in_array($map['product.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['product.owner_user_id'][1]) ?: []; //取差集
} else {
$auth_user_ids = array_intersect($map['product.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
@@ -102,25 +102,26 @@ class Product extends Common
$indexField = $fieldModel->getIndexField('crm_product', $user_id, 1) ? : ['name'];
$userField = $fieldModel->getFieldByFormType('crm_product', 'user'); //人员类型
$structureField = $fieldModel->getFieldByFormType('crm_product', 'structure'); //部门类型
-
+ $datetimeField = $fieldModel->getFieldByFormType('crm_product', 'datetime'); //日期时间类型
+
//排序
if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_product','product',$order_field,$order_type);
} else {
$order = 'product.update_time desc';
- }
+ }
$join = [
['__CRM_PRODUCT_CATEGORY__ product_category', 'product_category.category_id = product.category_id', 'LEFT'],
];
-
+ $map['product.delete_user_id']=0;
$list = db('crm_product')->alias('product')
->join($join)
->where($map)
->where($authMap)
->limit($request['offset'], $request['length'])
->field($indexField)
- ->field(array_merge($indexField, ['product_category.name' => 'category_name']))
+ ->field('product.*,product_category.name as category_name')
->orderRaw($order)
->select();
$dataCount = db('crm_product')->alias('product')
@@ -132,11 +133,16 @@ class Product extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
foreach ($userField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
}
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
//产品类型
$list[$k]['category_id_info'] = $v['category_name'];
# 处理日期格式
@@ -153,23 +159,25 @@ class Product extends Common
/**
* 创建产品主表信息
* @author Michael_xu
- * @param
- * @return
- */
+ * @param
+ * @return
+ */
public function createData($param)
{
$fieldModel = new \app\admin\model\Field();
$productCategoryModel = model('ProductCategory');
- // 自动验证
- $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
- $validate = new Validate($validateArr['rule'], $validateArr['message']);
-
- $result = $validate->check($param);
- if (!$result) {
- $this->error = $validate->getError();
- return false;
- }
-
+ $dataInfo = db('crm_product')->where(['name'=>$param['name'],'delete_user_id'=>0])->find();
+ if(isset($dataInfo)){
+ // 自动验证
+ $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
+ $validate = new Validate($validateArr['rule'], $validateArr['message']);
+
+ $result = $validate->check($param);
+ if (!$result) {
+ $this->error = $validate->getError();
+ return false;
+ }
+ }
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_product');
foreach ($arrFieldAtt as $k=>$v) {
@@ -200,17 +208,18 @@ class Product extends Common
} else {
$this->error = '添加失败';
return false;
- }
+ }
}
/**
* 编辑产品主表信息
* @author Michael_xu
- * @param
- * @return
- */
+ * @param
+ * @return
+ */
public function updateDataById($param, $product_id = '')
{
+ $userModel = new \app\admin\model\User();
$dataInfo = $this->getDataById($product_id);
$productCategoryModel = model('ProductCategory');
if (!$dataInfo) {
@@ -222,7 +231,7 @@ class Product extends Common
if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
$this->error = '无权操作';
return false;
- }
+ }
$param['product_id'] = $product_id;
//过滤不能修改的字段
@@ -232,15 +241,16 @@ class Product extends Common
}
$fieldModel = new \app\admin\model\Field();
- // 自动验证
- $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
- $validate = new Validate($validateArr['rule'], $validateArr['message']);
-
- $result = $validate->check($param);
- if (!$result) {
- $this->error = $validate->getError();
- return false;
- }
+ // 自动验证
+// $validateArr = $fieldModel->validateField($this->name); //获取自定义字段验证规则
+// $validate = new Validate($validateArr['rule'], $validateArr['message']);
+//
+// $result = $validate->check($param);
+// if (!$result) {
+// $this->error = $validate->getError();
+// return false;
+// }
+
//处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_product');
@@ -250,17 +260,16 @@ class Product extends Common
//产品分类
$category_id = $param['category_id'];
- if (is_array($category_id)) {
- $param['category_id'] = $productCategoryModel->getIdByStr($category_id);
- $param['category_str'] = arrayToString($category_id);
- }
+// if (is_array($category_id)) {
+// $param['category_id'] = $productCategoryModel->getIdByStr($category_id);
+// $param['category_str'] = arrayToString($category_id);
+// }
if(!is_int($category_id)){
$list=db('crm_product_category')->column('category_id','name');
+ $param['category_id']=1;
foreach ($list as $k=>$v){
- if($k==$param['category_id']){
+ if($k==$category_id){
$param['category_id']=$v;
- }else{
- $param['category_id']=0;
}
}
}
@@ -274,7 +283,7 @@ class Product extends Common
$this->rollback();
$this->error = '编辑失败';
return false;
- }
+ }
}
/**
@@ -287,8 +296,9 @@ class Product extends Common
* @throws \think\exception\DbException
*/
public function getDataById($id = '')
- {
+ {
$map['product_id'] = $id;
+ $map['delete_user_id'] = 0;
$dataInfo = db('crm_product')->where($map)->find();
if (!$dataInfo) {
$this->error = '暂无此数据';
@@ -302,8 +312,13 @@ class Product extends Common
$userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = $userModel->getUserById($dataInfo['create_user_id']);
- $dataInfo['category_id_info'] = db('crm_product_category')->where(['category_id' => $dataInfo['category_id']])->value('name');
+ $dataInfo['category_id_info'] = db('crm_product_category')->where(['category_id' => $dataInfo['category_id']])->value('name');
# 处理日期格式
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_product', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo;
@@ -320,19 +335,15 @@ class Product extends Common
*/
private function getProductImages($fileIds)
{
- $result = [];
+ $files = Db::name('admin_file')->whereIn('file_id', $fileIds)->select();
- $files = Db::name('admin_file')->field(['file_id', 'file_path_thumb', 'file_path', 'save_name'])->whereIn('file_id', $fileIds)->select();
foreach ($files AS $key => $value) {
- $result[] = [
- 'file_id' => $value['file_id'],
- 'file_path_thumb' => getFullPath($value['file_path_thumb']),
- 'file_path' => getFullPath($value['file_path']),
- 'save_name' => $value['save_name']
- ];
+ $files[$key]['file_path'] = getFullPath($value['file_path']);
+ $files[$key]['file_path_thumb'] = getFullPath($value['file_path_thumb']);
+ $files[$key]['size'] = format_bytes($value['size']);
}
- return $result;
+ return $files;
}
/**
@@ -346,10 +357,10 @@ class Product extends Common
* @param subtotal 小计(折扣后价格)
* @param unit 单位
* @param total_price 折扣后整单总价
- * @param discount_rate 整单折扣
+ * @param discount_rate 整单折扣
* @param objId 关联对象ID
- * @return
- */
+ * @return
+ */
public function createObject($types, $param, $objId)
{
switch ($types) {
@@ -375,7 +386,7 @@ class Product extends Common
$product[$key]['discount'] = $value['discount']; //折扣
$product[$key]['unit'] = $value['unit'] ? : ''; //单位
$product[$key]['subtotal'] = $value['subtotal'];
- // $total_price += $product[$key]['subtotal'] = round(($value['price'] * $value['num']) * $discount); //总价
+ // $total_price += $product[$key]['subtotal'] = round(($value['price'] * $value['num']) * $discount); //总价
$product[$key][$db_id] = $objId;
}
@@ -388,18 +399,18 @@ class Product extends Common
//产品合计
$rData['discount_rate'] = !empty($param['discount_rate']) ? $param['discount_rate'] : 0.00; //整单折扣
$discount_rate = ((100 - $rData['discount_rate']) > 0) ? (100 - $rData['discount_rate'])/100 : 0;
- // $rData['total_price'] = $total_price ? $total_price*$discount_rate : '0.00'; //整单合计
- $rData['total_price'] = $param['total_price'] ? : '0.00'; //整单合计
- db($rDb)->where([$db_id => $objId])->update($rData);
+ // $rData['total_price'] = $total_price ? $total_price*$discount_rate : '0.00'; //整单合计
+ $rData['total_price'] = $param['total_price'] ? : '0.00'; //整单合计
+ db($rDb)->where([$db_id => $objId])->update($rData);
// 提交事务
Db::commit();
- return true;
+ return true;
} catch (\Exception $e) {
$this->error = '产品数据创建出错';
// 回滚事务
- Db::rollback();
- return false;
+ Db::rollback();
+ return false;
}
} else {
//删除产品信息
@@ -425,7 +436,7 @@ class Product extends Common
$perUserIds = $userModel->getUserByPer('bi', 'product', 'read'); //权限范围内userIds
$whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件
$userIds = $whereData['userIds'];
- $between_time = $whereData['between_time'];
+ $between_time = $whereData['between_time'];
$where = [];
//时间段
$where['contract.create_time'] = ['between', $between_time];
@@ -457,7 +468,7 @@ class Product extends Common
$list[$k]['contract_id_info'] = $contract_info ? : array();
//产品
$product_info = [];
- $product_info['name'] = $v['product_name'];
+ $product_info['name'] = $v['product_name'];
$product_info['product_id'] = $v['product_id'];
$list[$k]['product_id_info'] = $product_info ? : array();
//负责人
@@ -467,14 +478,14 @@ class Product extends Common
$list[$k]['owner_user_name'] = $owner_user_id_info['realname'];
}
return $list;
- }
+ }
/**
* [根据产品类别ID,查询父级ID]
* @author Michael_xu
- * @param
- * @return
- */
+ * @param
+ * @return
+ */
public function getPidStr($category_id, $idArr, $first = '')
{
if ($first == 1) $idArr = [];
diff --git a/application/crm/model/Receivables.php b/application/crm/model/Receivables.php
index 394c222..3408058 100644
--- a/application/crm/model/Receivables.php
+++ b/application/crm/model/Receivables.php
@@ -83,7 +83,7 @@ class Receivables extends Common
if (!is_array($map['receivables.owner_user_id'][1])) {
$map['receivables.owner_user_id'][1] = [$map['receivables.owner_user_id'][1]];
}
- if ($map['receivables.owner_user_id'][0] == 'neq') {
+ if (in_array($map['receivables.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['receivables.owner_user_id'][1]) ? : []; //取差集
} else {
$auth_user_ids = array_intersect($map['receivables.owner_user_id'][1], $auth_user_ids) ? : []; //取交集
@@ -97,7 +97,8 @@ class Receivables extends Common
$indexField = $fieldModel->getIndexField('crm_receivables', $user_id, 1) ? : array('number');
//人员类型
$userField = $fieldModel->getFieldByFormType('crm_receivables', 'user');
- $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型
+ $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型
+ $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
if ($request['order_type'] && $request['order_field']) {
$order = $fieldModel->getOrderByFormtype('crm_receivables','receivables',$order_field,$order_type);
@@ -134,7 +135,7 @@ class Receivables extends Common
->where($map)
->where($authMap)
->limit($request['offset'], $request['length'])
- ->field(implode(',',$indexField).',customer.name as customer_name,contract.name as contract_name,contract.num as contract_num,contract.money as contract_money')
+ ->field('receivables.*,customer.name as customer_name,contract.name as contract_name,contract.num as contract_num,contract.money as contract_money')
->orderRaw($order)
->select();
@@ -150,11 +151,16 @@ class Receivables extends Common
$list[$k]['contract_id_info']['money'] = $v['contract_money'] ? : '0.00';
$list[$k]['contract_money'] = $v['contract_money'] ? : '0.00';
foreach ($userField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $userModel->getListByStr($v[$val]) : [];
+ $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
+ $list[$k][$val] = implode($usernameField, ',');
}
foreach ($structureField as $key => $val) {
- $list[$k][$val.'_info'] = isset($v[$val]) ? $structureModel->getDataByStr($v[$val]) : [];
+ $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
+ $list[$k][$val] = implode($structureNameField, ',');
}
+ foreach ($datetimeField as $key => $val) {
+ $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
+ }
$list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
//期数
$plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num');
@@ -403,6 +409,11 @@ class Receivables extends Common
$dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
$dataInfo['receivables_id'] = $id;
# 处理时间格式
+ $fieldModel = new \app\admin\model\Field();
+ $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
+ foreach ($datetimeField as $key => $val) {
+ $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
+ }
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
$dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
return $dataInfo;
diff --git a/application/oa/controller/Event.php b/application/oa/controller/Event.php
index f9604d6..168db11 100644
--- a/application/oa/controller/Event.php
+++ b/application/oa/controller/Event.php
@@ -236,7 +236,9 @@ class Event extends ApiCommon
$eventModel = model('Event');
$data = $eventModel->getDataById($this->param['event_id']);
-
+ if(!$data['title']){
+ return resultArray(['error' => '日程已删除']);
+ }
return resultArray(['data' => $data]);
}
diff --git a/application/oa/controller/Examine.php b/application/oa/controller/Examine.php
index c414ce5..f8cf20d 100644
--- a/application/oa/controller/Examine.php
+++ b/application/oa/controller/Examine.php
@@ -468,7 +468,7 @@ class Examine extends ApiCommon
$is_end = 1;
//审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3;
- $examineData['check_user_id'] = '';
+// $examineData['check_user_id'] = '';
} else {
//修改主体相关审批信息
$examineData['check_user_id'] = arrayToString($next_user_ids);
@@ -484,7 +484,7 @@ class Examine extends ApiCommon
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
- $examineData['check_user_id'] = '';
+// $examineData['check_user_id'] = '';
$examineData['check_status'] = 2;
}
} else {
@@ -588,8 +588,9 @@ class Examine extends ApiCommon
$checkData['status'] = $status;
$examineData['check_status'] = 4;
- $examineData['check_user_id'] = '';
- $examineData['flow_user_id'] = '';
+ # 如果将审批人置空,会导致普通员工在右上角消息中无法查看审批
+ $examineData['check_user_id'] = $dataInfo['check_user_id'];
+ $examineData['flow_user_id'] = '';
$resExamine = db('oa_examine')->where(['examine_id' => $examine_id])->update($examineData);
if ($resExamine) {
//将审批记录至为无效
diff --git a/application/oa/controller/Task.php b/application/oa/controller/Task.php
index c5936ea..0f86786 100644
--- a/application/oa/controller/Task.php
+++ b/application/oa/controller/Task.php
@@ -33,7 +33,7 @@ class Task extends ApiCommon
Hook::listen('check_auth', $action);
$request = Request::instance();
$a = strtolower($request->action());
-
+
if (!in_array($a, $action['permission'])) {
parent::_initialize();
}
@@ -48,7 +48,7 @@ class Task extends ApiCommon
}
}
}
-
+
//判断任务(需创建人和负责人才能编辑删除)
public function checkSub($task_id)
{
@@ -62,7 +62,7 @@ class Task extends ApiCommon
exit(json_encode(['code' => 102, 'error' => '没有权限']));
}
}
-
+
/**
* 查看下属创建的任务
* @param //负责和参与
@@ -71,9 +71,9 @@ class Task extends ApiCommon
*/
public function subTaskList()
{
-
+
}
-
+
/**
* 查看所有的项目
* @param
@@ -88,7 +88,7 @@ class Task extends ApiCommon
$data['count'] = $count;
return resultArray(['data' => $data]);
}
-
+
/**
* 查看某个项目下任务列表
* @param
@@ -104,7 +104,7 @@ class Task extends ApiCommon
$list = $taskModel->getDataList($param, $userInfo['id']);
return resultArray(['data' => $list]);
}
-
+
/**
* 查看我的任务
* @param
@@ -137,7 +137,6 @@ class Task extends ApiCommon
} else {
$where['t.status'] = [['=', 1], ['=', 5], 'OR'];
}
-
if ($param['main_user_id']) {
$where['t.main_user_id'] = $param['main_user_id'];
}
@@ -154,25 +153,25 @@ class Task extends ApiCommon
$subArr[] = $v;
$subArr[] = '|';
}
- $subValue = $subList ? arrayToString($subArr) : '';
+ $subValue = $subList ? arrayToString($subArr) : '';
$where['t.ishidden'] = 0;
$where['t.pid'] = 0;
if ($type != 0) {
switch ($type) {
case '1' :
- $type = 't.main_user_id in ('.$subStr.')';
+ $type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的
case '3' :
//使用正则查询
// SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)';
- $type = $subValue ? 't.owner_user_id REGEXP "('.$subValue.')"' : '';
+ $type = $subValue ? 't.owner_user_id REGEXP "(' . $subValue . ')"' : '';
break; //下属参与的
}
} else {
if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} else {
- $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "('.$subValue.')")';
+ $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "(' . $subValue . ')")';
}
}
// $where['t.work_id'] = 0;
@@ -195,13 +194,12 @@ class Task extends ApiCommon
$query->where($type);
})
->count();
-
- $completeCount = db('task') ->alias('t')->where($where)
+ $completeCount = db('task')->alias('t')
->where($map)
->where(function ($query) use ($type) {
$query->where($type);
- })->where('t.status', 5)->count();
-
+ })
+ ->where($map)->where(['t.status' => 5, 't.ishidden' => 0, 'priority' => $priority])->count();
foreach ($taskList as $k => $v) {
$temp = $v ?: [];
if ($v['pid']) {
@@ -217,7 +215,7 @@ class Task extends ApiCommon
$taskList[$k]['lableList'] = $v['lable_id'] ? $lableModel->getDataByStr($v['lable_id']) : [];
$taskList[$k]['main_user'] = $v['main_user_id'] ? $userModel->getUserById($v['main_user_id']) : array();
$taskList[$k]['relationCount'] = $taskModel->getRelationCount($v['task_id']);
-
+
$taskList[$k]['create_time'] = date('Y-m-d', $v['create_time']) ?: '';
$taskList[$k]['update_time'] = date('Y-m-d', $v['update_time']) ?: '';
$taskList[$k]['start_time'] = $v['start_time'] == 0 ? null : date('Y-m-d', $v['start_time']);;
@@ -226,7 +224,7 @@ class Task extends ApiCommon
if (!empty($v['stop_time']) && (strtotime(date('Ymd')) + 86400 > $v['stop_time'])) $is_end = 1;
$taskList[$k]['is_end'] = $is_end;
}
-
+
} else {
$map['t.pid'] = 0;
// $map['t.work_id'] = 0;
@@ -236,15 +234,15 @@ class Task extends ApiCommon
$type = 't.main_user_id =' . $userInfo['id'] . '';
break; //我负责的
case '3' :
- $type = 't.owner_user_id like "%,'.$userInfo['id'].',%"';
+ $type = 't.owner_user_id like "%,' . $userInfo['id'] . ',%"';
break; //我参与的
}
} else {
$adminIds = $userModel->getAdminId();
- if (in_array($userInfo['id'],$adminIds)) {
- $type = 't.is_open = 1';
+ if (in_array($userInfo['id'], $adminIds)) {
+ $type = 't.is_open = 1';
} else {
- $type = 't.is_open = 1 AND (t.main_user_id =' . $userInfo['id'] .' OR t.owner_user_id like "%,'.$userInfo['id'].',%")';
+ $type = 't.is_open = 1 AND (t.main_user_id =' . $userInfo['id'] . ' OR t.owner_user_id like "%,' . $userInfo['id'] . ',%")';
}
}
$where['t.ishidden'] = 0;
@@ -259,33 +257,35 @@ class Task extends ApiCommon
->order('t.task_id desc')
->select();
$dataCount = db('task')->alias('t')->where($where)->where($type)->where($map)->count();
- $completeCount = db('task')->alias('t')->where($where)->where($type)->where($map)->where('t.status', 5)->count();
+ $completeCount = db('task')->alias('t')
+ ->where($type)
+ ->where($map)->where(['t.status' => 5, 't.ishidden' => 0, 'priority' => $priority])->count();
foreach ($taskList as $key => $value) {
$pname = '';
if ($value['pid']) {
- $pname = Db::name('Task')->where('task_id ='.$value['pid'])->value('name');
+ $pname = Db::name('Task')->where('task_id =' . $value['pid'])->value('name');
}
- $taskList[$key]['pname'] = $pname ? : '';
+ $taskList[$key]['pname'] = $pname ?: '';
$taskList[$key]['thumb_img'] = $value['thumb_img'] ? getFullPath($value['thumb_img']) : '';
- $taskList[$key]['subcount'] = Db::name('Task')->where(['ishidden' => 0,'status' => 1,'pid' => $value['task_id']])->count(); //子任务
- $taskList[$key]['subdonecount'] = Db::name('Task')->where(['ishidden' => 0,'status' => 5,'pid' => $value['task_id']])->count(); //已完成子任务
- $taskList[$key]['commentcount'] = Db::name('AdminComment')->where(['type' => 'task','type_id' => $value['task_id']])->count();
- $taskList[$key]['filecount'] = Db::name('WorkTaskFile')->where('task_id ='.$value['task_id'])->count();
+ $taskList[$key]['subcount'] = Db::name('Task')->where(['ishidden' => 0, 'status' => 1, 'pid' => $value['task_id']])->count(); //子任务
+ $taskList[$key]['subdonecount'] = Db::name('Task')->where(['ishidden' => 0, 'status' => 5, 'pid' => $value['task_id']])->count(); //已完成子任务
+ $taskList[$key]['commentcount'] = Db::name('AdminComment')->where(['type' => 'task', 'type_id' => $value['task_id']])->count();
+ $taskList[$key]['filecount'] = Db::name('WorkTaskFile')->where('task_id =' . $value['task_id'])->count();
$taskList[$key]['lableList'] = $value['lable_id'] ? $lableModel->getDataByStr($value['lable_id']) : [];
-
- $taskList[$key]['create_time'] = date('Y-m-d', $value['create_time']) ?: '';
- $taskList[$key]['update_time'] = date('Y-m-d', $value['update_time']) ?: '';
- $taskList[$key]['start_time'] = $value['start_time']==0?null:date('Y-m-d', $value['start_time']);;
- $taskList[$key]['stop_time'] = $value['stop_time']==0?null:date('Y-m-d', $value['stop_time']);
+
+ $taskList[$key]['create_time'] = date('Y-m-d', $value['create_time']) ?: '';
+ $taskList[$key]['update_time'] = date('Y-m-d', $value['update_time']) ?: '';
+ $taskList[$key]['start_time'] = $value['start_time'] == 0 ? null : date('Y-m-d', $value['start_time']);;
+ $taskList[$key]['stop_time'] = $value['stop_time'] == 0 ? null : date('Y-m-d', $value['stop_time']);
//负责人信息
$taskList[$key]['main_user'] = $value['main_user_id'] ? $userModel->getDataById($value['main_user_id']) : array();
$taskList[$key]['relationCount'] = $taskModel->getRelationCount($value['task_id']);
$is_end = 0;
- if (!empty($value['stop_time']) && (strtotime(date('Ymd'))+86399 > $value['stop_time'])) $is_end = 1;
+ if (!empty($value['stop_time']) && (strtotime(date('Ymd')) + 86399 > $value['stop_time'])) $is_end = 1;
$taskList[$key]['is_end'] = $is_end;
}
}
-
+
$data = [];
$data['page']['list'] = $taskList ?: [];
$data['page']['dataCount'] = $dataCount ?: 0;
@@ -302,7 +302,7 @@ class Task extends ApiCommon
}
return resultArray(['data' => $data]);
}
-
+
/**
* 任务列表导出
* @return \think\response\Json|void
@@ -316,7 +316,7 @@ class Task extends ApiCommon
$data = $TaskLogic->excelExport($param);
return $data;
}
-
+
/**
* 获取任务详情
* @param
@@ -338,7 +338,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskmodel->getError()]);
}
}
-
+
/**
* 任务编辑保存
* @param
@@ -365,7 +365,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 解除关联关系
* @param
@@ -403,7 +403,7 @@ class Task extends ApiCommon
return resultArray(['error' => '操作失败']);
}
}
-
+
/**
* 获取任务操作记录
* @param
@@ -420,7 +420,7 @@ class Task extends ApiCommon
$list = $taskModel->getTaskLogList($param) ?: [];
return resultArray(['data' => $list]);
}
-
+
/**
* 优先级设置
* @param
@@ -432,7 +432,7 @@ class Task extends ApiCommon
$param = $this->param;
$userInfo = $this->userInfo;
$param['create_user_id'] = $userInfo['id'];
-
+
if (!isset($param['priority_id']) || !$param['task_id']) {
return resultArray(['error' => '参数错误']);
}
@@ -446,7 +446,7 @@ class Task extends ApiCommon
return resultArray(['error' => '操作失败']);
}
}
-
+
/**
* 参与人/参与部门编辑
* @param
@@ -481,7 +481,7 @@ class Task extends ApiCommon
}
return resultArray(['error' => '修改失败']);
}
-
+
/**
* 单独删除参与人
* @param
@@ -504,7 +504,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 单独删除参与部门
* @param
@@ -527,7 +527,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 设置任务截止时间
* @param
@@ -553,7 +553,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 添加删除标签
* @param
@@ -584,7 +584,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 任务标题描述更新
* @param
@@ -606,7 +606,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 任务标记结束
* @param
@@ -646,7 +646,7 @@ class Task extends ApiCommon
}
return resultArray(['data' => '操作成功']);
}
-
+
/**
* 日历任务展示/月份
* @param
@@ -666,7 +666,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 添加任务
* @param
@@ -689,7 +689,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 删除主负责人
* @param
@@ -717,7 +717,7 @@ class Task extends ApiCommon
}
return resultArray(['data' => '操作成功']);
}
-
+
/**
* 重命名任务
* @param
@@ -740,7 +740,7 @@ class Task extends ApiCommon
return resultArray(['error' => $workModel->getError()]);
}
}
-
+
/**
* 删除任务
* @param
@@ -765,7 +765,7 @@ class Task extends ApiCommon
return resultArray(['error' => $workModel->getError()]);
}
}
-
+
/**
* 归档任务 改变状态
* @param
@@ -793,7 +793,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 恢复归档任务
* @param
@@ -821,7 +821,7 @@ class Task extends ApiCommon
return resultArray(['error' => $taskModel->getError()]);
}
}
-
+
/**
* 归档任务列表
* @param
diff --git a/application/oa/logic/ExamineLogic.php b/application/oa/logic/ExamineLogic.php
index efee118..4c9f798 100644
--- a/application/oa/logic/ExamineLogic.php
+++ b/application/oa/logic/ExamineLogic.php
@@ -10,7 +10,193 @@ use think\Validate;
class ExamineLogic extends Common
{
private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回'];
-
+
+ public function getDataList($request)
+ {
+ $userModel = new \app\admin\model\User();
+ $fileModel = new \app\admin\model\File();
+ $recordModel = new \app\admin\model\Record();
+
+ $examine_by = $request['examine_by']; //1待我审批 2我已审批 all 全部
+ $user_id = $request['user_id'];
+ $bi = $request['bi_types'];
+ $check_status = $request['check_status']; //0 待审批 2 审批通过 4 审批拒绝 all 全部
+ unset($request['by']);
+ unset($request['bi_types']);
+ unset($request['user_id']);
+ unset($request['check_status']);
+ unset($request['examine_by']);
+ $request = $this->fmtRequest($request);
+ $map = $request['map'] ?: [];
+ if (isset($map['search']) && $map['search']) {
+ //普通筛选
+ $map['examine.content'] = ['like', '%' . $map['search'] . '%'];
+ } else {
+ $map = where_arr($map, 'oa', 'examine', 'index'); //高级筛选
+ }
+ unset($map['search']);
+ //审批类型
+ $map['examine.category_id'] = $map['examine.category_id'] ?: array('gt', 0);
+
+ $map_str = '';
+ $logmap = '';
+ switch ($examine_by) {
+ case 'all' :
+ //如果超管则能看到全部
+ if (!isSuperAdministrators($user_id)) {
+ $map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " ) OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
+ }
+ break;
+ case '1' :
+ $map['check_user_id'] = [['like', '%,' . $user_id . ',%']];
+ break; //待审
+ case '2' :
+ $map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " )
+ OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
+// $map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or'];
+ break; //已审
+ default:
+ $map['examine.create_user_id'] = $user_id;
+ break;
+ }
+ $order = 'examine.create_time desc,examine.update_time desc';
+ //发起时间
+ if ($map['examine.between_time'][0] && $map['examine.between_time'][1]) {
+ $start_time = $map['examine.between_time'][0];
+ $end_time = $map['examine.between_time'][1];
+ $map['examine.create_time'] = array('between', array($start_time, $end_time));
+ }
+ unset($map['examine.between_time']);
+
+ //审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部
+ if (isset($check_status)) {
+ if ($check_status == 'all') {
+ $map['examine.check_status'] = ['egt', 0];
+ if (isSuperAdministrators($user_id)) {
+ unset($map['examine.create_user_id']);
+ }
+ } elseif ($check_status == 4) {
+ $map['examine.check_status'] = ['eq', 3];
+ } elseif ($check_status == 0) {
+ $map['examine.check_status'] = ['<=', 1];
+ } else {
+ $map['examine.check_status'] = $check_status;
+ }
+ } else {
+ if ($examine_by == 'all') {
+ $map['examine.check_status'] = ['egt', 0];
+ } elseif ($examine_by == 1) {
+ $map['examine.check_status'] = ['elt', 1];
+ } elseif ($examine_by == 2) {
+ $map['examine.check_status'] = ['egt', 2];
+ }
+ }
+ $join = [
+ ['__ADMIN_USER__ user', 'user.id = examine.create_user_id', 'LEFT'],
+ ['__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT'],
+ ];
+ $list_view = db('oa_examine')
+ ->alias('examine')
+ ->where($map_str)
+ ->where($map)
+ ->join($join);
+ $res = [];
+ $list = $list_view
+ ->page($request['page'], $request['limit'])
+ ->field('examine.*,user.realname,user.thumb_img,examine_category.title as category_name,examine_category.category_id as examine_config,examine_category.icon as examineIcon')
+ ->order($order)
+ ->select();
+ foreach ($list as $k => $v) {
+ $causeCount = 0;
+ $causeTitle = '';
+ $duration = $v['duration'] ?: '0.0';
+ $money = $v['money'] ?: '0.00';
+
+ $list[$k]['causeTitle'] = $causeTitle;
+ $list[$k]['causeCount'] = $causeCount ?: 0;
+ $item = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->select();
+ if ($item) {
+ foreach ($item as $key => $value) {
+ if($v['check_status']==4){
+ $usernames = '';
+ }else{
+ $usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
+ }
+
+ //关联业务
+ $relationArr = [];
+ $relationArr = $recordModel->getListByRelationId('examine', $v['examine_id']);
+ $item[$key]['relation'] = arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['contactsList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['contractList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['customerList'], 'name'));
+ $res[] = [
+ 'category_name' => $v['category_name'],
+ 'create_time' => !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null,
+ 'realname' => $v['realname'],
+ 'check_status_info' => $this->statusArr[(int)$v['check_status']],
+ 'examine_name' => implode($usernames, ','),
+ 'content' => $v['content'],
+ 'remark' => $v['remark'],
+ 'duration' => $v['duration'],
+ 'vehicle' => $value['vehicle'],
+ 'trip' => $value['trip'],
+ 'money' => $value['money'],
+ 'traffic' => $value['traffic'],
+ 'stay' => $value['stay'],
+ 'diet' => $value['diet'],
+ 'other' => $value['other'],
+ 'start_address' => $value['start_address'],
+ 'end_address' => $value['end_address'],
+ 'start_time' => !empty($value['start_time']) ? date('Y-m-d H:i:s', $value['start_time']) : null,
+ 'end_time' => !empty($value['end_time']) ? date('Y-m-d H:i:s', $value['end_time']) : null,
+ 'description' => $value['description'],
+ 'replyList' => str_replace(',', ' ', $item[$key]['relation']),
+ ];
+ }
+ } else {
+ $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
+ $list[$k]['start_time'] = !empty($v['start_time']) ? date('Y-m-d H:i:s', $v['start_time']) : null;
+ $list[$k]['end_time'] = !empty($v['end_time']) ? date('Y-m-d H:i:s', $v['end_time']) : null;
+ if($v['check_status']==4){
+ $usernames = '';
+ }else{
+ $usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
+ }
+ //关联业务
+ $relationArr = [];
+ $relationArr = $recordModel->getListByRelationId('examine', $v['examine_id']);
+ $list[$k]['relation'] = arrayToString(array_column($relationArr['businessList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['contactsList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['contractList'], 'name')) . ' ' .
+ arrayToString(array_column($relationArr['customerList'], 'name'));
+ $res[] = [
+ 'category_name' => $v['category_name'],
+ 'create_time' => !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null,
+ 'realname' => $v['realname'],
+ 'check_status_info' => $this->statusArr[(int)$v['check_status']],
+ 'examine_name' => implode($usernames, ','),
+ 'content' => $v['content'],
+ 'remark' => $v['remark'],
+ 'duration' => $v['duration'],
+ 'vehicle' => '',
+ 'money' => $v['money'],
+ 'traffic' => '',
+ 'stay' => '',
+ 'diet' => '',
+ 'other' => '',
+ 'start_address' => '',
+ 'end_address' => '',
+ 'start_time' => !empty($v['start_time']) ? date('Y-m-d H:i:s', $v['start_time']) : null,
+ 'end_time' => !empty($v['end_time']) ? date('Y-m-d H:i:s', $v['end_time']) : null,
+ 'description' => '',
+ 'replyList' => str_replace(',', ' ', $item[$key]['relation']),
+ ];
+ }
+ }
+ return $res;
+ }
+
/**
* 审批导出
* @param $param
@@ -19,35 +205,125 @@ class ExamineLogic extends Common
public function excelExport($param)
{
$excelModel = new \app\admin\model\Excel();
- $field_list1 = [
- array('name' => '审批类型', 'field' => 'category_name', 'form_type' => 'text'),
- array('name' => '创建时间', 'field' => 'create_time', 'form_type' => ''),
- array('name' => '创建人', 'field' => 'create_user_id', 'form_type' => 'user'),
- array('name' => '状态', 'field' => 'check_status_info','form_type' => ''),
- array('name' => '当前审批人', 'field' => 'check_user_id','form_type' => 'userStr'),
- // array('name' => '下一审批人', 'field' => 'last_user_id','form_type' => 'user'),
- // array('name' => '关联业务', 'field' => 'relation','form_type' => ''),
- ];
- // 导出的字段列表
- $fieldModel = new \app\admin\model\Field();
- $field_list = $fieldModel->getIndexFieldConfig('oa_examine', $param['user_id'], $param['category_id']);
+ $data = $this->getDataList($param);
+ $list = [];
+ switch ($param['category_id']) {
+ case '1' :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '备注', 'field' => 'description'],
+ '6' => ['name' => '关联业务', 'field' => 'replyList'],
+ ];
+ break;
+ case '2' :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '审批内容', 'field' => 'content'],
+ '6' => ['name' => '开始时间', 'field' => 'start_time'],
+ '7' => ['name' => '结束时间', 'field' => 'end_time'],
+ '8' => ['name' => '时长', 'field' => 'duration'],
+ '9' => ['name' => '备注', 'field' => 'description'],
+ '10' => ['name' => '关联业务', 'field' => 'replyList'],
+ ];
+ break;
+ case '3' :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '出差事由', 'field' => 'content'],
+ '6' => ['name' => '备注', 'field' => 'remark'],
+ '7' => ['name' => '出差总天数', 'field' => 'duration'],
+ '8' => ['name' => '交通工具', 'field' => 'vehicle'],
+ '9' => ['name' => '单程往返', 'field' => 'trip'],
+ '10' => ['name' => '出发城市', 'field' => 'start_address'],
+ '11' => ['name' => '目的城市', 'field' => 'end_address'],
+ '12' => ['name' => '开始时间', 'field' => 'start_time'],
+ '13' => ['name' => '结束时间', 'field' => 'end_time'],
+ '14' => ['name' => '出差备注', 'field' => 'description'],
+ '15' => ['name' => '时长', 'field' => 'duration'],
+ '16' => ['name' => '关联业务', 'field' => 'replyList'],
+ ];
+ break;
+ case '4' :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname',],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '加班原因', 'field' => 'content'],
+ '6' => ['name' => '开始时间', 'field' => 'start_time'],
+ '7' => ['name' => '结束时间', 'field' => 'end_time'],
+ '8' => ['name' => '加班总天数', 'field' => 'duration'],
+ '9' => ['name' => '备注', 'field' => 'description'],
+ '10' => ['name' => '关联业务', 'field' => 'replyList'],
+ ];
+ break;
+ case '5':
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '差旅内容', 'field' => 'content'],
+ '6' => ['name' => '报销总金额', 'field' => 'money'],
+ '7' => ['name' => '备注', 'field' => 'remark'],
+ '8' => ['name' => '出发城市', 'field' => 'start_address'],
+ '9' => ['name' => '目的城市', 'field' => 'end_address'],
+ '10' => ['name' => '开始时间', 'field' => 'start_time'],
+ '11' => ['name' => '结束时间', 'field' => 'end_time'],
+ '12' => ['name' => '交通费', 'field' => 'traffic'],
+ '13' => ['name' => '住宿费', 'field' => 'stay'],
+ '14' => ['name' => '餐饮费', 'field' => 'diet'],
+ '15' => ['name' => '其他费用', 'field' => 'other'],
+ '16' => ['name' => '合计', 'field' => 'money'],
+ '17' => ['name' => '费用明细描述', 'field' => 'description'],
+ '18' => ['name' => '关联业务', 'field' => 'relation'],
+ ];
+ break;
+ case '6' :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '借款事由', 'field' => 'content'],
+ '6' => ['name' => '开始时间', 'field' => 'start_time'],
+ '7' => ['name' => '结束时间', 'field' => 'end_time'],
+ '8' => ['name' => '借款金额', 'field' => 'money'],
+ '9' => ['name' => '备注', 'field' => 'description'],
+ '10' => ['name' => '关联业务', 'field' => 'replyList'],
+ ];
+ break;
+ default :
+ $field_list = [
+ '0' => ['name' => '审批类型', 'field' => 'category_name'],
+ '1' => ['name' => '创建时间', 'field' => 'create_time'],
+ '2' => ['name' => '创建人', 'field' => 'realname'],
+ '3' => ['name' => '状态', 'field' => 'check_status_info'],
+ '4' => ['name' => '当前审批人', 'field' => 'examine_name'],
+ '5' => ['name' => '备注', 'field' => 'description'],
+ '6' => ['name' => '关联业务', 'field' => 'replyList'],
+
+ ];
+ }
$file_name = 'oa_examine';
- $temp_file = $param['temp_file'];
- unset($param['temp_file']);
- $page = $param['page'] ?: 1;
- $model = model('Examine');
- $field_list = array_merge_recursive($field_list1, $field_list);
-
- return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
- $param['page'] = $page;
- $param['limit'] = $limit;
- $data = $model->getDataList($param);
- // $newData['list'] = $model->exportHandle($data['page']['list'], $field_list, 'oa_examine');
- $newData['list'] = $data['page']['list'];
- return $newData;
- });
+ return $excelModel->dataExportCsv($file_name, $field_list, $data);
}
-
+
/**
* 审批数据
* @param $param
@@ -65,9 +341,9 @@ class ExamineLogic extends Common
$query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
};
} elseif ($param['status'] == 1) {
- $where['a.check_status'] = ['in', [2,3]];
- $whereOr = function ($query) use ( $user_id) {
- $query->where('a.check_user_id',['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
+ $where['a.check_status'] = ['in', [2, 3]];
+ $whereOr = function ($query) use ($user_id) {
+ $query->where('a.check_user_id', ['like', '%' . $user_id . '%'])->whereOr('a.flow_user_id', ['like', '%' . $user_id . '%']);
};
} elseif ($param['status'] == 3) {
$where['a.check_status'] = ['lt', 5];
@@ -98,7 +374,7 @@ class ExamineLogic extends Common
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
$list[$k]['customer_id_info']['name'] = $v['customer_name'];
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
-
+
}
$dataCount = db('crm_contract')
->alias('a')
@@ -135,7 +411,7 @@ class ExamineLogic extends Common
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
$list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
$list[$k]['contract_id_info']['name'] = $v['contract_name'];
-
+
}
break;
case '3':
@@ -153,7 +429,7 @@ class ExamineLogic extends Common
->select();
foreach ($list as $k => $v) {
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
-
+
}
$dataCount = db('crm_invoice')
->alias('a')
@@ -162,13 +438,13 @@ class ExamineLogic extends Common
->where($whereOr)
->count();
break;
-
+
}
-
+
foreach ($list as $key => $v) {
$list[$key]['create_time'] = date('Y-m-d H:i:s', $v['create_time']) ?: '';
}
-
+
$data = [];
$data['page']['list'] = $list;
$data['page']['dataCount'] = $dataCount ?: 0;
@@ -184,5 +460,5 @@ class ExamineLogic extends Common
}
return $data;
}
-
+
}
\ No newline at end of file
diff --git a/application/oa/logic/LogLogic.php b/application/oa/logic/LogLogic.php
index 77f12a9..d2d023c 100644
--- a/application/oa/logic/LogLogic.php
+++ b/application/oa/logic/LogLogic.php
@@ -38,15 +38,8 @@ class LogLogic extends Common
public function getDataList($request)
{
$userModel = new \app\admin\model\User();
- $structureModel = new \app\admin\model\Structure();
- $fileModel = new \app\admin\model\File();
$commonModel = new \app\admin\model\Comment();
- $BusinessModel = new \app\crm\model\Business();
- $ContactsModel = new \app\crm\model\Contacts();
- $ContractModel = new \app\crm\model\Contract();
- $CustomerModel = new \app\crm\model\Customer();
$recordModel = new \app\admin\model\Record();
-
$user_id = $request['read_user_id'];
$by = $request['by'] ?: '';
@@ -78,44 +71,39 @@ class LogLogic extends Common
}
$requestData = $this->requestData();
//获取权限范围内的员工
+ //获取权限范围内的员工
$auth_user_ids = getSubUserId();
- if ($request['send_user_id'] && !in_array(trim(arrayToString($request['send_user_id']), ','), $auth_user_ids)) {
- $map['log.create_user_id'] = $user_id;
- } else {
- if ($request['send_user_id'] && in_array(trim(arrayToString($request['send_user_id']), ','), $auth_user_ids)) {
- $map['log.create_user_id'] = ['in', trim(arrayToString($request['send_user_id']), ',')];
- $map['log.send_user_ids'] = ['like', '%,' . $request['read_user_id'] . ',%'];
- } else {
- $dataWhere['user_id'] = $user_id;
- $dataWhere['structure_id'] = $request['structure_id'];
- $dataWhere['auth_user_ids'] = $auth_user_ids;
- $logMap = '';
- switch ($by) {
- case 'me' :
- $map['log.create_user_id'] = $user_id;
- break;
- case 'other':
- $logMap = function ($query) use ($dataWhere) {
- $query->where('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
- ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
- };
- break;
- default :
- $logMap = function ($query) use ($dataWhere) {
- $query->where('log.create_user_id', array('in', implode(',', $dataWhere['auth_user_ids'])))
- ->whereOr('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
- ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
- };
- break;
- }
- }
+ $dataWhere['user_id'] = $user_id;
+ $dataWhere['structure_id'] = $request['structure_id'];
+ $dataWhere['auth_user_ids'] = $auth_user_ids;
+ $logMap = '';
+ if ($request['send_user_id'] != '') {
+ $map['log.create_user_id'] = ['in', trim(arrayToString($request['send_user_id']), ',')];
+ }
+ switch ($by) {
+ case 'me' :
+ $map['log.create_user_id'] = $user_id;
+ break;
+ case 'other':
+ $logMap = function ($query) use ($dataWhere) {
+ $query->where('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
+ ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
+ };
+ break;
+ default :
+ $logMap = function ($query) use ($dataWhere) {
+ $query->where('log.create_user_id', array('in', implode(',', $dataWhere['auth_user_ids'])))
+ ->whereOr('log.send_user_ids', array('like', '%,' . $dataWhere['user_id'] . ',%'))
+ ->whereOr('log.send_structure_ids', array('like', '%,' . $dataWhere['structure_id'] . ',%'));
+ };
+ break;
}
$list = Db::name('OaLog')
->where($map)
+ ->where($logMap)
->where($searchMap)
->alias('log')
->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT')
- ->page($request['page'], $request['limit'])
->field('log.*,user.realname')
->order('log.update_time desc')
->select();
@@ -651,11 +639,8 @@ class LogLogic extends Common
/**
* 销售简报跟进数量统计
- * @param $param
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ *
+ * @param $param 参数
*/
public function activityCount($param)
{
@@ -665,17 +650,18 @@ class LogLogic extends Common
if (empty($param['log_id'])) {
$between_time = [$start_time['start_time'], $start_time['end_time']];
$map['create_time'] = array('between', $between_time);
+ $map['create_user_id'] =$user_id;
} else {
-
$start_time = strtotime(date("Y-m-d", $item['create_time']));
$end_time = strtotime(date("Y-m-d H:i:s", $item['create_time']));
$between_time = [$start_time, $end_time];
$map['create_time'] = array('between', $between_time);
+ $map['create_user_id'] = $item['create_user_id'];
}
$map['status']=1;
$typesList = ['1', '2', '3', '5', '6'];
foreach ($typesList as $k => $v) {
- $activityData = db('crm_activity')->where($map)->where(['create_user_id' => $item['create_user_id'], 'type' => 1, 'activity_type' => $v])->count();
+ $activityData = db('crm_activity')->where($map)->where(['type' => 1, 'activity_type' => $v])->count();
if($v==1){
$arr[$k]['types'] ='crm_leads';
$arr[$k]['activity_type'] =1;
@@ -693,7 +679,6 @@ class LogLogic extends Common
$arr[$k]['activity_type'] =6;
}
$arr[$k]['dataCount'] = $activityData;
-
}
$data = $arr;
return $data;
diff --git a/application/oa/logic/TaskLogic.php b/application/oa/logic/TaskLogic.php
index 75fd869..d7851c1 100644
--- a/application/oa/logic/TaskLogic.php
+++ b/application/oa/logic/TaskLogic.php
@@ -15,8 +15,8 @@ class TaskLogic
$userModel = new \app\admin\model\User();
$taskModel = new TaskModel();
$recordModel = new \app\admin\model\Record();
- $str = ','.$param['user_id'].',';
-
+ $str = ',' . $param['user_id'] . ',';
+
//自定义时间
$map['t.stop_time'] = $param['dueDate'] ? strtotime($param['dueDate'] . ' +1 month -1 day') : ['>=', 0];
$search = $param['search'];
@@ -34,14 +34,14 @@ class TaskLogic
} else {
$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;
-
+ $where['t.priority'] = $priority;
+
if ($param['work_id'] != 0) {
$where['t.work_id'] = $param['work_id'];
$taskList = db('task')
@@ -56,9 +56,9 @@ class TaskLogic
$where = [];
$where['ishidden'] = 0;
$where['pid'] = 0;
- $where['whereStr'] = ' ( task.create_user_id =' . $param['user_id'] . ' or ( task.owner_user_id like "%,'.$param['user_id'].',%") or ( task.main_user_id = '.$param['user_id'].' ) )';
+ $where['whereStr'] = ' ( task.create_user_id =' . $param['user_id'] . ' or ( task.owner_user_id like "%,' . $param['user_id'] . ',%") or ( task.main_user_id = ' . $param['user_id'] . ' ) )';
if (!empty($this->param['search'])) {
- $where['taskSearch'] = ' and (task.name like "%'.$this->param['search'].'%" OR task.description like "%'.$this->param['search'].'%")';
+ $where['taskSearch'] = ' and (task.name like "%' . $this->param['search'] . '%" OR task.description like "%' . $this->param['search'] . '%")';
}
# 截止日期
$timeWhere = $this->getTimeParam($param['time_type']);
@@ -76,12 +76,11 @@ class TaskLogic
->join('AdminUser u', 'u.id = t.main_user_id', 'LEFT')
->field('t.task_id,t.name as task_name,t.main_user_id,t.description,t.priority,t.stop_time,t.create_time,t.owner_user_id,t.start_time,t.create_user_id,u.realname as main_user_name,t.is_top')
->where($where)
- ->where($whereStr)
->where($timeWhere)
->where($labelWhere)
->order('t.task_id desc')
->select();
-
+
} else {
///下属任务
if ($param['mold'] == 1) {
@@ -96,21 +95,21 @@ class TaskLogic
if ($type != 0) {
switch ($type) {
case '1' :
- $type = 't.main_user_id in ('.$subStr.')';
+ $type = 't.main_user_id in (' . $subStr . ')';
break; //下属负责的
case '3' :
//使用正则查询
// SELECT * FROM 5kcrm_task WHERE owner_user_id REGEXP '(,1,|,2,|,3,)';
- $type = $subValue ? 't.owner_user_id REGEXP "('.$subValue.')"' : '';
+ $type = $subValue ? 't.owner_user_id REGEXP "(' . $subValue . ')"' : '';
break; //下属参与的
}
} else {
if (!$subValue) {
$type = 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . '))';
} else {
- $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "('.$subValue.')")';
+ $type .= 't.is_open = 1 AND (t.main_user_id in (' . $subStr . ') or t.create_user_id in (' . $subStr . ') or t.owner_user_id REGEXP "(' . $subValue . ')")';
}
- }
+ }
$map['t.pid'] = 0;
$map['t.ishidden'] = 0;
$taskList = Db::name('Task')
@@ -121,12 +120,12 @@ class TaskLogic
)
->where(function ($query) use ($type) {
$query->where($type);
- })
+ })
->where($where)
->where($map)
->order('t.task_id desc')
- ->select();
- } else {
+ ->select();
+ } else {
$map['t.pid'] = 0;
// $map['t.work_id'] = 0;
if ($type != 0) {
@@ -135,15 +134,15 @@ class TaskLogic
$type = 't.main_user_id =' . $param['user_id'] . '';
break; //我负责的
case '3' :
- $type = 't.owner_user_id like "%,'.$param['user_id'].',%"';
+ $type = 't.owner_user_id like "%,' . $param['user_id'] . ',%"';
break; //我参与的
}
} else {
$adminIds = $userModel->getAdminId();
- if (in_array($param['user_id'],$adminIds)) {
- $type = 't.is_open = 1';
+ if (in_array($param['user_id'], $adminIds)) {
+ $type = 't.is_open = 1';
} else {
- $type = 't.is_open = 1 AND (t.main_user_id =' . $param['user_id'] .' OR t.owner_user_id like "%,'.$param['user_id'].',%")';
+ $type = 't.is_open = 1 AND (t.main_user_id =' . $param['user_id'] . ' OR t.owner_user_id like "%,' . $param['user_id'] . ',%")';
}
}
$where['t.ishidden'] = 0;
@@ -154,10 +153,9 @@ class TaskLogic
->where($where)
->where($type)
->where($map)
- ->page($param['page'], $param['limit'])
->order('t.task_id desc')
->select();
- }
+ }
}
}
foreach ($taskList as $key => $value) {
@@ -185,7 +183,7 @@ class TaskLogic
//创建时间
$taskList[$key]['create_time'] = $value['create_time'] ? date('Y-m-d H:i:s', $value['create_time']) : '';
//开始时间
- $taskList[$key]['start_time'] = $value['start_time'] ? date('Y-m-d H:i:s', $value['start_time']) : '';
+ $taskList[$key]['start_time'] = $value['start_time'] ? date('Y-m-d H:i:s', $value['start_time']) : '';
//结束时间
$taskList[$key]['stop_time'] = $value['stop_time'] ? date('Y-m-d H:i:s', $value['stop_time']) : '';
//优先级
@@ -217,14 +215,14 @@ class TaskLogic
}
return $taskList;
}
-
+
/**
* 任务导出
* @param $param
*/
public function excelExport($param)
{
-
+
$data = $this->getDataList($param);
$excelModel = new \app\admin\model\Excel();
if ($param['work_id'] != 0) {
@@ -280,7 +278,7 @@ class TaskLogic
}
return $excelModel->taskExportCsv($file_name, $field_list, $title, $data);
}
-
+
public function where($param)
{
$taskModel = new TaskModel();
@@ -289,11 +287,11 @@ class TaskLogic
$workModel = new WorkModel();
$userModel = new \app\admin\model\User();
$work_id = $param['work_id'] ?: '';
-
+
if ($param['main_user_id']) {
$map['t.main_user_id'] = ['in', $param['main_user_id']];
}
-
+
//截止时间
if ($param['stop_time_type']) {
if ($param['stop_time_type'] == '5') { //没有截至日期
@@ -326,7 +324,7 @@ class TaskLogic
$map['t.stop_time'] = ['between', [$timeAry[0], $timeAry[1]]];
}
}
-
+
if ($param['lable_id']) {
$taskIds = [];
$task_ids = [];
@@ -339,7 +337,7 @@ class TaskLogic
$lableWhere['ishidden'] = 0;
$lableWhere['pid'] = 0;
$lableWhere['is_archive'] = 0;
-
+
$task_id = $taskModel->where($lableWhere)->column('task_id');
if ($task_id && $task_ids) {
$task_ids = array_unique(array_filter(array_merge($task_ids, $task_id)));
@@ -349,12 +347,12 @@ class TaskLogic
}
$map['t.task_id'] = ['in', $task_ids];
} else {
-
+
$map['t.task_id'] = $work_id;
}
return $map;
}
-
+
/**
* 获取截止日期参数
* @param $type
@@ -363,46 +361,46 @@ class TaskLogic
private function getTimeParam($type)
{
$result = [];
-
+
# 今天
if ($type == 1) {
$result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')';
}
-
+
# 明天
if ($type == 2) {
$tomorrow = date("Y-m-d 23:59:59", strtotime("+1 day"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime($tomorrow) . ')';
}
-
+
# 本周
if ($type == 3) {
$week = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . $week . ')';
}
-
+
# 本月
if ($type == 4) {
$month = mktime(23, 59, 59, date("m"), date("t"), date("Y"));
$result = '(task.stop_time > 0 AND task.stop_time <= ' . $month . ')';
}
-
+
# 未设置截止日期
if ($type == 5) {
$result = $result = '(task.stop_time = 0)';;
}
-
+
# 已延期
if ($type == 6) {
$result = '(task.status = 2 OR task.stop_time >= ' . time() . ')';
}
-
+
# 今日更新
if ($type == 7) {
$result = '(task.update_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' AND task.update_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')';
}
-
+
return $result;
}
-
+
}
\ No newline at end of file
diff --git a/application/oa/logic/UserLogic.php b/application/oa/logic/UserLogic.php
index 69e72bd..e0afcee 100644
--- a/application/oa/logic/UserLogic.php
+++ b/application/oa/logic/UserLogic.php
@@ -27,42 +27,49 @@ class UserLogic
$initials_type = ($param['initials'] == 1) ? 1 : 2;
$where['user.status'] = 1;
if ($search) {
- $where = function ($query) use ($search) {
+ $whereMap = function ($query) use ($search) {
$query->where('user.realname', array('like', '%' . $search . '%'))
->whereOr('user.mobile', array('like', '%' . $search . '%'));
};
}
- if ($param['star_type'] == 1) {
- $item = Db::name('crm_star')->where('user_id', $user_id)->column('target_id');
- $where['user.id'] = ['in', $item];
- }
- if ($param['structure_id'] == '') {
- $list = Db::name('admin_user')
- ->alias('user')
- ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
- ->where($where)
- ->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile')
- ->page($param['page'], $param['limit'])
- ->select();
-
- foreach ($list as $k => $v) {
- $starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user'];
- $star = Db::name('crm_star')->where($starWhere)->value('star_id');
- $list[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
- $list[$k]['star'] = !empty($star) ? 1 : 0;
+ if($param['structure_id']){
+ $where['user.id']= $param['structure_id'];
+ }
+ if (isset($param['star_type'])) {
+ if ($param['star_type'] == 1) {
+ $item = Db::name('crm_star')->where(['user_id'=>$user_id,'type'=>'admin_user'])->column('target_id');
+ if(!empty($item)) {
+ $where['user.id'] = ['in', $item];
+ $list = Db::name('admin_user')
+ ->alias('user')
+ ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
+ ->where($where)
+ ->where($whereMap)
+ ->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name,user.mobile')
+ ->page($param['page'], $param['limit'])
+ ->select();
+ foreach ($list as $k => $v) {
+ $starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user'];
+ $star = Db::name('crm_star')->where($starWhere)->value('star_id');
+ $list[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
+ $list[$k]['star'] = !empty($star) ? 1 : 0;
+ }
+ $dataCount = Db::name('admin_user')
+ ->alias('user')
+ ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
+ ->where($where)
+ ->count();
+ $newarray = $this->groupByInitials($list, 'realname', $initials_type);
+ }else{
+ return false;
+ }
}
- $dataCount = Db::name('admin_user')
- ->alias('user')
- ->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
- ->where($where)
- ->count();
- $newarray = $this->groupByInitials($list, 'realname', $initials_type);
} else {
$list = Db::name('admin_user')
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
- ->where('structure.id', $param['structure_id'])
+ ->where($whereMap)
->field('user.id,user.thumb_img,user.realname,user.post,structure.name as structure_name')
->page($param['page'], $param['limit'])
->select();
@@ -70,7 +77,6 @@ class UserLogic
->alias('user')
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
->where($where)
- ->where('structure.id', $param['structure_id'])
->count();
foreach ($list as $k => $v) {
$starWhere = ['user_id' => $user_id, 'target_id' => $v['id'], 'type' => 'admin_user'];
diff --git a/application/oa/model/Event.php b/application/oa/model/Event.php
index ba94c48..e28dbd3 100644
--- a/application/oa/model/Event.php
+++ b/application/oa/model/Event.php
@@ -30,7 +30,7 @@ class Event extends Common
'start_time' => 'timestamp',
'end_time' => 'timestamp',
];
-
+
/**
* [getDataList 日程list]
* @param [by] $by [查询时间段类型]
@@ -42,7 +42,7 @@ class Event extends Common
$userModel = new \app\admin\model\User();
$recordModel = new \app\admin\model\Record();
$user_id = $param['user_id'];
-
+
//默认本账户or 自定义用户id
if ($param['start_time'] && $param['end_time']) {
$start_time = $param['start_time'];
@@ -51,38 +51,35 @@ class Event extends Common
$start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
}
-
+
$where = '( ( start_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )
OR ( ( end_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )
OR ( start_time < ' . $start_time . ' AND end_time > ' . $end_time . ' AND ( create_user_id = ' . $user_id . ' or owner_user_ids like "%,' . $user_id . ',%" ) )';
$event_date = Db::name('OaEvent')->where($where)->select();
-
- foreach ($event_date as $k => $v) {
+ foreach ($event_date as $k=>$v) {
$event_date[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
- $event_date[$k]['ownerList'] = $userModel->getDataByStr($v['owner_user_ids']) ?: [];
-
- $relationArr = [];
+ $event_date[$k]['ownerList'] = $userModel->getDataByStr($v['owner_user_ids']) ? : [];
+
+ $relationArr= [];
$relationArr = $recordModel->getListByRelationId('event', $v['event_id']);
$event_date[$k]['businessList'] = $relationArr['businessList'];
$event_date[$k]['contactsList'] = $relationArr['contactsList'];
$event_date[$k]['contractList'] = $relationArr['contractList'];
$event_date[$k]['customerList'] = $relationArr['customerList'];
- $event_date[$k]['type'] = 'event';
+
$event_date[$k]['remindtype'] = (int)$v['remindtype'];
$noticeInfo = Db::name('OaEventNotice')->where(['event_id' => $v['event_id']])->find();
$is_repeat = 0;
if ($noticeInfo) {
$is_repeat = 1;
}
- $color = db('admin_oa_schedule')->where('schedule_id', $v['schedule_id'])->find();
- $event_date[$k]['color'] = $color['color'];
$event_date[$k]['is_repeat'] = $is_repeat;
$event_date[$k]['stop_time'] = $noticeInfo ? $noticeInfo['stop_time'] : '';
$event_date[$k]['noticetype'] = $noticeInfo ? $noticeInfo['noticetype'] : '';
if ($noticeInfo['noticetype'] == '2') {
- $event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||', $noticeInfo['repeated']) : [];
+ $event_date[$k]['repeat'] = $noticeInfo['repeated'] ? explode('|||',$noticeInfo['repeated']) : [];
} else {
- $event_date[$k]['repeat'] = '';
+ $event_date[$k]['repeat'] = '';
}
//权限
$is_update = 0;
@@ -93,17 +90,15 @@ class Event extends Common
}
$permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete;
- $event_date[$k]['permission'] = $permission;
-
+ $event_date[$k]['permission'] = $permission;
$event_date[$k]['start_time'] = !empty($v['start_time']) ? $v['start_time'] * 1000 : null;
$event_date[$k]['end_time'] = !empty($v['end_time']) ? $v['end_time'] * 1000 : null;
-
+
$event_date[$k]['type_id'] = $v['schedule_id'];
}
-
- return $event_date ?: [];
+ return $event_date ? : [];
}
-
+
/**
* 系统自定义类型数据(任务)
*
@@ -116,7 +111,7 @@ class Event extends Common
public function eventTask($param)
{
$user_id = $param['user_id'];
-
+
// 默认本账户or 自定义用户id
if ($param['start_time'] && $param['end_time']) {
$start_time = $param['start_time'];
@@ -129,7 +124,7 @@ class Event extends Common
'((stop_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_id like "%,' . $user_id . ',%"))
OR ((stop_time > ' . $start_time . ' AND stop_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id like "%,' . $user_id . ',%"))
OR ((stop_time > ' . $start_time . ' AND stop_time >' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id like "%,' . $user_id . ',%"))';
-
+
//分配的任务 负责人或参与人是当前用户
$event_date = db('task')->where(['stop_time' => ['>', 0], 'ishidden' => ['=', 0]])->where($between_time)
->field('task_id,name,start_time,stop_time')->select();
@@ -142,7 +137,7 @@ class Event extends Common
}
return $event_date;
}
-
+
/**
* 系统自定义类型数据(客户)
*
@@ -157,8 +152,8 @@ class Event extends Common
$userModel = new \app\admin\model\User();
$recordModel = new \app\admin\model\Record();
$user_id = $param['user_id'];
-
-
+
+
//默认本账户or 自定义用户id
if ($param['start_time'] && $param['end_time']) {
$start_time = $param['start_time'];
@@ -174,7 +169,7 @@ class Event extends Common
$between_time = '((next_time BETWEEN ' . $start_time . ' AND ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . '))
OR ((next_time > ' . $start_time . ' AND next_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id =' . $user_id . '))
OR ((next_time > ' . $start_time . ' AND next_time > ' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . '))';
- $event_date = db('crm_customer')->where(['next_time'=> ['>', 0],'owner_user_id'=>['<>',0]])->where($between_time)->where('')
+ $event_date = db('crm_customer')->where(['next_time' => ['>', 0], 'owner_user_id' => ['<>', 0]])->where($between_time)->where('')
->field('next_time as start_time,customer_id,name ')->group('start_time')->select();
$item = [];
foreach ($event_date as $k2 => $v) {
@@ -233,10 +228,10 @@ class Event extends Common
$event_date[$k4]['stop_time'] = !empty($v['start_time']) ? strtotime($v['start_time']) * 1000 : null;
$item[] = $v['start_time'] ? $v['start_time'] : '';
}
-
+
$list_data['receivables'] = $item ? array_values(array_unique($item)) : [];
//需联系的线索 next_time
-
+
$between_time = '(( next_time BETWEEN ' . $start_time . ' AND ' . $end_time . ')AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ' ))
OR ((next_time > ' . $start_time . ' AND next_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ' ))
@@ -256,14 +251,14 @@ class Event extends Common
$event_date[$k5]['stop_time'] = !empty($v['start_time']) ? $v['start_time'] * 1000 : null;
$item[] = $v['start_time'] ? date('Y-m-d', $v['start_time']) : '';
}
-
+
$list_data['leads'] = $item ? array_values(array_unique($item)) : [];
//需联系的商机 next_time
$between_time =
'((next_time BETWEEN ' . $start_time . ' AND ' . $end_time . ' ) AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ' ))
OR ((next_time > ' . $start_time . ' AND next_time <' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ' ))
OR ((next_time > ' . $start_time . ' AND next_time >' . $end_time . ') AND ( create_user_id = ' . $user_id . ' or owner_user_id = ' . $user_id . ' ))';
-
+
$event_date = db('crm_business')->where($between_time)->where('next_time', '>', 0)->field('next_time as start_time,business_id,name ')->select();
unset($item);
foreach ($event_date as $k6 => $v) {
@@ -273,10 +268,10 @@ class Event extends Common
$event_date[$k6]['start_time'] = !empty($v['start_time']) ? strtotime($v['start_time']) * 1000 : null;
$event_date[$k6]['stop_time'] = !empty($v['start_time']) ? strtotime($v['start_time']) * 1000 : null;
$item[] = $v['start_time'] ? date('Y-m-d', $v['start_time']) : '';
-
+
}
$list_data['businessNext'] = $item ? array_values(array_unique($item)) : [];
-
+
//需要联系的客户 next_time crm_customer
$return_time = date('Y-m-d', $start_time);
$return_end = date('Y-m-d', $end_time);
@@ -292,7 +287,7 @@ class Event extends Common
->field('deal_date as start_time,business_id,name')
->group('start_time')
->select();
-
+
unset($item);
foreach ($event_date as $k7 => $v) {
$event_date[$k7]['color'] = 7;
@@ -305,7 +300,7 @@ class Event extends Common
$list_data['business'] = $item ? array_values(array_unique($item)) : [];
return $list_data ?: [];
}
-
+
/**
* 日历上显示
* @return array
@@ -316,7 +311,7 @@ class Event extends Common
public function listStatus($param)
{
$userId = $param['user_id'];
-
+
if ($param['start_time'] && $param['end_time']) {
$start_time = $param['start_time'];
$end_time = $param['end_time'];
@@ -324,7 +319,7 @@ class Event extends Common
$start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
}
-
+
$list = Db::name('oa_event')->where(['end_time' => ['>', 0], 'start_time' => ['>', 0]])
->where(function ($query) use ($userId) {
$query->whereOr('create_user_id', $userId);
@@ -336,7 +331,7 @@ class Event extends Common
}
return $list;
}
-
+
/**
* 类型列表
* @return array|void
@@ -367,7 +362,7 @@ class Event extends Common
$data['list'] = $list;
return $data;
}
-
+
/**
* 修改展示类型
* @param $param
@@ -395,11 +390,11 @@ class Event extends Common
->whereIn('schedule_id', arrayToString($param['schedule_id']))
->update(['type' => 1]);
}
-
+
} else {
db('admin_oa_schedule_relation')->where('user_id', $param['user_id'])->insert(['schedule_id' => $v, 'user_id' => $param['user_id'], 'type' => 1, 'create_time' => time()]);
}
-
+
} else {
db('admin_oa_schedule_relation')->where('user_id', $param['user_id'])->insert(['schedule_id' => $v, 'user_id' => $param['user_id'], 'type' => 1, 'create_time' => time()]);
}
@@ -407,7 +402,7 @@ class Event extends Common
$data = [];
return $data;
}
-
+
/**
* 创建日程信息
*
@@ -428,27 +423,27 @@ class Event extends Common
$param['create_time'] = time();
$param['update_time'] = time();
unset($param['user_id']);
-
+
# 关联数据
$relation = [];
if (!empty($param['customer_ids'])) $relation['customer_ids'] = arrayToString($param['customer_ids']);
if (!empty($param['contacts_ids'])) $relation['contacts_ids'] = arrayToString($param['contacts_ids']);
if (!empty($param['business_ids'])) $relation['business_ids'] = arrayToString($param['business_ids']);
if (!empty($param['contract_ids'])) $relation['contract_ids'] = arrayToString($param['contract_ids']);
-
+
# 提醒数据
$notice = $param['notice'];
-
+
# 删除多余字段
unset($param['customer_ids']);
unset($param['contacts_ids']);
unset($param['business_ids']);
unset($param['contract_ids']);
unset($param['notice']);
-
+
if ($this->allowField(true)->save($param)) {
$eventId = $this->event_id;
-
+
# 提醒
if (!empty($notice)) {
$noticeData = [];
@@ -467,18 +462,18 @@ class Event extends Common
}
if (!empty($noticeData)) Db::name('oa_event_notice')->insertAll($noticeData);
}
-
+
# 关联数据
if (!empty($relation)) {
$relation['event_id'] = $eventId;
$relation['status'] = 1;
$relation['create_time'] = time();
-
+
Db::name('oa_event_relation')->insert($relation);
}
-
+
actionLog($eventId, $param['owner_user_ids'], '', '创建了日程');
-
+
$data['event_id'] = $eventId;
// 站内信
$item = Db::name('oa_event_notice')->where('event_id', $eventId)->select();
@@ -500,18 +495,18 @@ class Event extends Common
],
stringToArray($param['owner_user_ids'])
);
-
+
}
-
+
return $data;
} else {
$this->error = '添加失败';
return false;
}
-
-
+
+
}
-
+
/**
* 即将到期合同列表
* @param $param
@@ -562,13 +557,13 @@ class Event extends Common
$event_date[$k]['return_date'] = $v['return_date'] ? $v['return_date'] : null;
}
}
-
+
$data = [];
$data['list'] = $event_date;
$data['countData'] = $count;
return $data;
}
-
+
/**
* 续联系客户
* @param $param
@@ -605,7 +600,7 @@ class Event extends Common
$data['countData'] = $count;
return $data;
}
-
+
/**
* 续联系客户
* @param $param
@@ -642,7 +637,7 @@ class Event extends Common
$data['countData'] = $count;
return $data;
}
-
+
/**
* 计划回款
* @param $param
@@ -659,7 +654,7 @@ class Event extends Common
//需要联系的客户 next_time crm_customer
$between_time['business.next_time'] = ['between', [$return_time, $return_end]];
$between_time['business.create_user_id|business.owner_user_id'] = ['eq', $user_id];
-
+
$event_date = db('crm_business')
->alias('business')
->join('__ADMIN_USER__ user', 'user.id = business.owner_user_id', 'LEFT')
@@ -682,7 +677,7 @@ class Event extends Common
$data['countData'] = $count;
return $data;
}
-
+
/**
* 预计成交商机
* @param $param
@@ -719,7 +714,7 @@ class Event extends Common
$data['countData'] = $count;
return $data;
}
-
+
/**
* 公共时间处理
* @param $param
@@ -728,8 +723,8 @@ class Event extends Common
{
$userModel = new \app\admin\model\User();
$recordModel = new \app\admin\model\Record();
-
-
+
+
//默认本账户or 自定义用户id
if ($param['start_time'] && $param['end_time']) {
$start_time = $param['start_time'];
@@ -744,7 +739,7 @@ class Event extends Common
$data = [$start_time, $end_time];
return $data;
}
-
+
/**
* 编辑日程信息
*
@@ -776,35 +771,35 @@ class Event extends Common
$param['end_time'] = !empty($param['end_time']) ? strtotime($param['end_time']) : $todayTime[1];
$param['update_time'] = time();
unset($param['user_id']);
-
+
# 关联数据
$relation = [];
if (!empty($param['customer_ids'])) $relation['customer_ids'] = arrayToString($param['customer_ids']);
- if (!empty($param['contacts_ids'])) $relation['contacts_ids'] = arrayToString($param['customer_ids']);
- if (!empty($param['business_ids'])) $relation['business_ids'] = arrayToString($param['customer_ids']);
- if (!empty($param['contract_ids'])) $relation['contract_ids'] = arrayToString($param['customer_ids']);
-
-
+ if (!empty($param['contacts_ids'])) $relation['contacts_ids'] = arrayToString($param['contacts_ids']);
+ if (!empty($param['business_ids'])) $relation['business_ids'] = arrayToString($param['business_ids']);
+ if (!empty($param['contract_ids'])) $relation['contract_ids'] = arrayToString($param['contract_ids']);
+
+
# 提醒数据
$notice = $param['notice'];
-
+
# 删除多余字段
unset($param['customer_ids']);
unset($param['contacts_ids']);
unset($param['business_ids']);
unset($param['contract_ids']);
unset($param['notice']);
-
+
if ($this->allowField(true)->save($param, ['event_id' => $event_id])) {
$eventId = $this->event_id;
actionLog($event_id, $param['owner_user_ids'], '', '修改了日程');
$list = db('oa_event_notice')->where('event_id', $eventId)->select();
- $item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete();
- if (!$item) {
+ if ($list) {
foreach ($list as $k => $v) {
Db::name('admin_message')->where(['type' => 9, 'action_id' => $v['id']])->delete();
}
}
+ $item = Db::name('OaEventNotice')->where(['event_id' => $eventId])->delete();
# 提醒
if (!empty($notice)) {
$noticeData = [];
@@ -813,7 +808,7 @@ class Event extends Common
if ($value['type'] == 1) $startTime = $param['start_time'] - ($value['number'] * 60);
if ($value['type'] == 2) $startTime = $param['start_time'] - ($value['number'] * 60 * 60);
if ($value['type'] == 3) $startTime = $param['start_time'] - ($value['number'] * 60 * 60 * 24);
-
+
$noticeData[] = [
'event_id' => $eventId,
'noticetype' => $value['type'],
@@ -822,47 +817,54 @@ class Event extends Common
'stop_time' => $param['end_time']
];
}
- if (!empty($noticeData)) Db::name('oa_event_notice')->insertAll($noticeData);
- }
-
- if (!$item) {
- $item = Db::name('OaEventNotice')->where('event_id', $eventId)->select();
- foreach ($item as $val) {
- if ($value['noticetype'] == '1') { //分
- $dd = strtotime($param['start_time']) - ($val['number'] * 60);
- } else if ($val['noticetype'] == '2') { //时
- $dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60);
- } else if ($val['noticetype'] == '3') {//天
- $dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60 * 24);
+ if (!empty($noticeData)) {
+ $item = Db::name('oa_event_notice')->insertAll($noticeData);
+ if ($item) {
+
+ $item = Db::name('oa_event_notice')->where('event_id', $eventId)->select();
+ foreach ($item as $val) {
+ if ($value['noticetype'] == '1') { //分
+ $dd = strtotime($param['start_time']) - ($val['number'] * 60);
+ } else if ($val['noticetype'] == '2') { //时
+ $dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60);
+ } else if ($val['noticetype'] == '3') {//天
+ $dd = strtotime($param['start_time']) - ($val['number'] * 60 * 60 * 24);
+ }
+ // 站内信
+ (new Message())->send(
+ Message::EVENT_MESSAGE,
+ [
+ 'title' => $param['title'],
+ 'action_id' => $val['id'],
+ 'advance_time' => $dd ?: 0
+ ],
+ stringToArray($param['owner_user_ids'])
+ );
+
+ }
}
- // 站内信
- (new Message())->send(
- Message::EVENT_MESSAGE,
- [
- 'title' => $param['title'],
- 'action_id' => $val['id'],
- 'advance_time' => $dd ?: 0
- ],
- array_diff(stringToArray($param['owner_user_ids']), stringToArray($dataInfo['owner_user_ids']))
- );
-
}
}
- $data['event_id'] = $event_id;
- Db::name('OaEventRelation')->where(['event_id' => $event_id])->update([
- 'customer_ids' => trim($relation['customer_ids'], ','),
- 'contacts_ids' => trim($relation['contacts_ids'], ','),
- 'business_ids' => trim($relation['business_ids'], ','),
- 'contract_ids' => trim($relation['contract_ids'], ','),
- ]);
+
+ $data['event_id'] = $event_id;
+ if (Db::name('OaEventRelation')->where(['event_id' => $event_id])->find()) {
+ Db::name('OaEventRelation')->where(['event_id' => $event_id])->update($relation);
+ } else {
+ if (!empty($relation)) {
+ $relation['event_id'] = $eventId;
+ $relation['status'] = 1;
+ $relation['create_time'] = time();
+ Db::name('OaEventRelation')->where(['event_id' => $event_id])->insert($relation);
+ }
+ }
return $data;
} else {
$this->error = '编辑失败';
return false;
}
}
-
+
/**
* 日程数据
*
@@ -876,25 +878,25 @@ class Event extends Common
{
# 日程数据
$eventData = Db::name('oa_event')->where('event_id', $eventId)->find();
-
+
# 颜色类型
$eventData['color'] = Db::name('admin_oa_schedule')->where('schedule_id', $eventData['schedule_id'])->value('color');
-
+
# 创建人信息
$eventData['create_user_name'] = Db::name('admin_user')->where('id', $eventData['create_user_id'])->value('realname');
-
+
# 参与人信息
$eventData['owner_user_info'] = Db::name('admin_user')->field(['id', 'realname'])->whereIn('id', trim($eventData['owner_user_ids'], ','))->select();
-
+
# 处理日程的日期数据
$eventData['start_time'] = !empty($eventData['start_time']) ? date('Y-m-d H:i:s', $eventData['start_time']) : '';
$eventData['end_time'] = !empty($eventData['end_time']) ? date('Y-m-d H:i:s', $eventData['end_time']) : '';
$eventData['create_time'] = !empty($eventData['create_time']) ? date('Y-m-d H:i:s', $eventData['create_time']) : '';
$eventData['update_time'] = !empty($eventData['update_time']) ? date('Y-m-d H:i:s', $eventData['update_time']) : '';
-
+
# 日程提醒数据
$noticeData = Db::name('oa_event_notice')->where('event_id', $eventId)->select();
-
+
# 整理日程提醒数据
$eventData['notice'] = [];
foreach ($noticeData as $key => $value) {
@@ -903,10 +905,10 @@ class Event extends Common
'value' => $value['number']
];
}
-
+
# 关联客户数据
$relationData = Db::name('oa_event_relation')->where('event_id', $eventId)->find();
-
+
# 关联的客户数据
$eventData['customer'] = [];
if (!empty($relationData['customer_ids'])) {
@@ -927,10 +929,10 @@ class Event extends Common
if (!empty($relationData['contract_ids'])) {
$eventData['contract'] = Db::name('crm_contract')->field(['contract_id', 'name'])->whereIn('contract_id', trim($relationData['contract_ids'], ','))->select();
}
-
+
return $eventData;
}
-
+
//根据ID 删除日程
public function delDataById($param)
{
@@ -939,12 +941,12 @@ class Event extends Common
$this->error = '数据不存在或已删除';
return false;
}
-
+
if ($dataInfo['create_user_id'] != $param['user_id']) {
$this->error = '没有编辑权限';
return false;
}
-
+
$map['event_id'] = $param['event_id'];
$map['create_user_id'] = $param['user_id'];
$flag = $this->where($map)->delete();
diff --git a/application/oa/model/Examine.php b/application/oa/model/Examine.php
index 4fea8f2..cd7d764 100644
--- a/application/oa/model/Examine.php
+++ b/application/oa/model/Examine.php
@@ -23,8 +23,8 @@ class Examine extends Common
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true;
- private $statusArr = ['待审核','审核中','审核通过','已拒绝','已撤回'];
-
+ private $statusArr = ['待审核', '审核中', '审核通过', '已拒绝', '已撤回'];
+
/**
* [getDataList 审批list]
* @param [string] $map [查询条件]
@@ -38,11 +38,13 @@ class Examine extends Common
$userModel = new \app\admin\model\User();
$fileModel = new \app\admin\model\File();
$recordModel = new \app\admin\model\Record();
-
+
$examine_by = $request['examine_by']; //1待我审批 2我已审批 all 全部
$user_id = $request['user_id'];
+ $bi = $request['bi_types'];
$check_status = $request['check_status']; //0 待审批 2 审批通过 4 审批拒绝 all 全部
unset($request['by']);
+ unset($request['bi_types']);
unset($request['user_id']);
unset($request['check_status']);
unset($request['examine_by']);
@@ -56,8 +58,8 @@ class Examine extends Common
}
unset($map['search']);
//审批类型
- $map['examine.category_id'] = $map['examine.category_id'] ? : array('gt', 0);
-
+ $map['examine.category_id'] = $map['examine.category_id'] ?: array('gt', 0);
+
$map_str = '';
$logmap = '';
switch ($examine_by) {
@@ -71,7 +73,9 @@ class Examine extends Common
$map['check_user_id'] = [['like', '%,' . $user_id . ',%']];
break; //待审
case '2' :
- $map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or'];
+ $map_str = "(( check_user_id LIKE '%," . $user_id . ",%' OR check_user_id = " . $user_id . " )
+ OR ( flow_user_id LIKE '%," . $user_id . ",%' OR `flow_user_id` = " . $user_id . " ) )";
+// $map['flow_user_id'] = [['like', '%,' . $user_id . ',%'], ['eq', $user_id], 'or'];
break; //已审
default:
$map['examine.create_user_id'] = $user_id;
@@ -85,9 +89,9 @@ class Examine extends Common
$map['examine.create_time'] = array('between', array($start_time, $end_time));
}
unset($map['examine.between_time']);
-
+
//审核状态 0 待审批 2 审批通过 4 审批拒绝 all 全部
- if ($check_status) {
+ if (isset($check_status)) {
if ($check_status == 'all') {
$map['examine.check_status'] = ['egt', 0];
if (isSuperAdministrators($user_id)) {
@@ -95,13 +99,20 @@ class Examine extends Common
}
} elseif ($check_status == 4) {
$map['examine.check_status'] = ['eq', 3];
+ } elseif ($check_status == 0) {
+ $map['examine.check_status'] = ['<=', 1];
} else {
$map['examine.check_status'] = $check_status;
- }
- } else {
- $map['examine.check_status'] = ['egt', 0];
+ }
+ }else{
+ if ($examine_by == 'all') {
+ $map['examine.check_status'] = ['egt', 0];
+ } elseif ($examine_by == 1) {
+ $map['examine.check_status'] = ['elt', 1];
+ } elseif($examine_by == 2) {
+ $map['examine.check_status'] = ['egt', 2];
+ }
}
-
$join = [
['__ADMIN_USER__ user', 'user.id = examine.create_user_id', 'LEFT'],
['__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT'],
@@ -111,7 +122,7 @@ class Examine extends Common
->where($map_str)
->where($map)
->join($join);
-
+
$list = $list_view
->page($request['page'], $request['limit'])
->field('examine.*,user.realname,user.thumb_img,examine_category.title as category_name,examine_category.category_id as examine_config,examine_category.icon as examineIcon')
@@ -123,7 +134,7 @@ class Examine extends Common
->join($join)
->count('examine_id');
$admin_user_ids = $userModel->getAdminId();
-
+
foreach ($list as $k => $v) {
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
$causeCount = 0;
@@ -131,10 +142,10 @@ class Examine extends Common
$duration = $v['duration'] ?: '0.0';
$money = $v['money'] ?: '0.00';
if (in_array($v['category_id'], ['3', '5'])) {
- $causeCount = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->count() ? : 0;
+ $causeCount = db('oa_examine_travel')->where(['examine_id' => $v['examine_id']])->count() ?: 0;
if ($v['category_id'] == 3) $causeTitle = $causeCount . '个行程,共' . $duration . '天';
if ($v['category_id'] == 5) $causeTitle = $causeCount . '个报销事项,共' . $money . '元';
-
+
//附件
$fileList = [];
$imgList = [];
@@ -152,11 +163,11 @@ class Examine extends Common
}
$list[$k]['fileList'] = $fileList ?: [];
$list[$k]['imgList'] = $imgList ?: [];
-
+
}
$list[$k]['causeTitle'] = $causeTitle;
- $list[$k]['causeCount'] = $causeCount ? : 0;
-
+ $list[$k]['causeCount'] = $causeCount ?: 0;
+
//关联业务
$relationArr = [];
$relationArr = $recordModel->getListByRelationId('examine', $v['examine_id']);
@@ -164,7 +175,7 @@ class Examine extends Common
$list[$k]['contactsList'] = $relationArr['contactsList'];
$list[$k]['contractList'] = $relationArr['contractList'];
$list[$k]['customerList'] = $relationArr['customerList'];
-
+
//附件
$fileList = [];
$imgList = [];
@@ -182,7 +193,7 @@ class Examine extends Common
}
$list[$k]['fileList'] = $fileList ?: [];
$list[$k]['imgList'] = $imgList ?: [];
-
+
//创建人或管理员有撤销权限
$permission = [];
$is_recheck = 0;
@@ -195,7 +206,7 @@ class Examine extends Common
$is_recheck = 1;
}
}
-
+
//创建人(失败、撤销状态时可编辑)
if ($v['create_user_id'] == $user_id && in_array($v['check_status'], ['3', '4'])) {
$is_update = 1;
@@ -210,25 +221,25 @@ class Examine extends Common
if ($examineFlowData['config'] == 1) {
//固定审批流
$examineStepModel = new \app\admin\model\ExamineStep();
- $nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
- $is_check = $nextStepData['next_user_ids'] ? 1 : 0;
+// $nextStepData = $examineStepModel->nextStepUser($user_id, $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
+ $is_check = in_array($user_id, stringToArray($v['check_user_id'])) && in_array($v['check_status'], [0, 1]) ? 1 : 0;
$is_end = 1;
} else {
$is_end = 0;
- if ($v['check_user_id'] == (',' . $user_id . ',')) {
+ if ($v['check_user_id'] == (',' . $user_id . ',') && in_array($v['check_status'], [0, 1])) {
$is_check = 1;
- }else{
+ } else {
$is_check = 0;
}
- }
- if ($v['last_user_id'] == 0) {
- $user_name = $userModel->getListByStr(stringToArray($v['check_user_id']));
- $list[$k]['examine_name'] = $user_name[0]['realname'];
- } else {
- $user_name = $userModel->getListByStr(stringToArray($v['last_user_id']));
- $list[$k]['examine_name'] = $user_name[0]['realname'];
}
-
+ if($v['check_status']==4){
+ $usernames = db('admin_user')->whereIn('id', stringToArray($user_id))->column('realname');
+ }else{
+ $usernames = db('admin_user')->whereIn('id', stringToArray($v['check_user_id']))->column('realname');
+ }
+
+ $list[$k]['examine_name'] = implode($usernames, ',');
+
$permission['is_check'] = $is_check;
$permission['is_delete'] = $is_delete;
$permission['is_recheck'] = $is_recheck;
@@ -236,12 +247,13 @@ class Examine extends Common
$list[$k]['permission'] = $permission;
$list[$k]['config'] = $is_end;
$list[$k]['check_status_info'] = $this->statusArr[(int)$v['check_status']];
- $list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
+ $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
+ $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
}
$data = [];
$data['page']['list'] = $list;
$data['page']['dataCount'] = $dataCount ?: 0;
-
+
if ($request['page'] != 1 && (int)($request['page'] * $request['limit']) >= (int)$dataCount) {
$data['page']['firstPage'] = false;
$data['page']['lastPage'] = true;
@@ -254,7 +266,7 @@ class Examine extends Common
}
return $data;
}
-
+
/**
* 创建审批信息
* @param
@@ -279,9 +291,9 @@ class Examine extends Common
$this->error = $validate->getError();
return false;
}
-
+
$categoryInfo = $examineCategoryModel->getDataById($param['category_id']);
-
+
$fileArr = $param['file_id']; //接收表单附件
unset($param['file_id']);
$param['start_time'] = $param['start_time'] ? strtotime($param['start_time']) : 0;
@@ -309,7 +321,7 @@ class Examine extends Common
$rdata['status'] = 1;
$rdata['create_time'] = time();
Db::name('OaExamineRelation')->insert($rdata);
-
+
//处理差旅相关
$resTravel = true;
if (in_array($param['category_id'], ['3', '5']) && $param['cause']) {
@@ -329,11 +341,11 @@ class Examine extends Common
],
$send_user_id
);
-
-
+
+
$data = [];
$data['examine_id'] = $this->examine_id;
-
+
# 添加活动记录
if (!empty($rdata['customer_ids']) || !empty($rdata['contacts_ids']) || !empty($rdata['business_ids']) || !empty($rdata['contract_ids'])) {
Db::name('crm_activity')->insert([
@@ -350,7 +362,7 @@ class Examine extends Common
'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '',
]);
}
-
+
return $data;
} else {
$this->error = $examineDataModel->getError();
@@ -361,7 +373,7 @@ class Examine extends Common
return false;
}
}
-
+
/**
* 编辑审批信息
*
@@ -387,14 +399,14 @@ class Examine extends Common
$this->error = '数据不存在或已删除';
return false;
}
-
+
//过滤不能修改的字段
$unUpdateField = ['create_user_id', 'is_deleted', 'delete_time'];
foreach ($unUpdateField as $v) {
unset($param[$v]);
}
$categoryInfo = $examineCategoryModel->getDataById($dataInfo['category_id']);
-
+
//验证
$fieldModel = new \app\admin\model\Field();
$validateArr = $fieldModel->validateField($this->name, $dataInfo['category_id']); //获取自定义字段验证规则
@@ -404,7 +416,7 @@ class Examine extends Common
$this->error = $validate->getError();
return false;
}
-
+
$fileArr = $param['file_id']; //接收表单附件
unset($param['file_id']);
$param['start_time'] = $param['start_time'] ? strtotime($param['start_time']) : 0;
@@ -422,7 +434,7 @@ class Examine extends Common
return false;
}
}
-
+
//站内信
$send_user_id = stringToArray($param['check_user_id']);
if ($send_user_id) {
@@ -435,7 +447,7 @@ class Examine extends Common
$send_user_id
);
}
-
+
//相关业务
$rdata = [];
$rdata['customer_ids'] = $param['oaExamineRelation']['customer_ids'] ? arrayToString($param['oaExamineRelation']['customer_ids']) : [];
@@ -443,7 +455,7 @@ class Examine extends Common
$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);
-
+
//处理差旅相关
$resTravel = true;
if (in_array($dataInfo['category_id'], ['3', '5']) && $param['cause']) {
@@ -465,10 +477,10 @@ class Examine extends Common
$send_user_id
);
}
-
+
$data = [];
$data['examine_id'] = $examine_id;
-
+
# 删除活动记录
Db::name('crm_activity')->where(['activity_type' => 9, 'activity_type_id' => $examine_id])->delete();
# 添加活动记录
@@ -487,7 +499,7 @@ class Examine extends Common
'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '',
]);
}
-
+
return $data;
} else {
$this->error = $examineDataModel->getError();
@@ -498,7 +510,7 @@ class Examine extends Common
return false;
}
}
-
+
/**
* 审批数据
* @param $id 审批ID
@@ -516,7 +528,7 @@ class Examine extends Common
->where($map)
->alias('examine')
->join('__OA_EXAMINE_CATEGORY__ examine_category', 'examine_category.category_id = examine.category_id', 'LEFT');
-
+
$dataInfo = $data_view
->field('examine.*,examine_category.title as category_name,examine_category.icon as examineIcon')
->find();
@@ -534,7 +546,7 @@ class Examine extends Common
// foreach ($fieldList as $k=>$v) {
// $dataInfo[$v] = $fieldModel->getFormValueByField($v, $dataInfo[$v]);
// }
-
+
//关联业务
$relationArr = [];
$relationArr = $recordModel->getListByRelationId('examine', $id);
@@ -542,7 +554,7 @@ class Examine extends Common
$dataInfo['contactsList'] = $relationArr['contactsList'];
$dataInfo['contractList'] = $relationArr['contractList'];
$dataInfo['customerList'] = $relationArr['customerList'];
-
+
$travelList = [];
if (in_array($dataInfo['category_id'], ['3', '5'])) {
//行程、费用明细
@@ -574,7 +586,7 @@ class Examine extends Common
}
}
$dataInfo['travelList'] = $travelList;
-
+
//附件
$fileList = [];
$imgList = [];
@@ -596,7 +608,7 @@ class Examine extends Common
$dataInfo['examine_id'] = $id;
return $dataInfo;
}
-
+
/**
* 审批差旅数据保存
* @param examine_id 审批ID
@@ -615,7 +627,7 @@ class Examine extends Common
unset($v['files']);
$newData = $v;
$newData['examine_id'] = $examine_id;
-
+
$fileArr = $v['file_id']; //接收表单附件
unset($newData['file_id']);
unset($newData['fileList']);
@@ -643,7 +655,7 @@ class Examine extends Common
}
return true;
}
-
+
/**
* 审批差旅数据编辑
* @param examine_id 审批ID
@@ -657,7 +669,7 @@ class Examine extends Common
}
$oldTravelIds = db('oa_examine_travel')->where(['examine_id' => $examine_id])->column('travel_id');
$oldTravelFileIds = db('oa_examine_travel_file')->where(['travel_id' => ['in', $oldTravelIds]])->column('r_id');
-
+
$successRes = true;
foreach ($data as $k => $v) {
$newData = [];
diff --git a/application/oa/model/Log.php b/application/oa/model/Log.php
index ba09500..ff15ff1 100644
--- a/application/oa/model/Log.php
+++ b/application/oa/model/Log.php
@@ -23,7 +23,7 @@ class Log extends Common
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true;
-
+
/**
* [getDataList 日志list]
* @param [string] $map [查询条件]
@@ -39,10 +39,10 @@ class Log extends Common
$fileModel = new \app\admin\model\File();
$commonModel = new \app\admin\model\Comment();
$recordModel = new \app\admin\model\Record();
-
+
$user_id = $request['read_user_id'];
$by = $request['by'] ?: '';
-
+
$map = [];
$search = $request['search'];
if (isset($request['search']) && $request['search']) {
@@ -138,7 +138,7 @@ class Log extends Common
$list[$k]['contactsList'] = $relationArr['contactsList'];
$list[$k]['contractList'] = $relationArr['contractList'];
$list[$k]['customerList'] = $relationArr['customerList'];
-
+
if ($v['is_relation'] == 1) {
$list[$k]['bulletin']['customerNum'] = $v['save_customer'];
$list[$k]['bulletin']['businessNum'] = $v['save_business'];
@@ -148,7 +148,7 @@ class Log extends Common
} else {
$list[$k]['bulletin'] = 0;
}
-
+
$is_update = 0;
$is_delete = 0;
//3天内的日志可删,可修改
@@ -183,11 +183,11 @@ class Log extends Common
$data['page']['firstPage'] = true;
$data['page']['lastPage'] = false;
}
-
+
return $data;
}
-
-
+
+
// 创建日志信息
public function createData($param)
{
@@ -209,7 +209,7 @@ class Log extends Common
foreach ($arr as $value) {
unset($param[$value]);
}
-
+
if ($param['category_id'] == 1) {
$param['title'] = date('Y-m-d') . '-日报';
} else if ($param['category_id'] == 2) {
@@ -217,7 +217,7 @@ class Log extends Common
} else if ($param['category_id'] == 3) {
$param['title'] = date('Y-m-d') . '-月报';
}
-
+
if ($this->data($param)->allowField(true)->save()) {
$log_id = $this->log_id;
//操作记录
@@ -231,7 +231,7 @@ class Log extends Common
return false;
}
}
-
+
$temp = User::where(['structure_id' => ['in', $param['send_structure_ids']]])->column('id');
(new Message())->send(
Message::LOG_SEND,
@@ -245,7 +245,7 @@ class Log extends Common
$data = [];
$data['log_id'] = $log_id;
$data = $param;
-
+
if (count($fileArr)) {
$fileList = Db::name('AdminFile')->where('file_id in (' . implode(',', $fileArr) . ')')->select();
foreach ($fileList as $k => $v) {
@@ -258,20 +258,20 @@ class Log extends Common
//发送部门
$data['sendStructureList'] = $param['send_structure_ids'] ? $userModel->getListByStr($param['send_structure_ids']) : [];
$data['log_id'] = $log_id;
-
+
$rdata['log_id'] = $log_id;
$rdata['status'] = 1;
$rdata['create_time'] = time();
//关联业务
Db::name('OaLogRelation')->insert($rdata);
-
+
//相关业务
$relationArr = $recordModel->getListByRelationId('log', $log_id);
$data['businessList'] = $relationArr['businessList'];
$data['contactsList'] = $relationArr['contactsList'];
$data['contractList'] = $relationArr['contractList'];
$data['customerList'] = $relationArr['customerList'];
-
+
# 添加活动记录
if (!empty($rdata['customer_ids']) || !empty($rdata['contacts_ids']) || !empty($rdata['business_ids']) || !empty($rdata['contract_ids'])) {
Db::name('crm_activity')->insert([
@@ -288,14 +288,14 @@ class Log extends Common
'contract_ids' => !empty($rdata['contract_ids']) ? trim($rdata['contract_ids'], ',') : '',
]);
}
-
+
return $data;
} else {
$this->error = '添加失败';
return false;
}
}
-
+
/**
* 编辑日志信息
* @param
@@ -318,7 +318,7 @@ class Log extends Common
$rdata['contacts_ids'] = $param['contacts_ids'] ? arrayToString($param['contacts_ids']) : '';
$rdata['business_ids'] = $param['business_ids'] ? arrayToString($param['business_ids']) : '';
$rdata['contract_ids'] = $param['contract_ids'] ? arrayToString($param['contract_ids']) : '';
-
+
$arr = ['customer_ids', 'contacts_ids', 'business_ids', 'contract_ids'];
foreach ($arr as $value) {
unset($param[$value]);
@@ -332,7 +332,7 @@ class Log extends Common
unset($param['file']);
$param['send_user_ids'] = $param['send_user_ids'] ? arrayToString($param['send_user_ids']) : '';
$param['send_structure_ids'] = $param['send_structure_ids'] ? arrayToString($param['send_structure_ids']) : '';
-
+
if ($this->allowField(true)->save($param, ['log_id' => $log_id])) {
//操作日志
Db::name('AdminActionLog')->where(['action_id' => $log_id])->update(['join_user_ids' => $this->send_user_ids, 'structure_ids' => $this->send_structure_ids]);
@@ -373,7 +373,7 @@ class Log extends Common
return false;
}
}
-
+
/**
* 日志数据
* @param $id 日志ID
@@ -385,7 +385,7 @@ class Log extends Common
$userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure();
$commonModel = new \app\admin\model\Comment();
-
+
$map['log.log_id'] = $id;
$data_view = db('oa_log')
->where($map)
@@ -396,7 +396,7 @@ class Log extends Common
$this->error = '暂无此数据';
return false;
}
-
+
$relation = Db::name('OaLogRelation')->where('log_id =' . $id)->find();
$BusinessModel = new \app\crm\model\Business(); //商机
$dataInfo['businessList'] = $relation['business_ids'] ? $BusinessModel->getDataByStr($relation['business_ids']) : [];
@@ -406,7 +406,7 @@ class Log extends Common
$dataInfo['contractList'] = $relation['contract_ids'] ? $ContractModel->getDataByStr($relation['contract_ids']) : [];
$CustomerModel = new \app\crm\model\Customer();//客户
$dataInfo['customerList'] = $relation['customer_ids'] ? $CustomerModel->getDataByStr($relation['customer_ids']) : [];
-
+
$dataInfo['create_user_info']['realname'] = $dataInfo['realname'] ?: '';
$dataInfo['create_user_info']['id'] = $dataInfo['create_user_id'] ?: '';
$dataInfo['create_user_info']['thumb_img'] = $dataInfo['thumb_img'] ? getFullPath($dataInfo['thumb_img']) : '';
@@ -430,7 +430,7 @@ class Log extends Common
$dataInfo['replyList'] = $commonModel->read($param);
return $dataInfo;
}
-
+
/**
* 日志删除
*
diff --git a/application/work/controller/Task.php b/application/work/controller/Task.php
index bb2d617..4c25364 100644
--- a/application/work/controller/Task.php
+++ b/application/work/controller/Task.php
@@ -333,8 +333,8 @@ class Task extends ApiCommon
# 获取任务的项目信息
$workInfo = Db::name('work')->field(['work_id', 'group_id', 'is_open'])->where('work_id', $taskData['work_id'])->find();
# 是否是公开项目
- $userId = empty($workInfo['is_open']) ? $userInfo['id'] : 0;
- $groupId = !empty($workInfo['is_open']) ? $workInfo['group_id '] : 0;
+ $userId = $userInfo['id'];
+ $groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
# 获取项目下的权限
$taskData['auth'] = !empty($taskData['work_id']) ? $this->getRuleList($workInfo['work_id'], $userId, $groupId) : [];
diff --git a/application/work/controller/Tasklable.php b/application/work/controller/Tasklable.php
index 627cc49..46c1864 100644
--- a/application/work/controller/Tasklable.php
+++ b/application/work/controller/Tasklable.php
@@ -84,6 +84,9 @@ class Tasklable extends ApiCommon
$str = ','.$userInfo['id'].',';
$param['whereStr'] = ' ( task.create_user_id ='.$userInfo['id'].' or ( task.owner_user_id like "%'.$str.'%") or ( task.main_user_id = '.$userInfo['id'].' ) )';
}
+ # 标签列表只查询项目下的任务
+ $param['work_id'] = ['neq', 0];
+
$resData = $taskModel->getTaskList($param);
$taskList = $resData['list'] ? : [];
diff --git a/application/work/controller/Work.php b/application/work/controller/Work.php
index 5f51854..3e64fb9 100644
--- a/application/work/controller/Work.php
+++ b/application/work/controller/Work.php
@@ -147,7 +147,7 @@ class work extends ApiCommon
$workInfo = $workModel->getDataById($this->param['work_id']);
# 是否是公开项目
- $userId = empty($workInfo['is_open']) ? $this->userInfo['id'] : 0;
+ $userId = $this->userInfo['id'];
$groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
# 项目成员
@@ -632,5 +632,25 @@ class work extends ApiCommon
return resultArray(['data' => '操作成功!']);
}
+
+ /**
+ * 项目排序
+ *
+ * @author alvin guogaobo
+ * @version 1.0 版本号
+ * @since 2021/2/23 0023 15:27
+ */
+// public function workStart(){
+// $param=$this->param;
+// $userInfo=$this->userInfo;
+// $param['work']=serialize($param);
+// $param['user_id']=$userInfo['id'];
+// $workStart=new WorkLogic();
+// $res=$workStart->workStart($param);
+// if(!$res){
+// return resultArray(['error'=>'操作失败']);
+// }
+// return resultArray(['data'=>'操作成功']);
+// }
}
\ No newline at end of file
diff --git a/application/work/logic/WorkLogic.php b/application/work/logic/WorkLogic.php
index b76f2d2..3f39a0d 100644
--- a/application/work/logic/WorkLogic.php
+++ b/application/work/logic/WorkLogic.php
@@ -14,40 +14,40 @@ use think\Db;
class WorkLogic
{
use WorkAuthTrait;
-
+
public function index($param)
{
# 排序
$orderField = 'work_id';
- $orderSort = 'asc';
+ $orderSort = 'asc';
if (!empty($param['sort_type']) && $param['sort_type'] == 1) {
$orderField = 'work_id';
- $orderSort = 'asc';
+ $orderSort = 'asc';
}
if (!empty($param['sort_type']) && $param['sort_type'] == 2) {
$orderField = 'work_id';
- $orderSort = 'desc';
+ $orderSort = 'desc';
}
if (!empty($param['sort_type']) && $param['sort_type'] == 3) {
$orderField = 'update_time';
- $orderSort = 'desc';
+ $orderSort = 'desc';
}
-
+
# 搜索
$searchWhere = '';
- $dateWhere = [];
- $userWhere = [];
+ $dateWhere = [];
+ $userWhere = [];
$ownerUserId = !empty($param['owner_user_id']) ? $param['owner_user_id'] : '';
- $search = !empty($param['search']) ? $param['search'] : '';
- $type = !empty($param['type']) ? $param['type'] : 0;
- $startTime = !empty($param['start_time']) ? $param['start_time'] : '';
- $endTime = !empty($param['end_time']) ? $param['end_time'] : '';
+ $search = !empty($param['search']) ? $param['search'] : '';
+ $type = !empty($param['type']) ? $param['type'] : 0;
+ $startTime = !empty($param['start_time']) ? $param['start_time'] : '';
+ $endTime = !empty($param['end_time']) ? $param['end_time'] : '';
unset($param['search']);
unset($param['type']);
unset($param['start_time']);
unset($param['end_time']);
unset($param['owner_user_id']);
-
+
switch ($type) {
case 1 :
# 今天
@@ -69,46 +69,136 @@ class WorkLogic
$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')))];
}
-
+
# 时间区间
if (!empty($startTime)) $dateWhere['update_time'] = ['egt', strtotime($startTime . '00:00:00')];
- if (!empty($endTime)) $dateWhere['update_time'] = ['elt', strtotime($endTime . '23:59:59')];
-
+ if (!empty($endTime)) $dateWhere['update_time'] = ['elt', strtotime($endTime . '23:59:59')];
+
# 搜索内容
if ($search) $searchWhere = '(name like "%' . $search . '%") OR (description like "%' . $search . '%")';
-
+
# 成员
if (!empty($ownerUserId)) {
$userIds = Db::name('work_user')->whereIn('user_id', $ownerUserId)->column('work_id');
$userWhere['work_id'] = ['in', $userIds];
}
-
- $userModel = new \app\admin\model\User();
+
+ $userModel = new \app\admin\model\User();
$perUserIds = $userModel->getUserByPer('work', 'work', 'index');
- $authUser = array_unique(array_merge([$param['user_id']], $perUserIds));
-
+ $authUser = array_unique(array_merge([$param['user_id']], $perUserIds));
+
$data = Db::name('work')
- ->where(function($query) {
- $query->where('status', 1);
- $query->where('ishidden', 0);
- })
- ->where(function ($query) use ($param, $authUser) {
- $query->whereOr(['create_user_id' => ['in', $authUser]]);
- $query->whereOr('is_open', 1);
- $query->whereOr(function ($query) use ($param) {
- $query->where('is_open', 0);
- $query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%');
- });
- })
- ->where($searchWhere)
- ->where($dateWhere)
- ->where($userWhere)
- ->order($orderField, $orderSort)->select();
+ ->where(function ($query) {
+ $query->where('status', 1);
+ $query->where('ishidden', 0);
+ })
+ ->where(function ($query) use ($param, $authUser) {
+ $query->whereOr(['create_user_id' => ['in', $authUser]]);
+ $query->whereOr('is_open', 1);
+ $query->whereOr(function ($query) use ($param) {
+ $query->where('is_open', 0);
+ $query->where('owner_user_id', 'like', '%' . $param['user_id'] . '%');
+ });
+ })
+ ->where($searchWhere)
+ ->where($dateWhere)
+ ->where($userWhere)
+ ->order($orderField, $orderSort)->select();
- foreach ($data AS $key => $value) {
+ foreach ($data as $key => $value) {
$data[$key]['authList']['project'] = $this->getRuleList($value['work_id'], $param['user_id'], $value['group_id']);
}
-
+
return $data;
}
+
+ /**
+ * @param $param work 排序数组值 user_id用户
+ *
+ * @author alvin guogaobo
+ * @version 1.0 版本号
+ * @since 2021/2/23 15:42
+ */
+// public function workStart($param)
+// {
+// $item = Db::name('workStart')->where('user_id', $param['user_id'])->find();
+// $data = [];
+// $data['datas'] = $param['work'];
+// $data['user_id'] = $param['user_id'];
+// if (!$item) {
+// return Db::name('workStart')->insertGetId($data);
+// } else {
+// return Db::name('workStart')->where('user_id', $param['user_id'])->update([$data]);
+// }
+// }
+
+ /**
+ * 根据数组指定键名排序数组
+ * @param $array array 被排序数组
+ * @param $key_name string 数组键名
+ * @param $sort string desc|asc 升序或者降序
+ * @return array 返回排序后的数组
+ */
+// function gw_sort($array, $param)
+// {
+// $whilr = array
+// (
+// [0] => ['work_id' => 5,
+// 'name' => 222,
+// 'status' => 1,
+// 'create_time' => 1613628469,
+// 'create_user_id' => 7,
+// 'description' => 222,
+// 'color' => '#53D397',
+// 'is_open' => 1,
+// 'owner_user_id' => ',1,2,3,4,5,7,',
+// 'ishidden' => 0,
+// 'archive_time' => 0,
+// 'group_id' => 12,
+// 'cover_url' => 'http://192.168.1.31/72crm-php/public/uploads/20210218/12ece02733c8684ce987f207062173b5.png',
+// 'update_time' => 1613629916,
+// 'is_follow' => 0,
+// 'is_system_cover' => 0,],
+//
+// [1] => [
+//
+// 'work_id' => 7,
+// 'name' => '啊啊',
+// 'status' => 1,
+// 'create_time' => 1614059388,
+// 'create_user_id' => 1,
+// 'description' => '',
+// 'color' => '#53D397',
+// 'is_open' => 0,
+// 'owner_user_id' => ',1,3,',
+// 'ishidden' => 0,
+// 'archive_time' => 0,
+// 'group_id' => 12,
+// 'cover_url' => 'https://file.72crm.com/static/pc/images/pm/project-cover-1.jpg',
+// 'update_time' => 1614059926,
+// 'is_follow' => 0,
+// 'is_system_cover' => 1,
+// ]
+//
+// );
+// $item = Db::name('workStart')->where('user_id', $param['user_id'])->find();
+// $key_name_array = array();//保存被排序数组键名
+// foreach ($whilr as $key => $val) {
+// foreach ($item as $v){
+// $key_name_array[] = array_merge(array_flip($val), $v);
+// }
+// }
+// $key_name_array = array_flip($key_name_array);//反转键名和值得到数组排序后的位置
+// $result = array();
+// foreach($array as $k=>$v){
+// foreach ($item as $vall){
+// $this_key_name_value = $v[$vall];//当前数组键名值依次是20,10,30
+// $save_position = $key_name_array[$this_key_name_value];//获取20,10,30排序后存储位置
+// $result[$save_position] = $v;//当前项存储到数组指定位置
+// }
+// }
+// ksort($result);
+//
+// return $result;
+// }
}
\ No newline at end of file
diff --git a/application/work/model/Task.php b/application/work/model/Task.php
index 070397c..398c633 100644
--- a/application/work/model/Task.php
+++ b/application/work/model/Task.php
@@ -50,6 +50,7 @@ class Task extends Common
$workModel = model('Work');
$userModel = new \app\admin\model\User();
$work_id = $request['work_id'];
+ $map=[];
$ret = $workModel->checkWork($work_id, $user_id);
if (!$ret) {
$this->error = $workModel->getError();
@@ -68,11 +69,7 @@ class Task extends Common
} else {
$newList = $classList['list'];
}
-
- if ($request['main_user_id']) {
- $map['main_user_id'] = ['in', $request['main_user_id']];
- }
- //截止时间
+
if ($request['stop_time_type']) {
if ($request['stop_time_type'] == '5') { //没有截至日期
$map['stop_time'] = '0';
@@ -104,6 +101,7 @@ class Task extends Common
$map['stop_time'] = ['between', [$timeAry[0], $timeAry[1]]];
}
}
+
if ($request['lable_id']) {
$taskIds = [];
$task_ids = [];
@@ -125,18 +123,20 @@ class Task extends Common
}
$map['task_id'] = ['in', $task_ids];
}
+
$data = array();
foreach ($newList as $key => $value) {
$data[$key]['class_id'] = $value['class_id'] ?: -1;
$data[$key]['class_name'] = $value['name'];
-
+
$map['status'] = $map['status'] ?: ['in', ['1', '5']];
+
$map['ishidden'] = 0;
$map['work_id'] = $request['work_id'];
$map['class_id'] = $value['class_id'];
$map['pid'] = 0;
$map['is_archive'] = 0;
-
+ $map['main_user_id']=$request['main_user_id'];
$taskList = [];
$resTaskList = $this->getTaskList($map);
$data[$key]['count'] = $resTaskList['count'];
@@ -414,7 +414,7 @@ class Task extends Common
unset($param[$value]);
}
$main_user_id = $param['main_user_id'] ?: $param['create_user_id'];
-
+ $param['owner_user_id'] = ','.$main_user_id.','; //参与人
$param['main_user_id'] = $main_user_id; //负责人
$param['start_time'] = !empty($param['start_time']) ? strtotime($param['start_time']) : 0;
$param['stop_time'] = !empty($param['stop_time']) ? strtotime($param['stop_time']) : 0;
@@ -443,14 +443,14 @@ class Task extends Common
//操作日志
actionLog($task_id, '', '', '新建了任务');
//抄送站内信
-// (new Message())->send(
-// Message::TASK_ALLOCATION,
-// [
-// 'title' => $param['name'],
-// 'action_id' => $task_id
-// ],
-// $param['owner_user_id']
-// );
+ (new Message())->send(
+ Message::TASK_ALLOCATION,
+ [
+ 'title' => $param['name'],
+ 'action_id' => $task_id
+ ],
+ trim(',',$param['owner_user_id'])
+ );
}
# 添加活动记录
@@ -642,14 +642,14 @@ class Task extends Common
//设置负责人
$userdet = $userModel->getDataById($param['main_user_id']);
$data['after'] = '设定' . $userdet['realname'] . '为主要负责人!';
-// (new Message())->send(
-// Message::TASK_ALLOCATION,
-// [
-// 'title' => $taskInfo['name'],
-// 'action_id' => $param['task_id']
-// ],
-// $param['main_user_id']
-// );
+ (new Message())->send(
+ Message::TASK_ALLOCATION,
+ [
+ 'title' => $taskInfo['name'],
+ 'action_id' => $param['task_id']
+ ],
+ $param['main_user_id']
+ );
break;
}
@@ -899,15 +899,17 @@ class Task extends Common
*/
public function getTaskList($request)
{
- $search = $request['search'];
+
+ $search = $request['search']?:'';
$whereStr = $request['whereStr'] ?: [];
$lable_id = $request['lable_id'] ?: '';
+ $main_user_id = $request['main_user_id'] ?: '';
$taskSearch = !empty($request['taskSearch']) ? $request['taskSearch'] : '';
$isArchive = !empty($request['is_archive']) ? $request['is_archive'] : 0;
- unset($request['search']);
- unset($request['whereStr']);
- unset($request['lable_id']);
- unset($request['taskSearch']);
+// unset($request['search']);
+// unset($request['whereStr']);
+// unset($request['lable_id']);
+ unset($request['main_user_id']);
$request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: [];
$userModel = new \app\admin\model\User();
@@ -924,6 +926,13 @@ class Task extends Common
}
$dataCount = db('task')->alias('task')->where($map)->where($whereStr)->where($taskSearch)->count();
$taskList = [];
+ $logWhere='';
+ if ($main_user_id) {
+ foreach ($main_user_id as $key => $value) {
+ $logWhere.= '( task.owner_user_id like "%,' . $value . ',%") OR ';
+ }
+ if (!empty($logWhere)) $logWhere = '(' . rtrim($logWhere, 'OR ') . ')';
+ }
if ($dataCount) {
$taskList = db('task')
->alias('task')
@@ -932,6 +941,7 @@ class Task extends Common
->field('task.task_id,task.name,task.main_user_id,task.is_top,task.work_id,task.lable_id,task.priority,task.stop_time,task.status,task.pid,task.create_time,task.owner_user_id,u.realname as main_user_name,u.thumb_img,w.name as work_name,color')
->where($map)
->where($whereStr)
+ ->where($logWhere)
->where($taskSearch)
->order('task.status asc,task.order_id asc')
->select();
@@ -1036,7 +1046,6 @@ class Task extends Common
->where($labelWhere)
->order($order)
->select();
-
foreach ($taskList as $key => $value) {
if ($value['pid'] > 0) {
$p_det = $this->field('task_id,name')->where(['task_id' => $value['pid']])->find();
@@ -1084,35 +1093,38 @@ class Task extends Common
# 今天
if ($type == 1) {
- $result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')';
+ $result = '(task.stop_time >= ' . strtotime(date('Y-m-d 00:00:00')) . ' AND task.stop_time <= ' . strtotime(date('Y-m-d 23:59:59')) . ')';
}
# 明天
if ($type == 2) {
$tomorrow = date("Y-m-d 23:59:59", strtotime("+1 day"));
- $result = '(task.stop_time > 0 AND task.stop_time <= ' . strtotime($tomorrow) . ')';
+ $start = date("Y-m-d 00:00:00", strtotime("+1 day"));
+ $result = '(task.stop_time >= ' . strtotime($start) . ' AND task.stop_time <= ' . strtotime($tomorrow) . ')';
}
# 本周
if ($type == 3) {
$week = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));
- $result = '(task.stop_time > 0 AND task.stop_time <= ' . $week . ')';
+ $start_week=mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
+ $result = '(task.stop_time >= ' . $start_week . ' AND task.stop_time <= ' . $week . ')';
}
# 本月
if ($type == 4) {
+ $timestamp = mktime(0, 0, 0, date('m'), 1, date('Y'));
$month = mktime(23, 59, 59, date("m"), date("t"), date("Y"));
- $result = '(task.stop_time > 0 AND task.stop_time <= ' . $month . ')';
+ $result = '(task.stop_time > ' . $timestamp . ' AND task.stop_time <= ' . $month . ')';
}
# 未设置截止日期
if ($type == 5) {
- $result = $result = '(task.stop_time = 0)';;
+ $result = '(task.stop_time = 0)';;
}
# 已延期
if ($type == 6) {
- $result = '(task.status = 2 OR task.stop_time >= ' . time() . ')';
+ $result = '(task.status = 2 OR task.stop_time < ' . time() . ')'.'AND task.stop_time <> 0 AND task.status = 1';
}
# 今日更新
diff --git a/application/work/model/Work.php b/application/work/model/Work.php
index 8888af1..b63a790 100644
--- a/application/work/model/Work.php
+++ b/application/work/model/Work.php
@@ -75,6 +75,7 @@ class Work extends Common
$ownerData['work_id'] = $workId;
$ownerData['create_user_id'] = $createUserId;
$ownerData['owner_user_id'] = $ownerUserId;
+ $ownerData['group_id'] = !empty($param['group_id']) ? $param['group_id'] : 0;
# 创建项目下的相关成员
$this->addOwner($ownerData);
@@ -129,6 +130,10 @@ class Work extends Common
$ownerData['is_open'] = $param['is_open'];
$ownerData['group_id'] = $param['group_id'];
$this->addOwner($ownerData);
+ }
+ # 公开项目更新时的权限变更
+ if ($param['is_open'] == 1 && !empty($param['group_id']) && $param['group_id'] != $workInfo['group_id']) {
+ db('work_user')->where(['work_id' => $workInfo['work_id'], 'user_id' => ['neq', $workInfo['create_user_id']]])->update(['group_id' => $param['group_id']]);
}
$resUpdata = $this->where($map)->update($param);
if ($resUpdata) {
@@ -307,7 +312,7 @@ class Work extends Common
$group_id = 1;
} else {
# 默认角色
- $group_id = db('admin_group')->where(['pid' => 5, 'system' => 1])->order('id asc')->value('id');
+ $group_id = !empty($param['group_id']) ? $param['group_id'] : db('admin_group')->where(['pid' => 5, 'system' => 1])->order('id asc')->value('id');
}
$data['group_id'] = $group_id;
$saveData[] = $data;
diff --git a/config/config.php b/config/config.php
index 379ac73..64285ae 100644
--- a/config/config.php
+++ b/config/config.php
@@ -265,5 +265,8 @@ return [
// 商业智能查询缓存时间(秒)
'bi_cache_time' => 1800,
// 商业智能慢查询查询时间(查询超过该时间进行数据缓存)(毫秒)
- 'bi_slow_query_time' => 500
+ 'bi_slow_query_time' => 500,
+ 'public_key' => '-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkqKFcAQtIp4rlkB5LOMnViyVY/hhA6x0R9ftwtEXsAFu4hBZrm9txdEvxSrDCUsx3Zwv/gdimeOzTtfSKffdoE/DwllNP9Zu6nsr2kGRgPrRwjtlO+j2FOM0b9UY1SQ/bWE+a9oQL2jL9xMSbtX1xG/+HcMo1bT+pa6FNQzs3egmvMt75/jaxINPSraj4kgNFawSBk7qDBEqDYiQwtPTuaNW1YZIs++/gZHsCRgGs/JrAbxNpl7+v/+Z503I3I2rs/8eUM5d16NXR8M7vtobUDCTIiQOgRahO8WMadgFlwavyVCYhy/TBXyj5RUfWaS26LrEN3vkj4TjoJu5m9LQ5QIDAQAB
+-----END PUBLIC KEY-----',
];
diff --git a/config/route_admin.php b/config/route_admin.php
index 8b8ec11..4c45a03 100644
--- a/config/route_admin.php
+++ b/config/route_admin.php
@@ -15,6 +15,7 @@ return [
'admin/install/step2' => ['admin/install/step2', ['method' => 'GET']],
'admin/install/step3' => ['admin/install/step3', ['method' => 'GET']],
'admin/install/step4' => ['admin/install/step4', ['method' => 'POST|AJAX']],
+ 'admin/install/step5' => ['admin/install/step5', ['method' => 'GET']],
'admin/install/progress' => ['admin/install/progress', ['method' => 'POST']],
//子部门列表
diff --git a/config/route_crm.php b/config/route_crm.php
index e00aa50..d7c7e9b 100644
--- a/config/route_crm.php
+++ b/config/route_crm.php
@@ -233,6 +233,8 @@ return [
'crm/receivables/system' => ['crm/receivables/system', ['method' => 'POST']],
// 【回款】菜单数量
'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']],
+ //【回款】导出
+ 'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']],
// 【回款计划】列表
'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']],
diff --git a/config/version.php b/config/version.php
index 2a23dbd..dcf4052 100644
--- a/config/version.php
+++ b/config/version.php
@@ -1,5 +1,5 @@
'11.0.0',
-'RELEASE'=>'20210205',
+'VERSION'=>'11.0.1',
+'RELEASE'=>'20210227',
);
\ No newline at end of file
diff --git a/public/sql/5kcrm.sql b/public/sql/5kcrm.sql
index 5c6b1ec..50b2c16 100644
--- a/public/sql/5kcrm.sql
+++ b/public/sql/5kcrm.sql
@@ -1708,10 +1708,10 @@ INSERT INTO `5kcrm_admin_scene` (`types`, `name`, `user_id`, `order_id`, `data`,
INSERT INTO `5kcrm_admin_scene` (`types`, `name`, `user_id`, `order_id`, `data`, `is_hide`, `type`, `bydata`, `create_time`, `update_time`) VALUES ('crm_visit', '下属负责的回访', '0', '1', '', '0', '1', 'sub', '1546272000', '1551515457');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'number', '回访编号', 'text', '', '0', '0', '1', '', NULL, '1', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'visit_time', '回访时间', 'date', '', '0', '0', '1', '', '', '2', '1', '1553788800', '1553788800', '0', '', '0');
-INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'visit_user_id', '回访人', 'user', '', '0', '0', '1', '', '', '3', '1', '1553788800', '1553788800', '0', '', '0');
+INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'owner_user_id', '回访人', 'single_user', '', '0', '0', '1', '', '', '9', '3', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'shape', '回访形式', 'select', '', '0', '0', '0', '', '见面拜访\r\n电话\r\n短信\r\n邮件\r\n微信', '4', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'customer_id', '客户名称', 'customer', '', '0', '0', '1', '', '', '5', '1', '1553788800', '1553788800', '0', '', '0');
-INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contacts_id', '联系人', 'contacts', '', '0', '0', '0', '', '', '6', '1', '1553788800', '1553788800', '0', '', '0');
+INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contacts_id', '联系人', 'contacts', '', '0', '0', '0', '', '', '6', '3', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'contract_id', '合同编号', 'contract', '', '0', '0', '1', '', '', '7', '1', '1553788800', '1553788800', '0', '', '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ('crm_visit', '0', 'satisfaction', '客户满意度', 'select', '', '0', '0', '0', '', '很满意\r\n满意\r\n一般不满意\r\n很不满意', '8', '1', '1553788800', '1553788800', '0', NULL, '0');
INSERT INTO `5kcrm_admin_field` ( `types`, `types_id`, `field`, `name`, `form_type`, `default_value`, `max_length`, `is_unique`, `is_null`, `input_tips`, `setting`, `order_id`, `operating`, `create_time`, `update_time`, `type`, `relevant`, `is_hidden`) VALUES ( 'crm_visit', '0', 'feedback', '客户反馈', 'textarea', '', '0', '0', '0', '', '', '9', '1', '1553788800', '1553788800', '0', '', '0');
@@ -1751,7 +1751,7 @@ DROP TABLE IF EXISTS `5kcrm_crm_visit`;
CREATE TABLE `5kcrm_crm_visit` (
`visit_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '回访id',
`owner_user_id` int(11) NOT NULL COMMENT '负责人',
- `visit_user_id` int(11) NOT NULL COMMENT '回访人',
+ `owner_user_id` int(11) NOT NULL COMMENT '回访人',
`create_user_id` int(11) NOT NULL COMMENT '创建人id',
`customer_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称',
`contract_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '合同编号',
@@ -1840,12 +1840,12 @@ ALTER TABLE `5kcrm_oa_examine` ADD COLUMN `last_user_id` varchar(200) not null d
ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读';
ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色';
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='65' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='63' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='2' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='3' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='4' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='5' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5');
+UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='6' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6');
INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0');
@@ -1955,7 +1955,7 @@ CREATE TABLE `5kcrm_crm_receivables_file` (
`receivables_id` int(10) unsigned NOT NULL,
`file_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`r_id`) USING BTREE
-) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED;
INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('activity_phrase', 'a:5:{i:0;s:18:\\\"电话无人接听\\\";i:1;s:15:\\\"客户无意向\\\";i:2;s:42:\\\"客户意向度适中,后续继续跟进\\\";i:3;s:42:\\\"客户意向度较强,成交几率较大\\\";i:4;s:3:\\\"312\\\";}', '跟进记录常用语');
INSERT INTO `5kcrm_crm_config` (`name`, `value`, `description`) VALUES ('visit_config', '1', '是否开启回访提醒:1开启;0不开启');
diff --git a/public/sql/install.sql b/public/sql/install.sql
index b1960ff..8bfd170 100644
--- a/public/sql/install.sql
+++ b/public/sql/install.sql
@@ -1,3 +1,3 @@
-insert into `5kcrm_admin_user` (`username`, `password`, `salt`, `realname`, `create_time`, `status`, `structure_id`, `parent_id`, `type`) values ( '18888888888', '302dd3f6dba54513f2a5a1bf696e2d8d', '1b2d', '管理员', '1487217060', 1, 1, 0, 1);
+insert into `5kcrm_admin_user` (`username`, `password`, `salt`, `realname`, `create_time`, `status`, `structure_id`, `parent_id`, `type`) values ( '18888888888', '05a9918b455b2209673c36676422bb81', '7217', '管理员', '1613611667', 1, 1, 0, 1);
-insert into `5kcrm_hrm_user_det` (`user_id`, `join_time`, `type`, `status`, `userstatus`, `create_time`, `update_time`) values ( 1, '1487217060', 1, 1, 2, '1487217060', '1487217060');
\ No newline at end of file
+insert into `5kcrm_hrm_user_det` (`user_id`, `join_time`, `type`, `status`, `userstatus`, `create_time`, `update_time`) values ( 1, '1613611667', 1, 1, 2, '1613611667', '1613611667');
\ No newline at end of file
diff --git a/public/sql/update_sql_20210207.sql b/public/sql/update_sql_20210207.sql
index 1773a15..9991853 100644
--- a/public/sql/update_sql_20210207.sql
+++ b/public/sql/update_sql_20210207.sql
@@ -380,13 +380,6 @@ ALTER TABLE `5kcrm_oa_examine` ADD COLUMN `last_user_id` varchar(200) not null d
ALTER TABLE `5kcrm_oa_announcement` ADD COLUMN `is_read` tinyint(2) not null default 0 comment '1表示已读 0表示未读';
ALTER TABLE `5kcrm_oa_examine_category` ADD COLUMN `icon` varchar(255) NOT NULL COMMENT '类型图标和颜色';
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='1', `title`='普通审批', `remark`='普通审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612576450', `update_time`='1612576450', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='65' ,`icon`='wk wk-leave,#00CAAB' WHERE (`category_id`='1');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='2', `title`='请假审批', `remark`='请假审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1612518097', `update_time`='1612518097', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='63' ,`icon`='wk wk-l-record,#3ABCFB' WHERE (`category_id`='2');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='3', `title`='出差审批', `remark`='出差审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-trip,#3ABCFB' WHERE (`category_id`='3');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='4', `title`='加班审批', `remark`='加班审批', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-overtime,#FAAD14' WHERE (`category_id`='4');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='5', `title`='差旅报销', `remark`='差旅报销', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-reimbursement,#3ABCFB' WHERE (`category_id`='5');
-UPDATE `5kcrm_oa_examine_category` SET `category_id`='6', `title`='借款申请', `remark`='借款申请', `create_user_id`='1', `status`='1', `is_sys`='1', `user_ids`='', `structure_ids`='', `create_time`='1548911542', `update_time`='1548911542', `is_deleted`='0', `delete_time`='0', `delete_user_id`='0', `flow_id`='1' ,`icon`='wk wk-go-out,#FF6033' WHERE (`category_id`='6');
-
INSERT INTO `5kcrm_admin_rule` VALUES ('154', '0', '其他设置', 'other_rule', '2', '105', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('155', '0', '日志欢迎语', 'welcome', '3', '154', '0');
INSERT INTO `5kcrm_admin_rule` VALUES ('156', '0', '设置欢迎语', 'setWelcome', '3', '154', '0');
diff --git a/public/sql/update_sql_20210227.sql b/public/sql/update_sql_20210227.sql
new file mode 100644
index 0000000..92089a8
--- /dev/null
+++ b/public/sql/update_sql_20210227.sql
@@ -0,0 +1,2 @@
+UPDATE `5kcrm_admin_field` SET `operating`= 3, `field` = 'owner_user_id', `form_type` = 'single_user' WHERE `types` = 'crm_visit' AND `field` = 'visit_user_id';
+UPDATE `5kcrm_admin_field` SET `operating`= 3 WHERE `types` = 'crm_visit' AND `field` = 'contacts_id';
\ No newline at end of file
diff --git a/public/static/icon/success_gray.png b/public/static/icon/success_gray.png
new file mode 100644
index 0000000..e520a10
Binary files /dev/null and b/public/static/icon/success_gray.png differ
diff --git a/public/static/img/bg.png b/public/static/img/bg.png
new file mode 100644
index 0000000..06c48ec
Binary files /dev/null and b/public/static/img/bg.png differ
diff --git a/public/static/js/step2.js b/public/static/js/step2.js
index d7c088c..e54c26c 100644
--- a/public/static/js/step2.js
+++ b/public/static/js/step2.js
@@ -45,7 +45,12 @@ var rules = {
required: true,
regexp: /^(?=.*[a-zA-Z])(?=.*\d).{6,20}$/,
label: '管理员密码(6~20位字母加数字组合)'
- }
+ },
+ wkcode: {
+ required: false,
+ regexp: null,
+ label: '序列号'
+ },
};
var timer = null;
@@ -63,32 +68,36 @@ $('.next').click(function () {
// 校验form数据 true 校验通过 false 校验失败
var forms = getFormData();
var result = checkForm();
- console.log('result---', result, forms);
+ // console.log('result---', result, forms);
if (result) {
- $.ajax({
- cache: true,
- type: "POST",
- dataType: 'json',
- url: "./step4",
- data: {
- form: forms
- },
- async: false,
- success: function (result) {
- if (result.code == '200') {
- alert(result.data);
- window.location = '../../../index.html';
- } else if (result.code == '400') {
- alert(result.error); //失败
- return false;
- // window.location = 'step3.html'
- } else {
- window.location = 'step3.html'
- alert('安装失败');
+
+ $('#cover').css('display', 'block');//显示遮罩层
+ setTimeout(()=>{
+ $.ajax({
+ cache: true,
+ type: "POST",
+ dataType: 'json',
+ url: "./step4",
+ data: {
+ form: forms
+ },
+ async: false,
+ success: function (result) {
+ if (result.code == '200') {
+ window.location = 'step5.html';
+ } else if (result.code == '400') {
+ $('#cover').css('display', 'none');
+ alert(result.error); //失败
+ return false;
+ // window.location = 'step3.html'
+ } else {
+ window.location = 'step3.html'
+ alert('安装失败');
+ }
}
- }
- // getRes();
- });
+ // getRes();
+ });
+ })
}
});
@@ -168,7 +177,7 @@ function _initFormValue() {
* @return {form}
*/
function getFormData() {
- $('input').each(function (index, item) {
+ $('.wkform').each(function (index, item) {
form[item.name] = item.value;
// 重置表单状态
$(item).removeClass('input-error');
@@ -186,6 +195,7 @@ function getFormData() {
* @return {boolean}
*/
function checkForm() {
+
var result = {};
for (var key in rules) {
var rule = rules[key];
@@ -228,9 +238,4 @@ function renderErrorMsg(key, msg) {
$(item).addClass('input-error')
}
})
-}
-
-/**
- * 提交表单
- */
-function submitForm() {}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/public/static/style/base.css b/public/static/style/base.css
index 4f18935..e46b4ce 100644
--- a/public/static/style/base.css
+++ b/public/static/style/base.css
@@ -10,6 +10,11 @@ html, body {
background-color: #f2f2f2;
font-family: 微软雅黑,Microsoft Yahei,LiHei Pro,Hiragino Sans,GBHelvetica Neue,Helvetica,Arial,PingFang SC,WenQuanYi Micro Hei,sans-serif;
}
+body {
+ background-image: url('../img/bg.png');
+ background-size: 100% 100%;
+ background-repeat: no-repeat;
+}
li {
list-style: none;
@@ -72,7 +77,10 @@ li {
.top {
width: 790px;
height: 65px;
- margin: 0 auto;
+ margin:40px auto 20px auto;
+ border: 1px solid white;
+ border-radius: 5px ;
+ background-color: #fff ;
}
/* container */
@@ -81,6 +89,7 @@ li {
min-height: 493px;
background-color: white;
border: 1px solid #e1e1e1;
+ border-radius:5px;
margin: 0 auto;
}
@@ -93,7 +102,7 @@ li {
width: 820px;
text-align: center;
font-size: 15px;
- color: #8c8c8c;
+ color: #fff;
line-height: 30px;
margin: 0 auto;
padding: 30px 0;
@@ -112,6 +121,9 @@ li {
text-align: center;
margin: 20px 0;
float: left;
+ display: flex;
+ align-items: center;
+ justify-content: center;
}
.step.line {
width: 10%;
@@ -122,12 +134,12 @@ li {
.step .sort {
width: 25px;
height: 25px;
- color: white;
+ color: #8c8c8c;
line-height: 25px;
text-align: center;
font-size: 14px;
border-radius: 50%;
- background-color: #d1d1d1;
+ /* background-color: #d1d1d1; */
margin-right: 5px;
display: inline-block;
}
@@ -139,13 +151,13 @@ li {
}
.step.active .sort {
- background-color: #3e84e9;
+ background-color: #fff;
}
.step.active .desc {
- color: #3e84e9;
+ color: black;
}
.step.active.line {
- background-color: #3e84e9;
+ /* background-color: #fff; */
}
@@ -156,7 +168,7 @@ li {
line-height: 40px;
font-size: 16px;
color: #3e84e9;
- border-radius: 40px;
+ border-radius: 5px;
background-color: white;
border: 1px solid #3e84e9;
display: inline-block;
@@ -172,16 +184,44 @@ li {
width: 100%;
height: 54px;
line-height: 54px;
- background-color: #f7f7f7;
+ /* background-color: #f7f7f7; */
padding: 0 26px;
- border-bottom: 1px solid #e1e1e1;
+ /* border-bottom: 1px solid #e1e1e1; */
+ font-weight: 600;
}
.base-top .title {
- color: #8c8c8c;
+ /* color: #8c8c8c; */
font-size: 16px;
}
.base-top .version {
font-size: 13px;
- color: #d1d1d1;
+ color: #8c8c8c;
float: right;
}
+
+.base-des {
+ margin: 0 auto;
+ line-height: 35px;
+ width: 790px;
+ background-color: #fff;
+ padding: 0 40px;
+ margin-bottom: 20px;
+ color: #8c8c8c;
+}
+
+.base-a{
+ cursor: pointer;
+ user-select: none;
+ text-decoration: none;
+ color: #3e84e9;
+}
+
+#cover{
+ position:absolute;left:0px;top:0px;
+ background:rgba(0, 0, 0, 0.4);
+ width:100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
+ height:100%;
+ opacity:0.6; /*非IE浏览器下设置透明度为60%*/
+ display:none;
+ z-Index:99;
+}
\ No newline at end of file
diff --git a/public/static/style/index.css b/public/static/style/index.css
index 8e40f26..23ad336 100644
--- a/public/static/style/index.css
+++ b/public/static/style/index.css
@@ -1,5 +1,6 @@
.container {
padding: 20px;
+ border-radius: 10px;
}
.agreement-title {
width: 100%;
diff --git a/public/static/style/loading.css b/public/static/style/loading.css
new file mode 100644
index 0000000..fc81d95
--- /dev/null
+++ b/public/static/style/loading.css
@@ -0,0 +1,52 @@
+#loader-container {
+ width: 200px;
+ height: 200px;
+ color: white;
+ margin: 0 auto;
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ margin-right: -50%;
+ transform: translate(-50%, -50%);
+ border: 5px solid #3498db;
+ border-radius: 50%;
+ -webkit-animation: borderScale 1s infinite ease-in-out;
+ animation: borderScale 1s infinite ease-in-out;
+ z-index: 100;
+ opacity:1
+}
+
+#loadingText {
+ font-family: 'Raleway', sans-serif;
+ font-weight: bold;
+ font-size: 2em;
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ margin-right: -50%;
+ transform: translate(-50%, -50%);
+}
+
+@-webkit-keyframes borderScale {
+ 0% {
+ border: 5px solid white;
+ }
+ 50% {
+ border: 25px solid #3498db;
+ }
+ 100% {
+ border: 5px solid white;
+ }
+}
+
+@keyframes borderScale {
+ 0% {
+ border: 5px solid white;
+ }
+ 50% {
+ border: 25px solid #3498db;
+ }
+ 100% {
+ border: 5px solid white;
+ }
+}
\ No newline at end of file
diff --git a/public/static/style/step1.css b/public/static/style/step1.css
index 158b32d..f0ca7a6 100644
--- a/public/static/style/step1.css
+++ b/public/static/style/step1.css
@@ -15,14 +15,18 @@
table {
width: 100%;
border: 1px solid #e1e1e1;
- border-collapse: collapse;
+ /* border-collapse: collapse; */
+ border-collapse: separate;
+ border-spacing: 0;
+ border-radius:5px;
+ overflow: hidden;
}
.table tr {
height: 34px;
text-align: center;
}
th, td {
- border: 1px solid #e1e1e1;
+ border-bottom: 1px solid #f7f7f7;
width: 30%;
}
th:first-child, td:first-child, th:last-child, td:last-child {
@@ -31,8 +35,9 @@ th:first-child, td:first-child, th:last-child, td:last-child {
th {
font-weight: normal;
- background-color: #3e84e9;
- color: white;
+ background-color: #f7f7f7;
+ /* color: white; */
+ font-weight: 600;
}
diff --git a/public/static/style/step2.css b/public/static/style/step2.css
index eda923d..3ccff18 100644
--- a/public/static/style/step2.css
+++ b/public/static/style/step2.css
@@ -28,13 +28,15 @@
float: left;
}
.content .form .form-item input {
- width: 276px;
- height: 34px;
- line-height: 34px;
+ width: 550px;
+ height: 40px;
+ line-height: 40px;
border: 1px solid #d7d7d7;
padding: 0 10px;
- margin-right: 20px;
+ /* margin-right: 20px; */
float: left;
+ border-radius: 5px;
+ color: #8c8c8c;
}
.content .form .form-item input:focus {
border-color: transparent !important;
@@ -51,13 +53,17 @@
float: left;
}
.content .form .form-item .remind {
- width: 292px;
- line-height: 34px;
+ font-size: 12px;
+ margin-top: 10px;
+ margin-left: 120px;
+ width: 550px;
+ line-height: 20px;
color: #777;
- background-color: #ecf8ff;
- padding: 0 16px;
+ background-color: #fff6e7;
+ padding: 0 12px;
border-radius: 3px;
float: left;
+ border:1px solid #d7d7d7;
}
.install_progress_a {
@@ -69,5 +75,20 @@
text-align: center;
padding: 20px 0;
color: #777;
+}
+.content .form .form-item textarea {
+ height: 100px;
+ width: 550px;
+ line-height: 25px;
+ border: 1px solid #d7d7d7;
+ padding: 0 10px;
+ /* margin-right: 20px; */
+ float: left;
+ border-radius: 5px;
+ color: #8c8c8c;
}
+.content .form .form-item textarea:focus {
+ border-color: transparent !important;
+ outline-color: #3e84e9;
+}
\ No newline at end of file
diff --git a/update_sql_20210227.sql b/update_sql_20210227.sql
new file mode 100644
index 0000000..92089a8
--- /dev/null
+++ b/update_sql_20210227.sql
@@ -0,0 +1,2 @@
+UPDATE `5kcrm_admin_field` SET `operating`= 3, `field` = 'owner_user_id', `form_type` = 'single_user' WHERE `types` = 'crm_visit' AND `field` = 'visit_user_id';
+UPDATE `5kcrm_admin_field` SET `operating`= 3 WHERE `types` = 'crm_visit' AND `field` = 'contacts_id';
\ No newline at end of file