def post(self): request_content = json.loads(self.request.body) code = request_content['code'] conn, cursor = methods.db_connection() sql = 'SELECT comment,invite_code,income_take,id from invitation_code where invite_code = "%s"' % code.upper( ) cursor.execute(sql) invite_code_list = cursor.fetchall() if len(invite_code_list) == 0: result = {'status_code': 1} # 乱输邀请码的话去死吧 else: i = invite_code_list[0] code_list = [] content = {'code': i[1], 'comment': json.loads(i[0])} if content['comment'] == '': content['comment'] = 'N/A' content['income'] = get_income(i[-1]) content['take'] = content['income'] - i[2] content['status_code'] = 0 result = content conn.close() self.write(json.dumps(result)) return
def post(self): try: user_token = self.get_secure_cookie("user").decode('utf-8') user_token = json.loads(user_token) username = user_token['username'] except: self.render('login.html') return # 没登录不能用 try: conn, cursor = methods.db_connection() sql = 'SELECT id from user_admin where user = "******"' % username cursor.execute(sql) admin_id = cursor.fetchall()[0][0] # 查询进行操作的人的id request_content = json.loads(self.request.body) code = request_content['code'] money = float(request_content['money']) if money < 0: result = {'status_code': -1} # 钱不够就别提现了 else: sql = 'SELECT id,income_take from invitation_code where invite_code = "%s"' % code.upper( ) cursor.execute(sql) invite_code_list = cursor.fetchall() if len(invite_code_list) == 0: result = {'status_code': 1} # 乱输邀请码去死好不好 else: user_id = invite_code_list[0][0] take_money = get_income( user_id) - money - invite_code_list[0][1] if take_money < 0: result = {'status_code': 65536} # 什么?你想输入一个负数来加钱?想多了! else: income_take = money + invite_code_list[0][1] # 更新提现总金额 time_now = int(time.time()) sql = 'UPDATE invitation_code SET income_take = %s where id = %s' % ( income_take, user_id) cursor.execute(sql) sql = 'INSERT INTO money_take_record(user_id,admin_id,time,money) VALUES(%s,%s,%s,%s)' % ( user_id, admin_id, time_now, money) cursor.execute(sql) # 插入提现记录 conn.commit() result = {'status_code': 0} except Exception as e: print(str(e)) result = {'status_code': 1} conn.close() self.write(json.dumps(result))
def get(self): conn, cursor = methods.db_connection() sql = 'SELECT comment,invite_code,income_take,id from invitation_code' cursor.execute(sql) invite_code_list = cursor.fetchall() if len(invite_code_list) == 0: result = {'status_code': 1} # 如果没有邀请码 else: code_list = [] for i in invite_code_list: content = {'code': i[1], 'comment': json.loads(i[0])} if content['comment'] == '': content['comment'] = 'N/A' content['income'] = get_income(i[-1]) content['take'] = content['income'] - i[2] code_list.append(content) result = {'status_code': 0, 'content': code_list} conn.close() # 返回邀请码相关信息 self.write(json.dumps(result)) return
def post(self): request_content = json.loads(self.request.body) invitation_code = request_content['invitation_code'] conn, cursor = methods.db_connection() sql = 'SELECT id from invitation_code where invite_code = "%s"' % invitation_code.upper( ) cursor.execute(sql) invitation_id = cursor.fetchall() result = {} if len(invitation_id) == 0: result = {'status_code': 1} else: invitation_id = invitation_id[0][0] tmp = search_detail(invitation_id) result['status_code'] = 0 result['content'] = tmp conn.close() if result['status_code'] == 0: result['code'] = invitation_code.upper() self.set_secure_cookie('user', json.dumps({'code': invitation_code})) # 把查询结果储存为cookie self.write(json.dumps(result)) return
def get_broadcast(): conn, cursor = methods.db_connection() sql = 'SELECT content,repeat_time,ctime,broadcast_time from broad_cast' cursor.execute(sql) result = cursor.fetchall() result = result[-1] content = { 'content': json.loads(result[0]), 'repeat_time': result[1], 'broadcast_time': result[3] - result[2] } return content
def write_broadcast(content): conn, cursor = methods.db_connection() content_json = json.dumps(content['content']).replace('\\', '\\\\').replace( '"', '\\"') sql = 'INSERT INTO broad_cast (content,ctime,repeat_time,broadcast_time) VALUES ("%s",%s,%s,%s)' % ( content_json, int(time.time()), int(content['repeat']), int(time.time()) + int(content['broadcast_time'])) print(sql) cursor.execute(sql) conn.commit() conn.close() return 0
def search_detail(invitation_id): conn, cursor = methods.db_connection() sql = 'SELECT user_id,invite_time from invitation where invite_id = %s' % invitation_id cursor.execute(sql) invitation_users = cursor.fetchall() result = [] user_id_list = [] if len(invitation_users) == 0: return result # 如果这个邀请码没有用户填过 else: for user in invitation_users: # 遍历填过这个邀请码的用户 sql = 'SELECT order_number from order_info where user_id = %s and create_time > %s and status = 2' % ( user[0], user[1]) cursor.execute(sql) order_list = cursor.fetchall() # 查找对应的结算过的订单 if len(order_list) == 0: continue else: for order in order_list: good_id = int(order[0].split('_')[-1]) good_type = order[0].split('_')[-2] good_time = int(order[0].split('_')[-0]) sql = 'SELECT money from %s where id = %s' % ( 'bag_' + good_type, good_id) cursor.execute(sql) money = cursor.fetchall()[0][0] # 查找对应订单的价格 sql = 'SELECT uuid from user where id = %s' % user[0] cursor.execute(sql) uuid = cursor.fetchall()[0][0] # 查找对应订单的uuid uuid = str(uuid)[:2] + '****' + str(uuid)[-2:] line = { 'uuid': uuid, 'money': money, 'time': methods.time_to_str(good_time), 'good': good_type } # 结果 result.append(line) conn.close() return result
def get_income(invite_id): conn, cursor = methods.db_connection() sql = 'SELECT income from invitation where invite_id = %s' % invite_id cursor.execute(sql) income_list = cursor.fetchall() if len(income_list) == 0: result = 0 else: result = 0 for i in income_list: result += i[0] conn.close() return result
def online_people(): result = {} conn, cursor = methods.db_connection() sql = 'SELECT id from user where is_online = 1' cursor.execute(sql) online_people = cursor.fetchall() result['online_people'] = len(online_people) sql = 'SELECT last_room_id from user where last_room_id != 0' cursor.execute(sql) online_room = cursor.fetchall() if len(online_room) != 0: result['online_room'] = len(set(list(online_room))) else: result['online_room'] = 0 return result
def post(self): request_content = json.loads(self.request.body) invite_comment = request_content['comment'] invite_comment = json.dumps(invite_comment).replace('\\', '\\\\').replace( '"', '\\"') # 格式化处理方便存入数据库 conn, cursor = methods.db_connection() sql = 'SELECT invite_code from invitation_code' cursor.execute(sql) invite_code_list = cursor.fetchall() if len(invite_code_list) == 0: invite_code = create_i_code() # 查找邀请码,看看是否存在 else: code_list = [] for i in invite_code_list: code_list.append(i[0]) while 1: invite_code = create_i_code() if invite_code in code_list: continue else: break # 避免重复 sql = 'INSERT into invitation_code(comment,invite_code) VALUES("%s","%s")' % ( invite_comment, invite_code) cursor.execute(sql) conn.commit() conn.close() # 插入邀请码 result = { 'status_code': 0, 'comment': request_content['comment'], 'invite_code': invite_code } self.write(json.dumps(result)) return