业务需求背景描述
我们公司进行的是从日本往国内售卖化妆品业务,BTC模式。
因为公司需求扩展,不仅仅是对国内售卖了,又增加了20个国家,这样一来我们的快递方式就变了,其中有几个国家只能走DHL,所以就对接了DHL,DHL快递是全球的,国内也有,但是我们公司是从日本往全球售卖,所以只能对接日本的DHL,在这期间我也咨询了国内的DHL工作人员,反馈的信息是只能通过当地国家的DHL来对接,没办法只能联系了日本的DHL,在这里我得由衷的感谢一下国内的DHL工作人员,他们帮助确定了我们是用哪个文档,刚开始日本给的是”DHL eCommerce Solutions“这个文档,这个是对接物流仓的,当时没搞清楚,一直在看这个文档,但是一直无法对接成功,因为我们的账号信息不对(肯定不对了,我们日本的账号是DHL Express类型的),后来国内的DHL工作人员跟我们明确了需求后,让我们跟日本的工作人员要DHL Express 的文档,这个文档是不对外开放的,你得先注册开发文档的账号信息,然后你再把你的注册的开发文档账号信息和你的DHL Express账号信息给到日本的DHL,他们核实后会给你开通DHL Express文档的权限同时给你一个测试账号和密码,等你使用测试账号成功创建货件后他们才会给你正式的账号和密码(PS:这期间的沟通都是通过邮件,当然,用的都是英文,日本那边的DHL只能通过邮件沟通,效率也是很慢,一天基本上回复一条,有时候你早上早点发的话,可以一天收到两条回复,不要尝试添加他们的FaceBook或者其他国外聊天软件,他们不会添加的!)
业务实现
一、对接到岸成本接口(快递费用)
接口地址: https://express.api.dhl.com/mydhlapi/landed-cost
请求方式:POST
验证方式:Basic认证
// 封装DHL类
class Dhl_EweiShopV2Model
{
// DHL 接口地址
public static $URL = 'https://express.api.dhl.com/mydhlapi';
// DHL 发货人信息
public static $SHIPPERDETAILS = [
"postalCode" => "000000",// 发货人邮编,没有就空着,但是这个字段得有
"cityName" => "Osaka", // 发货人城市 英文 必填
"countryCode" => "JP", // 发货人国家代码 必填
"provinceCode" => "Osaka", // 发货人城市代码 非必填
"addressLine1" => "test", // 发货人详细地址
"countyName" => "Osaka" // 发货人城市 跟上面一样就行了
];
// DHL 账号信息 accounts shipper是托运人的意思, number字段就是DHL Express的账号
public static $ACCOUNTS = ["typeCode" => "shipper","number" => "11111111"];
// DHL authorization信息(header头信息)
public function authorization()
{
return base64_encode('account:password');
}
//运费查询
public function getDhlExpressPrice($goods,$weight,$address)
{
// 获取系统配置
$shop_set = m('common')->getSysset('shop');
$item = [];
foreach ($goods as $key => $value) {
$item[$key]['number'] = $key+1;
$item[$key]['quantity'] = intval($value['total']);
$item[$key]['unitPrice'] = $value['unitprice'] * $shop_set['riyuan'];
$item[$key]['unitPriceCurrencyCode'] = 'JPY';
$item[$key]['commodityCode'] = '0000000000'; // HS 编码
}
$data = [
"customerDetails" => [
"shipperDetails" => static::$SHIPPERDETAILS,//发货人信息
"receiverDetails" => [// 收货人信息
"postalCode" => "", // 邮编 没有就填空 暂时空着就可以
"cityName" => $address['city'], //收货人城市
"countryCode" => $address['overseascountrycode'], // 国家代码
"provinceCode" => $address['overseascitycode'], //城市代码
"addressLine1" => $address['area'].' '.$address['address'], // 收件人详细地址
"countyName" => $address['city'] //收货人城市
]
],
"accounts" => [static::$ACCOUNTS],
"productCode" => "P", // DHL全球产品代码 P为普通,B为特殊
"localProductCode" => "P", // 本地产品代码 P为普通,B为特殊
"unitOfMeasurement" => "metric", // 请输入计量单位 metric公制 imperial 英制
"currencyCode" => "JPY", // 到岸成本计算结果将以此定义的货币返回
"isCustomsDeclarable" => true,
"getCostBreakdown" => false,
"shipmentPurpose"=>"commercial",
"transportationMode"=>"air",
"merchantSelectedCarrierName"=>"DHL",
"packages" => [
[
"weight" => round($weight/1000,3), // 重量 单位:千克
"dimensions" => [
"length" => 33, // 长
"width" => 18, // 宽
"height" => 10 // 高
]
]
],
"items" => $item
];
$res = $this->post_request(static::$URL.'/landed-cost',$data);
return round($res['products'][0]['detailedPriceBreakdown'][0]['breakdown'][3]['price']/$shop_set['riyuan'],2);
return $res;
}
// 发送请求
public function post_request($url,$data)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL =>$url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
"Authorization:Basic ".$this->authorization(),
"content-type: application/json",
"content-length:".strlen(json_encode($data)),
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
return json_decode($response,true);
}
}
二、封装DHL、EMS和Epacket邮费查询类
PS:EMS和Epacket是根据重量和区域计算价格的
// 海外地址快递和VAT税费计算
class Overseasexpress_EweiShopV2Model{
// 第一地带
public static $noeAddress = ["Philippines","Cambodia","Malaysia","Thailand","Indonesia"];
// 第二地带中的大洋洲
public static $twoOceaniaAddress = ["New Zealand"];
// 第二地带中的北美洲
public static $twoNorthAmericaAddress = ["United States"];
// 第二地带中的欧洲
public static $twoEuropeAddress = ["Ireland","Germany","France","Netherlands","Norway","Sweden","Spain","Italy","United Kingdom"];
// 加拿大、澳大利亚 用于判断走哪个快递模板
public static $overseascountry1 = ["Canada","Australia"];
// EMS 快递费阶段
public static $emsArray = [
// EMS第一地带
'noeAddress' => [
'0'=>0,
'500'=>1400,
'600'=>1540,
'700'=>1680,
'800'=>1820,
'900'=>1960,
'1000'=>2100,
'1250'=>2400,
'1500'=>2700,
'1750'=>3000,
'2000'=>3300,
'2500'=>3800,
'3000'=>4300
],
// EMS第二地带中的大洋洲
'twoOceaniaAddress'=> [
'0'=>0,
'500'=>2000,
'600'=>2180,
'700'=>2360,
'800'=>2540,
'900'=>2720,
'1000'=>2900,
'1250'=>3300,
'1500'=>3700,
'1750'=>4100,
'2000'=>4500,
'2500'=>5200,
'3000'=>5900,
],
// EMS第二地带中的欧洲
'twoEuropeAddress' => [
'0'=>0,
'500'=>2200,
'600'=>2400,
'700'=>2600,
'800'=>2800,
'900'=>3000,
'1000'=>3200,
'1250'=>3650,
'1500'=>4100,
'1750'=>4550,
'2000'=>5000,
'2500'=>5800,
'3000'=>6600
],
// EMS 第三地带南美洲或非洲
'AfricaOrSouthAmerica'=> [
'0'=>0,
'500'=>2400,
'600'=>2740,
'700'=>3080,
'800'=>3420,
'900'=>3760,
'1000'=>4100,
'1250'=>4900,
'1500'=>5700,
'1750'=>6500,
'2000'=>7300,
'2500'=>8800,
'3000'=>10300
]
];
// Epacket 快递费阶段
public static $EpacketArr = [
'noeAddress' => [
'0'=>690,
'200'=>780,
'300'=>870,
'400'=>960,
'500'=>1050,
'600'=>1140,
'700'=>1230,
'800'=>1320,
'900'=>1410,
'1000'=>1500,
'1100'=>1590,
'1200'=>1680,
'1300'=>1770,
'1400'=>1860,
'1500'=>1950,
'1600'=>2040,
'1700'=>2130,
'1800'=>2220,
'1900'=>2310,
'2000'=>2400
],
'twoOceaniaAddress' => [
'0'=>790,
'200'=>910,
'300'=>1030,
'400'=>1150,
'500'=>1270,
'600'=>1390,
'700'=>1510,
'800'=>1630,
'900'=>1750,
'1000'=>1870,
'1100'=>1990,
'1200'=>2110,
'1300'=>2230,
'1400'=>2350,
'1500'=>2470,
'1600'=>2590,
'1700'=>2710,
'1800'=>2830,
'1900'=>2950,
'2000'=>3070
],
'fourOceaniaAddress' => [
'0'=>1150,
'200'=>1280,
'300'=>1410,
'400'=>1540,
'500'=>1670,
'600'=>1800,
'700'=>1930,
'800'=>2060,
'900'=>2190,
'1000'=>2320,
'1100'=>2450,
'1200'=>2580,
'1300'=>2710,
'1400'=>2840,
'1500'=>2970,
'1600'=>3100,
'1700'=>3230,
'1800'=>3360,
'1900'=>3490,
'2000'=>3620
]
];
/**
* 获取快递费
* @param $province | string | 国家
* @param $express | string | 快递方式 1 EMS 2 Epacket
* @param $weight | float|string | 订单商品重量
* @param $address | array | 地址
* @param $goodsArr | array | 订单内商品
*/
public function expressPrice($province,$express=1,$weight=0,$address = [],$goodsArr = [])
{
global $_W;
// 获取系统配置
$shop_set = m('common')->getSysset('shop');
// 获取外包装重量
$weight += pdo_getcolumn('ewei_shop_packing_weight',['uniacid'=>$_W['uniacid']],'packing_weight');
// 默认为EMS
if ($express == 1 && !in_array($province,static::$overseascountry1)) {
// 判断是否在EMS第一地带
if (in_array($province,static::$noeAddress)) {
$expressPriceJpy = $this->weightRange(static::$emsArray['noeAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
// 判断是否在EMS第二地带中的大洋洲
if (in_array($province,static::$twoOceaniaAddress) || in_array($province,static::$twoNorthAmericaAddress)) {
$expressPriceJpy = $this->weightRange(static::$emsArray['twoOceaniaAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
// 判断是否在EMS第二地带中的欧洲
if (in_array($province,static::$twoEuropeAddress)) {
$expressPriceJpy = $this->weightRange(static::$emsArray['twoEuropeAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
}
if ($express == 2 && !in_array($province,static::$overseascountry1)) {
// 判断是否在epacket第一地带
if (in_array($province,static::$noeAddress)) {
$expressPriceJpy = $this->weightRange(static::$EpacketArr['noeAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
// 判断是否在epacket第二地带中的大洋洲 或 在第二地带中的欧洲
if (in_array($province,static::$twoOceaniaAddress) || in_array($province,static::$twoEuropeAddress)) {
$expressPriceJpy = $this->weightRange(static::$EpacketArr['twoOceaniaAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
// 判断是否在epacket第四地带中的北美洲
if (in_array($province,static::$twoNorthAmericaAddress)) {
$expressPriceJpy = $this->weightRange(static::$EpacketArr['fourOceaniaAddress'],$weight);
return round($expressPriceJpy/$shop_set['riyuan'],2);
}
}
// 根据国家判断是否只能走DHL
if (in_array($province,static::$overseascountry1)) {
return m('dhl')->getDhlExpressPrice($goodsArr,$weight,$address);
}
}
/**
* 获取快递重量范围的价钱
*/
public function weightRange($Array,$weight)
{
$weightArr = array_keys($Array);
foreach ($weightArr as $key => $value) {
if ($weight > $value && $weight <= $weightArr[$key+1]) {
return $Array[$weightArr[$key+1]];
}
}
}
}
三、小程序端调整
在order/create/index.wxml里面修改,修改的地方比较多,直接贴代码了
<view class="fui-cell-group" wx:if="">
<view class="fui-cell" wx:if="">
<view class="fui-cell-label">快递公司</view>
<view class="fui-cell-info">
<radio-group class="radio-group" bindchange="expressChange" id="expressEmsEpacket" >
<radio class="radio" value="1" checked="true">
<text>EMS</text>
</radio>
<radio class="radio" value="2" style="margin-left: 20rpx;">
<text>epacket</text>
</radio>
</radio-group>
</view>
</view>
<view class="fui-cell" wx:if="">
<view class="fui-cell-label">快递公司</view>
<view class="fui-cell-info">
<radio-group class="radio-group" bindchange="expressChange" id="expressDhl" >
<radio class="radio" value="3" checked="true">
<text>DHL</text>
</radio>
</radio-group>
</view>
</view>
</view>
在order/create/index.js里面修改
var t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
return typeof t;
} : function(t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
},
e = "function" == typeof Symbol && "symbol" == t(Symbol.iterator) ? function(e) {
return void 0 === e ? "undefined" : t(e);
} : function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : void 0 === e ? "undefined" : t(e);
},
a = getApp(),
i = a.requirejs("core"),
r = a.requirejs("foxui"),
s = a.requirejs("biz/diyform"),
d = a.requirejs("jquery"),
o = a.requirejs("biz/selectdate");
// 美国、加拿大、澳大利亚 用于判断走哪个快递模板
var overseascountry1 = ["Canada","Australia"],
// 除美国、加拿大、澳大利亚外国家 用于判断走哪个快递模板
overseascountry2 = [
"United States","Philippines","Cambodia","Malaysia","Thailand","Indonesia","Ireland","Germany","France",
"Netherlands","Norway","Sweden","Switzerland","Spain","Italy","United Kingdom","Argentina","New Zealand"
]
Page({
data: {
icons: a.requirejs("icons"),
list: {},
goodslist: {},
data: {
dispatchtype: 0,
remark: ""
},
areaDetail: {
detail: {
realname: "",
mobile: "",
areas: "",
street: "",
address: ""
}
},
merchid: 0,
showPicker: !1,
pvalOld: [0, 0, 0],
pval: [0, 0, 0],
areas: [],
street: [],
streetIndex: 0,
noArea: !1,
showaddressview: !1,
city_express_state: !1,
currentDate: "",
dayList: "",
currentDayList: "",
currentObj: "",
currentDay: "",
cycelbuy_showdate: "",
receipttime: "",
scope: "",
bargainid: "",
selectcard: "",
taxprice: 0,
taxtype: 0,
istax: 0,
iskuaidi:true,
price_status:0,
isoverseas:0,
overseasexpress:0,
express:1
},
onLoad: function(t) {
var e = this,
r = [];
if (t.goods) {
var s = JSON.parse(t.goods);
t.goods = s, this.setData({
ispackage: !0
});
}
e.setData({
options: t
}), e.setData({
bargainid: t.bargainid
}), a.url(t), i.get("order/create", e.data.options, function(t) {
if (t.error == 3333) {
wx.navigateBack();
}
if (0 == t.error) {
r = e.getGoodsList(t.goods);
var s = (e.data.originalprice - t.goodsprice).toFixed(2);
console.log(t)
//如果是中外运,默认顺丰+5
let kuaidifei = r[0]['taxtype'] == 1 ? 15 : 0;
if (e.data.iskuaidi) {
t.dispatch_priceyl = t.dispatch_price
t.realpriceyl = t.realprice
e.setData({
iskuaidi: false
});
}
t.dispatch_price = t.dispatch_priceyl + kuaidifei
t.realprice = t.realpriceyl + kuaidifei
var f_data = t.f_data,
fields = t.fields
if (t.address.isoverseas == 1) {
t.f_data=''
t.fields=[fields[2]]
t.zfqrtips = ''
if (overseascountry1.includes(t.address.province)) {
e.setData({
overseasexpress:1
})
if (!t.dispatch_price) {
e.setData({
dhlshow:0
})
}else{
e.setData({
dhlshow:!0
})
}
}
if (overseascountry2.includes(t.address.province)) {
e.setData({
overseasexpress:2
})
}
} else {
t.f_data = f_data
t.fields = fields
}
e.setData({
list: t,
istax: r[0]['istax'],
taxprice: r[0]['taxprice'],
taxtype: r[0]['taxtype'],
goods: t,
show: !0,
address: !0,
card_info: t.card_info || {},
cardid: t.card_info.cardid || "",
cardname: t.card_info.cardname || "",
carddiscountprice: t.card_info.carddiscountprice,
goodslist: r,
merchid: t.merchid,
comboprice: s,
diyform: {
f_data: t.f_data,
fields: t.fields
},
city_express_state: t.city_express_state,
cycelbuy_showdate: t.selectDate,
receipttime: t.receipttime,
iscycel: t.iscycel,
scope: t.scope,
fromquick: t.fromquick,
hasinvoice: t.hasinvoice,
price_status:t.price_status,
taxtext:t.taxtext,
f_data:f_data,
fields:fields,
isoverseas:t.address.isoverseas,
weight:t.weight
}), a.setCache("goodsInfo", {
goodslist: r,
merchs: t.merchs
}, 1800);
} else i.toast(t.message, "loading"), setTimeout(function() {
//wx.navigateBack(); //佣金暂时屏蔽
}, 1e3);
if ("" != t.fullbackgoods) {
if (void 0 == t.fullbackgoods) return;
var d = t.fullbackgoods.fullbackratio,
o = t.fullbackgoods.maxallfullbackallratio,
d = Math.round(d),
o = Math.round(o);
e.setData({
fullbackratio: d,
maxallfullbackallratio: o
});
}
1 == t.iscycel && e.show_cycelbuydate();
}), this.getQuickAddressDetail(), a.setCache("coupon", ""), setTimeout(function() {
e.setData({
areas: a.getCache("cacheset").areas
});
}, 3e3);
},
show_cycelbuydate: function() {
var t = this,
e = o.getCurrentDayString(this, t.data.cycelbuy_showdate),
a = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
t.setData({
currentObj: e,
currentDate: e.getFullYear() + "." + (e.getMonth() + 1) + "." + e.getDate() + " " + a[e.getDay()],
currentYear: e.getFullYear(),
currentMonth: e.getMonth() + 1,
currentDay: e.getDate(),
initDate: Date.parse(e.getFullYear() + "/" + (e.getMonth() + 1) + "/" + e.getDate()),
checkedDate: Date.parse(e.getFullYear() + "/" + (e.getMonth() + 1) + "/" + e.getDate()),
maxday: t.data.scope
});
},
onShow: function() {
var t = this,
r = a.getCache("orderAddress"),
f_datatemporary = t.data.list.f_data,
fieldstemporary = t.data.list.fields,
s = a.getCache("orderShop");
var zfqrtips = t.data.list.zfqrtips
// 境外订单去除身份证
if (r.isoverseas == 1) {
console.log(2222)
t.setData({
diyform:{
f_data:"",
fields:[fieldstemporary[2]]
},
isoverseas:r.isoverseas
})
if (overseascountry1.includes(r.province)) {
t.setData({
overseasexpress:1
})
}
if (overseascountry2.includes(r.province)) {
t.setData({
overseasexpress:2
})
}
t.data.list.zfqrtips = ''
} else {
t.setData({
diyform:{
f_data:f_datatemporary,
fields:fieldstemporary
},
isoverseas:0,
overseasexpress:0
})
}
a.getCache("isIpx") ? t.setData({
isIpx: !0,
iphonexnavbar: "fui-iphonex-navbar",
paddingb: "padding-b"
}) : t.setData({
isIpx: !1,
iphonexnavbar: "",
paddingb: ""
}), r && (this.setData({
"list.address": r
}), t.caculate(t.data.list)), s && this.setData({
"list.carrierInfo": s,
"list.storeInfo": s
});
var o = a.getCache("coupon");
"object" == (void 0 === o ? "undefined" : e(o)) && 0 != o.id ? (this.setData({
"data.couponid": o.id,
"data.couponname": o.name
}), i.post("order/create/getcouponprice", {
couponid: o.id,
goods: this.data.goodslist,
goodsprice: this.data.list.goodsprice,
discountprice: this.data.list.discountprice,
isdiscountprice: this.data.list.isdiscountprice
}, function(e) {
0 == e.error ? (delete e.$goodsarr, t.setData({
coupon: e
}), t.caculate(t.data.list)) : i.alert(e.message);
}, !0)) : (this.setData({
"data.couponid": 0,
"data.couponname": null,
coupon: null
}), d.isEmptyObject(t.data.list) || t.caculate(t.data.list));
},
gouwuxuzhi:function() {
wx.navigateTo({
url: "/pages/custom/index?pageid=20",
})
},
getGoodsList: function(t) {
var e = [];
d.each(t, function(t, a) {
d.each(a.goods, function(t, a) {
e.push(a);
});
});
for (var a = 0, i = 0; i < e.length; i++) a += e[i].price;
return this.setData({
originalprice: a
}), e;
},
toggle: function(t) {
var e = i.pdata(t),
a = e.id,
r = {};
r[e.type] = 0 == a || void 0 === a ? 1 : 0, this.setData(r);
},
phone: function(t) {
i.phone(t);
},
dispatchtype: function(t) {
var e = i.data(t).type;
this.setData({
"data.dispatchtype": e
}), this.caculate(this.data.list);
},
number: function(t) {
var e = this,
a = i.pdata(t),
s = r.number(this, t),
o = a.id,
c = e.data.list,
n = 0,
l = 0;
d.each(c.goods, function(t, e) {
d.each(e.goods, function(e, a) {
a.id == o && (c.goods[t].goods[e].total = s), n += parseInt(c.goods[t].goods[e].total),
l += parseFloat(n * c.goods[t].goods[e].price);
});
}), c.total = n, c.goodsprice = d.toFixed(l, 2), e.setData({
list: c,
goodslist: e.getGoodsList(c.goods)
}), this.caculate(c);
},
caculate: function(t) {
var e = this,
a = 0;
e.data.data && 0 != e.data.data.couponid && (a = e.data.data.couponid), i.post("order/create/caculate", {
goods: this.data.goodslist,
dflag: this.data.data.dispatchtype,
addressid: this.data.list.address ? this.data.list.address.id : 0,
packageid: this.data.list.packageid,
bargain_id: this.data.bargainid,
discountprice: this.data.list.discountprice,
cardid: this.data.cardid,
couponid: a,
express:this.data.express,
weight:this.data.weight
}, function(a) {
console.log(a)
t.dispatch_price = a.price, t.enoughdeduct = a.deductenough_money,
t.enoughmoney = a.deductenough_enough, t.taskdiscountprice = a.taskdiscountprice,
t.discountprice = a.discountprice, t.isdiscountprice = a.isdiscountprice, t.seckill_price = a.seckill_price,
t.deductcredit2 = a.deductcredit2, t.deductmoney = a.deductmoney, t.deductcredit = a.deductcredit,
t.gifts = a.gifts, e.data.data.deduct && (a.realprice -= a.deductmoney), e.data.data.deduct2 && (a.realprice -= a.deductcredit2),
e.data.coupon && void 0 !== e.data.coupon.deductprice && (e.setData({
"coupon.deductprice": a.coupon_deductprice
}), a.realprice -= a.coupon_deductprice), a.card_info && (t.card_free_dispatch = a.card_free_dispatch),
0 == e.data.goods.giftid && e.setData({
"goods.gifts": a.gifts
}), t.realprice <= 0 && (t.realprice = 1e-6), t.realprice = d.toFixed(a.realprice + e.data.taxprice, 2),
e.setData({
list: t,
cardid: a.card_info.cardid,
cardname: a.card_info.cardname,
goodsprice: a.card_info.goodsprice,
carddiscountprice: a.card_info.carddiscountprice,
city_express_state: a.city_express_state,
});
var customstax = e.data.list
customstax.customstax = a.taxprice
var f_data = e.data.f_data
if (a.address.isoverseas==1) {
e.setData({
taxprice:a.taxprice,
taxtext:a.taxtext,
list:customstax,
diyform:{
f_data:e.data.f_data,
fields:[e.data.fields[2]]
},
isoverseas:a.address.isoverseas
})
if (overseascountry1.includes(a.address.province)) {
e.setData({
overseasexpress:1
})
if (!a.price) {
e.setData({
dhlshow:0
})
}else{
e.setData({
dhlshow:!0
})
}
}
if (overseascountry2.includes(a.address.province)) {
e.setData({
overseasexpress:2
})
}
} else {
e.setData({
taxprice:0,
taxtext:a.taxtext,
diyform:{
f_data:e.data.f_data,
fields:e.data.fields
},
isoverseas:0,
overseasexpress:0
})
}
}, !0);
},
submit: function(res) {
let formid = res.detail.formId
i.get("util/form", {
formid
}, response => {});
getApp().checkAuth();
var t = this.data,
e = this,
a = this.data.diyform,
r = t.goods.giftid || t.giftid,
list_realprice = this.data;
if (0 == this.data.goods.giftid && 1 == this.data.goods.gifts.length && (r = this.data.goods.gifts[0].id), !t.submit && s.verify(this, a)) {
t.list.carrierInfo = t.list.carrierInfo || {};
var o = {
id: t.options.id ? t.options.id : 0,
goods: t.goodslist,
gdid: t.options.gdid,
dispatchtype: t.data.dispatchtype,
fromcart: t.list.fromcart,
carrierid: 1 == t.data.dispatchtype && t.list.carrierInfo ? t.list.carrierInfo.id : 0,
addressid: t.list.address ? t.list.address.id : 0,
carriers: 1 == t.data.dispatchtype || t.list.isvirtual || t.list.isverify ? {
carrier_realname: t.list.member.realname,
carrier_mobile: t.list.member.mobile,
realname: t.list.carrierInfo.realname,
mobile: t.list.carrierInfo.mobile,
storename: t.list.carrierInfo.storename,
address: t.list.carrierInfo.address
} : "",
remark: t.data.remark,
deduct: t.data.deduct,
deduct2: t.data.deduct2,
couponid: t.data.couponid,
cardid: t.cardid,
invoicename: t.list.invoicename,
submit: !0,
packageid: t.list.packageid,
giftid: r,
diydata: t.diyform.f_data,
receipttime: t.receipttime,
bargain_id: e.data.options.bargainid,
fromquick: t.fromquick,
kuaidi: t.data.kuaidi,
price_status:t.price_status,
taxprice:t.taxprice
};
if (t.list.storeInfo && (o.carrierid = t.list.storeInfo.id), 1 == t.data.dispatchtype || t.list.isvirtual || t.list.isverify) {
if ("" == d.trim(t.list.member.realname) && "0" == t.list.set_realname) return void i.alert("请填写联系人!");
if ("" == d.trim(t.list.member.mobile) && "0" == t.list.set_mobile) return void i.alert("请填写联系方式!");
if (!/^[1][3-9]\d{9}$|^([6|9])\d{7}$|^[0][9]\d{8}$|^[6]([8|6])\d{5}$/.test(d.trim(t.list.member.mobile))) return void i.alert("请填写正确联系电话!");
if (t.list.isforceverifystore && !t.list.storeInfo) return void i.alert("请选择门店!");
o.addressid = 0;
} else if (!o.addressid && !t.list.isonlyverifygoods) return void i.alert("地址没有选择!");
if (t.price_status == 1) return void i.alert("单笔订单金额不能超5000");
e.setData({
submit: !0
}), i.post("order/create/submit", o, function(t) {
e.setData({
submit: !1
}), 0 == t.error ? wx.navigateTo({
url: "/pages/order/pay/index?id=" + t.orderid
}) : i.alert(t.message);
}, !0);
}
},
dataChange: function(t) {
var e = this.data.data,
a = this.data.list;
switch (t.target.id) {
case "remark":
e.remark = t.detail.value;
break;
case "kuaidi":
e.kuaidi = t.detail.value;
let kuaidifei = e.kuaidi == 2 ? 15 :0;
if (this.data.iskuaidi){
a.dispatch_priceyl = a.dispatch_price
a.realpriceyl = a.realprice
this.setData({
iskuaidi: false
});
}
a.dispatch_price = a.dispatch_priceyl + kuaidifei
a.realprice = a.realpriceyl + kuaidifei
break;
case "deduct":
if (e.deduct = t.detail.value, e.deduct2) return;
i = parseFloat(a.realprice), i += e.deduct ? -parseFloat(a.deductmoney) : parseFloat(a.deductmoney),
a.realprice = i;
break;
case "deduct2":
if (e.deduct2 = t.detail.value, e.deduct) return;
var i = parseFloat(a.realprice);
i += e.deduct2 ? -parseFloat(a.deductcredit2) : parseFloat(a.deductcredit2), a.realprice = i;
}
a.realprice <= 0 && (a.realprice = 1e-6), a.realprice = d.toFixed(a.realprice, 2),
this.setData({
data: e,
list: a
});
},
expressChange:function(t) {
var e = this
var tempdata = e.data;
console.log(e.data)
i.get("order/create/expressprice",{
express:t.detail.value,
weight:e.data.list.weight,
province:e.data.list.address.province
},function(t){
tempdata.list.realprice = tempdata.list.goodsprice+t.dispatch_price;
tempdata.list.dispatch_price = t.dispatch_price;
tempdata.express =
e.setData(tempdata)
})
},
listChange: function(t) {
var e = this.data.list;
switch (t.target.id) {
case "invoicename":
e.invoicename = t.detail.value;
break;
case "realname":
e.member.realname = t.detail.value;
break;
case "mobile":
e.member.mobile = t.detail.value;
}
this.setData({
list: e
});
},
url: function(t) {
var e = i.pdata(t).url;
wx.redirectTo({
url: e
});
},
onChange: function(t) {
return s.onChange(this, t);
},
DiyFormHandler: function(t) {
return s.DiyFormHandler(this, t);
},
selectArea: function(t) {
return s.selectArea(this, t);
},
bindChange: function(t) {
return s.bindChange(this, t);
},
onCancel: function(t) {
return s.onCancel(this, t);
},
onConfirm: function(t) {
s.onConfirm(this, t);
var e = this.data.pval,
a = this.data.areas,
i = this.data.areaDetail.detail;
i.province = a[e[0]].name, i.city = a[e[0]].city[e[1]].name, i.datavalue = a[e[0]].code + " " + a[e[0]].city[e[1]].code,
a[e[0]].city[e[1]].area && a[e[0]].city[e[1]].area.length > 0 ? (i.area = a[e[0]].city[e[1]].area[e[2]].name,
i.datavalue += " " + a[e[0]].city[e[1]].area[e[2]].code, this.getStreet(a, e)) : i.area = "",
i.street = "", this.setData({
"areaDetail.detail": i,
streetIndex: 0,
showPicker: !1
});
},
getIndex: function(t, e) {
return s.getIndex(t, e);
},
showaddressview: function(t) {
var e = "";
e = "open" == t.target.dataset.type, this.setData({
showaddressview: e
});
},
onChange2: function(t) {
var e = this,
a = e.data.areaDetail.detail,
i = t.currentTarget.dataset.type,
r = d.trim(t.detail.value);
"street" == i && (a.streetdatavalue = e.data.street[r].code, r = e.data.street[r].name),
a[i] = r, e.setData({
"areaDetail.detail": a
});
},
getStreet: function(t, e) {
if (t && e) {
var a = this;
if (a.data.areaDetail.detail.province && a.data.areaDetail.detail.city && this.data.openstreet) {
var r = t[e[0]].city[e[1]].code,
s = t[e[0]].city[e[1]].area[e[2]].code;
i.get("getstreet", {
city: r,
area: s
}, function(t) {
var e = t.street,
i = {
street: e
};
if (e && a.data.areaDetail.detail.streetdatavalue)
for (var r in e)
if (e[r].code == a.data.areaDetail.detail.streetdatavalue) {
i.streetIndex = r, a.setData({
"areaDetail.detail.street": e[r].name
});
break;
}
a.setData(i);
});
}
}
},
getQuickAddressDetail: function() {
var t = this,
e = t.data.id;
i.get("member/address/get_detail", {
id: e
}, function(e) {
var a = {
openstreet: e.openstreet,
show: !0
};
if (!d.isEmptyObject(e.detail)) {
var i = e.detail.province + " " + e.detail.city + " " + e.detail.area,
r = t.getIndex(i, t.data.areas);
a.pval = r, a.pvalOld = r, a.areaDetail.detail = e.detail;
}
t.setData(a), e.openstreet && r && t.getStreet(t.data.areas, r);
});
},
submitaddress: function() {
var t = this,
e = t.data.areaDetail.detail;
t.data.posting || ("" != e.realname && e.realname ? "" != e.mobile && e.mobile ? "" != e.city && e.city ? !(t.data.street.length > 0) || "" != e.street && e.street ? "" != e.address && e.address ? e.datavalue ? (e.id = 0,
t.setData({
posting: !0
}), i.post("member/address/submit", e, function(a) {
if (0 != a.error) return t.setData({
posting: !1
}), void r.toast(t, a.message);
e.id = a.addressid, t.setData({
showaddressview: !1,
"list.address": e
}), i.toast("保存成功");
})) : r.toast(t, "地址数据出错,请重新选择") : r.toast(t, "请填写详细地址") : r.toast(t, "请选择所在街道") : r.toast(t, "请选择所在地区") : r.toast(t, "请填写联系电话") : r.toast(t, "请填写收件人"));
},
giftPicker: function() {
this.setData({
active: "active",
gift: !0
});
},
emptyActive: function() {
this.setData({
active: "",
slider: "out",
tempname: "",
showcoupon: !1,
gift: !1
});
},
radioChange: function(t) {
this.setData({
giftid: t.currentTarget.dataset.giftgoodsid,
gift_title: t.currentTarget.dataset.title
});
},
sendclick: function() {
wx.navigateTo({
url: "/pages/map/index"
});
},
clearform: function() {
var t = this.data.diyform,
e = {};
d.each(t, function(a, i) {
d.each(i, function(a, i) {
5 == i.data_type && (t.f_data[i.diy_type].count = 0, t.f_data[i.diy_type].images = [],
e[i.diy_type] = t.f_data[i.diy_type]);
});
}), t.f_data = e, this.setData({
diyform: t
});
},
syclecancle: function() {
this.setData({
cycledate: !1
});
},
sycleconfirm: function() {
this.setData({
cycledate: !1
});
},
editdate: function(t) {
o.setSchedule(this), this.setData({
cycledate: !0,
create: !0
});
},
doDay: function(t) {
o.doDay(t, this);
},
selectDay: function(t) {
o.selectDay(t, this), o.setSchedule(this);
},
showinvoicepicker: function() {
var t = this.data.list;
0 == t.invoice_type && (t.invoice_info.entity = !0), 1 == t.invoice_type && (t.invoice_info.entity = !1),
this.setData({
invoicepicker: !0,
list: t
});
},
noinvoicepicker: function() {
this.setData({
invoicepicker: !1
});
},
clearinvoice: function() {
var t = this.data.list;
t.invoicename = "", this.setData({
invoicepicker: !1,
list: t
});
},
chaninvoice: function(t) {
var e = this.data.list;
"0" == t.currentTarget.dataset.type ? e.invoice_info.entity = !1 : e.invoice_info.entity = !0,
this.setData({
list: e
});
},
changeType: function(t) {
var e = this.data.list;
"0" == t.currentTarget.dataset.type ? e.invoice_info.company = !1 : e.invoice_info.company = !0,
this.setData({
list: e
});
},
invoicetitle: function(t) {
var e = this.data.list;
e.invoice_info.title = t.detail.value.replace(/\s+/g, ""), this.setData({
list: e
});
},
invoicenumber: function(t) {
var e = this.data.list;
e.invoice_info.number = t.detail.value.replace(/\s+/g, ""), this.setData({
list: e
});
},
confirminvoice: function() {
var t = this.data.list;
t.invoice_info.company || this.setData({
invoicenumber: ""
});
var e = t.invoice_info.entity ? "[纸质] " : "[电子] ",
a = t.invoice_info.title + " ",
i = t.invoice_info.company ? "(单位: " + t.invoice_info.number + ")" : "(个人)";
t.invoicename = e + a + i, t.invoice_info.title ? t.invoice_info.company && !t.invoice_info.number ? r.toast(this, "请填写税号") : this.setData({
list: t,
invoicepicker: !1
}) : r.toast(this, "请填写发票抬头");
},
selectCard: function() {
this.setData({
selectcard: "in"
});
},
cancalCard: function() {
this.setData({
cardid: ""
});
},
changecard: function(t) {
var e = this;
e.data.card_info, e.setData({
selectcard: "",
cardid: t.currentTarget.dataset.id
});
var a = t.currentTarget.dataset.id,
r = {
cardid: a,
goodsprice: this.data.list.goodsprice,
dispatch_price: this.data.list.dispatch_price,
discountprice: this.data.list.discountprice
};
i.post("order/create/getcardprice", r, function(t) {
if ("" != a)
if (0 == t.error) {
var r = {
carddiscount_rate: t.carddiscount_rate,
carddiscountprice: t.carddiscountprice,
cardid: t.cardid,
cardname: t.name,
dispatch_price: t.dispatch_price,
totalprice: t.totalprice,
comboprice: 0
};
e.setData(r), e.caculate(e.data.list);
} else i.alert(t.message);
else {
var s = {
cardid: "",
selectcard: "",
cardname: "",
carddiscountprice: 0,
ispackage: !1
},
o = (e.data.originalprice - e.data.list.goodsprice).toFixed(2);
e.data.options.goods && (s.ispackage = !0, s.comboprice = o), e.setData(s), d.isEmptyObject(e.data.list) || e.caculate(e.data.list);
}
}, !0);
},
closeCardModal: function() {
this.setData({
selectcard: ""
});
}
});
修改后端addons/ewei_shopv2/plugin/app/app/mobile/order/create.php文件修改三个方法(main\caculate\submit)增加一个方法(expressprice)
main()
{
// 如果是海外地址
if ($result['address']['isoverseas'] == '1') {
$result['taxtext'] = 'VAT税费';
$result['customstax'] = 0;
$result['dispatch_price'] = m('overseasexpress')->expressPrice($result['address']['province'],1,$shopweight,$address,$allgoods[0]['goods']);
$result['realprice'] += $result['dispatch_price'];
}
}
caculate()
{
if ($address['isoverseas'] == '1') {
$return_array['taxtext'] = 'VAT税费';
$return_array['taxprice'] = 0;
$return_array['address'] = $address;
$return_array['price'] = m('overseasexpress')->expressPrice($address['province'],1,$_GPC['weight'],$address,$goodsarr);
$return_array['express'] = $_GPC['express'];
}
}
submit()
{
// 道理同上!就不写了
}


