def cbcd_current(request): data = { 'index': 'member', 'sub_index': 'my-cbcd', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'errmsg': '', 'data': {} } try: result = UserOrderSell.objects \ .filter(status=0).filter(seller_user=request.user) \ .aggregate(num=Sum('num_unsell'))[0] sell_num = int(result.get('num')) except: sell_num = 0 ubalance = services.get_balance(request.user) data['data']['num'] = sell_num + int(ubalance['point']) current_order = services.get_current_order() data['data']['price_buy'] = current_order['price'] data['data']['price_sell'] = current_order['price'] return utils.crender(request, 'frontend/member/cbcd_current.html', data)
def dashboard(request): weekday2name = { 'cn': ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'], 'en': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] } data = { 'index': 'member', 'sub_index': 'balance', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'data': { 'curr_weekday': { 'cn': '', 'en': '' } }, } curr_weekday = timezone.now().weekday() data['data']['curr_weekday']['cn'] = weekday2name['cn'][curr_weekday] data['data']['curr_weekday']['en'] = weekday2name['en'][curr_weekday] data['data']['invite_users'] = UserConnection.objects \ .filter(parent=request.user).count() data['data']['buy_users'] = UserConnectionBuying.objects \ .filter(parent=request.user).count() data['data']['total_users'] = data['data']['invite_users'] + data['data']['buy_users'] data['data']['balance'] = services.get_balance(request.user) return utils.crender(request, 'frontend/member/dashboard.html', data)
def trading_hall(request, ctype): data = { 'index': 'member', 'sub_index': 'hall', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'errmsg': '', 'ctype': ctype, 'data': {} } result = UserOrderSell.objects.filter(status=0) \ .aggregate(total=Sum('num_unsell')) try: data['data']['total'] = int(result.get('total', 0)) except: data['data']['total'] = 0 data['data']['price_init'] = services.get_init_price() current_order = services.get_current_order() data['data']['price_current'] = current_order['price'] if ctype == 'sell': ubalance = services.get_balance(request.user) data['data']['point'] = ubalance['point'] else: data['data']['point'] = current_order['num'] data['data']['price_open'] = services.get_opening_price() data['data']['price_up'] = data['data']['price_current'] - data['data']['price_open'] data['data']['ratio'] = (data['data']['price_current'] - data['data']['price_init'])*100 / data['data']['price_init'] return utils.crender(request, 'frontend/member/trading_hall.html', data)
def selling(request): data = { 'index': 'member', 'sub_index': 'home', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'data': { 'uconnect': [] } } uconnections = UserConnection.objects \ .filter(parent=request.user).filter(is_selling=0) for uconnect in uconnections: ubalance = services.get_balance(uconnect.user) data['data']['uconnect'].append({ 'user_id': uconnect.user.id, 'username': uconnect.user.username, 'total_investment': ubalance['total_investment'] }) if request.method == 'POST': user_id = request.POST.get('user_id', '') if user_id: mall = UserSellingMall( user_id=user_id, parent_user=request.user ) mall.save() UserConnection.objects \ .filter(user_id=user_id).update(is_selling=1) return HttpResponseRedirect('/member/selling/') return utils.crender(request, 'frontend/member/selling.html', data)
def promotion(request): data = { 'index': 'member', 'sub_index': 'home', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'data': { 'uconnect': [], 'ucount': 0 } } invite_code = UserInfo.objects.get(user=request.user).invite_code uconnections = UserConnection.objects.filter(parent=request.user) data['data']['invite_url'] = '%sregister?invite_code=%s' % \ (settings.SITE_URL, invite_code) data['data']['ubalance'] = services.get_balance(request.user) for uconnect in uconnections: recommends = services.get_recommends(uconnect.user) invite_benifit = services.get_invite_benifit(uconnect.user) try: last_login = utils.dt_field_to_local(uconnect.user.last_login) except: last_login = '' data['data']['uconnect'].append({ 'username': uconnect.user.username, 'reg_time': utils.dt_field_to_local(uconnect.user.date_joined), 'recommends': recommends, 'last_login': last_login, 'invite_benifit': invite_benifit }) data['data']['ucount'] = len(data['data']['uconnect']) return utils.crender(request, 'frontend/member/promotion.html', data)
def withdraw(request): data = { 'index': 'member', 'sub_index': 'deposite', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'errmsg': '', 'data': {'withdraws': []} } ubalance = services.get_balance(request.user) uinfo = UserInfo.objects.get(user=request.user) initial = { 'cash': ubalance['cash'], 'pay_type': uinfo.bank_code, 'pay_account': uinfo.bank_card, } data['form'] = WithDrawForm(initial=initial) withdraws = UserWithDraw.objects.filter(user=request.user).order_by('-id') for w in withdraws: data['data']['withdraws'].append({ 'order_id': w.order_id, 'create_time': w.create_time, 'amount': float(w.amount), 'status': UserWithDraw.STATUS[w.status] }) if request.method == 'POST': data['form'] = WithDrawForm(request.POST) if data['form'].is_valid(): uauth = authenticate(username=request.user.username, password=request.POST['password']) if uauth: pay_amount = float(request.POST.get('amount')) if services.pay_cash(request.user, pay_amount): udraw = UserWithDraw( user=request.user, pay_type=request.POST.get('pay_type'), pay_account=request.POST.get('pay_account'), bank_code=request.POST.get('bank_code', ''), amount=float(request.POST.get('amount')) ) udraw.save() return HttpResponseRedirect('/member/withdraw/') else: data['errmsg'] = '余额不足' else: data['errmsg'] = '密码不正确' return utils.crender(request, 'frontend/member/withdraw.html', data)
def buying(request): data = { 'index': 'member', 'sub_index': 'home', 'errmsg': '', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'data': { 'members': [] } } sellings = UserSellingMall.objects \ .exclude(parent_user=request.user) \ .exclude(user=request.user) \ .order_by('-id') for s in sellings: data['data']['members'].append({ 'user_id': s.user.id, 'username': s.user.username, 'reg_time': utils.dt_field_to_local(s.user.date_joined) }) if request.method == 'POST': user_id = request.POST.get('user_id') # todo: 扣钱 ssetings = SiteSetting.objects.first() if services.pay_cash(request.user, int(ssetings.user_buy_price)*settings.CURRENCY_RATIO): ucb = UserConnectionBuying( user_id=user_id, parent=request.user, ratio=100 ) ucb.save() UserSellingMall.objects \ .filter(user_id=user_id).delete() return HttpResponseRedirect('/member/buying/') else: should_pay = int(ssetings.user_buy_price)*settings.CURRENCY_RATIO ubalance = services.get_balance(request.user) need_pay = should_pay - float(ubalance['cash']) data['errmsg'] = '余额不足,请充值: %s元' % need_pay return utils.crender(request, 'frontend/member/buying.html', data)
def change_recommend_user(request): data = { 'index': 'member', 'sub_index': 'home', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'form': ChangeRecommendForm(), 'data': { 'changelist': [] }, 'errmsg': '' } changelist = UserChangeRecommend.objects \ .filter(user_id=request.user.id) \ .values('user_id') \ .annotate(times=Count('id')) \ .order_by('-times') for c in changelist: uinfo = UserInfo.objects.get(user_id=c.get('user_id')) ubalance = services.get_balance(uinfo.user) data['data']['changelist'].append({ 'username': uinfo.user.username, 'recommend_user': uinfo.recommend_user, 'investment': ubalance['total_investment'], 'reg_time': utils.dt_field_to_local(uinfo.user.date_joined), 'times': c.get('times', 1) }) if request.method == 'POST': data['form'] = ChangeRecommendForm(request.POST) if data['form'].is_valid(): change_times = UserChangeRecommend.objects \ .filter(user=request.user).count() recommend_username = request.POST.get('username', '') unifo = UserInfo.objects.get(user=request.user) if recommend_username == request.user.username: data['errmsg'] = '不能把自己设置为转介人' elif recommend_username == unifo.recommend_user: data['errmsg'] = '%s已经是你的当前推荐人' % recommend_username.encode('UTF-8') else: if change_times < 3: ruinfo = UserInfo.objects \ .get(user__username=recommend_username) ucr = UserChangeRecommend( user_id=request.user.id, recommend_user_id=ruinfo.user_id ) ucr.save() UserInfo.objects \ .filter(user=request.user) \ .update(recommend_user=request.POST.get('username')) UserConnection.objects \ .filter(user_id=request.user.id) \ .update(parent_id=ruinfo.user_id) return HttpResponseRedirect('/member/change-recommend-user/') else: data['errmsg'] = '你的转介次数已满3次,不能再次转介' return utils.crender(request, 'frontend/member/change_recommend_user.html', data)