Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
doublescreen-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengguangpu
doublescreen-front
Commits
da16d384
Commit
da16d384
authored
Feb 25, 2020
by
gaodapeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs
parent
7debfeaa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
281 additions
and
294 deletions
+281
-294
apiurl.js
const/apiurl.js
+1
-1
balance.js
pages/balance/balance.js
+76
-73
home.js
pages/home/home.js
+4
-8
scan.js
pages/scan/scan.js
+64
-77
payUtils.js
utils/payUtils.js
+127
-126
scan.js
utils/scan.js
+9
-9
No files found.
const/apiurl.js
View file @
da16d384
...
@@ -10,5 +10,5 @@ export const API_CREATE_ORDER = "order/create";
...
@@ -10,5 +10,5 @@ export const API_CREATE_ORDER = "order/create";
export
const
API_PAY
=
"pay/micropay"
;
export
const
API_PAY
=
"pay/micropay"
;
//查询支付结果
//查询支付结果
export
const
API_QUERY
=
"order/query"
;
export
const
API_QUERY
=
"order/query"
;
//退款接口
export
const
API_REFUND
=
"order/refund"
;
export
const
API_REFUND
=
"order/refund"
;
\ No newline at end of file
pages/balance/balance.js
View file @
da16d384
var
api
=
require
(
"../../utils/api.js"
);
var
api
=
require
(
"../../utils/api.js"
);
var
payUtils
=
require
(
"../../utils/payUtils.js"
);
var
payUtils
=
require
(
"../../utils/payUtils.js"
);
import
{
ACTION_GO_SCAN
}
from
'../../const/actioncmd'
import
{
ACTION_GO_SCAN
,
ACTION_GO_HOME
}
from
'../../const/actioncmd'
import
{
ACTION_ON_PAY_SUCCESS
}
from
'../../const/actioncmd'
import
{
ACTION_ON_PAY_SUCCESS
}
from
'../../const/actioncmd'
import
{
ACTION_ON_PAY_FAILED
}
from
'../../const/actioncmd'
import
{
ACTION_ON_PAY_FAILED
}
from
'../../const/actioncmd'
Page
({
Page
({
data
:
{
data
:
{
goodsNum
:
0
,
goodsNum
:
0
,
payPrice
:
0.00
,
payPrice
:
0.00
,
totalPrice
:
0.00
,
totalPrice
:
0.00
,
couponPrice
:
0.00
,
couponPrice
:
0.00
,
qrPayShow
:
false
,
qrPayShow
:
false
,
list
:[],
list
:
[],
orderNo
:
""
,
orderNo
:
""
,
isCashierClosed
:
false
,
isCashierClosed
:
false
,
isPaying
:
false
,
isPaying
:
false
,
},
},
onLoad
(
options
)
{
onLoad
(
options
)
{
...
@@ -21,7 +21,7 @@ Page({
...
@@ -21,7 +21,7 @@ Page({
var
totalPrice
=
options
.
totalPrice
var
totalPrice
=
options
.
totalPrice
var
totalDisc
=
options
.
totalDisc
var
totalDisc
=
options
.
totalDisc
this
.
setData
({
this
.
setData
({
list
:
options
.
goods
,
list
:
options
.
goods
,
});
});
if
(
totalQuantity
!=
null
)
{
if
(
totalQuantity
!=
null
)
{
...
@@ -39,35 +39,38 @@ Page({
...
@@ -39,35 +39,38 @@ Page({
})
})
}
}
//商品数据
//商品数据
let
context
=
this
;
let
context
=
this
;
my
.
getStorage
({
my
.
getStorage
({
key
:
'goods'
,
key
:
'goods'
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
console
.
log
(
"商品信息 ===》 "
+
JSON
.
stringify
(
res
));
console
.
log
(
"商品信息 ===》 "
+
JSON
.
stringify
(
res
));
context
.
setData
({
context
.
setData
({
list
:
res
.
data
list
:
res
.
data
})
})
},
},
fail
:
function
(
res
)
{
fail
:
function
(
res
)
{
console
.
log
(
"商品信息 ===》 "
+
JSON
.
stringify
(
res
));
console
.
log
(
"商品信息 ===》 "
+
JSON
.
stringify
(
res
));
}
}
});
});
},
},
onShow
(){
onShow
()
{
my
.
ix
.
onBuddyMessage
({
my
.
ix
.
onBuddyMessage
({
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
info
(
`onBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
console
.
info
(
`onBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
if
(
res
.
action
==
ACTION_GO_SCAN
)
{
//返回扫码页
if
(
res
.
action
==
ACTION_GO_SCAN
)
{
//返回扫码页
//增加跳转回去的内容
//增加跳转回去的内容
my
.
navigateBack
();
my
.
navigateBack
();
}
else
{
}
else
if
(
res
.
action
==
ACTION_GO_HOME
)
{
//未知指令
//去首页
my
.
reLaunch
({
url
:
"/pages/home/home"
,
});
}
}
}
}
});
});
...
@@ -83,21 +86,21 @@ Page({
...
@@ -83,21 +86,21 @@ Page({
* @todo 支付结果的获取
* @todo 支付结果的获取
* @todo 跳转数据的保存
* @todo 跳转数据的保存
*/
*/
startPay
(){
startPay
()
{
//开始loading
//开始loading
my
.
showLoading
({});
my
.
showLoading
({});
//获取order
//获取order
var
payAmount
=
payUtils
.
yuan2Fen
(
this
.
data
.
payPrice
);
var
payAmount
=
payUtils
.
yuan2Fen
(
this
.
data
.
payPrice
);
payUtils
.
getOrder
(
/*payAmount*/
1
,
this
.
data
.
list
,
function
(
res
)
{
payUtils
.
getOrder
(
/*payAmount*/
1
,
this
.
data
.
list
,
function
(
res
)
{
if
(
res
!=
null
)
{
if
(
res
!=
null
)
{
console
.
log
(
"callback调用,res="
+
JSON
.
stringify
(
res
));
console
.
log
(
"callback调用,res="
+
JSON
.
stringify
(
res
));
if
(
res
.
resultCode
==
1
)
{
if
(
res
.
resultCode
==
1
)
{
this
.
setData
({
this
.
setData
({
orderNo
:
res
.
data
orderNo
:
res
.
data
});
});
this
.
payWithOpenCashier
(
res
.
data
);
this
.
payWithOpenCashier
(
res
.
data
);
}
}
}
}
}.
bind
(
this
));
}.
bind
(
this
));
...
@@ -106,10 +109,10 @@ Page({
...
@@ -106,10 +109,10 @@ Page({
/**
/**
* 打开收银台,进行扫码收款
* 打开收银台,进行扫码收款
*/
*/
payWithOpenCashier
(){
payWithOpenCashier
()
{
try
{
try
{
console
.
info
(
"收银台版本"
+
my
.
ix
.
getVersionSync
({
console
.
info
(
"收银台版本"
+
my
.
ix
.
getVersionSync
({
packageName
:
'zoloz.phone.android.alipay.com.dragonfly'
packageName
:
'zoloz.phone.android.alipay.com.dragonfly'
}).
versionName
);
}).
versionName
);
//开启收银台监听
//开启收银台监听
...
@@ -125,7 +128,7 @@ Page({
...
@@ -125,7 +128,7 @@ Page({
this
.
data
.
isCashierClosed
=
true
;
this
.
data
.
isCashierClosed
=
true
;
this
.
doPay
(
this
.
data
.
orderNo
,
res
.
barCode
);
this
.
doPay
(
this
.
data
.
orderNo
,
res
.
barCode
);
}
}
},
fail
:
(
res
)
=>
{
},
fail
:
(
res
)
=>
{
my
.
showToast
({
my
.
showToast
({
type
:
'exception'
,
type
:
'exception'
,
content
:
api
.
decodeErrorMessage
(
res
.
error
),
content
:
api
.
decodeErrorMessage
(
res
.
error
),
...
@@ -146,7 +149,7 @@ Page({
...
@@ -146,7 +149,7 @@ Page({
//如果正在支付中,则等待支付结果返回
//如果正在支付中,则等待支付结果返回
}
else
{
}
else
{
//跳转支付结果页面,说明支付已完成,无论取消支付还是支付成功等都跳转支付结果页
//跳转支付结果页面,说明支付已完成,无论取消支付还是支付成功等都跳转支付结果页
// if (this.data.actualPayPriceYuan != null) {
// if (this.data.actualPayPriceYuan != null) {
// my.redirectTo({
// my.redirectTo({
// //payPrice和couponPrice需要考虑支付宝优惠
// //payPrice和couponPrice需要考虑支付宝优惠
...
@@ -166,59 +169,59 @@ Page({
...
@@ -166,59 +169,59 @@ Page({
else
else
console
.
log
(
'RESULT: '
+
res
.
bizType
);
console
.
log
(
'RESULT: '
+
res
.
bizType
);
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
"收银台启动回调 异常==>"
+
JSON
.
stringify
(
err
));
console
.
log
(
"收银台启动回调 异常==>"
+
JSON
.
stringify
(
err
));
}
}
},
},
//调用收款接口
//调用收款接口
doPay
(
orderNo
,
payCode
)
{
doPay
(
orderNo
,
payCode
)
{
console
.
log
(
"doPay调用"
);
console
.
log
(
"doPay调用"
);
this
.
setData
({
isPaying
:
true
});
this
.
setData
({
isPaying
:
true
});
//使用barCode来当面付
//使用barCode来当面付
var
payAmount
=
payUtils
.
yuan2Fen
(
this
.
data
.
payPrice
);
var
payAmount
=
payUtils
.
yuan2Fen
(
this
.
data
.
payPrice
);
payUtils
.
startPay
(
orderNo
,
payCode
,
/*payAmount*/
1
,
this
.
data
.
list
,
function
(
res
)
{
payUtils
.
startPay
(
orderNo
,
payCode
,
/*payAmount*/
1
,
this
.
data
.
list
,
function
(
res
)
{
my
.
hideLoading
();
my
.
hideLoading
();
console
.
log
(
"支付回调 ===>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"支付回调 ===>"
+
JSON
.
stringify
(
res
));
this
.
setData
({
isPaying
:
false
});
this
.
setData
({
isPaying
:
false
});
if
(
res
==
null
)
{
if
(
res
==
null
)
{
return
;
return
;
}
}
if
(
res
.
resultCode
==
1
)
{
if
(
res
.
resultCode
==
1
)
{
//成功
//成功
console
.
log
(
"支付回调成功,跳转 "
);
console
.
log
(
"支付回调成功,跳转 "
);
// if(data.isCashierClosed == true){
// if(data.isCashierClosed == true){
my
.
ix
.
offCashierEventReceive
();
my
.
ix
.
offCashierEventReceive
();
this
.
saveData
(
this
.
data
.
list
,
res
.
data
);
this
.
saveData
(
this
.
data
.
list
,
res
.
data
);
my
.
redirectTo
({
my
.
redirectTo
({
url
:
'/pages/paysuccess/paysuccess'
,
url
:
'/pages/paysuccess/paysuccess'
,
});
});
//发送支付成功到后屏
//发送支付成功到后屏
my
.
ix
.
sendBuddyMessage
({
my
.
ix
.
sendBuddyMessage
({
// 填入目标小程序的 AppID
// 填入目标小程序的 AppID
target
:
getApp
().
globalData
.
backScreenAppId
,
target
:
getApp
().
globalData
.
backScreenAppId
,
data
:
{
data
:
{
action
:
ACTION_ON_PAY_SUCCESS
,
action
:
ACTION_ON_PAY_SUCCESS
,
data
:
res
.
data
data
:
res
.
data
},
},
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
info
(
`sendBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
console
.
info
(
`sendBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
},
},
fail
:
(
res
)
=>
{
fail
:
(
res
)
=>
{
console
.
info
(
`sendBuddyMessage failed:
${
JSON
.
stringify
(
res
)}
`
);
console
.
info
(
`sendBuddyMessage failed:
${
JSON
.
stringify
(
res
)}
`
);
}
}
});
});
// }
// }
}
else
{
}
else
{
console
.
log
(
"支付回调失败,toast提示 "
);
console
.
log
(
"支付回调失败,toast提示 "
);
my
.
ix
.
offCashierEventReceive
();
my
.
ix
.
offCashierEventReceive
();
my
.
showToast
({
my
.
showToast
({
type
:
'fail'
,
type
:
'fail'
,
content
:
res
.
message
,
content
:
res
.
message
,
duration
:
2000
duration
:
2000
});
});
//发送支付失败到后屏
//发送支付失败到后屏
my
.
ix
.
sendBuddyMessage
({
my
.
ix
.
sendBuddyMessage
({
...
@@ -239,7 +242,7 @@ Page({
...
@@ -239,7 +242,7 @@ Page({
}.
bind
(
this
));
}.
bind
(
this
));
},
},
/**
/**
* 保存最近支付成功的相关信息,每次支付成功都需刷新
* 保存最近支付成功的相关信息,每次支付成功都需刷新
* @param paySuccessGoodsList 支付成功的商品列表信息
* @param paySuccessGoodsList 支付成功的商品列表信息
...
@@ -255,6 +258,6 @@ Page({
...
@@ -255,6 +258,6 @@ Page({
data
:
paySuccessResponse
data
:
paySuccessResponse
});
});
},
},
});
});
pages/home/home.js
View file @
da16d384
var
api
=
require
(
"../../utils/api.js"
);
var
api
=
require
(
"../../utils/api.js"
);
import
{
Page
}
from
'../../utils/scan'
;
import
{
Page
}
from
'../../utils/scan'
;
import
{
API_USE_COUPON
}
from
'../../const/apiurl'
import
{
API_USE_COUPON
}
from
'../../const/apiurl'
import
{
API_REFUND
}
from
'../../const/apiurl'
import
{
ACTION_GO_SCAN
}
from
'../../const/actioncmd'
import
{
ACTION_GO_SCAN
}
from
'../../const/actioncmd'
import
{
ACTION_GET_ACCOUNT
}
from
'../../const/actioncmd'
import
{
ACTION_GET_ACCOUNT
}
from
'../../const/actioncmd'
import
{
ACTION_DIRECT_PAYMENT
}
from
'../../const/actioncmd'
import
{
ACTION_DIRECT_PAYMENT
}
from
'../../const/actioncmd'
...
@@ -10,7 +11,6 @@ import { ACTION_REFUND } from '../../const/actioncmd'
...
@@ -10,7 +11,6 @@ import { ACTION_REFUND } from '../../const/actioncmd'
import
{
ACTION_REFUND_FAILED
}
from
'../../const/actioncmd'
import
{
ACTION_REFUND_FAILED
}
from
'../../const/actioncmd'
import
{
ACTION_REFUND_SUCCESS
}
from
'../../const/actioncmd'
import
{
ACTION_REFUND_SUCCESS
}
from
'../../const/actioncmd'
import
{
ACTION_PRINT_LAST_ORDER
}
from
'../../const/actioncmd'
import
{
ACTION_PRINT_LAST_ORDER
}
from
'../../const/actioncmd'
import
{
API_REFUND
}
from
'../../const/apiurl'
Page
({
Page
({
...
@@ -118,6 +118,7 @@ Page({
...
@@ -118,6 +118,7 @@ Page({
dialogResultFailureRemind
:
"退款失败"
,
dialogResultFailureRemind
:
"退款失败"
,
dialogResultFailureText
:
"退款失败!无效的订单码"
,
dialogResultFailureText
:
"退款失败!无效的订单码"
,
});
});
console
.
log
(
"ACTION_REFUND"
);
}
else
if
(
res
.
action
==
ACTION_GO_HOME
)
{
}
else
if
(
res
.
action
==
ACTION_GO_HOME
)
{
//home界面收到,则返回界面上
//home界面收到,则返回界面上
...
@@ -315,13 +316,7 @@ Page({
...
@@ -315,13 +316,7 @@ Page({
});
});
},
},
//增加扫码内容,以及退款等操作的内容
onKeyPress
(
r
)
{
//只有在弹窗出现时才扫码
if
(
this
.
data
.
scanDialogDisplay
>
0
)
{
this
.
refund
(
r
);
}
},
//退款
//退款
refund
(
barcode
)
{
refund
(
barcode
)
{
...
@@ -402,4 +397,5 @@ Page({
...
@@ -402,4 +397,5 @@ Page({
});
});
pages/scan/scan.js
View file @
da16d384
var
api
=
require
(
"../../utils/api.js"
);
var
api
=
require
(
"../../utils/api.js"
);
import
{
Page
}
from
'../../utils/scan'
;
import
{
Page
}
from
'../../utils/scan'
;
import
{
API_SCAN
}
from
'../../const/apiurl'
import
{
API_SCAN
}
from
'../../const/apiurl'
import
{
API_USE_COUPON
}
from
'../../const/apiurl'
import
{
API_USE_COUPON
}
from
'../../const/apiurl'
import
{
ACTION_GOODS
}
from
'../../const/actioncmd'
import
{
ACTION_GOODS
}
from
'../../const/actioncmd'
import
{
ACTION_REQUEST_GOOD_INFO
}
from
'../../const/actioncmd'
import
{
ACTION_REQUEST_GOOD_INFO
}
from
'../../const/actioncmd'
import
{
ACTION_GO_BALANCE
}
from
'../../const/actioncmd'
import
{
ACTION_GO_BALANCE
}
from
'../../const/actioncmd'
...
@@ -13,62 +13,48 @@ Page({
...
@@ -13,62 +13,48 @@ Page({
//单位是元
//单位是元
totalPrice
:
0.00
,
totalPrice
:
0.00
,
totalQuantity
:
0
,
totalQuantity
:
0
,
totalDisc
:
0.00
,
totalDisc
:
0.00
,
memberPhone
:
''
,
memberPhone
:
''
,
memberPoint
:
0
memberPoint
:
0
},
},
onLoad
:
function
(
options
)
{
onLoad
:
function
(
options
)
{
var
barcode
=
options
.
barcode
var
barcode
=
options
.
barcode
if
(
barcode
!=
null
)
{
if
(
barcode
!=
null
)
{
console
.
log
(
"首页传递过来的商品条码是 "
+
barcode
);
console
.
log
(
"首页传递过来的商品条码是 "
+
barcode
);
this
.
getGoodInfoByBarcode
(
barcode
)
this
.
getGoodInfoByBarcode
(
barcode
)
}
}
},
},
onShow
()
{
onShow
()
{
//开启后屏监听
//开启后屏监听
let
context
=
this
;
let
context
=
this
;
my
.
ix
.
onBuddyMessage
({
my
.
ix
.
onBuddyMessage
({
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
info
(
`onBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
console
.
info
(
`onBuddyMessage success:
${
JSON
.
stringify
(
res
)}
`
);
if
(
res
.
action
==
ACTION_GOODS
)
{
if
(
res
.
action
==
ACTION_GOODS
)
{
//商品信息同步
//商品信息同步
let
viewGoodsInfo
=
res
.
data
let
viewGoodsInfo
=
res
.
data
context
.
setData
({
context
.
setData
({
goods
:
viewGoodsInfo
.
goods
,
goods
:
viewGoodsInfo
.
goods
,
totalPrice
:
viewGoodsInfo
.
totalPrice
,
totalPrice
:
viewGoodsInfo
.
totalPrice
,
totalQuantity
:
viewGoodsInfo
.
totalQuantity
,
totalQuantity
:
viewGoodsInfo
.
totalQuantity
,
totalDisc
:
viewGoodsInfo
.
totalDisc
,
totalDisc
:
viewGoodsInfo
.
totalDisc
,
})
}
else
if
(
res
.
action
==
ACTION_GO_BALANCE
)
{
//去结算页面
context
.
goBalance
();
my
.
ix
.
sendBuddyMessage
({
target
:
getApp
().
globalData
.
backScreenAppId
,
data
:
{
action
:
ACTION_GO_BALANCE
,
data
:
null
},
success
:
(
res
)
=>
{
console
.
log
(
"发送商品数据到后屏小程序成功 ===》"
+
JSON
.
stringify
(
res
));
},
fail
:
(
res
)
=>
{
console
.
log
(
"发送商品数据到后屏小程序 失败 ===》 "
+
JSON
.
stringify
(
res
));
//发送失败重试
}
})
})
}
else
if
(
res
.
action
==
ACTION_REQUEST_GOOD_INFO
){
//去结算页面
}
else
if
(
res
.
action
==
ACTION_GO_BALANCE
)
{
context
.
getGoodInfoByBarcode
(
res
.
data
);
//去结算页面
}
else
if
(
res
.
action
==
ACTION_GO_HOME
){
context
.
goBalance
();
//去首页
}
else
if
(
res
.
action
==
ACTION_REQUEST_GOOD_INFO
)
{
my
.
reLaunch
({
//去结算页面
url
:
"/pages/home/home"
,
context
.
getGoodInfoByBarcode
(
res
.
data
);
});
}
else
if
(
res
.
action
==
ACTION_GO_HOME
)
{
}
//去首页
my
.
reLaunch
({
url
:
"/pages/home/home"
,
});
}
}
}
});
});
},
},
...
@@ -137,12 +123,12 @@ Page({
...
@@ -137,12 +123,12 @@ Page({
//转化商品信息
//转化商品信息
parseGoodInfo
(
goodinfo
)
{
parseGoodInfo
(
goodinfo
)
{
//价格 分转元
//价格 分转元
goodinfo
.
quantity
=
1
;
goodinfo
.
quantity
=
1
;
goodinfo
.
price
=
goodinfo
.
price
/
100
goodinfo
.
price
=
goodinfo
.
price
/
100
goodinfo
.
salePrice
=
goodinfo
.
salePrice
/
100
goodinfo
.
salePrice
=
goodinfo
.
salePrice
/
100
goodinfo
.
discnt
=
goodinfo
.
discnt
/
100
goodinfo
.
discnt
=
goodinfo
.
discnt
/
100
//总数量
//总数量
let
totalQuantityTemp
=
0
let
totalQuantityTemp
=
0
...
@@ -155,60 +141,61 @@ Page({
...
@@ -155,60 +141,61 @@ Page({
let
goodstemp
=
[]
let
goodstemp
=
[]
let
goodtemp
let
goodtemp
lastgoods
.
forEach
(
function
(
item
,
index
,
array
)
{
lastgoods
.
forEach
(
function
(
item
,
index
,
array
)
{
if
(
item
.
barcode
==
goodinfo
.
barcode
)
{
if
(
item
.
barcode
==
goodinfo
.
barcode
)
{
let
quantitytemp
=
item
.
quantity
let
quantitytemp
=
item
.
quantity
item
.
quantity
=
quantitytemp
+
1
item
.
quantity
=
quantitytemp
+
1
isHasSame
=
true
isHasSame
=
true
goodtemp
=
item
goodtemp
=
item
}
else
{
}
else
{
totalQuantityTemp
=
totalQuantityTemp
+
item
.
quantity
totalQuantityTemp
=
totalQuantityTemp
+
item
.
quantity
totalPriceTemp
=
totalPriceTemp
+
item
.
price
*
item
.
quantity
totalPriceTemp
=
totalPriceTemp
+
item
.
price
*
item
.
quantity
goodstemp
.
push
(
item
)
goodstemp
.
push
(
item
)
}
}
})
if
(
isHasSame
){
totalQuantityTemp
=
totalQuantityTemp
+
goodtemp
.
quantity
totalPriceTemp
=
totalPriceTemp
+
goodtemp
.
price
*
goodtemp
.
quantity
let
nowgoods
=
[]
})
nowgoods
.
push
(
goodtemp
);
if
(
isHasSame
)
{
var
newgoods
=
nowgoods
.
concat
(
goodstemp
)
totalQuantityTemp
=
totalQuantityTemp
+
goodtemp
.
quantity
this
.
setData
({
goods
:
newgoods
})
totalPriceTemp
=
totalPriceTemp
+
goodtemp
.
price
*
goodtemp
.
quantity
}
else
{
totalQuantityTemp
=
totalQuantityTemp
+
1
let
nowgoods
=
[]
totalPriceTemp
=
totalPriceTemp
+
goodinfo
.
price
nowgoods
.
push
(
goodtemp
);
let
nowgoods
=
[]
var
newgoods
=
nowgoods
.
concat
(
goodstemp
)
nowgoods
.
push
(
goodinfo
);
this
.
setData
({
goods
:
newgoods
})
var
newgoods
=
nowgoods
.
concat
(
lastgoods
)
}
else
{
this
.
setData
({
goods
:
newgoods
})
totalQuantityTemp
=
totalQuantityTemp
+
1
totalPriceTemp
=
totalPriceTemp
+
goodinfo
.
price
let
nowgoods
=
[]
nowgoods
.
push
(
goodinfo
);
var
newgoods
=
nowgoods
.
concat
(
lastgoods
)
this
.
setData
({
goods
:
newgoods
})
}
}
//汇总
this
.
setData
({
totalQuantity
:
totalQuantityTemp
,
totalPrice
:
totalPriceTemp
,
})
//同步信息到后端
//汇总
this
.
sendGoodInfoToBack
();
this
.
setData
({
totalQuantity
:
totalQuantityTemp
,
totalPrice
:
totalPriceTemp
,
})
//同步信息到后端
this
.
sendGoodInfoToBack
();
},
},
//把所有的商品数据发送到后屏
//把所有的商品数据发送到后屏
sendGoodInfoToBack
()
{
sendGoodInfoToBack
()
{
let
context
=
this
;
let
context
=
this
;
var
commonRequest
=
{
var
commonRequest
=
{
action
:
ACTION_GOODS
,
action
:
ACTION_GOODS
,
data
:
this
.
data
data
:
this
.
data
};
};
my
.
ix
.
sendBuddyMessage
({
my
.
ix
.
sendBuddyMessage
({
target
:
getApp
().
globalData
.
backScreenAppId
,
target
:
getApp
().
globalData
.
backScreenAppId
,
data
:
commonRequest
,
data
:
commonRequest
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
log
(
"发送商品数据到后屏小程序成功 ===》"
+
JSON
.
stringify
(
res
));
console
.
log
(
"发送商品数据到后屏小程序成功 ===》"
+
JSON
.
stringify
(
res
));
},
},
fail
:
(
res
)
=>
{
fail
:
(
res
)
=>
{
console
.
log
(
"发送商品数据到后屏小程序 失败 ===》 "
+
JSON
.
stringify
(
res
));
console
.
log
(
"发送商品数据到后屏小程序 失败 ===》 "
+
JSON
.
stringify
(
res
));
//发送失败重试
//发送失败重试
context
.
sendGoodInfoToBack
();
context
.
sendGoodInfoToBack
();
}
}
...
...
utils/payUtils.js
View file @
da16d384
var
api
=
require
(
"/utils/api.js"
);
var
api
=
require
(
"/utils/api.js"
);
import
{
API_CREATE_ORDER
}
from
'/const/apiurl'
import
{
API_CREATE_ORDER
}
from
'/const/apiurl'
import
{
API_PAY
}
from
'/const/apiurl'
import
{
API_PAY
}
from
'/const/apiurl'
import
{
API_QUERY
}
from
'/const/apiurl'
import
{
API_QUERY
}
from
'/const/apiurl'
/**
/**
* tradeAmount int
* tradeAmount int
...
@@ -17,16 +17,17 @@ import{API_QUERY} from'/const/apiurl'
...
@@ -17,16 +17,17 @@ import{API_QUERY} from'/const/apiurl'
*
*
*/
*/
function
getOrder
(
function
getOrder
(
tradeAmount
,
tradeAmount
,
list
,
//物品列表
list
,
//物品列表
callback
callback
){
)
{
if
(
checkGoodsList
(
list
)
!=
true
){
// if (checkGoodsList(list) != true) {
console
.
log
(
"物品列表不是数组"
);
// console.log("物品列表不是数组");
callback
({
resultCode
:
-
1
,
message
:
"物品列表不是数组"
});
// callback({ resultCode: -1, message: "物品列表不是数组" });
return
// return;
}
// }
var
app
=
getApp
();
var
app
=
getApp
();
var
orderCreateRequest
=
api
.
createCommonRequest
();
var
orderCreateRequest
=
api
.
createCommonRequest
();
if
(
app
.
globalData
.
localAccountInfo
!=
null
)
{
if
(
app
.
globalData
.
localAccountInfo
!=
null
)
{
...
@@ -36,38 +37,38 @@ function getOrder(
...
@@ -36,38 +37,38 @@ function getOrder(
orderCreateRequest
.
deviceType
=
"ALIPAY"
;
orderCreateRequest
.
deviceType
=
"ALIPAY"
;
orderCreateRequest
.
list
=
list
;
orderCreateRequest
.
list
=
list
;
orderCreateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
orderCreateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
console
.
log
(
"请求创建订单 ==>"
+
JSON
.
stringify
(
orderCreateRequest
));
console
.
log
(
"请求创建订单 ==>"
+
JSON
.
stringify
(
orderCreateRequest
));
var
orderUrl
=
getApp
().
globalData
.
BASE_URL
+
API_CREATE_ORDER
;
var
orderUrl
=
getApp
().
globalData
.
BASE_URL
+
API_CREATE_ORDER
;
console
.
log
(
"createOrderUrl"
+
orderUrl
);
console
.
log
(
"createOrderUrl"
+
orderUrl
);
my
.
request
({
my
.
request
({
url
:
orderUrl
,
url
:
orderUrl
,
method
:
'POST'
,
method
:
'POST'
,
dataType
:
'json'
,
dataType
:
'json'
,
timeout
:
30000
,
timeout
:
30000
,
data
:
orderCreateRequest
,
data
:
orderCreateRequest
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
//判断返回值
//判断返回值
if
(
res
.
data
.
success
!=
true
)
{
if
(
res
.
data
.
success
!=
true
)
{
console
.
log
(
"创建订单接口返回失败 ==>"
+
JSON
.
stringify
(
res
.
data
));
console
.
log
(
"创建订单接口返回失败 ==>"
+
JSON
.
stringify
(
res
.
data
));
callback
({
resultCode
:
-
1
,
message
:
"获取订单号失败"
});
callback
({
resultCode
:
-
1
,
message
:
"获取订单号失败"
});
}
else
{
}
else
{
if
(
res
.
data
.
data
!=
null
){
//返回值有效
if
(
res
.
data
.
data
!=
null
)
{
//返回值有效
var
response
=
{
resultCode
:
1
,
message
:
"获取订单号成功"
,
data
:
res
.
data
.
data
};
var
response
=
{
resultCode
:
1
,
message
:
"获取订单号成功"
,
data
:
res
.
data
.
data
};
callback
(
response
);
callback
(
response
);
}
console
.
log
(
"创建订单成功 ==>"
+
JSON
.
stringify
(
res
));
}
}
},
console
.
log
(
"创建订单成功 ==>"
+
JSON
.
stringify
(
res
));
fail
:
(
res
)
=>
{
console
.
log
(
"创建订单接口调用失败 ==>"
+
JSON
.
stringify
(
res
)
+
"
\
terror:"
+
res
.
error
);
my
.
showToast
({
type
:
'exception'
,
content
:
api
.
decodeErrorMessage
(
res
.
error
),
duration
:
2000
});
callback
({
resultCode
:
-
1
,
message
:
"获取订单号失败"
});
}
}
});
},
fail
:
(
res
)
=>
{
console
.
log
(
"创建订单接口调用失败 ==>"
+
JSON
.
stringify
(
res
)
+
"
\
terror:"
+
res
.
error
);
my
.
showToast
({
type
:
'exception'
,
content
:
api
.
decodeErrorMessage
(
res
.
error
),
duration
:
2000
});
callback
({
resultCode
:
-
1
,
message
:
"获取订单号失败"
});
}
});
}
}
...
@@ -80,19 +81,19 @@ function getOrder(
...
@@ -80,19 +81,19 @@ function getOrder(
* barcode string
* barcode string
*
*
*/
*/
function
checkGoodsList
(
list
){
function
checkGoodsList
(
list
)
{
if
((
list
instanceof
Array
)
!==
true
)
{
if
((
list
instanceof
Array
)
!==
true
)
{
console
.
log
(
"数组判断有效"
);
console
.
log
(
"数组判断有效"
);
return
false
;
return
false
;
}
}
if
(
list
.
length
>
0
)
{
if
(
list
.
length
>
0
)
{
var
tempGoods
;
var
tempGoods
;
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
tempGoods
=
list
[
i
];
tempGoods
=
list
[
i
];
if
(
tempGoods
==
null
)
{
if
(
tempGoods
==
null
)
{
continue
;
continue
;
}
}
if
(
tempGoods
.
price
==
0
||
tempGoods
.
salePrice
==
0
)
{
if
(
tempGoods
.
price
==
0
||
tempGoods
.
salePrice
==
0
)
{
return
false
;
return
false
;
}
}
}
}
...
@@ -108,13 +109,13 @@ function checkGoodsList(list){
...
@@ -108,13 +109,13 @@ function checkGoodsList(list){
* quantity
* quantity
* activityId
* activityId
*/
*/
function
transGoodsList
(
originList
){
function
transGoodsList
(
originList
)
{
var
newList
=
[];
var
newList
=
[];
var
tempOldGoods
;
var
tempOldGoods
;
var
tempNewGoods
;
var
tempNewGoods
;
for
(
i
=
0
;
i
<
originList
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
originList
.
length
;
i
++
)
{
tempOldGoods
=
originList
[
i
];
tempOldGoods
=
originList
[
i
];
if
(
tempOldGoods
==
null
)
{
if
(
tempOldGoods
==
null
)
{
continue
;
continue
;
}
}
tempNewGoods
=
{};
tempNewGoods
=
{};
...
@@ -141,8 +142,8 @@ function transGoodsList(originList){
...
@@ -141,8 +142,8 @@ function transGoodsList(originList){
* merchantId 商户id
* merchantId 商户id
// * operatorId 操作员id
// * operatorId 操作员id
*/
*/
function
onPaySuccess
(
res
,
callback
){
function
onPaySuccess
(
res
,
callback
)
{
var
response
=
{
resultCode
:
1
,
message
:
"支付成功"
,
data
:{}
};
var
response
=
{
resultCode
:
1
,
message
:
"支付成功"
,
data
:
{}
};
//todo 返回正确数据到调用方
//todo 返回正确数据到调用方
response
.
data
=
res
;
response
.
data
=
res
;
//或者可以解析出来res的内容,然后重组发给外界
//或者可以解析出来res的内容,然后重组发给外界
...
@@ -150,8 +151,8 @@ function onPaySuccess(res, callback){
...
@@ -150,8 +151,8 @@ function onPaySuccess(res, callback){
}
}
function
startPay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
){
function
startPay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
)
{
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
0
);
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
0
);
}
}
/**
/**
* @todo 写支付
* @todo 写支付
...
@@ -170,7 +171,7 @@ function startPay(tradeNo, payCode, payPrice, list, callback){
...
@@ -170,7 +171,7 @@ function startPay(tradeNo, payCode, payPrice, list, callback){
quantity
quantity
activityId
activityId
*/
*/
function
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
){
function
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
)
{
var
payRequest
=
api
.
createCommonRequest
();
var
payRequest
=
api
.
createCommonRequest
();
payRequest
.
tradeNo
=
tradeNo
;
payRequest
.
tradeNo
=
tradeNo
;
payRequest
.
channel
=
"alipay"
;
payRequest
.
channel
=
"alipay"
;
...
@@ -182,7 +183,7 @@ function pay(tradeNo, payCode, payPrice, list, callback, retryCount){
...
@@ -182,7 +183,7 @@ function pay(tradeNo, payCode, payPrice, list, callback, retryCount){
payRequest
.
authCode
=
payCode
;
payRequest
.
authCode
=
payCode
;
payRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
payRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
var
payUrl
=
getApp
().
globalData
.
BASE_URL
+
API_PAY
;
var
payUrl
=
getApp
().
globalData
.
BASE_URL
+
API_PAY
;
console
.
log
(
"pay ===> url:"
+
payUrl
+
"
\
t body"
+
JSON
.
stringify
(
payRequest
));
console
.
log
(
"pay ===> url:"
+
payUrl
+
"
\
t body"
+
JSON
.
stringify
(
payRequest
));
my
.
request
({
my
.
request
({
url
:
payUrl
,
url
:
payUrl
,
method
:
'POST'
,
method
:
'POST'
,
...
@@ -190,24 +191,24 @@ function pay(tradeNo, payCode, payPrice, list, callback, retryCount){
...
@@ -190,24 +191,24 @@ function pay(tradeNo, payCode, payPrice, list, callback, retryCount){
timeout
:
30000
,
timeout
:
30000
,
data
:
payRequest
,
data
:
payRequest
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
log
(
"支付接口回掉 ==>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"支付接口回掉 ==>"
+
JSON
.
stringify
(
res
));
//增加数据判断,增加重试
//增加数据判断,增加重试
console
.
log
(
"支付接口回调 ==>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"支付接口回调 ==>"
+
JSON
.
stringify
(
res
));
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
console
.
log
(
"支付未成功 ==>"
+
JSON
.
stringify
(
res
.
data
.
message
));
console
.
log
(
"支付未成功 ==>"
+
JSON
.
stringify
(
res
.
data
.
message
));
retryOrFailed
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
);
retryOrFailed
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
);
}
else
{
console
.
log
(
"支付返回值 ==>"
+
JSON
.
stringify
(
res
.
data
));
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
)
{
onPaySuccess
(
res
.
data
.
data
,
callback
);
}
else
if
(
res
.
data
.
data
.
tradeStatus
==
"1"
)
{
//需要查询结果
//轮询查询,最多12次
queryPayStateWithRetry
(
tradeNo
,
callback
,
0
);
}
else
{
}
else
{
console
.
log
(
"支付返回值 ==>"
+
JSON
.
stringify
(
res
.
data
));
//查询一次
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
){
queryPayState
(
tradeNo
,
callback
);
onPaySuccess
(
res
.
data
.
data
,
callback
);
}
else
if
(
res
.
data
.
data
.
tradeStatus
==
"1"
){
//需要查询结果
//轮询查询,最多12次
queryPayStateWithRetry
(
tradeNo
,
callback
,
0
);
}
else
{
//查询一次
queryPayState
(
tradeNo
,
callback
);
}
}
}
}
},
},
fail
:
(
res
)
=>
{
fail
:
(
res
)
=>
{
console
.
log
(
"支付失败 ==>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"支付失败 ==>"
+
JSON
.
stringify
(
res
));
...
@@ -226,34 +227,34 @@ function sleep(numberMillis) {
...
@@ -226,34 +227,34 @@ function sleep(numberMillis) {
}
}
}
}
function
retryOrFailed
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
){
function
retryOrFailed
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
retryCount
)
{
if
(
retryCount
<
12
)
{
if
(
retryCount
<
12
)
{
sleep
(
5000
);
sleep
(
5000
);
console
.
log
(
"重试中...重试次数: ==>"
+
(
retryCount
+
1
));
console
.
log
(
"重试中...重试次数: ==>"
+
(
retryCount
+
1
));
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
++
retryCount
);
pay
(
tradeNo
,
payCode
,
payPrice
,
list
,
callback
,
++
retryCount
);
}
else
{
}
else
{
console
.
log
(
"支付接口重试超限,支付失败"
);
console
.
log
(
"支付接口重试超限,支付失败"
);
var
response
=
{
resultCode
:
-
1
,
message
:
"支付接口重试超限,支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付接口重试超限,支付失败"
};
callback
(
response
);
callback
(
response
);
}
}
}
}
/**
/**
* 带重试的查询
* 带重试的查询
*/
*/
function
queryPayStateWithRetry
(
tradeNo
,
callback
,
retryCount
){
function
queryPayStateWithRetry
(
tradeNo
,
callback
,
retryCount
)
{
if
(
retryCount
>=
12
)
{
if
(
retryCount
>=
12
)
{
console
.
log
(
"支付接口重试超限,支付失败"
);
console
.
log
(
"支付接口重试超限,支付失败"
);
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
return
;
return
;
}
}
var
queryStateRequest
=
api
.
createCommonRequest
();
var
queryStateRequest
=
api
.
createCommonRequest
();
queryStateRequest
.
tradeNo
=
tradeNo
;
queryStateRequest
.
tradeNo
=
tradeNo
;
queryStateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
queryStateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
var
queryUrl
=
getApp
().
globalData
.
BASE_URL
+
API_QUERY
;
var
queryUrl
=
getApp
().
globalData
.
BASE_URL
+
API_QUERY
;
console
.
log
(
"开始查询状态==> url:"
+
queryUrl
+
"
\
trequest:"
+
JSON
.
stringify
(
queryStateRequest
));
console
.
log
(
"开始查询状态==> url:"
+
queryUrl
+
"
\
trequest:"
+
JSON
.
stringify
(
queryStateRequest
));
my
.
request
({
my
.
request
({
url
:
queryUrl
,
url
:
queryUrl
,
method
:
'POST'
,
method
:
'POST'
,
...
@@ -261,30 +262,30 @@ function queryPayStateWithRetry(tradeNo, callback, retryCount){
...
@@ -261,30 +262,30 @@ function queryPayStateWithRetry(tradeNo, callback, retryCount){
timeout
:
30000
,
timeout
:
30000
,
data
:
queryStateRequest
,
data
:
queryStateRequest
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
console
.
log
(
"支付结果回掉"
+
JSON
.
stringify
(
res
));
console
.
log
(
"支付结果回掉"
+
JSON
.
stringify
(
res
));
//增加数据判断,增加重试
//增加数据判断,增加重试
console
.
log
(
"查询结果"
+
JSON
.
stringify
(
res
));
console
.
log
(
"查询结果"
+
JSON
.
stringify
(
res
));
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
//不知名原因导致失败,直接报失败
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
//不知名原因导致失败,直接报失败
console
.
log
(
"查询失败,支付失败"
);
console
.
log
(
"查询失败,支付失败"
);
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
}
else
{
}
else
{
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
){
//成功直接报成功
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
)
{
//成功直接报成功
onPaySuccess
(
res
.
data
.
data
,
callback
);
onPaySuccess
(
res
.
data
.
data
,
callback
);
}
else
if
(
res
.
data
.
data
.
tradeStatus
==
"1"
){
//需要查询结果,继续轮询
}
else
if
(
res
.
data
.
data
.
tradeStatus
==
"1"
)
{
//需要查询结果,继续轮询
console
.
log
(
"查询结果显示支付未成功,重试 "
);
console
.
log
(
"查询结果显示支付未成功,重试 "
);
sleep
(
5000
);
sleep
(
5000
);
queryPayStateWithRetry
(
tradeNo
,
callback
,
++
retryCount
);
queryPayStateWithRetry
(
tradeNo
,
callback
,
++
retryCount
);
}
else
{
//其他状况直接报失败
}
else
{
//其他状况直接报失败
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
}
}
}
}
},
},
fail
:
(
res
)
=>
{
//接口访问失败,继续轮询
fail
:
(
res
)
=>
{
//接口访问失败,继续轮询
console
.
log
(
"查询失败 ==>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"查询失败 ==>"
+
JSON
.
stringify
(
res
));
sleep
(
5000
);
sleep
(
5000
);
queryPayStateWithRetry
(
tradeNo
,
callback
,
++
retryCount
);
queryPayStateWithRetry
(
tradeNo
,
callback
,
++
retryCount
);
}
}
});
});
}
}
...
@@ -292,13 +293,13 @@ function queryPayStateWithRetry(tradeNo, callback, retryCount){
...
@@ -292,13 +293,13 @@ function queryPayStateWithRetry(tradeNo, callback, retryCount){
/**
/**
* 不带重试的查询
* 不带重试的查询
*/
*/
function
queryPayState
(
tradeNo
,
callback
){
function
queryPayState
(
tradeNo
,
callback
)
{
var
queryStateRequest
=
api
.
createCommonRequest
();
var
queryStateRequest
=
api
.
createCommonRequest
();
queryStateRequest
.
tradeNo
=
tradeNo
;
queryStateRequest
.
tradeNo
=
tradeNo
;
queryStateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
queryStateRequest
.
batchNo
=
""
+
Date
.
parse
(
new
Date
());
var
queryUrl
=
getApp
().
globalData
.
BASE_URL
+
API_QUERY
;
var
queryUrl
=
getApp
().
globalData
.
BASE_URL
+
API_QUERY
;
console
.
log
(
"开始查询状态==> url:"
+
queryUrl
+
"
\
trequest:"
+
JSON
.
stringify
(
queryStateRequest
));
console
.
log
(
"开始查询状态==> url:"
+
queryUrl
+
"
\
trequest:"
+
JSON
.
stringify
(
queryStateRequest
));
my
.
request
({
my
.
request
({
url
:
queryUrl
,
url
:
queryUrl
,
method
:
'POST'
,
method
:
'POST'
,
...
@@ -306,25 +307,25 @@ function queryPayState(tradeNo, callback){
...
@@ -306,25 +307,25 @@ function queryPayState(tradeNo, callback){
timeout
:
30000
,
timeout
:
30000
,
data
:
queryStateRequest
,
data
:
queryStateRequest
,
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
//增加数据判断,增加重试
//增加数据判断,增加重试
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
//不知名原因导致失败,直接报失败
if
(
res
==
null
||
res
.
data
==
null
||
res
.
data
.
success
!=
true
||
res
.
data
.
data
==
null
)
{
//不知名原因导致失败,直接报失败
console
.
log
(
"查询失败,支付失败"
);
console
.
log
(
"查询失败,支付失败"
);
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
}
else
{
}
else
{
console
.
log
(
"查询结果 ==>"
+
JSON
.
stringify
(
res
.
data
));
console
.
log
(
"查询结果 ==>"
+
JSON
.
stringify
(
res
.
data
));
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
){
//成功直接报成功
if
(
res
.
data
.
data
.
tradeStatus
==
"3"
)
{
//成功直接报成功
onPaySuccess
(
res
.
data
.
data
,
callback
);
onPaySuccess
(
res
.
data
.
data
,
callback
);
}
else
{
//其他状况直接报失败
}
else
{
//其他状况直接报失败
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
}
}
}
}
},
},
fail
:
(
res
)
=>
{
//接口访问失败,继续轮询
fail
:
(
res
)
=>
{
//接口访问失败,继续轮询
console
.
log
(
"查询失败 ==>"
+
JSON
.
stringify
(
res
));
console
.
log
(
"查询失败 ==>"
+
JSON
.
stringify
(
res
));
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
var
response
=
{
resultCode
:
-
1
,
message
:
"支付失败"
};
callback
(
response
);
callback
(
response
);
}
}
});
});
}
}
...
...
utils/scan.js
View file @
da16d384
...
@@ -9,20 +9,20 @@ export default class scan {
...
@@ -9,20 +9,20 @@ export default class scan {
if
(
!
page
.
_keyEventListener
)
{
if
(
!
page
.
_keyEventListener
)
{
my
.
ix
.
onKeyEventChange
(
page
.
_keyEventListener
=
(
r
)
=>
{
my
.
ix
.
onKeyEventChange
(
page
.
_keyEventListener
=
(
r
)
=>
{
let
cur
=
getCurrentPages
().
slice
(
-
1
)[
0
];
let
cur
=
getCurrentPages
().
slice
(
-
1
)[
0
];
if
(
cur
&&
cur
.
onKeyPress
){
if
(
cur
&&
cur
.
onKeyPress
)
{
if
(
isScaning
==
false
)
{
if
(
isScaning
==
false
)
{
isScaning
=
true
isScaning
=
true
code
=
(
r
.
keyCode
-
7
)
+
''
code
=
(
r
.
keyCode
-
7
)
+
''
setTimeout
(()
=>
{
setTimeout
(()
=>
{
cur
.
onKeyPress
.
call
(
cur
,
code
);
cur
.
onKeyPress
.
call
(
cur
,
code
);
isScaning
=
false
isScaning
=
false
},
5
00
);
},
7
00
);
}
else
{
}
else
{
//特殊处理 keycode需要减7
//特殊处理 keycode需要减7
code
=
code
+
(
r
.
keyCode
-
7
)
code
=
code
+
(
r
.
keyCode
-
7
)
}
}
}
}
});
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment