Files
OMS/app/erpapi/lib/shop/response/express.php
2026-01-04 19:08:31 +08:00

130 lines
3.8 KiB
PHP

<?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.
*/
/**
* 指定快递(店小蜜)
*
* @author wangbiao<wangbiao@shopex.cn>
* @version 0.1
*/
class erpapi_shop_response_express extends erpapi_shop_response_abstract
{
/**
* 接收参数
*/
public $_sdf = array();
/**
* 获取指定快递可用物流公司
*/
public function getcorp($params=array()){
$corpObj = app::get('ome')->model('dly_corp');
$this->__apilog['title'] = '获取指定快递对应物流公司';
//按权重优先级
$sql = "SELECT corp_id, type, name FROM sdb_ome_dly_corp WHERE disabled='false' AND d_type=1 GROUP BY type ORDER BY weight DESC, corp_id DESC";
$corpList = $corpObj->db->select($sql);
if(empty($corpList)){
$this->__apilog['result']['msg'] = '没有可使用的物流公司!';
return false;
}
return $corpList;
}
/**
* 指定快递
*
* @param array $params
* @return array
*/
public function assign($params){
$this->__apilog['title'] = '指定快递';
//format params
$params = $this->_returnParams($params);
if(empty($params)){
$this->__apilog['result']['msg'] = '指定快递: 该平台不支持订单指定快递';
return false;
}
$this->__apilog['original_bn'] = $params['order_bn'];
$this->__apilog['result']['data'] = $params;
if(empty($params['order_bn'])) {
$this->__apilog['result']['msg'] = '指定快递: 没有可处理的订单!';
return false;
}
//检查订单
$orderObj = app::get('ome')->model('orders');
$this->_sdf = $orderObj->dump(array('order_bn'=>$params['order_bn']), 'order_id, order_bn, process_status, status, ship_status');
if(empty($this->_sdf)){
$this->__apilog['result']['msg'] = '指定快递: 订单不存在,请检查!';
return false;
}
if($this->_sdf['status'] == 'dead'){
$this->__apilog['result']['msg'] = '指定快递: 订单已作废,不能指定快递!';
return false;
}
if(!in_array($this->_sdf['ship_status'], array('0', '2'))){
$this->__apilog['result']['msg'] = '指定快递: 订单已发货,不能指定快递!';
return false;
}
$this->_sdf = array_merge($this->_sdf, $params);
return $this->_sdf;
}
/**
* 获取数据
*
* @param array $params
* @return array:
*/
protected function _returnParams($params) {
return array();
}
/**
* 格式化参数
*
* @param array $params
* @return array:
*/
protected function _formatParams($params) {
//订单号
$order_bn = $params['tid'];
//物流公司编码
$express_code = strtoupper($params['company_code']);
//组织数据
$sdf = array(
'order_bn' => $order_bn,
'express_code' => $express_code,
);
return $sdf;
}
}