Skip to content

Commit

Permalink
update pay
Browse files Browse the repository at this point in the history
  • Loading branch information
onedou committed Jul 24, 2017
1 parent abe7f2c commit e3e68aa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
7 changes: 7 additions & 0 deletions paraengine.sig
@@ -0,0 +1,7 @@
PARAENGINE_NGISIHZIXIL_VER0001
======================
Do NOT edit this file
======================

This file is the signature file for ParaEngine. It is used for locating the root of ParaEngine executable.
Currently it is only used for ParaX model exporter. Please only put this file to the root directory.
2 changes: 1 addition & 1 deletion wikicraft.csproj
Expand Up @@ -1277,7 +1277,7 @@
<Content Include="www\wiki\html\wikiEditor.html" />
<Content Include="www\wiki\html\worksApply.html" />
<Content Include="www\wiki\index.page" />
<Content Include="www\wiki\js\app.js" />
<Content Include="www\wiki\js\mod\app.js" />
<Content Include="www\wiki\js\app\config.js" />
<Content Include="www\wiki\js\app\controller\contactController.js" />
<Content Include="www\wiki\js\app\controller\dataSourceController.js" />
Expand Down
Binary file modified www/wiki/assets/imgs/pay-qrcode-wechat-bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 30 additions & 24 deletions www/wiki/models/pay.page
Expand Up @@ -11,17 +11,22 @@ include_once("./goods.page");
include_once("./oauth_app.page");
include_once("./wallet.page");

local pay = inherit(models.abstract.multi_user_base,gettable("models.pay"));
local goods = models.goods:new();
local oauth_app = models.oauth_app:new();
local wallet = models.wallet:new();
local user = models.user:new();
local pay = inherit(models.abstract.multi_user_base,gettable("models.pay"));
local tradeno = inherit(models.abstract.multi_user_base,gettable("models.tradeno"));

local goods = models.goods:new();
local oauth_app = models.oauth_app:new();
local wallet = models.wallet:new();
local user = models.user:new();

pay.db_name = "pay";
pay.apiUrl = "https://api.pingxx.com/v1/";
pay.appToken = KEEPWORK["config"]["default"]["threeService"]["pingxx"]["appToken"];
pay.appId = KEEPWORK["config"]["default"]["threeService"]["pingxx"]["appId"];

tradeno.db_name = "tradeno";
tradeno = tradeno:new();

function pay:ctor()
-- keepwork username
self:addfield("username", "string",false);
Expand Down Expand Up @@ -93,13 +98,13 @@ function pay:api_createCharge(params)
end
end

self:getTradeNo(resume);
tradeno:getTradeNo(resume);
local err, trade_no = yield();

if not trade_no then
return errors:wrap(errors.SERVER_INNER_ERROR);
end

log("a")
local url = self.apiUrl .. "charges";
local apiParams = {};
apiParams.order_no = trade_no;
Expand All @@ -116,10 +121,10 @@ function pay:api_createCharge(params)
elseif(apiParams.channel == "wx_pub_qr") then
apiParams.extra = {product_id = trade_no};
end

log("b")
self:http("POST", url, apiParams, resume);
local err, chargeObject = yield();

log("c")
if(not chargeObject) then
return errors:wrap(errors.SERVER_INNER_ERROR);
end
Expand All @@ -137,10 +142,10 @@ function pay:api_createCharge(params)
tradeInfo.app_goods_id = query.app_goods_id;
tradeInfo.additional = query.additional;
tradeInfo.create_date = self:getNow();

self:db():insertOne({["+trade_no"] = {trade_no}}, tradeInfo, resume);
log(tradeInfo, true);
self:db():insertOne(tradeInfo, resume);
local err, _ = yield();

log("d")
if(not err) then
return errors:wrap(nil, chargeObject);
else
Expand All @@ -162,7 +167,7 @@ function pay:api_spend(params)
end

function pay:spend(query, callback)
self:getTradeNo(resume);
tradeno:getTradeNo(resume);
local err, trade_no = yield();

local appGoodsInfo = self:getGoodsInfo(query);
Expand Down Expand Up @@ -359,28 +364,29 @@ function pay:http(method, url, params, callback)

local err, response = yield();



if(type(callback) == "function") then
callback(err, response);
end
end

function pay:getTradeNo(callback)
local trade_no = tostring(math.random(1000000,9999999));
function pay:getNow()
return ParaGlobal.GetDateFormat("yyyy-MM-dd") .. " " .. ParaGlobal.GetTimeFormat("HH:mm:ss");
end

self:db():findOne({trade_no = trade_no}, resume);
function tradeno:getTradeNo(callback)
self:db():insertOne({},resume);
local err, response = yield();

if not err and response == nil then
if not err then
local number = ParaGlobal.GetDateFormat("yyyyMMdd") .. response._id;

if(type(callback) == "function") then
callback(nil, trade_no);
callback(nil, number);
end
else
self:getTradeNo(callback);
if(type(callback) == "function") then
callback(true, nil);
end
end
end

function pay:getNow()
return ParaGlobal.GetDateFormat("yyyy-MM-dd") .. " " .. ParaGlobal.GetTimeFormat("HH:mm:ss");
end

0 comments on commit e3e68aa

Please sign in to comment.