pull/26/head
张萌 2 years ago
parent 80d1af3d0d
commit 7c31cc34bf

@ -70,6 +70,10 @@ function resultArray($array)
} elseif (isset($array['error'])) {
$code = 400;
$array['data'] = '';
} elseif (isset($array['success'])) {
$array['error'] = '';
$array['data'] =$array['success'] ;
$code = 200;
}
return json([
'code' => $code,
@ -390,128 +394,128 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
// 创建人、负责人
if (in_array($key, ['create_user_id', 'owner_user_id'])) {
if($value['condition'] == 'contains'){
if ($value['condition'] == 'contains') {
$result[$c . $key] = ['in', $value['value']];
}else if ($value['condition'] == 'notContains') {
} else if ($value['condition'] == 'notContains') {
$result[$c . $key] = ['not in', $value['value']];
}else if ($value['condition'] == 'isNull') {
} else if ($value['condition'] == 'isNull') {
$result[$c . $key] = ['eq', ''];
}else if ($value['condition'] == 'isNotNull') {
} else if ($value['condition'] == 'isNotNull') {
$result[$c . $key] = ['neq', ''];
}
}
// 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人
if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website','user',])) {
if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website', 'user',])) {
$res = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
if($key == 'order_id'){
if ($key == 'order_id') {
$arr = [];
if($c == 'outbound.'){
if ($c == 'outbound.') {
$retreatOutboundIds = db('jxc_retreat')
->alias('a')
->join('jxc_outbound b','a.retreat_id = b.order_id')
->join('jxc_outbound b', 'a.retreat_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '采购退货出库')
// ->fetchSql()
->column('outbound_id');
$saleOutboundIds = db('jxc_sale')
->alias('a')
->join('jxc_outbound b','a.sale_id = b.order_id')
->join('jxc_outbound b', 'a.sale_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '销售出库')
// ->fetchSql()
->column('outbound_id');
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds,$saleOutboundIds);
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds, $saleOutboundIds);
$result[$c . 'outbound_id'] = ['in', $arr];
}elseif ($c == 'receipt.') {
} elseif ($c == 'receipt.') {
$purchaseOutboundIds = db('jxc_purchase')
->alias('a')
->join('jxc_receipt b','a.purchase_id = b.order_id')
->join('jxc_receipt b', 'a.purchase_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '采购入库')
// ->fetchSql()
->column('b.receipt_id');
$salereturnOutboundIds = db('jxc_salereturn')
->alias('a')
->join('jxc_receipt b','a.salereturn_id = b.order_id')
->join('jxc_receipt b', 'a.salereturn_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '销售退货入库')
// ->fetchSql()
->column('b.receipt_id');
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds,$salereturnOutboundIds);
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds, $salereturnOutboundIds);
$result[$c . 'receipt_id'] = ['in', $arr];
}
}else if($key == 'related_id'){
} else if ($key == 'related_id') {
$arr = [];
if($c == 'collection.'){
if ($c == 'collection.') {
$retreatOutboundIds = db('jxc_retreat')
->alias('a')
->join('jxc_collection b','a.retreat_id = b.related_id')
->join('jxc_collection b', 'a.retreat_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '采购退货')
// ->fetchSql()
->column('collection_note_id');
$saleOutboundIds = db('jxc_sale')
->alias('a')
->join('jxc_collection b','a.sale_id = b.related_id')
->join('jxc_collection b', 'a.sale_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '销售回款')
// ->fetchSql()
->column('collection_note_id');
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds,$saleOutboundIds);
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds, $saleOutboundIds);
$result[$c . 'collection_note_id'] = ['in', $arr];
}elseif ($c == 'payment.') {
} elseif ($c == 'payment.') {
$purchaseOutboundIds = db('jxc_purchase')
->alias('a')
->join('jxc_payment b','a.purchase_id = b.related_id')
->join('jxc_payment b', 'a.purchase_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '采购')
// ->fetchSql()
->column('b.payment_note_id');
$salereturnOutboundIds = db('jxc_salereturn')
->alias('a')
->join('jxc_payment b','a.salereturn_id = b.related_id')
->join('jxc_payment b', 'a.salereturn_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '销售退货')
// ->fetchSql()
->column('b.payment_note_id');
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds,$salereturnOutboundIds);
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds, $salereturnOutboundIds);
$result[$c . 'payment_note_id'] = ['in', $arr];
}
}else if($key == 'collection_object'){
} else if ($key == 'collection_object') {
$arr = [];
if($c == 'collection.'){
if ($c == 'collection.') {
$supplierOutboundIds = db('jxc_supplier')
->alias('a')
->join('jxc_collection b','a.supplier_id = b.collection_object')
->join('jxc_collection b', 'a.supplier_id = b.collection_object')
->where('a.supplier_name', [$res[0], $res[1]])
->where('b.collection_type', '采购退货')
// ->fetchSql()
->column('collection_note_id');
$customerOutboundIds = db('crm_customer')
->alias('a')
->join('jxc_collection b','a.customer_id = b.collection_object')
->join('jxc_collection b', 'a.customer_id = b.collection_object')
->where('a.name', [$res[0], $res[1]])
->where('b.collection_type', '销售回款')
// ->fetchSql()
->column('collection_note_id');
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds,$customerOutboundIds);
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds, $customerOutboundIds);
$result[$c . 'collection_note_id'] = ['in', $arr];
}elseif ($c == 'payment.') {
} elseif ($c == 'payment.') {
$supplierOutboundIds = db('jxc_supplier')
->alias('a')
->join('jxc_payment b','a.supplier_id = b.collection_object')
->join('jxc_payment b', 'a.supplier_id = b.collection_object')
->where('a.supplier_name', [$res[0], $res[1]])
->where('b.payment_type', '采购')
// ->fetchSql()
->column('b.payment_note_id');
$customerOutboundIds = db('crm_customer')
->alias('a')
->join('jxc_payment b','a.customer_id = b.collection_object')
->join('jxc_payment b', 'a.customer_id = b.collection_object')
->where('a.name', [$res[0], $res[1]])
->where('b.payment_type', '销售退货')
// ->fetchSql()
->column('b.payment_note_id');
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds,$customerOutboundIds);
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds, $customerOutboundIds);
$result[$c . 'payment_note_id'] = ['in', $arr];
}
// }else if($key == 'sp_data_value'){
@ -521,7 +525,7 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
// $w['sp_data_value'] = ['like', $arr, 'OR'];
// $product_ids = db('jxc_product')->where($w)->fetchSql()->column('product_id');
// $result[$c . 'sp_data_value'] = [$res[0], $product_ids];
}else{
} else {
$result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
}
}
@ -729,9 +733,9 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
// 处理查询参数
if(in_array($condition, ['contains', 'notContains']) && in_array($key,['create_user_id','owner_user_id'])){
if (in_array($condition, ['contains', 'notContains']) && in_array($key, ['create_user_id', 'owner_user_id'])) {
$data = advancedQueryDataUserform($data, $condition);
}elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])){
} elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])) {
$data = advancedQueryDataTransform($data, $condition);
}
@ -753,7 +757,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
$data[0] = str_replace('已作废', 6, $data[0]);
}
return advancedQueryWhere($condition, $data,$key);
return advancedQueryWhere($condition, $data, $key);
}
/**
@ -765,7 +769,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
* @since 2021-05-22
* @author fanqi
*/
function advancedQueryWhere($condition, $data, $key='')
function advancedQueryWhere($condition, $data, $key = '')
{
$result = [];
@ -774,9 +778,9 @@ function advancedQueryWhere($condition, $data, $key='')
if ($condition == "in") $result = ['in', $data]; // 等于
if ($condition == 'is') $result = ['in', $data]; // 等于
if ($condition == 'isNot') $result = [['notin', $data],['null'],'OR']; // 不等于
if ($condition == 'isNot') $result = [['notin', $data], ['null'], 'OR']; // 不等于
if ($condition == 'contains') $result = ['like', $data, 'OR']; // 包含
if ($condition == 'notContains') $result = [['notlike', $data, 'AND'],['null'],'OR']; // 不包含
if ($condition == 'notContains') $result = [['notlike', $data, 'AND'], ['null'], 'OR']; // 不包含
if ($condition == 'startWith') $result = ['like', $data, 'OR']; // 开始于
if ($condition == 'endWith') $result = ['like', $data, 'OR']; // 结束于
if ($condition == 'gt') $result = ['gt', $data]; // 大于
@ -787,8 +791,8 @@ function advancedQueryWhere($condition, $data, $key='')
if ($condition == 'range') $result = ['between', $data]; // 处于某个时间段
if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR']; // 为空
if ($condition == 'isNotNull') $result = [['neq', ''], ['not null'], 'AND']; // 不为空
if ($condition == 'contains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['in', $data]; // 暂定为创建人 负责人 包含
if ($condition == 'notContains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
if ($condition == 'contains' && in_array($key, ['create_user_id', 'owner_user_id'])) $result = ['in', $data]; // 暂定为创建人 负责人 包含
if ($condition == 'notContains' && in_array($key, ['create_user_id', 'owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
return $result;
}
@ -834,7 +838,8 @@ function advancedQueryDataTransform($data, $condition)
* @version: 11.1.0
* Date: 2021/9/2 14:44
*/
function advancedQueryDataUserform($data, $condition){
function advancedQueryDataUserform($data, $condition)
{
if (in_array($condition, ['contains', 'notContains'])) {
array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value;
@ -842,6 +847,7 @@ function advancedQueryDataUserform($data, $condition){
}
return $data;
}
/**
* 等于(时间段)数据处理
*
@ -2891,7 +2897,7 @@ if (!function_exists('getFieldGrantStatus')) {
function getFieldGrantStatus($field, $grantData)
{
# 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
$result = ['read' => 0, 'write' => 0,'maskType'=>0];
$result = ['read' => 0, 'write' => 0, 'maskType' => 0];
foreach ($grantData as $key => $value) {
$fieldBool = false;
@ -2906,7 +2912,7 @@ if (!function_exists('getFieldGrantStatus')) {
$result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write'];
}
if ($va['field'] == $field && $va['maskType'] != 0) {
$result['maskType'] = !empty($va['maskType'])?$va['maskType']:0;
$result['maskType'] = !empty($va['maskType']) ? $va['maskType'] : 0;
}
if ($va['field'] == $field) $fieldBool = true;
}
@ -3301,50 +3307,50 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
// $result[$c . 'rw_user_id'] = advancedQueryFormatForPersonnel($v['value'], $v['condition']);
// }
// }
$date=[];
$date2=[];
$condition=$requestMap['condition'];
$z='';
foreach ($requestMap['value'] as $val){
if($condition=='contains'){
$z='like';
$val="'".'%,'.$val.',%'."'";
}elseif($condition=='notContains'){
$z='NOT LIKE';
$val="'".'%,'.$val.',%'."'";
}
$date[]=$prefix.'ro_user_id '.$z.$val;
$date2[]=$prefix.'rw_user_id '.$z.$val;
}
if($condition =='isNull'){
$z='IS NULL';
$date[]=$prefix.'ro_user_id '.'= '."''";
$date2[]=$prefix.'rw_user_id '.'= '."''";
}elseif($condition =='isNotNull'){
$z='IS NOT NULL';
$date[]=$prefix.'ro_user_id '.'<> '."''";
$date2[]=$prefix.'rw_user_id '.'<> '."''";
}
if($date && $date2){
$rest='';
$date=implode('OR ', $date);
$date2=implode('OR ', $date2);
$type='';
switch ($z){
$date = [];
$date2 = [];
$condition = $requestMap['condition'];
$z = '';
foreach ($requestMap['value'] as $val) {
if ($condition == 'contains') {
$z = 'like';
$val = "'" . '%,' . $val . ',%' . "'";
} elseif ($condition == 'notContains') {
$z = 'NOT LIKE';
$val = "'" . '%,' . $val . ',%' . "'";
}
$date[] = $prefix . 'ro_user_id ' . $z . $val;
$date2[] = $prefix . 'rw_user_id ' . $z . $val;
}
if ($condition == 'isNull') {
$z = 'IS NULL';
$date[] = $prefix . 'ro_user_id ' . '= ' . "''";
$date2[] = $prefix . 'rw_user_id ' . '= ' . "''";
} elseif ($condition == 'isNotNull') {
$z = 'IS NOT NULL';
$date[] = $prefix . 'ro_user_id ' . '<> ' . "''";
$date2[] = $prefix . 'rw_user_id ' . '<> ' . "''";
}
if ($date && $date2) {
$rest = '';
$date = implode('OR ', $date);
$date2 = implode('OR ', $date2);
$type = '';
switch ($z) {
case 'like':
$rest='('.$date.')'.'OR'.'('.$date2.')';
$rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
break;
case 'NOT LIKE':
$rest='('.$date.')'.'AND'.'('.$date2.')';
$rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
break;
case 'IS NULL':
$rest='('.$date.')'.'OR'.'('.$date2.')';
$rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
break;
case 'IS NOT NULL':
$rest='('.$date.')'.'AND'.'('.$date2.')';
$rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
break;
default:
break;
@ -3363,15 +3369,15 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
*/
function getUserSuperior($structure_id, $level = 0)
{
if($level == 0){
if ($level == 0) {
$owner_user_id = db('admin_structure')->where('id', $structure_id)->value('owner_user_id');
if($owner_user_id == 0){
if ($owner_user_id == 0) {
$pid = db('admin_structure')->where('id', $structure_id)->value('pid');
$owner_user_id = db('admin_structure')->where('id', $pid)->value('owner_user_id');
}
}else{
} else {
$pid = db('admin_structure')->where('id', $structure_id)->value('pid');
return getUserSuperior($pid, $level-1);
return getUserSuperior($pid, $level - 1);
}
return $owner_user_id;

@ -390,7 +390,6 @@ class Business extends ApiCommon
$userModel = new \app\admin\model\User();
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
$remark = $param['statusRemark'];
$param['check_user_id'] = 1;// 临时测试需删除
unset($param['examineStatus']);
if (!$param['business_id']) {
@ -411,12 +410,12 @@ class Business extends ApiCommon
// 审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($userInfo['id'], 'crm_business')) {
return '暂无审批人,无法创建';
return resultArray(['error' => '暂无审批人,无法创建']);
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($userInfo['id'], 'crm_business');
if (!$examineFlowData) {
return '无可用审批流,请联系管理员';
return resultArray(['error' => '无可用审批流,请联系管理员']);
}
$data['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
@ -430,7 +429,8 @@ class Business extends ApiCommon
$check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (!$check_user_id) {
return '无可用审批人,请联系管理员';
return resultArray(['error' => '无可用审批人,请联系管理员']);
}
$data['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else {
@ -456,7 +456,6 @@ class Business extends ApiCommon
$send_user_id
);
}
# 创建待办事项的关联数据
$checkUserIds = db('crm_business')->where('business_id', $param['business_id'])->value('check_user_id');
$checkUserIdArray = stringToArray($checkUserIds);
@ -703,8 +702,8 @@ class Business extends ApiCommon
}
//已审批人ID
$businessCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$resCustomerCheck = db('crm_business')->where(['business_id' => $param['id']])->update($businessCheckData);
if ($resCustomerCheck) {
$resBusiness = db('crm_business')->where(['business_id' => $param['id']])->update($businessCheckData);
if ($resBusiness) {
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
//审核通过,修改相关信息
@ -726,10 +725,11 @@ class Business extends ApiCommon
$businessData['statusRemark'] = $dataInfo['submit_remark'];
$result = $this->advanceAfterCheck($businessData);
echo $result;
echo '\\n';
echo !empty($result);
if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '领取成功!']);
echo '12345';
} else {
if ($status) {
//发送站内信
@ -754,7 +754,8 @@ class Business extends ApiCommon
);
}
}
return resultArray(['data' => '审批成功']);
echo '1234';
return resultArray(['success' => '审批成功']);
} else {
return resultArray(['error' => '审批失败,请重试!']);
}
@ -802,7 +803,7 @@ class Business extends ApiCommon
// }
$data['status_id'] = $status_id;
$data['status_time'] = time();
$data['submit_remark'] = $param['submit_remark'];
$data['remark'] = $param['submit_remark'];
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
if (!$res) {
return resultArray(['error' => '推进失败,请重试']);

@ -394,31 +394,6 @@ class Business extends Common
}
}
}
//站内信
$send_user_id = stringToArray(getUserSuperior($param['create_user_id']));
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'title' => $param['name'],
'action_id' => $this->business_id
],
$send_user_id
);
$data = [];
$data['business_id'] = $this->business_id;
# 创建待办事项的关联数据
$dealtData = [];
foreach ($send_user_id as $kk => $vv) {
$dealtData[] = [
'types' => 'crm_business_new',
'types_id' => $data['business_id'],
'user_id' => $vv
];
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
# 设置今日需联系商机
if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
@ -462,6 +437,30 @@ class Business extends Common
});
db('crm_business_data')->insertAll($businessData);
//站内信
$send_user_id = stringToArray(getUserSuperior($param['create_user_id']));
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'title' => $param['name'],
'action_id' => $this->business_id
],
$send_user_id
);
$data = [];
$data['business_id'] = $this->business_id;
# 创建待办事项的关联数据
$dealtData = [];
foreach ($send_user_id as $kk => $vv) {
$dealtData[] = [
'types' => 'crm_business_new',
'types_id' => $data['business_id'],
'user_id' => $vv
];
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
return $data;
} else {
$this->error = '添加失败';

Loading…
Cancel
Save