예제 #1
0
def new_user_balance(user):
    pass
    try:
        b_new = Balance()
        b_new.user = user.id
        b_new.balance = 5
        b_new.created = int(time.time())
        b_new.stype = 0
        b_new.log = u'新用户注册即送5元账户余额'
        b_new.save()
        msg = u'恭喜您,注册成功!并获得系统赠送5元现金余额,请登录车装甲个人中心查收。'
        sms = {
            'mobile': user.username,
            'body': msg,
            'signtype': '1',
            'isyzm': '1'
        }
        create_msg(simplejson.dumps(sms), 'sms')
    except Exception, ex:
        msg = u'新用户注册送5元账户余额失败,用户名' + user.username + u' 错误信息:' + ex.message
        email = {
            u'receiver':
            ['*****@*****.**', '*****@*****.**'],
            u'subject': u'新用户注册即送5元账户余额失败',
            u'body': msg
        }
        create_msg(simplejson.dumps(email), 'email')
예제 #2
0
파일: api.py 프로젝트: havocesp/clitopia
    def get_balance(self, currency=None):
        balance = self.fetch_balance()
        del balance['info'], balance['used'], balance['free'], balance['total']

        result = {k: v for k, v in balance.items() if v['total'] > 0.0}
        if currency is not None:
            result = Balance(**balance.get(currency, {}))
        return result
예제 #3
0
파일: pay2.py 프로젝트: scaperow/carive
    def post(self):
        alipay = Alipay(**self.settings)

        params = {}
        ks = self.request.arguments.keys()

        for k in ks:
            params[k] = self.get_argument(k)

        if alipay.notify_verify(params):
            tn = self.get_argument("out_trade_no", None)
            trade_no = self.get_argument("trade_no", None)
            trade_status = self.get_argument("trade_status", None)
            strPrice = self.get_argument("total_fee", None)
            #buyer_email = self.get_argument("buyer_email", None) #买家支付宝帐号
            logging.info("return:%s - %s - %s" % (tn, trade_no, trade_status))
            uid = int(tn.split('_')[0].replace('U', ''))

            try:

                log = u'充值成功 - %s' % tn
                b = Balance.select().where(Balance.log == log)
                if b.count() == 0:
                    balance = Balance()
                    balance.user = uid
                    balance.balance = float(strPrice)
                    balance.stype = 0
                    balance.log = log
                    balance.created = int(time.time())
                    balance.save()
                    user_top_up_balance(balance)

                user = User.get(id=uid)
                self.session['user'] = user
                self.session.save()
            except Exception, ex:
                logging.error(ex)
                self.write("fail")

            if trade_status == 'WAIT_SELLER_SEND_GOODS':
                alipay.send_goods_confirm_by_platform(trade_no)

            self.write("success")
예제 #4
0
def user_top_up_balance(balance):
    max_price = int(setting.Balance_Max_Price)  #最大返利金额
    end_date = time.mktime(time.strptime(setting.Balance_End_Date,
                                         "%Y-%m-%d"))  #活动结束时间
    date = int(time.time())
    if date < end_date:
        try:
            b = Balance.select(
                db.fn.SUM(Balance.balance).alias('total_price')).where(
                    (Balance.user == balance.user) & (Balance.stype == 0)
                    & (Balance.log == '充值返现活动赠送')).dicts()
            need_price = 0
            if b[0]["total_price"]:
                if b[0]["total_price"] < max_price:
                    need_price = max_price - b[0]["total_price"]
                    if (balance.balance / 2 < need_price):
                        need_price = balance.balance / 2
                else:
                    return
            else:
                need_price = balance.balance / 2
                if need_price > max_price:
                    need_price = max_price
            b_new = Balance()
            b_new.user = balance.user
            b_new.balance = need_price
            b_new.created = int(time.time())
            b_new.stype = 0
            b_new.log = u'充值返现活动赠送'
            b_new.save()
            msg = u'恭喜您,充值成功!并获得充值返现金额 ' + str(need_price) + u' 元,请登录车装甲查收。'
            sms = {
                'mobile': balance.user.username,
                'body': msg,
                'signtype': '1',
                'isyzm': '1'
            }
            create_msg(simplejson.dumps(sms), 'sms')
        except Exception, ex:
            logging.error(ex)
            pass
예제 #5
0
    def test(self):
        now = datetime.now()
        id = 12
        self.register.receive(Receive("F-01", now, Decimal('2'), 100, id))

        ll = self.register.list()
        self.assertEqual(len(ll), 1)
        balance = Balance(id, now, 'F-01', Decimal('2'), 100, 100)
        self.assertEqual(balance, ll[0])

        self.register.dispatch(id, 5)

        ll = self.register.list()
        self.assertEqual(len(ll), 1)
        balance = Balance(id, now, 'F-01', Decimal('2'), 100, 95)
        self.assertEqual(balance, ll[0])

        self.register.dispatch(id, 95)

        ll = self.register.list()
        self.assertEqual(len(ll), 0)
예제 #6
0
def old_new_user_balance(order):
    try:
        rate = float(setting.Old_New_User_Rate)  #首单返利利率
        max_price = float(setting.Old_New_Max_Price)  #首单返利最大金额
        oc = Order.select().where((Order.user == order.user)
                                  & (Order.status == 4)
                                  & (Order.ordered <= order.ordered))
        if oc.count() == 1:
            fl_price = oc[0].currentprice - oc[
                0].shippingprice  #商品金额 = 订单实际支付金额 - 订单运费
            if (fl_price >= 0):
                return_balance = round((fl_price * rate), 2)
                if return_balance > max_price:
                    return_balance = max_price
                up = User_Promote.get(User_Promote.new_user == order.user)
                if up:
                    balance = Balance()
                    balance.user = up.old_user
                    balance.balance = return_balance
                    balance.created = int(time.time())
                    balance.stype = 0
                    balance.log = u'老推新首单返利。'
                    balance.save()
                    msg = u'恭喜您,您推荐的好友'+order.user.username+u'首次订单已经完成,您获得'+str(return_balance)+\
                          u'元余额返利,请登录车装甲查收。'
                    sms = {
                        'mobile': up.old_user.username,
                        'body': msg,
                        'signtype': '1',
                        'isyzm': '1'
                    }
                    create_msg(simplejson.dumps(sms), 'sms')

                    up.first_order_gift = 1
                    up.first_order_time = int(time.time())
                    up.first_order_content = msg
                    up.save()
    except:
        pass
예제 #7
0
 def _get_balance(self, path):
     ret_code = 0
     ret_value = {}
     error_msg = ''
     try:
         f = open(path, 'r')
         for line in f:
             if len(line) < 10: continue
             raw_data = json.loads(line.strip())
             ret_value['RMP'] = Balance(raw_data)
         f.close()
     except IOError:
         ret_code = 1
         error_msg = traceback.format_exc()
     except:
         ret_code = 2
         error_msg = traceback.format_exc()
     return (ret_code, ret_value, error_msg, self.local_log_path)
예제 #8
0
def register():
    tag = get_tag_one()
    amount = get_amount()
    comment = get_comment()
    month = get_month_save()

    input_date = date.today()
    if month == 'last month':
        input_date = date.today().replace(day=1) - timedelta(1)

    register = confirm_entry()

    if register is True:
        Balance(
            amount=amount,
            tag=tag,
            comment=comment,
            date=input_date
        ).save()
예제 #9
0
def edit_entry():
    entry_id = get_entry_id()

    entry = Balance.get_or_none(Balance.id == entry_id)
    if entry is None:
        print("Not an entry")
    else:
        result = []
        result.append(dict(
            id=entry.id,
            amount=entry.amount,
            tag=entry.tag,
            comment=entry.comment,
            date=entry.date,
        ))

        print("{:<15} {:<15} {:<8} {:<40} {:<}"
              .format('ID', 'Tag', 'Amount', 'Comment', 'Date'))
        print_table_2(result)

        delete = confirm_delete()
        if delete is not True:
            entry.delete_instance()
        else:
            tag = get_tag_one()
            amount = get_amount()
            comment = get_comment()

            register = confirm_entry()

            if register is True:
                entry.amount = amount
                entry.tag = tag
                entry.comment = comment
                entry.date = entry.date
                entry.save()
예제 #10
0
            print(block_info["result"]["index"])
            for tx in block_info["result"]["tx"][1:]:

                for vout in tx["vout"]:
                    if vout["asset"] == NEO_ASSETID:

                        NeoVout.save(tx_id=tx["txid"],
                                     address=vout["address"],
                                     asset_id=vout["asset"],
                                     vout_number=vout["n"],
                                     value=vout["value"])
                        exist_instance = session.query(Balance).filter(
                            Balance.address == vout["address"]).first()
                        if exist_instance:
                            exist_instance.neo_balance += int(vout["value"])
                            Balance.save(exist_instance)
                        else:
                            new_instance = Balance(address=vout["address"],
                                                   neo_balance=vout["value"])
                            Balance.save(new_instance)

                    elif vout["asset"] == GAS_ASSETID:
                        GasVout.save(tx_id=tx["txid"],
                                     address=vout["address"],
                                     asset_id=vout["asset"],
                                     vout_number=vout["n"],
                                     value=Decimal(vout["value"]))
                        exist_instance = session.query(Balance).filter(
                            Balance.address == vout["address"]).first()
                        if exist_instance: