コード例 #1
0
def trade(handler, *args, **kwargs):
    ck = handler.json_args.get("ck", "")
    uid = session.get_by_ck(ck).get('uid')
    params = handler.json_args
    params.update({"uid": uid})
    pid = None
    try:
        # 账户检查
        paymoney = UserBean().check_account(params)

        # 下单
        with get_rpc_conn("trade") as proxy:
            try:
                resp = proxy.call("place_order", params)
            except RpcException as ex:
                raise ews.EwsError(ews.STATUS_RPC_TRADE_ERROR, ex.message)
    except:
        logger.error(traceback.format_exc())
        raise
    account = UserBean().user_account({"uid": uid})
    ret = {
        "pid": resp.get("pid"),
        "balance": Decimal(account.get("balance")) - Decimal(paymoney),
        "balance_draw": account.get("balance_draw")
    }
    return handler.ok(ret)
コード例 #2
0
ファイル: jl.py プロジェクト: dragonflylxp/lottory
def trade_follow(handler, *args, **kwargs):
    ck = handler.json_args.get("ck", "")
    uid = session.get_by_ck(ck).get('uid')
    pid = handler.json_args.get("pid")
    lotid = handler.json_args.get("lotid", 47)
    allmoney = handler.json_args.get("allmoney")
    beishu = handler.json_args.get("beishu")

    params = handler.json_args
    params.update({"uid": uid, "couponid": 0})
    try:

        module = "trade"
        method = "proj_detail"
        proj_detail = {}
        with get_rpc_conn(module) as proxy:
            proj_detail = proxy.call(method, params)
            proj_detail = ujson.loads(proj_detail)

        if not proj_detail:
            raise ews.EwsError(ews.STATUS_PROJ_NOT_FOUND)
        ptype = proj_detail.get("f_ptype")
        if str(ptype) != "1":
            raise ews.EwsError(ews.STATUS_PROJ_FORBID_FOLLOW)

        orderstatus = proj_detail.get("f_orderstatus")

        if orderstatus in [2, 4]:
            raise ews.EwsError(ews.STATUS_PROJ_FORBID_FOLLOW)

        firsttime = proj_detail.get("f_firsttime")
        if firsttime < time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()):
            raise ews.EwsError(ews.STATUS_PROJ_DEADLINE)

        _allmoney = proj_detail.get("f_allmoney")
        _beishu = proj_detail.get("f_beishu")
        # 下单

        if int(beishu) > 10000:
            raise ews.EwsError(ews.STATUS_PROJ_ALLMONEY_ERROR)
        single = int(float(_allmoney)) / int(_beishu)
        if allmoney != str(single * int(beishu)):
            raise ews.EwsError(ews.STATUS_PROJ_ALLMONEY_ERROR)

        # 账户检查
        paymoney = UserBean().check_account(params)
        params = {
            'lotid': lotid,
            'wtype': proj_detail.get("f_wtype"),
            'beishu': beishu,
            'zhushu': proj_detail.get("f_zhushu"),
            'ggtype': proj_detail.get("f_ggtype"),
            'allmoney': allmoney,
            'couponid': proj_detail.get("f_couponid"),
            'isquchu': proj_detail.get("f_isquchu"),
            'danma': proj_detail.get("f_danma"),
            'rqlist': proj_detail.get("f_rqlist"),
            'ratelist': proj_detail.get("f_ratelist"),
            'fileorcode': proj_detail.get("f_fileorcode"),
            'uid': uid,
            'fid': pid,
            'ptype': '-1',
            'firsttime': proj_detail.get("f_firsttime"),
            'lasttime': proj_detail.get("f_lasttime")
        }
        with get_rpc_conn("trade") as proxy:
            try:
                resp = proxy.call("place_order", params)
            except RpcException as ex:
                raise ews.EwsError(ews.STATUS_RPC_TRADE_ERROR, ex.message)
    except:
        logger.error(traceback.format_exc())
        raise

    account = UserBean().user_account({"uid": uid})
    ret = {
        "pid": resp.get("pid"),
        "balance": Decimal(account.get("balance")) - Decimal(paymoney),
        "balance_draw": account.get("balance_draw")
    }
    return handler.ok(ret)