【优化】实收退导入界面

【新增】快捷菜单功能入口

【新增】爱库存电子面单获取
This commit is contained in:
chenping
2026-04-21 22:36:45 +08:00
parent 8b4b4cc49f
commit b20d422532
45 changed files with 2367 additions and 191 deletions

View File

@@ -348,7 +348,8 @@ EOF;
$data['shop_id'] = $_POST['shop_id'];
$is_ome_bind_unionpay = false;
#检测是否已绑定银联
//检测是否已绑定银联
base_kvstore::instance('ome/bind/unionpay')->fetch('ome_bind_unionpay', $is_ome_bind_unionpay);
if (!$is_ome_bind_unionpay) {
$bind_status = kernel::single('erpapi_router_request')->set('unionpay', '1705101437')->unionpay_bind();
@@ -359,7 +360,7 @@ EOF;
}
}
} elseif ($data['channel_type'] == 'jdalpha') {
#编辑的时候,支付方式,不允许改
//编辑的时候,支付方式,不允许改
if ($_POST['channel_id']) {
$channel = $channelObj->dump(array('channel_id' => $_POST['channel_id']));
$sfinfo = explode('|||', $channel['shop_id']);
@@ -518,13 +519,11 @@ EOF;
kernel::single('wms_event_trigger_logistics_electron')->bufferGetWaybill($data['channel_id']);
}
if (in_array($data['channel_type'], ['taobao','jdalpha'])) {
//默认获取发货地址
//默认获取发货地址
$extendObj = app::get('logisticsmanager')->model('channel_extend');
$extend = $extendObj->dump(array('channel_id' => $data['channel_id']), 'id');
if (!$extend) {
kernel::single('erpapi_router_request')->set('logistics', $data['channel_id'])->electron_getWaybillISearch();
}
}
echo "SUCC";
@@ -852,11 +851,14 @@ EOF;
if ($res['request_logistics_code']!=$v['delivery_id']) {
continue;
}
$key = $v['acct_id'];
if (isset($v['_unique_acct_id']) && $v['_unique_acct_id']) {
$key = $v['_unique_acct_id'];
// 与云起一致xhs/美团医药/爱库存等接口可能返回空 acct_id不能用 acct_id 作数组键,否则单选 value 为空且 POST 校验失败
$uniqueKey = $v['acct_id'];
if (in_array($res['channel_type'], array('xhs', 'meituan4medicine', 'aikucun'))) {
$uniqueKey = $k + 1;
} elseif (isset($v['_unique_acct_id']) && $v['_unique_acct_id']) {
$uniqueKey = $v['_unique_acct_id'];
}
$accountList[$key] = [
$accountList[$uniqueKey] = [
'available' => $v['available'],
'status' => $v['status'],
'delivery_id' => $v['delivery_id'],
@@ -882,6 +884,7 @@ EOF;
'district_name' => $v['district_name'],
'city_code' => $v['city_code'],
'province_name' => $v['province_name'],
'bizLine' => isset($v['bizLine']) ? $v['bizLine'] : '',
];
}
}
@@ -906,7 +909,8 @@ EOF;
}
$accountList = json_decode($_POST['account_list_json'], 1);
$accountInfo = $accountList[$_POST['_unique_acct_id']];
$pickKey = (string) $_POST['_unique_acct_id'];
$accountInfo = isset($accountList[$pickKey]) ? $accountList[$pickKey] : null;
if (!$accountInfo) {
$this->end(false, '电子面单账号id无效');
}
@@ -926,8 +930,8 @@ EOF;
'address_detail' => $accountInfo['detail_address'],
'street' => $accountInfo['street_name'],
'default_sender' => $accountInfo['name'],
'mobile' => $accountInfo['mobile'],
'tel' => $accountInfo['phone'],
'mobile' => $accountInfo['mobile'] ? $accountInfo['mobile'] : $accountInfo['phone'],
'tel' => $accountInfo['phone'] ? $accountInfo['phone'] : $accountInfo['mobile'],
'shop_name' => $accountInfo['site_name'],
'seller_id' => $accountInfo['acct_id'],
);
@@ -938,6 +942,7 @@ EOF;
'site_code' => $accountInfo['site_code'],
'acct_id' => $accountInfo['acct_id'],
'shop_id' => $accountInfo['shop_id'],
'bizLine' => isset($accountInfo['bizLine']) ? $accountInfo['bizLine'] : '',
];
}
@@ -1125,10 +1130,6 @@ EOF;
$this->end(false, '保存失败:'.$channelMdl->db->errorinfo());
}
$channelExt = [
'channel_id' => $channel['channel_id'],
'province' => $netsite_address['province_name'],

View File

@@ -40,6 +40,7 @@ class logisticsmanager_ctl_admin_express_cainiao extends desktop_controller {
'dewu'=>'得物品牌直发电子面单',
'meituan4bulkpurchasing'=>'美团电商',
'youzan'=>'有赞电子面单',
'aikucun'=>'爱库存电子面单',
];
$this->display('admin/express/pre_sync_tpl.html');
}

View File

@@ -20,7 +20,7 @@ class logisticsmanager_ctl_admin_express_template extends desktop_controller{
var $workground = "setting_tools";
function index(){
$base_filter = array('template_type' => array('normal', 'electron' , 'cainiao', 'cainiao_standard', 'cainiao_user', 'pdd_standard', 'pdd_user', 'jd_standard', 'jd_user', 'douyin_standard', 'douyin_user','kuaishou_standard','kuaishou_user','wphvip_standard','wphvip_user', 'sf', 'xhs_standard', 'xhs_user', 'wxshipin_standard', 'wxshipin_user','dewu_ppzf','dewu_ppzf_zy','meituan4bulkpurchasing_user','youzan_standard'));
$base_filter = array('template_type' => array('normal', 'electron' , 'cainiao', 'cainiao_standard', 'cainiao_user', 'pdd_standard', 'pdd_user', 'jd_standard', 'jd_user', 'douyin_standard', 'douyin_user','kuaishou_standard','kuaishou_user','wphvip_standard','wphvip_user', 'sf', 'xhs_standard', 'xhs_user', 'aikucun_standard', 'aikucun_user', 'wxshipin_standard', 'wxshipin_user','dewu_ppzf','dewu_ppzf_zy','meituan4bulkpurchasing_user','youzan_standard'));
$params = array(
'title'=>'快递面单管理',
'actions' => array(
@@ -78,6 +78,7 @@ class logisticsmanager_ctl_admin_express_template extends desktop_controller{
'wphvip' => array('label' => app::get('base')->_('唯品会vip'), 'filter' => array('filter_sql' => 'template_type in("wphvip_user","wphvip_standard")', 'status' => 'true'), 'optional' => false),
'sf' => array('label' => app::get('base')->_('顺丰'), 'filter' => array('filter_sql' => 'template_type in("sf")', 'status' => 'true'), 'optional' => false),
'xhs' => array('label' => app::get('base')->_('小红书'), 'filter' => array('filter_sql' => 'template_type in("xhs_standard","xhs_user")', 'status' => 'true'), 'optional' => false),
'aikucun' => array('label' => app::get('base')->_('爱库存'), 'filter' => array('filter_sql' => 'template_type in("aikucun_standard","aikucun_user")', 'status' => 'true'), 'optional' => false),
'wxshipin' => array('label' => app::get('base')->_('微信视频号'), 'filter' => array('filter_sql' => 'template_type in("wxshipin_standard","wxshipin_user")', 'status' => 'true'), 'optional' => false),
'youzan' => array('label' => app::get('base')->_('有赞'), 'filter' => array('filter_sql' => 'template_type in("youzan_standard")', 'status' => 'true'), 'optional' => false),
'dewu' => array('label' => app::get('base')->_('得物'), 'filter' => array('filter_sql' => 'template_type in("dewu_ppzf","dewu_ppzf_zy")', 'status' => 'true'), 'optional' => false),

View File

@@ -74,18 +74,32 @@ class logisticsmanager_ctl_admin_waybill extends desktop_controller{
* @return mixed 返回结果
*/
public function getEncryptPrintData() {
$logiNo = trim($_POST['logi_no']);
$batchLogiNo = trim($_POST['batch_logi_no']);
$deliveryId = intval($_POST['delivery_id']);
$channelId = trim($_POST['channel_id']);
$logiNo = trim($_POST['logi_no']);
$batchLogiNo = trim($_POST['batch_logi_no']);
$deliveryId = intval($_POST['delivery_id']);
$channelId = trim($_POST['channel_id']);
$requestData = [
'logi_no' => $logiNo,
'batch_logi_no' => $batchLogiNo,
'delivery_id' => $deliveryId,
];
$channelType = '';
if ($channelId) {
$channel = app::get('logisticsmanager')->model('channel')->dump(['channel_id' => $channelId], 'channel_type');
$channelType = isset($channel['channel_type']) ? $channel['channel_type'] : '';
}
if ($channelType === 'aikucun') {
$requestData['print_name'] = isset($_POST['print_name']) ? trim($_POST['print_name']) : '';
$requestData['mode'] = isset($_POST['mode']) ? trim($_POST['mode']) : '';
$requestData['prepare_data'] = isset($_POST['prepare_data']) ? $_POST['prepare_data'] : '';
} elseif (isset($_POST['custom_data'])) {
$requestData['custom_data'] = $_POST['custom_data'];
}
$rs = kernel::single('erpapi_router_request')
->set('logistics',$channelId)
->electron_getEncryptPrintData([
'logi_no' =>$logiNo,
'batch_logi_no' =>$batchLogiNo,
'delivery_id' =>$deliveryId,
'custom_data' => $_POST['custom_data']
]);
->set('logistics', $channelId)
->electron_getEncryptPrintData($requestData);
echo json_encode($rs);
}
}

View File

@@ -76,6 +76,8 @@ $db['express_template'] = array(
'sf' => '顺丰面单',
'xhs_standard'=>'小红书面单',
'xhs_user'=>'小红书面单',
'aikucun_standard'=>'爱库存面单',
'aikucun_user'=>'爱库存自定义面单',
'wxshipin_standard'=>'微信视频号面单',
'wxshipin_user'=>'微信视频号面单',
'meituan4bulkpurchasing_user'=>'美团电商面单',

View File

@@ -150,7 +150,7 @@ class logisticsmanager_print_tmpl {
}
return array('rs'=>'fail', 'msg'=>$title);
}
if (!in_array($data['template_type'],array('normal', 'electron', 'delivery', 'stock','cainiao', 'cainiao_standard', 'cainiao_user', 'pdd_standard', 'pdd_user','jd_standard','jd_user', 'douyin_standard', 'douyin_user','kuaishou_standard','kuaishou_user','wphvip_standard','wphvip_user','sf','xhs_standard','xhs_user','wxshipin_standard','wxshipin_user','dewu_ppzf','dewu_ppzf_zy','meituan4bulkpurchasing_user','youzan_standard'))) {
if (!in_array($data['template_type'],array('normal', 'electron', 'delivery', 'stock','cainiao', 'cainiao_standard', 'cainiao_user', 'pdd_standard', 'pdd_user','jd_standard','jd_user', 'douyin_standard', 'douyin_user','kuaishou_standard','kuaishou_user','wphvip_standard','wphvip_user','sf','xhs_standard','xhs_user','aikucun_standard','aikucun_user','wxshipin_standard','wxshipin_user','dewu_ppzf','dewu_ppzf_zy','meituan4bulkpurchasing_user','youzan_standard'))) {
return array('rs'=>'fail', 'msg'=>'面单类型不符合规则!');
}
if(!$data['template_width'] || !$data['template_height']){

View File

@@ -14,29 +14,289 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class logisticsmanager_waybill_aikucun {
//获取物流公司
/**
* logistics
* @param mixed $logistics_code logistics_code
* @return mixed 返回值
*/
public function service_code($param)
{
$cpCode = $param['logistics'];
$service = array(
'zhongtong' => array(
),
'jtexpress' => array(
),
'shunfeng' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
'productType' => array(
'text' => '产品类型',
'code' => 'productType',
'input_type' => 'select',
'options' => array(
'' => '',
'1' => '顺丰特快',
'2' => '顺丰标快',
'6' => '顺丰即日',
'10' => '国际小包',
'23' => '顺丰国际特惠(文件)',
'24' => '顺丰国际特惠(包裹)',
'26' => '国际大件',
'29' => '国际电商专递-标准',
'30' => '三号便利箱(特快)',
'31' => '便利封/袋(特快)',
'32' => '二号便利箱(特快)',
'33' => '岛内件(80CM)',
'35' => '物资配送',
'39' => '岛内件(110CM)',
'40' => '岛内件(140CM)',
'41' => '岛内件(170CM)',
'42' => '岛内件(210CM)',
'43' => '台湾岛内件-批(80CM)',
'44' => '台湾岛内件-批(110CM)',
'45' => '台湾岛内件-批(140CM)',
'46' => '台湾岛内件-批(170CM)',
'47' => '台湾岛内件-批(210CM)',
'48' => '台湾岛内件店取(80CM)',
'49' => '台湾岛内件店取(110CM)',
'50' => '千点取60',
'51' => '千点取80',
'52' => '千点取100',
'53' => '电商盒子F1',
'54' => '电商盒子F2',
'55' => '电商盒子F3',
'56' => '电商盒子F4',
'57' => '电商盒子F5',
'58' => '电商盒子F6',
'59' => 'E顺递',
'60' => '顺丰特快(文件)',
'61' => 'C1类包裹',
'62' => 'C2类包裹',
'63' => 'C3类包裹',
'64' => 'C4类包裹',
'65' => 'C5类包裹',
'66' => '特快D类',
'73' => 'F5超值箱',
'99' => '顺丰国际标快(文件)',
'100' => '顺丰国际标快(包裹)',
'104' => '岛内件(80CM,1kg以内)',
'106' => '国际重货-门到门',
'111' => '顺丰干配',
'113' => '便利封/袋(标快)',
'114' => '二号便利箱(标快)',
'115' => '三号便利箱(标快)',
'116' => '国际标快-BD2',
'117' => '国际标快-BD3',
'118' => '国际标快-BD4',
'119' => '国际标快-BD5',
'120' => '国际标快-BD6',
'121' => '国际标快-BDE',
'126' => '掌柜-大格',
'127' => '掌柜-中格',
'128' => '掌柜-小格',
'129' => '掌柜-柜到柜(单程)',
'130' => '掌柜-柜到柜(双程)',
'132' => '顺丰国际特惠(FBA)',
'136' => '国际集运',
'144' => '当日配-门(80CM/1KG以内)',
'145' => '当日配-门(80CM)',
'146' => '当日配-门(110CM)',
'147' => '当日配-门(140CM)',
'148' => '当日配-门(170CM)',
'149' => '当日配-门(210CM)',
'150' => '标快D类',
'153' => '整车直达',
'160' => '国际重货-港到港',
'178' => '一号便利箱(特快)',
'179' => '一号便利箱(标快)',
'180' => '岛內件-专车普运',
'184' => '顺丰国际标快+(文件)',
'186' => '顺丰国际标快+(包裹)',
'201' => '冷运标快',
'202' => '顺丰微小件',
'207' => '限时寄递',
'215' => '大票直送',
'218' => '国际电商专递-CD',
'221' => '香港冷运到家(≤60厘米)',
'222' => '香港冷运到家(61-80厘米)',
'223' => '香港冷运到家(81-100厘米)',
'224' => '香港冷运到家(101-120厘米)',
'225' => '香港冷运到家(121-150厘米)',
'231' => '陆运包裹',
'235' => '预售当天达',
'236' => '电商退货',
'241' => '国际电商专递-快速',
'244' => '店到店',
'245' => '店到门',
'246' => '门到店',
'247' => '电商标快',
'249' => '丰礼遇',
'252' => '前置小时达',
'253' => '前置当天达',
'255' => '顺丰卡航',
'256' => '顺丰卡航D类',
'257' => '医药温控配送',
'258' => '退换自寄',
'259' => '极速配',
'261' => 'O2O店配',
'262' => '前置标快',
'263' => '同城半日达',
'265' => '预售电标',
'266' => '顺丰空配(新)',
'267' => '行李送递-上门',
'268' => '行李送递',
'269' => '酒类配送',
'270' => '行李托运-上门',
'271' => '行李托运',
'272' => '行李送递-上门 (九龙)',
'273' => '温控配送自取',
'274' => '温控配送上门',
'275' => '酒类温控自取',
'276' => '酒类温控上门',
'277' => '跨境FBA空运',
'278' => '跨境FBA海运',
'283' => '填舱标快',
'285' => '填舱电标',
'288' => '冷运大件到港',
'289' => '跨城急件',
'293' => '特快包裹(新)',
'297' => '样本安心递',
'299' => '标快零担',
'303' => '专享急件',
'308' => '国际特快(文件)',
'310' => '国际特快(包裹)',
'316' => '前置次日达',
'318' => '航空港到港',
'323' => '电商微小件',
'325' => '温控包裹',
'329' => '填舱大件',
),
),
),
'yunda' => array(
),
'yuantong' => array(
),
'shentong' => array(
),
'youzhengguonei' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
),
'ems' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
),
'yzdsbk' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
),
'jd' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
'productType' => array(
'text' => '产品类型',
'code' => 'productType',
'input_type' => 'select',
'options' => array(
'' => '',
'ed-m-0001' => '京东标快',
'ed-m-0002' => '京东特快',
'LL-HD-M' => '生鲜标快',
'LL-SD-M' => '生鲜特快',
'ed-m-0017' => '函速达',
'ed-m-0012' => '特惠包裹',
'ed-m-0059' => '电商标快',
'ed-m-0019' => '电商特惠',
'ed-m-0005' => '同城急送',
'fr-m-0004' => '特快重货',
'fr-m-0007' => '航空重货',
'fr-m-0017' => '特惠专配',
'fr-m-0018' => '爱宝速递',
'ed-m-00000' => '智能分单',
),
),
),
'debangwuliu' => array(
'customerCode' => array(
'text' => '月结卡号',
'code' => 'customerCode',
'input_type' => 'input',
'require' => 'true',
),
'productType' => array(
'text' => '产品类型',
'code' => 'productType',
'input_type' => 'select',
'options' => array(
'' => '',
'RCP' => '大件快递3.60',
'PACKAGE'=> '标准快递',
'TZKJC' => '特快专递',
'HKDJG' => '航空大件隔日达',
'HKDJC' => '航空大件次日达',
'NZBRH' => '重包入户',
'NFLF' => '精准卡航(新)',
'NJZZH' => '精准重货(新)',
'NLRF' => '精准汽运(新)',
),
),
),
);
return isset($service[$cpCode]) ? $service[$cpCode] : [];
}
public function template_cfg()
{
$arr = array(
'template_name' => '爱库存',
'shop_name' => '爱库存',
'print_url' => 'https://mx-lews-web.aikucun.com/merchant/xiazai',
'shop_type' => 'aikucun',
'control_type' => 'aikucun',
'request_again' => true,
);
return $arr;
}
public function logistics($logistics_code = '') {
$logistics = array(
'ZTO' => array('code' => 'ZTO', 'name' => '中通速递','mode'=>'join'),
'YUNDA' => array('code' => 'YUNDA', 'name' => '韵达快递','mode'=>'join'),
'YTO' => array('code' => 'YTO','name'=>'圆通快递','mode'=>'join'),
'DBL' => array('code' => 'DBL','name'=>'德邦快递','mode'=>'direct'),
'UC' => array('code' => 'UC', 'name'=>'优速快递','mode'=>'join'),
'JD' => array('code' => 'JD', 'name'=>'京东快递'),
'zhongtong' => array('code' => 'zhongtong', 'name' => '中通速递', 'mode' => 'join'),
'jtexpress' => array('code' => 'jtexpress', 'name' => '极兔速递', 'mode' => 'join'),
'shunfeng' => array('code' => 'shunfeng', 'name' => '顺丰速运', 'mode' => 'direct'),
'yunda' => array('code' => 'yunda', 'name' => '韵达快递', 'mode' => 'join'),
'yuantong' => array('code' => 'yuantong', 'name' => '圆通快递', 'mode' => 'join'),
'shentong' => array('code' => 'shentong', 'name' => '申通速递', 'mode' => 'join'),
'youzhengguonei' => array('code' => 'youzhengguonei', 'name' => '中国邮政', 'mode' => 'direct'),
'ems' => array('code' => 'ems', 'name' => 'EMS', 'mode' => 'direct'),
'yzdsbk' => array('code' => 'yzdsbk', 'name' => '邮政电商标快', 'mode' => 'direct'),
'jd' => array('code' => 'jd', 'name' => '京东快递', 'mode' => 'direct'),
'debangwuliu' => array('code' => 'debangwuliu', 'name' => '德邦快递', 'mode' => 'direct'),
);
if(!empty($logistics_code)) {
if (!empty($logistics_code)) {
return $logistics[$logistics_code];
}
return $logistics;
}
}
}

View File

@@ -17,7 +17,7 @@
class logisticsmanager_mdl_channel extends dbeav_model {
public $getWaybillAccountFromApi = ['wxshipin', 'xhs', 'meituan4bulkpurchasing'];
public $getWaybillAccountFromApi = ['wxshipin', 'xhs', 'meituan4bulkpurchasing', 'aikucun'];
function modifier_status($row){
if ($row == 'false') {

View File

@@ -37,6 +37,8 @@
return new SfPrinter(options);
case 'xhs':
return new XhsPrinter(options);
case 'aikucun':
return new AikucunPrinter(options);
case 'wxshipin':
return new WxshipinPrinter(options);
case 'dewuppzf': // 得物品牌直发
@@ -1829,6 +1831,468 @@ var CaiNiaoPrinter = new Class({
},
});
var AikucunPrinter = new Class({
Extends: Printer,
printerInfoQueryResolved: false,
aikucunTaskMap: {},
aikucunHandledResponseMap: {},
refreshingEncryptData: false,
signVerifyDialog: null,
initialize: function(options){
this.parent(options);
this.warmupAikucunPrepareData();
this.webSocket = new WebSocket('ws://localhost:2750');
this.webSocket.onopen = function(event) {
this.webSocket.onmessage = function(event)
{
console.log('====onmessage:', event);
eval('var data = ' + event.data);
if (this.handleAikucunPrinterInfoQueryResponse(data)) {
return;
}
if (this.handleAikucunPrintResponse(data)) {
return;
}
switch(data.cmd) {
case 'print':
if (data.previewImage) {
this.fireEvent('preview', data);break;
} else {
this.fireEvent('printComplete', data);break;
}
case 'notifyPrintResult':
if(data.taskStatus == 'printed') {
this.fireEvent('printSuccess', data);break;
} else if(data.taskStatus == 'failed') {
this.fireEvent('printFailure', data);break;
}
}
}.bind(this);
this.webSocket.onclose = function(event)
{
this.fireEvent('close');
}.bind(this);
this.fireEvent('open');
}.bind(this);
this.webSocket.onerror = function(event)
{
this.fireEvent('error');
}.bind(this);
},
isReady:function(){
if (this.webSocket.readyState == 0) {
this.fireEvent('error',{errmsg:'正在连接爱库存打印组件,请稍后再试!'});
return false;
}
return true;
},
showAikucunSignVerifyDialog:function(){
if (this.signVerifyDialog) {
return;
}
this.signVerifyDialog = new Dialog(new Element("div.tableform",{html:'<div class="division"><div><h4>数据验证中......</h4><div style="margin-left: 5px;">正在请求签名参数,请稍等。</div></div></div>'}),
{
title:'打印数据校验',
width:420,
height:120,
resizeable:false,
});
},
closeAikucunSignVerifyDialog:function(){
if (!this.signVerifyDialog) {
return;
}
this.signVerifyDialog.close();
this.signVerifyDialog = null;
},
parseAikucunJsonPacket:function(jsonPacket){
if (typeof jsonPacket === 'string') {
return JSON.decode(jsonPacket.replace(/“/g, '"'));
}
return jsonPacket;
},
getAikucunOptionData:function(){
var data = this.options.data;
if (typeof data === 'string'){
data = JSON.decode(data);
}
return data || [];
},
requestAikucunPrepareData:function(printRow, callback){
new Request.JSON({
url:'index.php?app=logisticsmanager&ctl=admin_waybill&act=getEncryptPrintData',
data:{
'logi_no':printRow['logi_no'],
'batch_logi_no':printRow['batch_logi_no'],
'delivery_id':printRow['delivery_id'],
'channel_id':printRow['channel_id'],
'mode':'prepare'
},
onComplete:function(rs) {
if (rs && rs.rsp == 'succ' && rs.data) {
callback(true, rs.data);
return;
}
callback(false, null);
}
}).send();
},
warmupAikucunPrepareData:function(){
var data = this.getAikucunOptionData();
if (!data || !data.length) {
return;
}
var queueNum = 5;
var total = data.length;
var finished = 0;
var _this = this;
var process = function(idx){
if (idx >= total) {
finished++;
if (finished < queueNum) {
return;
}
_this.options.data = typeof _this.options.data === 'string' ? _this.toUnicode(JSON.encode(data)) : data;
return;
}
if (!data[idx]) {
process(idx + queueNum);
return;
}
var jsonPacket = _this.parseAikucunJsonPacket(data[idx]['json_packet']);
var prepareData = _this.resolveAikucunPrepareData(jsonPacket, data[idx]);
if (prepareData && prepareData.mxEctData) {
process(idx + queueNum);
return;
}
_this.requestAikucunPrepareData(data[idx], function(ok, prepareRsp){
if (ok) {
data[idx]['json_packet'] = prepareRsp;
}
process(idx + queueNum);
});
};
for (var i = 0; i < queueNum; i++) {
process(i);
}
},
refreshAikucunSignData:function(printName, onComplete){
var data = this.getAikucunOptionData();
var iTotal = data.length;
if (!iTotal) {
if (typeOf(onComplete) === 'function') {
onComplete({success: true, failCount: 0, total: 0});
}
return;
}
var iFail = 0;
var queueNum = 5;
var finishQueueNum = 0;
var _this = this;
var process = function(idx){
if (idx >= iTotal) {
finishQueueNum++;
if (finishQueueNum < queueNum) {
return;
}
_this.options.data = typeof _this.options.data === 'string' ? _this.toUnicode(JSON.encode(data)) : data;
if (typeOf(onComplete) === 'function') {
onComplete({success: iFail === 0, failCount: iFail, total: iTotal});
}
return;
}
if (!data[idx]) {
process(idx + queueNum);
return;
}
var jsonPacket = this.parseAikucunJsonPacket(data[idx]['json_packet']);
var prepareData = this.resolveAikucunPrepareData(jsonPacket, data[idx]);
var continueSign = function(currentPrepareData){
if (!currentPrepareData || !currentPrepareData.mxEctData) {
iFail++;
process(idx + queueNum);
return;
}
new Request.JSON({
url:'index.php?app=logisticsmanager&ctl=admin_waybill&act=getEncryptPrintData',
data:{
'logi_no':data[idx]['logi_no'],
'batch_logi_no':data[idx]['batch_logi_no'],
'delivery_id':data[idx]['delivery_id'],
'channel_id':data[idx]['channel_id'],
'print_name':printName ? printName : '',
'mode':'sign',
'prepare_data':JSON.encode(currentPrepareData)
},
onComplete:function(rs) {
if(rs.rsp == 'succ') {
rs.data.prepareData = currentPrepareData;
data[idx]['json_packet'] = rs.data;
} else {
iFail++;
}
process(idx + queueNum);
}
}).send();
};
if (!prepareData || !prepareData.mxEctData) {
this.requestAikucunPrepareData(data[idx], function(ok, prepareRsp){
if (!ok) {
iFail++;
process(idx + queueNum);
return;
}
data[idx]['json_packet'] = prepareRsp;
var fallbackPacket = this.parseAikucunJsonPacket(data[idx]['json_packet']);
continueSign(this.resolveAikucunPrepareData(fallbackPacket, data[idx]));
}.bind(this));
return;
}
continueSign(prepareData);
}.bind(this);
for (var i = 0; i < queueNum; i++) {
process(i);
}
},
resolveAikucunPrepareData:function(jsonPacket, printData){
if (!jsonPacket || typeof jsonPacket !== 'object') {
return null;
}
if (jsonPacket.prepareData && typeof jsonPacket.prepareData === 'object' && jsonPacket.prepareData.mxEctData) {
return JSON.decode(JSON.encode(jsonPacket.prepareData));
}
var pd = jsonPacket.printData && typeof jsonPacket.printData === 'object' ? jsonPacket.printData : null;
if (!pd || !pd.mxEctData) {
return null;
}
return {
orderId: jsonPacket.orderId ? jsonPacket.orderId : '',
logisticsNo: pd.logisticsNo ? pd.logisticsNo : (jsonPacket.logisticsNo ? jsonPacket.logisticsNo : (printData.logi_no ? printData.logi_no : '')),
mxEctData: pd.mxEctData
};
},
executeAikucunPrint:function(printer, isPreview){
if (!this.isReady()) {
return false;
}
if (this.refreshingEncryptData) {
this.fireEvent('error', {errmsg:'正在刷新打印签名数据,请稍后再试'});
return false;
}
this.refreshingEncryptData = true;
this.showAikucunSignVerifyDialog();
this.refreshAikucunSignData(printer.name, function(result){
this.refreshingEncryptData = false;
this.closeAikucunSignVerifyDialog();
if (!result || result.failCount > 0) {
this.fireEvent('error', {errmsg:'获取打印签名数据失败,请重试'});
return;
}
var tasks = this.formatData(this.options.data, isPreview);
tasks.each(function(task){
this.aikucunTaskMap[task.requestId] = {
documentID: task.documentID,
is_preview: isPreview
};
this.aikucunHandledResponseMap[task.requestId] = false;
console.log(
isPreview
? '======Aikucun send preview payload json(with params):'
: '======Aikucun send print payload json(with params):',
JSON.stringify(task.payload)
);
this.webSocket.send(JSON.stringify(task.payload));
}.bind(this));
}.bind(this));
return true;
},
print:function(printer){
return this.executeAikucunPrint(printer, false);
},
preview:function(printer){
return this.executeAikucunPrint(printer, true);
},
getPrinters:function(){
if (!this.isReady()) {
return false;
}
this.printerInfoQueryResolved = false;
var req = {esubrc: 'printerInfoQuery'};
this.webSocket.send(JSON.stringify(req));
return true;
},
markPrinterInfoQueryResolved:function(){
this.printerInfoQueryResolved = true;
},
handleAikucunPrinterInfoQueryResponse:function(data){
if (!data || data.cmd) {
return false;
}
var isPrinterInfoRsp = data.esubrc === 'printerInfoQuery' || typeof data.printers !== 'undefined';
if (!isPrinterInfoRsp) {
return false;
}
if (String(data.code || '') !== '' && String(data.code) !== '00000') {
this.markPrinterInfoQueryResolved();
this.fireEvent('error', {errmsg: data.message ? data.message : '获取打印机列表失败'});
return true;
}
if (this.printerInfoQueryResolved) {
return true;
}
var normalized = this.normalizeAikucunPrintersResponse(data);
if (!normalized) {
this.markPrinterInfoQueryResolved();
this.fireEvent('error', {errmsg: data.message ? data.message : '获取打印机列表失败'});
return true;
}
this.markPrinterInfoQueryResolved();
this.fireEvent('getPrinters', normalized);
return true;
},
normalizeAikucunPrintersResponse:function(data){
if (!data || !data.printers || !data.printers.length) {
return false;
}
var printers = [];
var defaultPrinter = '';
data.printers.each(function(item){
var name = item.printName ? item.printName : item.name;
if (!name) {
return;
}
printers.push({name: name});
if (!defaultPrinter && String(item.defaultPrinter) === '1') {
defaultPrinter = name;
}
});
if (!printers.length) {
return false;
}
if (!defaultPrinter) {
defaultPrinter = printers[0].name;
}
return {
printers: printers,
defaultPrinter: defaultPrinter,
msg: data.message ? data.message : ''
};
},
extractAikucunPushMessage:function(data){
var push = data.pushBackMessage ? data.pushBackMessage : {};
if (push && push.length && push[0]) {
return push[0];
}
return push;
},
resolveAikucunResponseRequestId:function(data, push){
if (push && push.requestId) {
return String(push.requestId);
}
if (data.requestId) {
return String(data.requestId);
}
return '';
},
buildAikucunResponsePayload:function(data, meta, push, isSuccess){
var logiNo = (push && push.logisticsNo) ? push.logisticsNo : '';
var documentID = meta && meta.documentID ? meta.documentID : ((meta && meta.is_preview ? '1_' : '0_') + (logiNo || this.getUUID(8, 16)));
var rsp = {
status: isSuccess ? 'success' : 'fail',
msg: data.message ? data.message : '',
printStatus: [{
documentID: documentID,
status: isSuccess ? 'success' : 'fail',
detail: data.message ? data.message : ''
}],
taskID: documentID
};
if (data.previewImage) {
rsp.previewImage = data.previewImage;
}
return rsp;
},
fireAikucunResultEvent:function(meta, isSuccess, rsp){
if (meta && meta.is_preview) {
this.fireEvent('preview', rsp);
return;
}
this.fireEvent(isSuccess ? 'printSuccess' : 'printFailure', rsp);
},
formatData:function(data,is_preview){
var tasks = [];
data.each(function(printData){
var jsonPacket = this.parseAikucunJsonPacket(printData.json_packet);
if(!jsonPacket) {
alert('数据结构不完整,\n无法打印');
return;
}
if (typeof jsonPacket.printData === 'string') {
var printDataObj = JSON.decode(jsonPacket.printData.replace(/“/g, '"'))
} else {
var printDataObj = jsonPacket.printData;
}
if (!printDataObj || typeof printDataObj !== 'object') {
return;
}
var payload = JSON.decode(JSON.encode(printDataObj));
var reqId = payload.requestId ? String(payload.requestId) : this.getUUID(16, 16);
payload.requestId = reqId;
var logiNo = printData.batch_logi_no ? printData.batch_logi_no : printData.logi_no;
var docId = logiNo ? logiNo : reqId;
tasks.push({
documentID:(is_preview ? '1_' : '0_') + docId,
requestId: reqId,
payload: payload,
logisticsNo: logiNo
});
}.bind(this));
return tasks;
},
handleAikucunPrintResponse:function(data){
if (!data || data.cmd || (typeof data.code === 'undefined' && typeof data.success === 'undefined')) {
return false;
}
var code = String(data.code);
var isSuccess = (code === '00000') || (code === '200') || (data.success === true);
var push = this.extractAikucunPushMessage(data);
var reqId = this.resolveAikucunResponseRequestId(data, push);
if (reqId && this.aikucunHandledResponseMap[reqId]) {
return true;
}
var meta = reqId && this.aikucunTaskMap[reqId] ? this.aikucunTaskMap[reqId] : null;
var rsp = this.buildAikucunResponsePayload(data, meta, push, isSuccess);
if (reqId && this.aikucunTaskMap[reqId]) {
delete this.aikucunTaskMap[reqId];
}
if (reqId) {
this.aikucunHandledResponseMap[reqId] = true;
}
this.fireAikucunResultEvent(meta, isSuccess, rsp);
return true;
},
getRequestObject:function(cmd){
var request = new Object();
request.requestID=this.getUUID(8, 16);
request.cmd=cmd;
request.version="1.0";
return request;
},
});
var WxshipinPrinter = new Class({
Extends: Printer,
initialize: function(options){