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')
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")
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
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