Files
OMS/app/organization/lib/organizations/check.php
2026-01-04 19:08:31 +08:00

182 lines
5.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 企业组织结构数据验证Lib类
*
* @access public
* @author wangbiao<wangbiao@shopex.cn>
* @version $Id: check.php 2016-07-29 15:00
*/
class organization_organizations_check
{
/**
* 检查企业组织编码
*/
public function check_org_no_exist($org_no, &$error_msg, $org_type = null)
{
$organizationObj = app::get('organization')->model('organization');
// 如果是经销商类型(org_type=3)需要添加BS_前缀来检查唯一性
if ($org_type == 3) {
$check_org_no = 'BS_' . $org_no;
} else {
$check_org_no = $org_no;
}
$rsinfo_org_no = $organizationObj->dump(array("org_no"=>$check_org_no),"org_id");
if(empty($rsinfo_org_no)){
return true;
}else{
$error_msg = '该组织编码已经存在';
return false;
}
}
/**
* 检查企业组织名称
*/
public function check_org_name_exist($org_name, &$error_msg)
{
// $organizationObj = app::get('organization')->model('organization');
// $rsinfo_org_name = $organizationObj->dump(array("org_name"=>$org_name),"org_id");
// if(empty($rsinfo_org_name)){
// return true;
// }else{
// $error_msg = '该组织名称已经存在';
// return false;
// }
//组织名称允许重复
return true;
}
/**
* 查询企业组织信息
*/
public function get_one_org_info($org_id)
{
if(!$org_id){
return false;
}
$organizationObj = app::get('organization')->model('organization');
return $organizationObj->dump(array("org_id"=>$org_id),"*");
}
/**
* 检查组织结构层级
*/
public function check_org_level($level_num, &$error_msg)
{
if(intval($level_num) > 5)
{
$error_msg = '组织结构层级最多五层';
return false;
}
return true;
}
/**
* Post数据验证有效性
*
* @param Array $params
* @param String $error_msg
* @return Boolean
*/
public function checkParams(&$params, &$err_msg)
{
$chk_err_msg = '';
$check_org_no_exist = $this->check_org_no_exist($params['org_no'], $chk_err_msg);
if(!$check_org_no_exist)
{
$err_msg = $chk_err_msg;
return false;
}
$check_org_name_exist = $this->check_org_name_exist($params['org_name'], $chk_err_msg);
if(!$check_org_name_exist)
{
$err_msg = $chk_err_msg;
return false;
}
//insert start
$current_int_time = time();
$insert_arr = array(
'org_no' => $params["org_no"],
'org_name' => $params["org_name"],
'create_time' => $current_int_time,
'org_type' => $params["org_type"] > 0 ? $params["org_type"] : 1,
);
//新增组织 确定 org_level_num\parent_id\parent_no
if($params['organizationSelected'])
{
//所属上级 :有选择
list($package,$org_name,$org_id) = explode(':', $params["organizationSelected"]);
if(!$org_id){
$err_msg = '所属上级层级不存在';
return false;
}
$insert_arr["parent_id"] = $org_id;
$current_org_info = $this->get_one_org_info($org_id);
if(empty($current_org_info))
{
$err_msg = '所属上父级不存在';
return false;
}
$insert_arr['org_level_num'] = intval($current_org_info["org_level_num"])+1;//新增层级是上级层级加1
$insert_arr['parent_no'] = $current_org_info["org_no"];
$insert_arr["org_parents_structure"] = $params["organizationSelected"];
}
else
{
//所属上级 :无选择 parent_id\parent_no 都为空
$insert_arr["org_level_num"] = 1;
$insert_arr["parent_id"] = 0; // 没有上级给0null不好处理
}
//目前组织结构最大五层层级
$chk_org_level = $this->check_org_level($insert_arr['org_level_num'], $chk_err_msg);
if(!$chk_org_level)
{
$err_msg = $chk_err_msg;
return false;
}
if($params["status"] == 1){
$insert_arr["recently_enabled_time"] = $current_int_time;
$insert_arr["first_enable_time"] = $current_int_time;
$insert_arr["status"] = 1;
$doWhat = "doActive";
}else{
$insert_arr['recently_stopped_time'] = $current_int_time;
$insert_arr["status"] = 2;
$doWhat = "doUnactive";
}
$insert_arr['doWhat'] = $doWhat;
return $insert_arr;
}
}