Files
OMS/app/ome/lib/preprocess/entrance.php
2026-01-04 19:08:31 +08:00

112 lines
3.5 KiB
PHP
Raw Permalink 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.
*/
class ome_preprocess_entrance {
static private $__instance = array();
static private $__methods_list = array('label','tbgift','invoice','crm','outstorage');
private $__use_method = null;
/**
* 设置Method
* @param mixed $method method
* @return mixed 返回操作结果
*/
public function setMethod($method){
$method = strtolower($method);
if(in_array($method,self::$__methods_list)){
$this->__use_method = $method;
}else{
$this->__use_method = -1;
}
return $this;
}
/**
* 处理
* @param mixed $params 参数
* @param mixed $msg msg
* @return mixed 返回值
*/
public function process($params,&$msg){
$orderIds = $this->_mergeGroup($params);
$process_status = true;
if($this->__use_method == -1){
$msg = 'use error method';
return false;
}elseif($this->__use_method && $this->__use_method != -1){
$obj = self::_instanceObj($this->__use_method);
foreach ($orderIds as $orderId){
if(!$obj->process($orderId,$flag_msg)){
$process_status = false;
$msg[$orderId][] = $flag_msg;
}
}
}else{
#应用类型暂时只有crm类型应用
$app_type = channel_ctl_admin_channel::$appType;
#检测crm节点有没有绑定
$obj_channel = app::get('channel')->model('channel');
$node_info = $obj_channel->getList('node_id',array('channel_type'=>$app_type['crm']));
#未安装crm应用则不需要执行crm相关流程[第三方仓储版没有Crm目录App]
if(!app::get('crm')->is_installed())
{
unset(self::$__methods_list['2']);
}
foreach (self::$__methods_list as $method){
$obj = self::_instanceObj($method);
foreach ($orderIds as $orderId){
if(!$obj->process($orderId,$flag_msg)){
$process_status = false;
$msg[$orderId][] = $flag_msg;
}
}
}
}
if($process_status){
return true;
}else{
return false;
}
}
static private function _instanceObj($key){
if(!isset(self::$__instance[$key])){
self::$__instance[$key] = kernel::single(sprintf('ome_preprocess_%s',$key));
}
return self::$__instance[$key];
}
private function _mergeGroup($params) {
$ids = array();
if(is_array($params)){
foreach ($params as $item) {
$ids = array_merge($ids, $item['orders']);
}
}else{
$ids = array($params);
}
return $ids;
}
}