def insert(user_id, module, describe): try: sql = "INSERT INTO sys_log (user_id,[module],[describe]) VALUES ('{}','{}','{}');".format( user_id, module, describe) sql_exec(sql) return responseJSON_1('更新成功') except Exception as error: responseJSON_0('更新失败', error)
def Logout_user(mobile): try: user_id = sql_select( "SELECT id FROM biz_user WHERE mobile = {}".format(mobile)) if user_id == []: return responseJSON_0('用户不存在!') sql_exec("exec RemoveUserByMobile '{}';".format(mobile)) insert(user_id[0][0], 'Logout_user', '账户注销') return responseJSON_1('注销成功', mobile) except Exception as error: return responseJSON_0('deleteUser异常', error)
def addMoney(mobile, money): setMealList = [0.1, 0.5, 1, 3, 6] user_start = userStatus(mobile) if user_start['code'] == 0: return user_start if float(money) <= 6: if float(money) not in setMealList: return responseJSON_0("充值月份不在范围!") vip_status = vipStatus(mobile) status = vip_status['code'] if status == 0: return vip_status if float(money) == 0.1: user_id = sql_select("SELECT id FROM biz_user WHERE mobile = {}".format(mobile))[0][0] if status == 2: user_id = vip_status['table_s'][0] validTime = vip_status['table_s'][1] timeArray = time.strptime(validTime, "%Y-%m-%d %H:%M:%S") timeStamp = int(time.mktime(timeArray)) validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(864000 * money + timeStamp)) return setBizVipRecord(user_id, validTime, money) else: validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(864000 * money + int(time.time()))) return setBizVipRecord(user_id, validTime, money) # 未开通 if status == 1: user_id = sql_select("SELECT id FROM biz_user WHERE mobile = {}".format(mobile))[0][0] validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(2678400 * money + int(time.time()))) return setBizVipRecord(user_id, validTime, money) # 已开通 elif status == 2: user_id = vip_status['table_s'][0] validTime = vip_status['table_s'][1] timeArray = time.strptime(validTime, "%Y-%m-%d %H:%M:%S") timeStamp = int(time.mktime(timeArray)) validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(2678400 * money + timeStamp)) return setBizVipRecord(user_id, validTime, money) # 已过期 elif status == 3: user_id = vip_status['table_s'][0] validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(2678400 * money + int(time.time()))) return setBizVipRecord(user_id, validTime, money) else: money = int(money) if money > 4000 or money < 10: return responseJSON_0('充值失败!', '充值金额范围10~4000') sql_exec("exec GiveMeTheMoney %s,%d;" % (mobile, money)) bizWallet = getBizWallet(mobile) insert(bizWallet['table_s'][0][1], 'setBizVipRecord', 'TEST:充值{}个聚源币'.format(money)) if bizWallet['code'] == 0: return bizWallet return responseJSON_1('充值成功!', '当前余额为{}币'.format(bizWallet['table_s'][0][0]))
def userStatus(mobile): ''' 用户是否认证 :param mobile: :return: ''' try: user_status = sql_select("SELECT status FROM biz_user WHERE mobile = '{}';".format(mobile)) if user_status == []: return responseJSON_0('用户不存在!', mobile) if user_status[0][0] == 4: return responseJSON_1('已认证!', mobile) else: return responseJSON_0('未认证!', mobile) except Exception as error: return responseJSON_0('userStatus接口异常', error)
def vipStatus(mobile): ''' 会员状态 :param mobile: :return: ''' sql = ''' SELECT A.id, B.expire_time FROM biz_user A JOIN biz_vip_record B ON A.id = B.user_id WHERE sex = 1 AND A.mobile= '{}'; '''.format(mobile) try: vip_status = sql_select(sql) if vip_status == []: return responseJSON(code=1, msg='未开通') timeArray = time.strptime(vip_status[0][1], "%Y-%m-%d %H:%M:%S") timeStamp = int(time.mktime(timeArray)) if timeStamp > int(time.time()): return responseJSON(code=2, msg='已开通', data=vip_status[0]) return responseJSON(code=3, msg='已过期', data=vip_status[0]) except Exception as error: return responseJSON_0('vipStatus接口异常', error)
def Member(request): if request.method == "POST": mobile = json.loads(request.body.decode().replace("'", "\"")).get('mobile') money = json.loads(request.body.decode().replace("'", "\"")).get('money') return HttpResponse(json.dumps(addMoney(mobile, money))) else: return HttpResponse(json.dumps(responseJSON_0('请使用POST请求!')))
def getBizWallet(mobile): try: sql = "SELECT currency,user_id FROM biz_wallet A JOIN biz_user B ON A.user_id = B.id WHERE B.mobile = N'{}';".format( mobile) sql = sql_select(sql) return responseJSON_1('查询成功', sql) except Exception as error: return responseJSON_0('getBizWallet异常', error)
def getBizVipRecord(parameter): if len(parameter) == 11: sql = ''' SELECT B.expire_time FROM biz_user A JOIN biz_vip_record B ON A.id = B.user_id WHERE sex = 1 AND A.mobile= '{}'; '''.format(parameter) else: sql = "SELECT expire_time FROM biz_vip_record WHERE user_id = {};".format( parameter) sql = sql_select(sql) if len(sql) < 1: return responseJSON_0('未开通会员') return responseJSON_1(sql[0][0])
def setBizVipRecord(user_id, expire_time, money): print('时间', user_id, expire_time) try: sql = "SELECT * FROM biz_vip_record WHERE user_id = '{}';".format( user_id) sql = sql_select(sql) if sql == []: sql = ''' INSERT INTO biz_vip_record (user_id,expire_time) VALUES ({},'{}'); update biz_user set is_vip=1 where id={}; '''.format(user_id, expire_time, user_id) sql_exec(sql) insert(user_id, 'setBizVipRecord', 'TEST:充值{}个月会员'.format(money)) return responseJSON_1('充值成功!', '会员时间:{}'.format(expire_time)) sql = ''' UPDATE biz_vip_record SET expire_time='{}' WHERE user_id= {}; UPDATE biz_user set is_vip=1 where id={}; '''.format(expire_time, user_id, user_id) sql_exec(sql) insert(user_id, 'setBizVipRecord', 'TEST:充值{}个月会员'.format(money)) return responseJSON_1('充值成功!', '会员时间:{}'.format(expire_time)) except Exception as error: return responseJSON_0('setBizVipRecord方法异常', error)
def Logout(request): if request.method == "POST": mobile = json.loads(request.body.decode().replace("'", "\"")).get('mobile') return HttpResponse(json.dumps(Logout_user(mobile))) else: return HttpResponse(json.dumps(responseJSON_0('请使用POST请求!')))