ShopModel.lua
7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
cc.exports.ShopModel = {}
function ShopModel.init()
cmsg.on("gateway_msg.notify_pay_succ_msg_res",ShopModel.onPayResFun);
end
function ShopModel.onPayResFun(params)
local product = params.data.product;
print("产品订购成功:"..product);
local payInfo = ShopInfo.getPayInfoByProduct(product);
if payInfo then
local params = nil;
if payInfo.type == 1 then
params = payInfo.rmb.."&"..payInfo.itemList[1].num;
UmengHelper.onEvent("coupons_buy_"..payInfo.itemList[1].num);
print("购买点券:".."coupons_buy_"..payInfo.itemList[1].num);
elseif payInfo.type == 2 then
UserModel.addVip(payInfo.id);
params = payInfo.rmb.."&"..1;
if payInfo.id == 201 then
UmengHelper.onEvent("buy_vip_month");
print("购买vip月卡");
elseif payInfo.id == 202 then
UmengHelper.onEvent("buy_vip_season");
print("购买vip季卡");
end
elseif payInfo.type == 3 then
UserModel.addFirstPayID(payInfo.id);
params = payInfo.rmb.."&"..1;
UmengHelper.onEvent("buy_first_gift&rmb,"..payInfo.rmb);
print("购买首充礼包:".."buy_first_gift&rmb,"..payInfo.rmb);
elseif payInfo.type == 4 then
UserModel.addFirstPayDailyID(payInfo.id);
params = payInfo.rmb.."&"..1;
UmengHelper.onEvent("buy_first_daily_gift&rmb,"..payInfo.rmb);
print("购买每日首充礼包:".."buy_first_daily_gift&rmb,"..payInfo.rmb);
elseif payInfo.type == 5 then
UserModel.addFirstCyclePayID(payInfo.id);
params = payInfo.rmb.."&"..1;
UmengHelper.onEvent("buy_first_cycle_gift&rmb,"..payInfo.rmb);
print("周期首充礼包:".."buy_first_cycle_gift&rmb,"..payInfo.rmb);
end
if params then
logUI("umeng pay:"..params);
UmengHelper.pay(params,callBack);
end
end
end
function ShopModel.buy(id,cnt,callBack,timeoutCallBack)
num = num or 1;
local function onBuyResFun(params)
cmsg.off("gateway_msg.shop_buy_msg_res",onBuyResFun);
if params.errcode == EnumErrorCode.EC_SUCCESS then
if callBack then
callBack(params);
end
local shopInfo = ShopInfo.getShopInfo(id);
local costNum = shopInfo.costList[1].num;
UmengHelper.buy(id.."&"..cnt.."&"..costNum,nil);
elseif params.errcode == EnumErrorCode.EC_INEXISTENT_ITEM then
Alert.showOne(strings.msg_1003);
else
Alert.showOne(strings.msg_1003);
end
end
local function timeoutFn(params)
cmsg.off("gateway_msg.shop_buy_msg_res",onBuyResFun);
if timeoutCallBack then
timeoutCallBack(params);
end
end
cmsg.on("gateway_msg.shop_buy_msg_res",onBuyResFun);
SocketClient:getInstance():send("gateway_msg.shop_buy_msg",
{
id = id,
cnt = cnt
},timeoutFn);
end
--function ShopModel.pay(productId,productName,productPrice,callBack,timeoutCallBack)
-- local function onGetOrderResFun(params)
-- cmsg.off("gateway_msg.pay_get_id_msg_res",onGetOrderResFun);
-- if params.errcode == EnumErrorCode.EC_SUCCESS then
-- local tradeNo = params.data.pay_id; --订单号
-- local productId = productId; --商品ID
-- local subject = productName; --商品名称
-- local amount = productPrice; --商品价格
-- local notificationURL = params.data.url_callback;--回调URL
-- local zfb_url_callback = params.data.zfb_url_callback;--支付宝回调URL
-- local wx_url_callback = params.data.wx_url_callback;--微信回调URL
-- local peng_bo_shi_token = params.data.peng_bo_shi_token;--鹏博士密钥
-- logUI("订单号获取成功token:"..peng_bo_shi_token);
-- local function callbackLua(params)
-- if params == "success" then
-- if callBack then
-- callBack(params);
-- end
-- elseif params == "no" then
-- local subject = DeviceUtil.getAppName().." "..productName;
-- local reciever = require("app.views.view.QrPayView"):show({trade_no=tradeNo,subject=subject,price=productPrice,zfb_url=zfb_url_callback,wx_url=wx_url_callback,callBackFun=callBack});
-- local scene = cc.Director:getInstance():getRunningScene();
-- scene.keypadManager:addKeypadReceiver(reciever);
-- end
-- logUI(params);
-- end
-- local pay_params = tradeNo..","..productId..","..subject..","..amount..","..notificationURL..","..peng_bo_shi_token;
-- DeviceUtil.sendBilling(pay_params,callbackLua);
-- else
-- Alert.showOne(strings.msg_1010..params.errcode);
-- end
-- end
-- local function timeoutFn(params)
-- cmsg.off("gateway_msg.pay_get_id_msg_res",onGetOrderResFun);
-- if timeoutCallBack then
-- timeoutCallBack(params);
-- end
-- end
-- cmsg.on("gateway_msg.pay_get_id_msg_res",onGetOrderResFun);
-- SocketClient:getInstance():send("gateway_msg.pay_get_id_msg",
-- {
-- product = productId
-- },timeoutFn);
--end
function ShopModel.pay(productId,productName,productPrice,callBack,timeoutCallBack)
local function onGetPayIDSuccessFun(_params)
local data = json.decode(_params);
if data.pay_id == "" then
Alert.showOne("获取订单号失败!");
return;
end
local tradeNo = data.pay_id; --订单号
local productId = productId; --商品ID
local subject = productName; --商品名称
local amount = productPrice; --商品价格
local notificationURL = data.url_callback;--回调URL
local zfb_url_callback = data.zfb_url_callback;--支付宝回调URL
local wx_url_callback = data.wx_url_callback;--微信回调URL
local peng_bo_shi_token = data.peng_bo_shi_token;--鹏博士密钥
logUI("订单号获取成功token:"..peng_bo_shi_token);
local function callbackLua(params)
if params == "success" then
if callBack then
callBack(params);
end
elseif params == "no" then
local subject = DeviceUtil.getAppName().." "..productName;
local reciever = require("app.views.view.QrPayView"):show({trade_no=tradeNo,subject=subject,price=productPrice,zfb_url=zfb_url_callback,wx_url=wx_url_callback,callBackFun=callBack});
local scene = cc.Director:getInstance():getRunningScene();
scene.keypadManager:addKeypadReceiver(reciever);
end
logUI(params);
end
local pay_params = tradeNo..","..productId..","..subject..","..amount..","..notificationURL..","..peng_bo_shi_token;
DeviceUtil.sendBilling(pay_params,callbackLua);
end
local function onGetPayIDFaildFun(params)
if timeoutCallBack then
timeoutCallBack(params);
end
end
local get_pay_id_url = string.gsub(GAME_LOGIN_URL,"login","pay_get_id");
if CHANNEL == "cmcc" and cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
local paramsStr = "uid="..UserModel.getStringUID().."&product="..productId.."&account="..UserModel.account;
DeviceUtil.sendHttpRequest("POST,"..get_pay_id_url..","..PROXY_HTTP_ADDR..","..paramsStr,onGetPayIDSuccessFun);
else
HttpRequest:getInstance():post(get_pay_id_url,{uid=UserModel.getStringUID(),product=productId,account=UserModel.account},onGetPayIDSuccessFun,onGetPayIDFaildFun);
end
end
return ShopModel