def addMoney(request): if request.method == "POST": mobile = json.loads(request.body.decode().replace("'", "\"")).get('mobile') money = json.loads(request.body.decode().replace("'", "\"")).get('money') setMealList = [0.5, 1, 3, 6] if float(money) in setMealList: money = float(money) is_mobile = sql.sql_select("SELECT status FROM biz_user WHERE mobile = '{}';".format(mobile)) if is_mobile == []: return HttpResponse(json.dumps({"code": 0, "msg": "用户不存在!", "table_s": ""})) if is_mobile[0][0] != 4: return HttpResponse(json.dumps({"code": 0, "msg": "用户还未完成认证!", "table_s": ""})) if float(money) not in [0.5, 1, 3, 6]: return HttpResponse(json.dumps({"code": 0, "msg": "充值失败,充值月份不在范围!", "table_s": ""})) is_true = sql.sql_select( "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)) if is_true == []: user_id = sql.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()))) sql.sql_exec( "INSERT INTO biz_vip_record (user_id,expire_time) VALUES ({},'{}');" "update biz_user set is_vip=1 where id={};".format(user_id, validTime, user_id)) return HttpResponse( json.dumps({"code": 1, "msg": "未充值VIP!", "table_s": "user_id: {},会员时间:{}".format(user_id, validTime)})) user_id = is_true[0][0] timeArray = time.strptime(is_true[0][1], "%Y-%m-%d %H:%M:%S") timeStamp = int(time.mktime(timeArray)) if timeStamp > int(time.time()): validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(2678400 * money + timeStamp)) sql.sql_exec("UPDATE biz_vip_record SET expire_time='{}' WHERE user_id= {};" "update biz_user set is_vip=1 where id={};".format(validTime, user_id, user_id)) return HttpResponse(json.dumps({"code": 1, "msg": "未过期!", "table_s": "{}".format(validTime)})) if timeStamp < int(time.time()): validTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(2678400 * money + int(time.time()))) sql.sql_exec( "UPDATE biz_vip_record SET expire_time='{}' WHERE user_id= {};" "update biz_user set is_vip=1 where id={};".format(validTime, user_id, user_id)) return HttpResponse(json.dumps({"code": 1, "msg": "过期!", "table_s": ""})) else: if money == "" or mobile == "": return HttpResponse(json.dumps({"code": 0, "msg": "金额或金额类型异常", "table_s": ""})) if type(money) != int: money = int(money) if is_int.is_number(money) or type(money) != int: return HttpResponse(json.dumps({"code": 0, "msg": "金额或金额类型异常", "table_s": ""})) if money > 4000 or money < 1: return HttpResponse(json.dumps({"code": 0, "msg": "金额充值范围1~4000币", "table_s": ""})) is_mobile = sql.sql_select("SELECT status FROM biz_user WHERE mobile = '{}';".format(mobile)) if is_mobile == []: return HttpResponse(json.dumps({"code": 0, "msg": "用户不存在!", "table_s": ""})) if is_mobile[0][0] != 4: return HttpResponse(json.dumps({"code": 0, "msg": "用户还未完成认证!", "table_s": ""})) return HttpResponse(json.dumps({"code": 1, "msg": "充值成功!", "table_s": "当前账户余额:{}"})) else: return HttpResponse(json.dumps({"code": 0, "msg": "请使用POST请求!", "table_s": ""}))
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 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 headPortrait(self, sql): # list_a = [] dataSQL = sql_select(sql) # print(dataSQL) for i in dataSQL: urls = i[1][:-4] + "_zoom.png" # print(urls) try: request = urllib.request.Request(urls) response = urllib.request.urlopen(request) get_img = response.read() # 图片下载至 C:\picture path = self.path + str(i[0]) + '.jpg' with open(path, 'wb') as fp: fp.write(get_img) # print('图片下载完成:{}'.format(i[0])) is_true = self.isValid(path) # print('is_true',is_true) if is_true == False: os.remove(path) else: # updateSQL = "UPDATE biz_user SET picture = '{}' WHERE id = {};".format(urls[25:],i[0]) # sql_exec(updateSQL) print(i[0]) print(urls) except: print('访问为空:{}'.format(i[0])) continue
def is_true(self): print(2) self.driver.find_element_by_id("com.tencent.mm:id/ef9").click() time.sleep(0.5) self.driver.tap([(810, 444), (1050, 2160)], 500) time.sleep(0.5) data = sql_select( "SELECT TOP 3 id ,wechat FROM biz_user WHERE sex = 2 AND wechat != '' and len(wechat) BETWEEN 6 and 20 AND is_valid != 0;" ) for i in data: wx = i[1] self.driver.find_element_by_id("com.tencent.mm:id/fcn").click() time.sleep(0.3) self.driver.find_element_by_id("com.tencent.mm:id/bhn").send_keys( wx) time.sleep(0.3) self.driver.find_element_by_id("com.tencent.mm:id/bhn").click() time.sleep(0.3) self.driver.press_keycode(66) time.sleep(0.3) try: text = self.driver.find_element_by_id( "com.tencent.mm:id/g6f").text if text == '添加到通讯录': ride_file('{}:{}'.format(i[0], wx)) print('真实的', wx) self.driver.press_keycode(4) time.sleep(0.3) self.driver.press_keycode(4) time.sleep(0.3) except Exception as ERR: time.sleep(0.3) self.driver.find_element_by_id("com.tencent.mm:id/aay").click()
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 Complain(): yesterday = datetime.date.today() + datetime.timedelta(-1) startTime = '{} 00:00:00'.format(yesterday) endTime = '{} 23:59:59'.format(yesterday) startTimestamp = int(time.mktime(time.strptime(startTime, "%Y-%m-%d %H:%M:%S"))) endTimestamp = int(time.mktime(time.strptime(endTime, "%Y-%m-%d %H:%M:%S"))) # print(startTime) try: re_data = sql_select( "SELECT COUNT(*) FROM biz_complain WHERE create_time BETWEEN '{}' AND '{}';".format(startTime, endTime)) re_data1 = sql_select( "SELECT COUNT(*) FROM biz_report WHERE create_time BETWEEN '{}' AND '{}';".format(startTime, endTime)) print(re_data[0][0]) if re_data[0][0] != 0 or re_data1[0][0] != 0: writeLog("用户投诉", "昨天有{}位用户发起投诉,{}用户发起举报!".format(re_data[0][0], re_data1[0][0])) except Exception as Err: writeLog("Complain:异常", Err)
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 IOSRechargeRecord(): ''' 检测IOS充值未处理的订单 :return: ''' try: re_data = sql_select("SELECT order_sn FROM apple_pay_callback_log WHERE status = 0 GROUP BY order_sn;") print(re_data) if re_data != []: writeLog("IOS充值未成功订单", re_data) except Exception as Err: writeLog("IOSRechargeRecord:异常", Err)
def removeUser(request): if request.method == "POST": print(request.body) mobile = json.loads(request.body.decode().replace("'", "\"")).get('mobile') is_mobile = sql.sql_select("SELECT status FROM biz_user WHERE mobile = '{}';".format(mobile)) if is_mobile == []: return HttpResponse(json.dumps({"code": 0, "msg": "要删除的用户不存在!", "table_s": ""})) re = sql.sql_exec("exec RemoveUserByMobile '{}';".format(mobile)) print("删除手机", mobile) return HttpResponse(json.dumps({"code": 1, "msg": "删除成功!", "table_s": "{}".format(re)})) else: return HttpResponse(json.dumps({"code": 0, "msg": "请使用POST请求!", "table_s": ""}))
def iosCallBack(self): try: data = sql_select( 'SELECT order_sn,receipt FROM apple_pay_callback_log WHERE status != 0 ;' ) for i in data: self.diteData[i[1]] = i[0] print(self.diteData[i[1]]) print(self.diteData) print(len(self.diteData)) except Exception as a: return a
def photoAlbum(self, sql): list1 = [] # 都没有 list2 = [] # 小图有 list3 = [] # 大图有 list4 = [] # 都图有 dataSQL = sql_select(sql) for i in dataSQL: minUrl = 'http://app.juyuanpark.com' + i[1] maxUrl = 'http://app.juyuanpark.com' + i[2] try: request = urllib.request.Request(minUrl) response = urllib.request.urlopen(request) get_img = response.read() # 图片下载至 C:\picture path1 = self.path + 'min' + str(i[0]) + '.jpg' with open(path1, 'wb') as fp: fp.write(get_img) is_true1 = self.isValid(path1) request = urllib.request.Request(maxUrl) response = urllib.request.urlopen(request) get_img = response.read() # 图片下载至 C:\picture path2 = self.path + 'max' + str(i[0]) + '.jpg' with open(path2, 'wb') as fp: fp.write(get_img) is_true2 = self.isValid(path2) if is_true1 == True and is_true2 == True: os.remove(path1) os.remove(path2) elif is_true1 == True and is_true2 == False: os.remove(path1) list2.append(i[0]) # sql_exec("UPDATE biz_album SET water_img_url = '{}' WHERE id = {};".format(i[1],i[0])) elif is_true1 == False and is_true2 == True: os.remove(path2) # sql_exec("UPDATE biz_album SET img_url = '{}' WHERE id = {};".format(i[2],i[0])) list3.append(i[0]) elif is_true1 == False and is_true2 == False: # sql_exec('DELETE FROM biz_album WHERE id = {}'.format(i[0])) list1.append(i[0]) except: print('访问为空:{}'.format(i[0])) continue print('list1', list1) print('list2', list2) print('list3', list3) print('list4', list4)
def update_base64(): # table_s = sql_select("SELECT id,recommend_mobile FROM biz_invite_code WHERE recommend_mobile LIKE 'MT%';") data = sql_select( "SELECT id,recommend_mobile FROM biz_invite_code WHERE recommend_mobile != '' AND id > 11356;" ) for i in data: if not is_num_by_except(i[1]): try: temp = base64.b64decode(i[1].replace('\n', '').replace('\r', '')) sql_exec( "UPDATE biz_invite_code SET recommend_mobile = '{}' WHERE id = {};" .format(temp.decode(), i[0])) print(i[1], '转换为:', temp.decode()) except: break
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 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 downloadImage(self, sql): ''' 下载图片 :return: ''' dataSQL = sql_select(sql) self.errList = [] self.noneList = [] for i in dataSQL: # print(i) if i[1][-9:] == "_zoom.png": url = 'http://app.juyuanpark.com' + i[1] else: url = 'http://app.juyuanpark.com' + i[1][:-10] + "_zoom.png" # print(url) try: request = urllib.request.Request(url) response = urllib.request.urlopen(request) get_img = response.read() # 图片下载至 C:\picture path = self.path + str(i[0]) + '.jpg' with open(path, 'wb') as fp: fp.write(get_img) is_true = self.isValid(path) if is_true == False: self.errList.append(i[0]) shutil.move(path, self.path2 + str(i[0]) + '.jpg') # shutil.copy2(path,self.path2 + str(i[0]) + '.jpg') # else: # os.remove(path) except: self.noneList.append(i[0]) print('访问为空:{}'.format(i[0])) continue print('损坏的图片:') print(self.errList) print('为空的图片:') print(self.noneList)
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)
AND buy_type = 11 ) FROM biz_order WHERE create_time >= ( SELECT CONVERT ( VARCHAR, GETDATE( ), 23 ) + ' 00:00:00' ) AND status = 1 AND currency = 0 ) vip, ( SELECT COUNT ( sex ) FROM biz_user WHERE create_time >= ( SELECT CONVERT ( VARCHAR, GETDATE( ), 23 ) + ' 00:00:00' ) AND status = 4 ) count_user FROM biz_order WHERE create_time >= ( SELECT CONVERT ( VARCHAR, GETDATE( ), 23 ) + ' 00:00:00' ) AND status = 1;''' from test_server.data.sql import sql_select a = sql_select(a) data = {'money': a[0][0], 'order': a[0][1], 'vip': a[0][2], 'user': a[0][3]} print(data)