Files
OMS/app/erpapi/lib/shop/response/process/shop.php
2026-01-04 17:22:44 +08:00

145 lines
5.2 KiB
PHP

<?php
/**
* Copyright 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.
*/
/**
* 平台通知OMS业务
*
* @author wangbiao<wangbiao@shopex.cn>
* @version 2023.01.05
*/
class erpapi_shop_response_process_shop
{
/**
* 翱象系统通知签约信息给到OMS
*
* @param array $params
* @return array
*/
public function aoxiang_signed($params)
{
$shopMdl = app::get('ome')->model('shop');
$queueMdl = app::get('base')->model('queue');
//data
$shop_id = $params['shop_id'];
$signed_type = strtolower($params['signed_type']); //签约模式(sign签约、cancel取消签约)
$signed_time = ($params['bizRequestTime'] ? $params['bizRequestTime'] : time());
//店铺信息
$shopInfo = $shopMdl->dump(array('shop_id'=>$shop_id), '*');
//check
if(empty($shopInfo)){
return array('rsp'=>'fail', 'msg'=>'店铺数据ERP无法找到', 'msg_code'=>'AX_CHECK_0001');
}
if(!in_array($shopInfo['shop_type'], array('taobao', 'tmall'))){
return array('rsp'=>'fail', 'msg'=>'店铺不是淘宝类型,禁止操作', 'msg_code'=>'AX_CHECK_0001');
}
//update
$msg = '';
$is_auto = false;
switch ($signed_type)
{
case 'sign':
$msg = '店铺签约成功';
if($shopInfo['aoxiang_signed'] == '1'){
$msg = '店铺已经是签约状态,请不要重复通知';
break;
}
//update
$shopMdl->update(array('aoxiang_signed'=>'1', 'aoxiang_signed_time'=>$signed_time), array('shop_id'=>$shop_id));
//自动分配任务标识
$is_auto = true;
break;
case 'cancel':
$msg = '取消签约成功';
if($shopInfo['aoxiang_signed'] == '2'){
$msg = '店铺已经是取消签约状态,请不要重复通知';
break;
}
//update
$shopMdl->update(array('aoxiang_signed'=>'2', 'aoxiang_signed_time'=>$signed_time), array('shop_id'=>$shop_id));
break;
default:
return array('rsp'=>'fail', 'msg'=>'无效的签约方式');
}
//自动分配任务
if($is_auto){
$aoxiangLib = kernel::single('dchain_aoxiang');
//get config
$aoxiangConfig = $aoxiangLib->getAoxiangSyncConfig($shop_id);
//仓库自动分配队列任务
if($aoxiangConfig['sync_branch'] != 'false'){
$queueData = array(
'queue_title' => '仓库自动分配翱象队列任务',
'start_time' => time(),
'params' => array(
'sdfdata' => array('shop_id'=>$shop_id),
'app' => 'dchain',
'mdl' => 'aoxiang_branch',
),
'worker'=> 'dchain_aoxiang.autoTaskAddBranch',
);
$queueMdl->save($queueData);
}
//物流公司自动分配队列任务
if($aoxiangConfig['sync_logistics'] != 'false') {
$queueData = array(
'queue_title' => '物流公司自动分配翱象队列任务',
'start_time' => time(),
'params' => array(
'sdfdata' => array('shop_id' => $shop_id),
'app' => 'dchain',
'mdl' => 'aoxiang_logistics',
),
'worker' => 'dchain_aoxiang.autoTaskAddLogistics',
);
$queueMdl->save($queueData);
}
//所有商品自动分配队列任务
if($aoxiangConfig['sync_product'] != 'false') {
$queueData = array(
'queue_title' => '所有商品自动分配队列任务',
'start_time' => time(),
'params' => array(
'sdfdata' => array('shop_id' => $shop_id),
'app' => 'dchain',
'mdl' => 'aoxiang_product',
),
'worker' => 'dchain_inventorydepth.autoTimerProduct',
);
$queueMdl->save($queueData);
}
}
return array('rsp'=>'succ', 'msg'=>$msg);
}
}