Example #1
0
        public JArray initBuyOrder(
            string userId,
            string accessToken,
            string projId,
            string rewardId,
            string amount,
            string rewardAmount,
            string connectorName,
            string connectorTel,
            string connectorAddress,
            string connectorEmail,
            string connectorMessage
            )
        {
            if (!TokenHelper.checkAccessToken(tokenUrl, userId, accessToken, out string code))
            {
                return(getErrorRes(code));
            }
            var findStr = new JObject {
                { "rewardId", rewardId }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, findStr);

            if (queryRes.Count == 0 ||
                queryRes[0]["activeState"].ToString() != RewardActiveState.Valid_Yes ||
                queryRes[0]["projId"].ToString() != projId
                )
            {
                // 无效回报id
                return(getErrorRes(DaoReturnCode.Invalid_RewardId));
            }
            var item = queryRes[0];

            if (!getProjTokenName(projId, out string tokenName, out string fundName))
            {
                return(getErrorRes(DaoReturnCode.S_InvalidProjId));
            }
            string projName = getProjName(projId);
            var    orderId  = DaoInfoHelper.genProjRewardOrderId(projId, rewardId, userId);
            var    now      = TimeHelper.GetTimeStamp();
            var    newdata  = new JObject {
                { "projId", projId },
                { "projName", projName },
                { "rewardId", rewardId },
                { "orderId", orderId },
                { "orderState", OrderState.WaitingPay },
                { "rewardName", item["rewardName"] },
                { "price", item["price"] },
                { "priceUnit", fundName },
                { "amount", amount },
                { "totalCost", (decimal.Parse(item["price"].ToString()) * decimal.Parse(amount)).ToString() },
                { "totalCostUnit", fundName },
                { "rewardAmount", rewardAmount },
                { "rewardAmountUnit", tokenName },
                { "senderNote", "" },
                { "connectorName", connectorName },
                { "connectorTel", connectorTel },
                { "connectorEmail", connectorEmail },
                { "connectorAddress", connectorAddress },
                { "connectorMessage", connectorMessage },
                { "distributeWay", item["distributeWay"] },
                { "txid", "" },
                { "userId", userId },
                { "originInfo", item },
                { "markTime", now },
                { "time", now },
                { "lastUpdateTime", now }
            };

            mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceOrderCol, newdata);
            return(getRes(new JObject {
                { "orderId", orderId }, { "time", now }
            }));
        }