def getGroupJd(self, msg, good_url): cm = ConnectMysql() print('开始查询分享商品的信息......', msg['Text']) wei_info = itchat.search_chatrooms(userName=msg['FromUserName']) sku_arr = good_url.split('https://item.m.jd.com/product/') if sku_arr == None: msg_text = tu.tuling(msg) print(msg_text) itchat.send(msg_text, msg['FromUserName']) return sku = sku_arr[1].split('.') res = self.get_good_link(sku[0]) logger.debug(res) if res['data']['shotCouponUrl'] == '': text = ''' 一一一一返利信息一一一一 【商品名】%s 【京东价】%s元 返利链接:%s ''' % (res['logTitle'], res['logUnitPrice'], res['data']['shotUrl']) itchat.send(text, msg['FromUserName']) insert_sql = "INSERT INTO taojin_query_record(good_title, good_price, good_coupon, username, create_time) VALUES('" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '0', '" + wei_info[ 'NickName'] + "', '" + str(time.time()) + "')" cm.ExecNonQuery(insert_sql) return else: text = ''' 一一一一返利信息一一一一 【商品名】%s 【京东价】%s元 【优惠券】%s元 【券后价】%s元 领券链接:%s ''' % (res['logTitle'], res['logUnitPrice'], res['youhuiquan_price'], res['coupon_price'], res['data']['shotCouponUrl']) insert_sql = "INSERT INTO taojin_query_record(good_title, good_price, good_coupon, username, create_time) VALUES('" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '" + res['coupon_price2'] + "', '" + \ wei_info['NickName'] + "', '" + str(time.time()) + "')" cm.ExecNonQuery(insert_sql) itchat.send(text, msg['FromUserName']) return
def get_jd_order(self, bot, msg, orderId, userInfo, puid, raw): # try: order_id = int(orderId) timestr = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) cm = ConnectMysql() # 查询订单是否已经提现过了 check_order_sql = "SELECT * FROM taojin_order WHERE order_id='" + str(order_id) + "' AND bot_puid='"+ bot.self.puid +"' AND puid='"+puid+"';" check_order_res = cm.ExecQuery(check_order_sql) # 判断该订单是否已经提现 if len(check_order_res) >= 1: cm.Close() sendtext = ''' 一一一一 订单消息 一一一一 订单【%s】提交成功,请勿重复提交 ''' % (order_id) return sendtext cm.ExecNonQuery("INSERT INTO taojin_order(wx_bot, username, order_id, completion_time, order_source, puid, bot_puid, status) VALUES('"+ str(bot.self.nick_name) +"', '" + str(userInfo['NickName']) + "', '" + str(order_id) + "', '" + str(timestr) + "', '2', '"+puid+"', '"+ bot.self.puid +"', '1')") send_text =''' 一一一一 订单消息 一一一一 订单【%s】提交成功,请耐心等待订单结算 结算成功后机器人将自动返利到您个人账户 ''' % (order_id) return send_text
def get_good_info(self, bot): cm = ConnectMysql() self.load_cookies() page = 1 sku_num = 0 while sku_num < 20: url = "https://media.jd.com/gotoadv/goods?searchId=2011005331%23%23%23st3%23%23%23kt0%23%23%2378dc30b6-fa14-4c67-900c-235b129ab4bb&pageIndex="+str(page)+"&pageSize=50&property=&sort=&goodsView=&adownerType=&pcRate=&wlRate=&category1=&category=&category3=&condition=1&fromPrice=&toPrice=&dataFlag=0&keyword=&input_keyword=&hasCoupon=1&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC&price=PC" page += 1 self.logger.debug(page) res = self.se.get(url) soup = BeautifulSoup(res.text, 'lxml') skuList = [] for li in soup.find_all('li', skuid = re.compile('^[0-9]+$')): sku = li.get('skuid') exists_sql = "SELECT * FROM taojin_good_info WHERE skuid='"+str(sku)+"' AND bot_puid='"+ bot.self.puid +"';" is_exists = cm.ExecQuery(exists_sql) if len(is_exists) != 0: print('0....') continue sku_num += 1 skuList.append(sku) if skuList == []: print('[]....') continue for item in skuList: link_info = self.get_good_link(str(item)) # item_image = link_info['data']['qRcode'] item_image = link_info['imgUrl'] # 请求图片 res_img = requests.get(item_image) img_name = item_image.split('/') # 拼接图片名 file_name = "images/" + img_name[-1] fp = open(file_name, 'wb') # 写入图片 fp.write(res_img.content) fp.close() if link_info['data']['shotCouponUrl'] == '': continue else: sql = "INSERT INTO taojin_good_info(wx_bot, skuid, title, image, price, rebate, yhq_price, coupon_price, shoturl, shotcouponurl, status, create_time, bot_puid) VALUES('"+ bot.self.nick_name +"', '" + str( item) + "', '" + str(link_info['logTitle']) + "', '" + str(item_image) + "', '" + str( link_info['logUnitPrice']) + "', '" + str(link_info['rebate']) + "', '" + str( link_info['youhuiquan_price']) + "', '" + str(link_info['coupon_price']) + "', '" + str( link_info['data']['shotUrl']) + "', '" + str( link_info['data']['shotCouponUrl']) + "', '1', '" + str(time.time()) + "', '"+ bot.self.puid +"')" cm.ExecNonQuery(sql) print("insert success!")
def setData(): cm = ConnectMysql() # 需要从request对象读取表单内容: formdata = request.form username = formdata['username'] for item in formdata: if item != 'username': insert_sql = "INSERT INTO taojin_group_message(username, groupid, groupname, create_time) VALUES('"+username+"', '"+item+"', '"+formdata[item]+"', '"+str(time.time())+"')" cm.ExecNonQuery(insert_sql) # 执行群发任务 fmm.start_send_msg_thread() return "添加成功!"
def send_group_meg(self): cm = ConnectMysql() res = itchat.web_init() select_sql = "SELECT * FROM taojin_group_message WHERE username='******'User']['NickName']) + "';" group_info = cm.ExecQuery(select_sql) while True: a = datetime.datetime.now().hour if int(a) < 8 | int(a) >= 20: print('时间不够') continue print('ok') time.sleep(300) data_sql = "SELECT * FROM taojin_good_info WHERE status=1 LIMIT 1" data1 = cm.ExecQuery(data_sql) if data1 == (): mjd.get_good_info() cm.Close() cm2 = ConnectMysql() data = cm2.ExecQuery(data_sql) text = ''' 一一一一优惠信息一一一一 【商品名】%s 【京东价】%s元 【优惠券】%s元 【券后价】%s元 领券链接:%s 请点击链接领取优惠券,下单购买! ''' % (data[0][2], data[0][4], data[0][6], data[0][7], data[0][9]) delete_sql = "UPDATE taojin_good_info SET status='2' WHERE id='" + str(data[0][0]) + "'" cm.ExecNonQuery(delete_sql) img_name = data[0][3].split('/') img_path = "images/" + img_name[-1] for item in group_info: time.sleep(2) itchat.send_image(img_path, item[2]) itchat.send(text, item[2])
def groupMessages(self, bot): global bot2 bot2 = bot time.sleep(10) yorn = input("是否重新选群?y/n:") if yorn == 'n': self.start_send_msg_thread() return print('start select groups.....') # 删除原有群聊数据 cm = ConnectMysql() select_sql = "DELETE FROM taojin_group_message WHERE bot_puid='" + bot2.self.puid + "';" cm.ExecNonQuery(select_sql) group = bot2.groups() print(group) template_demo = """ <!DOCTPE html> <html> <head> <meta charset="utf-8"/> <title>选择群聊</title> </head> <body> <div> <form action='/formdata' method='post'> <h2>选择群聊</h2> <input type="hidden" name="username" value="{{ res }}" /> <input type="hidden" name="bot_puid" value="{{ bot_puid }}" /> <ul> % for item in items: <li><input type="checkbox" name="{{ item.user_name }}" value="{{ item.nick_name }}" />{{ item.nick_name }}</li> %end </ul> <h2>输入需要群发内容:</h2> <textarea name="sendText" rows="3" cols="20"></textarea> <input type='submit' value='提交' /> </form> </div> </body> </html> """ html = template(template_demo, items=group, res=bot2.self.nick_name, bot_puid=bot2.self.puid) with open('form.html', 'w', encoding='utf-8') as f: f.write(html) self.run()
def setData(): cm = ConnectMysql() # 需要从request对象读取表单内容: formdata = request.form username = formdata['username'] bot_puid = formdata['bot_puid'] # 把需要群发的信息写入send.txt with open('send.txt', 'w') as fw: # 写入 fw.write(formdata['sendText']) # 把群聊信息写入数据库 for item in formdata: if item != 'username' and item != 'sendText' and item != 'bot_puid': insert_sql = "INSERT INTO taojin_group_message(username, groupid, groupname, create_time, bot_puid) VALUES('" + username + "', '" + item + "', '" + \ formdata[item] + "', '" + str(time.time()) + "', '" + bot_puid + "')" cm.ExecNonQuery(insert_sql) # 执行群发任务 fmm.start_send_msg_thread() return "添加成功!"
def groupMessages(self): time.sleep(30) yorn = input("是否重新选群?y/n:") if yorn == 'n': self.start_send_msg_thread() return print('start.....') cm = ConnectMysql() res = itchat.web_init() select_sql = "DELETE FROM taojin_group_message WHERE username='******'User']['NickName']) + "';" cm.ExecNonQuery(select_sql) group = itchat.get_chatrooms(update=True, contactOnly=False) template_demo = """ <!DOCTPE html> <html> <head> <meta charset="utf-8"/> <title>选择群聊</title> </head> <body> <div> <form action='/formdata' method='post'> <input type="hidden" name="username" value="{{ res['User']['NickName'] }}" /> % for item in items: <input type="checkbox" name="{{ item['UserName'] }}" value="{{ item['NickName'] }}" />{{ item['NickName'] }} %end <input type='submit' value='提交' /> </form> </div> </body> </html> """ html = template(template_demo, items=group, res=res) with open('form.html', 'w', encoding='utf-8') as f: f.write(html) self.run()
def get_group_detail(self, q, msg): cm = ConnectMysql() chatrooms = itchat.search_chatrooms(userName=msg['FromUserName']) try: t = int(time.time() * 1000) tb_token = self.se.cookies.get('_tb_token_', domain="pub.alimama.com") pvid = '10_%s_1686_%s' % (self.myip, t) url = 'http://pub.alimama.com/items/search.json?q=%s&_t=%s&auctionTag=&perPageSize=40&shopTag=&t=%s&_tb_token_=%s&pvid=%s' % ( urllib.quote(q.encode('utf8')), t, t, tb_token, pvid) headers = { 'method': 'GET', 'authority': 'pub.alimama.com', 'scheme': 'https', 'path': '/items/search.json?%s' % url.split('search.json?')[-1], 'accept': 'application/json, text/javascript, */*; q=0.01', 'x-requested-with': 'XMLHttpRequest', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0', 'referer': 'https://pub.alimama.com', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en;q=0.5', } res = self.get_url(url, headers) print(res.text) rj = res.json() if rj['data']['pageList'] != None: insert_sql = "INSERT INTO taojin_query_record(good_title, good_price, good_coupon, username, create_time) VALUES('" + rj[ 'data']['pageList'][0]['title'] + "', '" + str( rj['data']['pageList'][0]['zkPrice']) + "', '" + str( rj['data']['pageList'][0]['couponAmount'] ) + "', '" + chatrooms['NickName'] + "', '" + str( time.time()) + "')" cm.ExecNonQuery(insert_sql) cm.Close() return rj['data']['pageList'][0] else: return 'no match item' except Exception as e: trace = traceback.format_exc() self.logger.warning("error:{},trace:{}".format(str(e), trace))
def changeInfoAlimama(self, puid, orderInfo): try: cm = ConnectMysql() # 查询用户是否有上线 check_user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "';" check_user_res = cm.ExecQuery(check_user_sql) this_user = self.bot.friends().search( nick_name=check_user_res[0][4])[0] # 定义SQL语句 查询用户是否已经存在邀请人 # 判断是否已经有邀请人了 if check_user_res and check_user_res[0][17] != '0': # 获取邀请人信息 get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str( check_user_res[0] [17]) + "' AND bot_puid='" + self.bot.self.puid + "';" get_parent_info = cm.ExecQuery(get_parent_sql) # 计算返佣 add_balance = round( float(orderInfo[9]) * float(self.config.get('BN', 'bn3t')), 2) # 累加余额 withdrawals_amount = round( float(check_user_res[0][9]) + add_balance, 2) # 累加淘宝总返利 taobao_rebate_amount = round( float(check_user_res[0][8]) + add_balance, 2) # 累加总返利 total_rebate_amount = round( float(check_user_res[0][6]) + add_balance, 2) jishen = round( float(orderInfo[4]) * float(orderInfo[5]) - float(orderInfo[6])) if jishen < 0: jishen = 0 # 计算共节省金额,商品原价减去实际支付价格,加上原有节省金额加上返佣 save_money = round( check_user_res[0][10] + jishen + add_balance, 2) # 总订单数加一 total_order_num = int(check_user_res[0][11]) + 1 # 淘宝订单数加一 taobao_order_num = int(check_user_res[0][13]) + 1 # 邀请人返利金额 add_parent_balance = round( float(orderInfo[9]) * float(self.config.get('BN', 'bn4')), 2) # 给邀请人好友返利加上金额 friends_rebatr = round( float(get_parent_info[0][19]) + float(add_parent_balance)) # 邀请人总钱数加上返利金额 withdrawals_amount2 = round( float(get_parent_info[0][9]) + float(add_parent_balance), 2) cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "', save_money='" + str(save_money) + "', taobao_rebate_amount='" + str(taobao_rebate_amount) + "', total_rebate_amount='" + str(total_rebate_amount) + "', order_quantity='" + str(total_order_num) + "', taobao_order_quantity='" + str(taobao_order_num) + "', update_time='" + str(time.time()) + "' WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "';") cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount2) + "', friends_rebate='" + str(friends_rebatr) + "', update_time='" + str(time.time()) + "' WHERE lnivt_code='" + str(check_user_res[0][17]) + "' AND bot_puid='" + self.bot.self.puid + "';") #select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'" # 订单已完成,修改备注 '''order_num = cm.ExecQuery(select_order_num) if order_num == (): split_arr = this_user.remark_name.split('_') new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3]) bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'") cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'") # 累计订单数量 order_nums = cm.ExecQuery(select_order_num) split_arr2 = this_user.remark_name.split('_') new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums)) bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'") ''' args = { 'wx_bot': self.bot.self.nick_name, 'bot_puid': self.bot.self.puid, 'username': check_user_res[0][4], 'puid': puid, 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) parent_puid = get_parent_info[0][2] args2 = { 'wx_bot': self.bot.self.nick_name, 'bot_puid': self.bot.self.puid, 'username': get_parent_info[0][4], 'puid': parent_puid, 'rebate_amount': add_parent_balance, 'type': 4, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args2) parent_user_text = ''' 一一一一 推广信息 一一一一 好友【%s】又完成一笔订单 返利提成%s元已发放到个人账户 回复【个人信息】可查询账户详情 ''' % (check_user_res[0][4], add_parent_balance) user_text = ''' 一一一一系统消息一一一一 订单【%s】返利成功 返利金%s元已发放到个人账户 回复【个人信息】可查询账户详情 回复【提现】可申请账户余额提现 ''' % (orderInfo[1], add_balance) cm.Close() parent_user = self.bot.friends().search( nick_name=get_parent_info[0][4])[0] parent_user.send(parent_user_text) this_user.send(user_text) else: add_balance = round( float(orderInfo[9]) * float(self.config.get('BN', 'bn3t')), 2) withdrawals_amount = round( float(check_user_res[0][9]) + add_balance, 2) taobao_rebate_amount = round( float(check_user_res[0][8]) + add_balance, 2) total_rebate_amount = round( float(check_user_res[0][6]) + add_balance, 2) jishen = add_balance if jishen < 0: jishen = 0 save_money = round( check_user_res[0][10] + jishen + add_balance, 2) total_order_num = int(check_user_res[0][11]) + 1 taobao_order_num = int(check_user_res[0][13]) + 1 cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "', save_money='" + str(save_money) + "', taobao_rebate_amount='" + str(taobao_rebate_amount) + "', total_rebate_amount='" + str(total_rebate_amount) + "', order_quantity='" + str(total_order_num) + "', taobao_order_quantity='" + str(taobao_order_num) + "', update_time='" + str(time.time()) + "' WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "';") #select_order_num = "SELECT * FROM taojin_order WHERE puid='" + puid + "' AND bot_puid='" + self.bot.self.puid + "'" # 订单已完成,修改备注 '''order_num = cm.ExecQuery(select_order_num) if order_num == (): split_arr = this_user.remark_name.split('_') new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'C', '_', split_arr[3]) self.logger.debug(new_remark_name) bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'") cm.ExecNonQuery("UPDATE taojin_order SET status=2 WHERE order_id='"+str(orderInfo[1])+"'") # 累计订单数量 order_nums = cm.ExecQuery(select_order_num) split_arr2 = this_user.remark_name.split('_') new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', split_arr2[2], '_', len(order_nums)) bot.core.set_alias(userName=this_user.user_name, alias=new_remark_name2) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + puid + "' AND bot_puid='" + bot.self.puid + "'")''' args = { 'wx_bot': self.bot.self.nick_name, 'bot_puid': self.bot.self.puid, 'username': check_user_res[0][4], 'puid': puid, 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) user_text = ''' 一一一一系统消息一一一一 订单【%s】返利成功 返利金%s元已发放到个人账户 回复【个人信息】可查询账户详情 回复【提现】可申请账户余额提现 ''' % (orderInfo[1], add_balance) cm.Close() this_user.send(user_text) except Exception as e: trace = traceback.format_exc() self.logger.warning("error:{},trace:{}".format(str(e), trace)) return {'info': 'feild'}
def getText(self, raw, bot, msg): wei_info = bot.core.search_friends(userName=msg['FromUserName']) patternURL = re.compile('^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+') pattern_bz = re.compile('^帮助$') pattern_profile = re.compile('^个人信息$') pattern_tixian = re.compile('^提现$') pattern_tuig = re.compile('^推广$') pattern_proxy = re.compile('^代理$') appect_friend = re.compile('^我通过了你的朋友验证请求,现在我们可以开始聊天了$') # 判断是否是URL链接 if patternURL.search(msg['Text']) == None: pattern_s = re.compile('^搜') pattern_z = re.compile('^找') pattern_m = re.compile('^买') if (pattern_s.search(msg['Text']) != None) | (pattern_z.search( msg['Text']) != None) | (pattern_m.search(msg['Text']) != None): res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) jdurl = quote(config.get('URL', 'jdshopingurl') + msg['Text'][1:], safe='/:?=&') tburl = quote(config.get('URL', 'tbshopingurl') + msg['Text'][1:], safe='/:?=&') res1 = self.movie.getShortUrl(jdurl) res2 = self.movie.getShortUrl(tburl) print('WEEWEWEW', msg) text = ''' 一一一一系统消息一一一一 亲,以下是【%s】优惠券集合 京东:%s 淘宝:%s ''' % (msg['Text'][1:], res1, res2) return text elif appect_friend.search(msg['Text']) != None: # 获取生成的备注 ramerkName = self.ort.generateRemarkName(bot) self.logger.debug(ramerkName) # 修改备注 bot.core.set_alias(userName=msg['FromUserName'], alias=ramerkName) # 被邀请人puid user_wxid = self.ort.getPuid(bot, msg['FromUserName']) self.ort.create_user_info(raw, bot, msg, lnivt_code=0, tool=True, wxid=user_wxid) text = ''' Hi~我是24h在线的淘小券机器人 分享【京东商品】 分享【淘口令】 分享【拼多多商品】 回复【互助】查看机器人指令 精准查询全网内部优惠券哦,您也可以访问下边优惠券商城自主查询呢! 京东优惠券商城: ''' + config.get('URL', 'jdshop') + ''' 淘宝优惠券商城: ''' + config.get('URL', 'tbshop') + ''' 邀请好友得返利说明: ''' + config.get('URL', 'lnvit') + ''' ''' return text elif ('你已添加了' in msg['Text']) and ('现在可以开始聊天了' in msg['Text']): arrstr = msg['Text'].split(',') str = arrstr[0][5:] self.logger.debug(str) user = bot.friends().search(str)[0] self.logger.debug(str, user) # 获取生成的备注 ramerkName = self.ort.generateRemarkName(bot) self.logger.debug(ramerkName) # 修改备注 bot.core.set_alias(nickName=user.user_name, alias=ramerkName) # 被邀请人puid user_wxid = user.puid self.ort.create_user_info(raw, bot, msg, lnivt_code=0, tool=True, wxid=user_wxid) text = ''' Hi~我是24h在线的淘小券机器人 分享【京东商品】 分享【淘口令】 分享【拼多多商品】 回复【互助】查看机器人指令 精准查询全网内部优惠券哦,您也可以访问下边优惠券商城自主查询呢! 京东优惠券商城: ''' + config.get('URL', 'jdshop') + ''' 淘宝优惠券商城: ''' + config.get('URL', 'tbshop') + ''' 邀请好友得返利说明: ''' + config.get('URL', 'lnvit') + ''' ''' return text elif pattern_bz.search(msg['Text']) != None: res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) # 帮助操作 text = ''' Hi~我是24h在线的淘小券机器人,用淘小券,免费领取任意淘宝,天猫,京东,拼多多商品优惠券,好用的话记得分享给好友哦 回复【帮助】可查询指信息 回复【提现】申请账户余额提现 回复【推广】可申请机器人代理 回复【个人信息】可看个当前账户信息 回复【买+商品名称】 回复【找+商品名称】 回复【搜+商品名称】查看商品优惠券合集 分享【京东商品】 分享【淘宝淘口令】 分享【拼多多商品】 精准查询商品优惠券和返利信息! 分享【VIP视频链接】免费查看高清VIP视频! 优惠券使用教程: http://t.cn/RnAKqWW 跑堂优惠券常见问题: http://t.cn/RnAK1w0 免费看电影方法: http://t.cn/RnAKMul 京东优惠券商城: http://jdyhq.ptjob.net 淘宝优惠券商城: http://xiaoquan.ptjob.net 邀请好友得返利说明: http://t.cn/RnAKafe ''' return text elif pattern_tixian.search(msg['Text']) != None: cm = ConnectMysql() res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) select_user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" select_user_res = cm.ExecQuery(select_user_sql) timestr = round(time.time()) timestr2 = repr(timestr) # 设置提现门槛 if float(select_user_res[0][9]) < int( config.get('SYS', 'tixianprice')): text2 = ''' 一一一一 提现信息 一一一一 提现申请失败 当前账户余额为%s 最小提现金额为%s元! ''' % ( select_user_res[0][9], config.get( 'SYS', 'tixianprice')) return text2 adminuser = bot.friends().search( config.get('ADMIN', 'ADMIN_USER'))[0] if float(select_user_res[0][9]) > 0: # 修改余额 update_sql = "UPDATE taojin_user_info SET withdrawals_amount='0', update_time='" + timestr2 + "' WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" total_amount = float(select_user_res[0][6]) + float( select_user_res[0][9]) update_total_sql = "UPDATE taojin_user_info SET total_rebate_amount='" + repr( total_amount ) + "',update_time='" + timestr2 + "' WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" # 插入提现日志 insert_current_log_sql = "INSERT INTO taojin_current_log(wx_bot, username, amount, create_time, puid, bot_puid) VALUES('" + bot.self.nick_name + "', '" + wei_info[ 'NickName'] + "', '" + repr( select_user_res[0][9] ) + "', '" + timestr2 + "', '" + raw.sender.puid + "', '" + bot.self.puid + "')" to_admin_text = ''' 一一一一 提现通知 一一一一 机器人:%s 提现人:%s 提现金额:%s元 提现时间:%s ''' % ( bot.self.nick_name, wei_info['NickName'], select_user_res[0][9], time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) cm.ExecNonQuery(update_sql) cm.ExecNonQuery(update_total_sql) cm.ExecNonQuery(insert_current_log_sql) to_user_text = ''' 一一一一 提现信息 一一一一 恭喜你成功提现【%s】元 提现金额将以微信红包发放,请耐心等待 ''' % (select_user_res[0][9]) adminuser.send(to_admin_text) return to_user_text else: text2 = ''' 一一一一 提现信息 一一一一 提现申请失败,账户余额为0! ''' return text2 elif pattern_profile.search(msg['Text']) != None: cm = ConnectMysql() res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" user_info = cm.ExecQuery(user_sql) current = "SELECT sum(amount) FROM taojin_current_log WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" current_info = cm.ExecQuery(current) # 如果总提现金额不存在,赋值为0 if current_info[0][0] == None: current_info = 0 else: current_info = current_info[0][0] text = ''' 一一一一 个人信息 一一一一 总返利金额:%s元 京东返利金额:%s元 淘宝返利金额:%s元 拼多多返利金额:%s元 可提现余额:%s元 累计提现金额:%s元 累计订单量:%s 京东订单量:%s 淘宝订单量:%s 拼多多订单量:%s 总好友返利:%s 总好友个数:%s ''' % ( user_info[0][6], user_info[0][7], user_info[0][8], user_info[0][25], user_info[0][9], current_info, user_info[0][11], user_info[0][12], user_info[0][13], user_info[0][26], user_info[0][19], user_info[0][20]) cm.Close() return text elif pattern_tuig.search(msg['Text']) != None: cm = ConnectMysql() res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) user_sql = "SELECT * FROM taojin_user_info WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "';" cm.ExecQuery(user_sql) text = ''' 一一一一 推广信息 一一一一 将机器人名片分享到群或者好友 好友添加机器人为好友 您和好友都将获取''' + config.get('BN', 'bn2') + '''元现金奖励 且您将永久享受好友返利10%提成 邀请好友得返利说明: ''' + config.get('URL', 'lnvit') + ''' ''' return text elif pattern_proxy.search(msg['Text']) != None: res = self.ort.ishaveuserinfo(bot, msg, raw) if res['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) text = ''' 一一一一系统消息一一一一 点击链接:''' + config.get('URL', 'proxy') + ''' 添加好友备注:优惠券代理 客服人员将尽快和您取得联系,请耐心等待! ''' return text elif (msg['Text'].isdigit()) and (len(msg['Text']) == 11): res2 = self.ort.ishaveuserinfo(bot, msg, raw) if res2['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) res = self.mjd.get_jd_order(bot, msg, msg['Text'], wei_info, raw.sender.puid, raw) return res elif (msg['Text'].isdigit()) and (len(msg['Text']) == 18): res2 = self.ort.ishaveuserinfo(bot, msg, raw) if res2['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) res = self.al.order(msg['Text'], raw) return res elif ('-' in msg['Text']) and (len(msg['Text'].split('-')[1]) == 15) and (len(msg['Text']) == 22): res2 = self.ort.ishaveuserinfo(bot, msg, raw) if res2['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) res = self.pdd.order_pdd(bot, msg, 123456, wei_info, raw.sender.puid, raw) return res else: if config.get('SYS', 'tl') == 'yes': msg_text = self.tu.tuling(msg) self.logger.debug(msg_text) return msg_text else: return else: res2 = self.ort.ishaveuserinfo(bot, msg, raw) if res2['res'] == 'not_info': self.ort.create_user_info(raw, bot, msg, 0, tool=False) self.mjd.getJd(raw, bot, msg, msg['Text'])
def getGood(self, raw, msg): cm = ConnectMysql() try: # 获取商品信息,首先获取商品id arr1 = msg['Text'].split('元') arr2 = arr1[1].split('拼多多') good_id = self.getDetail(arr2[0]) if good_id == 'GetGoodIdError': error_text = ''' 一一一一 返利信息 一一一一 亲,当前商品暂无优惠券,建议您换一个商品试试呢,您也可以在下边的优惠券商城中查找哦 京东优惠券商城: ''' + self.config.get('URL', 'jdshop') + ''' 淘宝优惠券商城: ''' + self.config.get('URL', 'tbshop') + ''' 邀请好友得返利说明: ''' + self.config.get('URL', 'lnvit') + ''' ''' return error_text pid = self.getPromotion() if pid == 'GetPromotionIdError': error_text = ''' 一一一一 返利信息 一一一一 亲,当前商品暂无优惠券,建议您换一个商品试试呢,您也可以在下边的优惠券商城中查找哦 京东优惠券商城: ''' + self.config.get('URL', 'jdshop') + ''' 淘宝优惠券商城: ''' + self.config.get('URL', 'tbshop') + ''' 邀请好友得返利说明: ''' + self.config.get('URL', 'lnvit') + ''' ''' return error_text pid = pid['result']['promotionChannelList'][0]['pid'] res = self.getLink(good_id['result']['goodsList'][0]['goodsId'], pid) good = good_id['result']['goodsList'][0]['goodsId'] # 判断是否有优惠券 if good_id['result']['goodsList'][0]['hasCoupon'] == True: # 原价 minGroupPrice = float( int(good_id['result']['goodsList'][0]['minGroupPrice']) / 1000) # 优惠券 coupon = int( int(good_id['result']['goodsList'][0]['couponDiscount']) / 1000) # 卷后价 couponPrice = round(float(minGroupPrice - coupon), 2) # 返利金额 backPrice = round(((float( couponPrice * (int(good_id['result']['goodsList'][0]['promotionRate']) / 1000)))) * float(self.config.get('BN', 'bn3p')), 2) text = ''' 一一一一拼多多返利一一一一 【商品名】%s 【拼多多】%s元 【优惠券】%s元 【劵后价】%s元 【返红包】%s元 领券链接:%s 获取返红包步骤: 1,复制本条消息打开淘宝领券 2,下单后复制订单号发给我 ''' % (arr2[0], minGroupPrice, coupon, couponPrice, backPrice, res['result']['shortUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, skuid, type) VALUES('"+ self.bot.self.nick_name +"', '" + \ arr2[0] + "', '" + str(minGroupPrice) + "', '"+str(coupon)+"', '" + raw.sender.nick_name + "', '" + str(time.time()) + "', '"+ raw.sender.puid +"', '"+ self.bot.self.puid +"', '"+ str(good) +"', '3')" cm.ExecNonQuery(insert_sql) return text else: # 原价 minGroupPrice = float( int(good_id['result']['goodsList'][0]['minGroupPrice']) / 1000) # 返利金额 backPrice = round(((float( minGroupPrice * (int(good_id['result']['goodsList'][0]['promotionRate']) / 1000)))) * float(self.config.get('BN', 'bn3p')), 2) text = ''' 一一一一拼多多返利一一一一 【商品名】%s 【拼多多】%s元 【返红包】%s元 返利链接:%s 获取返红包步骤: 1,复制本条消息打开淘宝领券 2,下单后复制订单号发给我 ''' % (arr2[0], minGroupPrice, backPrice, res['result']['shortUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, skuid, type) VALUES('" + self.bot.self.nick_name + "', '" + arr2[ 0] + "', '" + str( minGroupPrice ) + "', '0', '" + raw.sender.nick_name + "', '" + str( time.time() ) + "', '" + raw.sender.puid + "', '" + self.bot.self.puid + "', '" + str( good) + "', '3')" cm.ExecNonQuery(insert_sql) return text except Exception as e: trace = traceback.format_exc() print("error:{},trace:{}".format(str(e), trace))
def changeInfo(self, msg, info, order_id, userInfo): cm = ConnectMysql() # try: # 查询用户是否有上线 check_user_sql = "SELECT * FROM taojin_user_info WHERE wx_number='" + str( userInfo['NickName']) + "';" check_user_res = cm.ExecQuery(check_user_sql) # 判断是否已经有个人账户,没有返回信息 if len(check_user_res) < 1: cm.Close() return {"info": "not_info"} else: get_query_sql = "SELECT * FROM taojin_query_record WHERE good_title='" + info[ 'skuList'][0]['skuName'] + "'AND username='******' ORDER BY create_time LIMIT 1;" get_query_info = cm.ExecQuery(get_query_sql) # 定义SQL语句 查询用户是否已经存在邀请人 # 判断是否已经有邀请人了 if check_user_res and check_user_res[0][16] != 0: get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str( check_user_res[0][16]) + "';" get_parent_info = cm.ExecQuery(get_parent_sql) print(get_parent_info) add_balance = round( float(info['skuList'][0]['actualFee']) * 0.3, 2) withdrawals_amount = round( float(check_user_res[0][8]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) jd = round( float(check_user_res[0][6]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) total_rebate_amount = round( float(check_user_res[0][5]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) save_money = round( check_user_res[0][9] + (float(get_query_info[0][2]) - float(info['skuList'][0]['payPrice'])), 2) add_parent_balance = round( float(info['skuList'][0]['actualFee']) * 0.1, 2) withdrawals_amount2 = round( float(get_parent_info[0][8]) + float(add_balance) * 0.1, 2) cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "', save_money='" + str(save_money) + "', jd_rebate_amount='" + str(jd) + "', total_rebate_amount='" + str(total_rebate_amount) + "', update_time='" + str(time.time()) + "' WHERE wx_number='" + str(userInfo['NickName']) + "';") cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount2) + "', update_time='" + str(time.time()) + "' WHERE lnivt_code='" + str(check_user_res[0][16]) + "';") cm.ExecNonQuery( "INSERT INTO taojin_order(username, order_id, order_source) VALUES('" + str(userInfo['NickName']) + "', '" + str(order_id) + "', '1')") args = { 'username': check_user_res[0][1], 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) args2 = { 'username': get_parent_info[0][1], 'rebate_amount': add_parent_balance, 'type': 4, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args2) parent_user_text = ''' 一一一一 推广信息 一一一一 您的好友【%s】又完成了一笔订单,返利提成%s元已发放到您的账户 回复【个人信息】查询账户信息及提成 ''' % (check_user_res[0][3], add_parent_balance) user_text = ''' 一一一一系统消息一一一一 订单【%s】已完成! 返利金%s元已发放到您的个人账户! 回复【提现】可申请账户余额提现 回复【个人信息】可看个当前账户信息 分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息! 分享【VIP视频链接】免费查看高清VIP视频! 优惠券使用教程: http://t.cn/RnAKqWW 京东优惠券网站: http://jdyhq.ptjob.net 淘宝优惠券网站: http://tbyhq.ptjob.net 邀请好友得返利: http://t.cn/RnAKafe ''' % (order_id, add_balance) cm.Close() return { 'parent_user_text': parent_user_text, 'user_text': user_text, 'info': 'success', 'parent': get_parent_info[0][1] } else: add_balance = round( float(info['skuList'][0]['actualFee']) * 0.3, 2) withdrawals_amount = round( float(check_user_res[0][8]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) jd = round( float(check_user_res[0][6]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) total_rebate_amount = round( float(check_user_res[0][5]) + float(info['skuList'][0]['actualFee']) * 0.3, 2) save_money = round( check_user_res[0][9] + (float(get_query_info[0][2]) - float(info['skuList'][0]['payPrice'])), 2) up_sql = "UPDATE taojin_user_info SET jd_rebate_amount='" + str( jd) + "', withdrawals_amount='" + str( withdrawals_amount) + "', save_money='" + str( save_money) + "', total_rebate_amount='" + str( total_rebate_amount ) + "', update_time='" + str( time.time()) + "' WHERE wx_number='" + str( userInfo['NickName']) + "';" cm.ExecNonQuery(up_sql) # cm.ExecNonQuery("UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "' WHERE wx_number='" + str(msg['FromUserName']) + "';") cm.ExecNonQuery( "INSERT INTO taojin_order(username, order_id, order_source) VALUES('" + str(userInfo['NickName']) + "', '" + str(order_id) + "', '2')") args = { 'username': check_user_res[0][1], 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) user_text = ''' 一一一一 订单消息 一一一一 订单【%s】标记成功,返利金%s已发放到您的账户 回复【个人信息】 查看订单及返利信息 ''' % (order_id, add_balance) cm.Close() return { 'user_text': user_text, 'info': 'not_parent_and_success' }
def changeInfo(self, msg, info, order_id, userInfo): try: cm = ConnectMysql() # 查询用户是否有上线 check_user_sql = "SELECT * FROM taojin_user_info WHERE wx_number='" + str( userInfo['NickName']) + "';" check_user_res = cm.ExecQuery(check_user_sql) # 判断是否已经有个人账户,没有返回信息 if len(check_user_res) < 1: cm.Close() return {"info": "not_info"} else: get_query_sql = "SELECT * FROM taojin_query_record WHERE good_title='" + info[ 'auctionTitle'] + "'AND username='******' ORDER BY create_time LIMIT 1;" get_query_info = cm.ExecQuery(get_query_sql) # 定义SQL语句 查询用户是否已经存在邀请人 # 判断是否已经有邀请人了 if check_user_res and check_user_res[0][16] != 0: get_parent_sql = "SELECT * FROM taojin_user_info WHERE lnivt_code='" + str( check_user_res[0][16]) + "';" get_parent_info = cm.ExecQuery(get_parent_sql) add_balance = round(float(info['feeString']) * 0.3, 2) withdrawals_amount = round( float(check_user_res[0][8]) + float(info['feeString']) * 0.3, 2) taobao_rebate_amount = round( float(check_user_res[0][7]) + float(info['feeString']) * 0.3, 2) total_rebate_amount = round( float(check_user_res[0][5]) + float(info['feeString']) * 0.3, 2) save_money = round( check_user_res[0][9] + (float(get_query_info[0][2]) - float(info['realPayFeeString'])) + add_balance, 2) total_order_num = int(check_user_res[0][10]) + 1 taobao_order_num = int(check_user_res[0][12]) + 1 add_parent_balance = round( float(info['feeString']) * 0.1, 2) friends_rebatr = float( get_parent_info[0][18]) + float(add_balance) withdrawals_amount2 = round( float(get_parent_info[0][8]) + float(add_balance) * 0.1, 2) cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "', save_money='" + str(save_money) + "', taobao_rebate_amount='" + str(taobao_rebate_amount) + "', total_rebate_amount='" + str(total_rebate_amount) + "', order_quantity='" + str(total_order_num) + "', taobao_order_quantity='" + str(taobao_order_num) + "', update_time='" + str(time.time()) + "' WHERE wx_number='" + str(userInfo['NickName']) + "';") cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount2) + "', friends_rebate='" + str(friends_rebatr) + "', update_time='" + str(time.time()) + "' WHERE lnivt_code='" + str(check_user_res[0][16]) + "';") cm.ExecNonQuery( "INSERT INTO taojin_order(username, order_id, order_source) VALUES('" + str(userInfo['NickName']) + "', '" + str(order_id) + "', '2')") args = { 'username': check_user_res[0][1], 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) args2 = { 'username': get_parent_info[0][1], 'rebate_amount': add_parent_balance, 'type': 4, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args2) parent_user_text = ''' 一一一一 推广信息 一一一一 您的好友【%s】又完成了一笔订单,返利提成%s元已发放到您的账户 回复【个人信息】查询账户信息及提成 ''' % (check_user_res[0][3], add_parent_balance) user_text = ''' 一一一一系统消息一一一一 订单【%s】已完成! 返利金%s元已发放到您的个人账户! 回复【提现】可申请账户余额提现 回复【个人信息】可看个当前账户信息 分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息! 分享【VIP视频链接】免费查看高清VIP视频! 优惠券使用教程: http://t.cn/RnAKqWW 京东优惠券网站: http://jdyhq.ptjob.net 淘宝优惠券网站: http://tbyhq.ptjob.net 邀请好友得返利: http://t.cn/RnAKafe ''' % (order_id, add_balance) return { 'parent_user_text': parent_user_text, 'user_text': user_text, 'info': 'success', 'parent': get_parent_info[0][1] } else: add_balance = round(float(info['feeString']) * 0.3, 2) withdrawals_amount = round( float(check_user_res[0][8]) + float(info['feeString']) * 0.3, 2) taobao_rebate_amount = round( float(check_user_res[0][7]) + float(info['feeString']) * 0.3, 2) total_rebate_amount = round( float(check_user_res[0][5]) + float(info['feeString']) * 0.3, 2) save_money = round( check_user_res[0][9] + (float(get_query_info[0][2]) - float(info['realPayFeeString'])) + add_balance, 2) total_order_num = int(check_user_res[0][10]) + 1 taobao_order_num = int(check_user_res[0][12]) + 1 cm.ExecNonQuery( "UPDATE taojin_user_info SET withdrawals_amount='" + str(withdrawals_amount) + "', save_money='" + str(save_money) + "', taobao_rebate_amount='" + str(taobao_rebate_amount) + "', total_rebate_amount='" + str(total_rebate_amount) + "', order_quantity='" + str(total_order_num) + "', taobao_order_quantity='" + str(taobao_order_num) + "', update_time='" + str(time.time()) + "' WHERE wx_number='" + str(userInfo['NickName']) + "';") cm.ExecNonQuery( "INSERT INTO taojin_order(username, order_id, order_source) VALUES('" + str(userInfo['NickName']) + "', '" + str(order_id) + "', '2')") args = { 'username': check_user_res[0][1], 'rebate_amount': add_balance, 'type': 3, 'create_time': time.time() } # 写入返利日志 cm.InsertRebateLog(args) user_text = ''' 一一一一系统消息一一一一 订单【%s】已完成! 返利金%s元已发放到您的个人账户! 回复【提现】可申请账户余额提现 回复【个人信息】可看个当前账户信息 分享【京东商品链接】或者【淘口令】精准查询商品优惠券和返利信息! 分享【VIP视频链接】免费查看高清VIP视频! 优惠券使用教程: http://t.cn/RnAKqWW 京东优惠券网站: http://jdyhq.ptjob.net 淘宝优惠券网站: http://tbyhq.ptjob.net 邀请好友得返利: http://t.cn/RnAKafe ''' % (order_id, add_balance) return { 'user_text': user_text, 'info': 'not_parent_and_success' } except Exception as e: self.logger.debug(e) return {'info': 'feild'}
def getTaobaoOrder(self): if self.config.get('SYS', 'tb') == 'yes': while True: nowtime = time.strftime('%H:%M', time.localtime(time.time())) if self.config.get('TIME', 'tbend') > nowtime > self.config.get( 'TIME', 'tbstart'): cm = ConnectMysql() # 前60天的时间 yesterDay = datetime.date.today() - datetime.timedelta( days=60) # 定义订单的几种状态,便于存储 status = {'订单结算': 1, '订单付款': 2, '订单失效': 3, '订单成功': 4} # 请求订单接口 url = 'http://tuijian.ptjob.net/phpsdk/sdkList/orderGet.php?startTime=' + str( yesterDay) + '&endTime=' + str(datetime.date.today()) print('!!!!!!!!!!!Order Get Url is', url) res = self.se.get(url) # print('Get the orders', res.text) # 转json resj = json.loads(res.text) print(len(resj)) # 数据存入数据库 for item in resj: is_sql = "SELECT * FROM taojin_get_orders WHERE order_id='" + item[ 'cate'] + "';" # 判断数据是否存在 is_ext = cm.ExecQuery(is_sql) if is_ext == (): in_sql = "INSERT INTO taojin_get_orders(order_id, good_id, good_name, good_price, good_num, order_price, order_source, order_status, order_commission, create_time, settlement_time, bot_puid) VALUES('" + str( item['cate'] ) + "', '" + str( item['good_id'] ) + "', '" + item['good_title'] + "', '" + str( item['good_price'] ) + "', '" + str(item['good_num']) + "', '" + str( item['amount_pay']) + "', '1', '" + str( status[item['order_state']] ) + "', '" + item[ 'commission_percent'] + "', '" + str( item['add_time']) + "', '" + str( item['settlement_time'] ) + "', '" + self.bot.self.puid + "')" cm.ExecNonQuery(in_sql) else: del_sql = "DELETE FROM taojin_get_orders WHERE order_id='" + item[ 'cate'] + "';" cm.ExecNonQuery(del_sql) in_sql = "INSERT INTO taojin_get_orders(order_id, good_id, good_name, good_price, good_num, order_price, order_source, order_status, order_commission, create_time, settlement_time, bot_puid) VALUES('" + str( item['cate'] ) + "', '" + str( item['good_id'] ) + "', '" + item['good_title'] + "', '" + str( item['good_price'] ) + "', '" + str(item['good_num']) + "', '" + str( item['amount_pay']) + "', '1', '" + str( status[item['order_state']] ) + "', '" + item[ 'commission_percent'] + "', '" + str( item['add_time']) + "', '" + str( item['settlement_time'] ) + "', '" + self.bot.self.puid + "')" cm.ExecNonQuery(in_sql) # 获取用户的订单 user_orders = cm.ExecQuery( "SELECT * FROM taojin_order WHERE status='1' AND order_source = '1' AND bot_puid='" + self.bot.self.puid + "' AND completion_time>'" + str(yesterDay) + "';") user_orders_id_list = [] for item in user_orders: user_orders_id_list.append(item[3]) # 把获取到的订单信息收集到list里,方便操作数据 orders_list = [] for item2 in resj: orders_list.append(item2['cate']) # 遍历用户订单和获取到的订单对比,根据订单状态不同给用户返利或不返利 for item3 in user_orders_id_list: if item3 in orders_list: userOrder = cm.ExecQuery( "SELECT * FROM taojin_get_orders WHERE order_id=" + item3 + "") userOrder2 = cm.ExecQuery( "SELECT * FROM taojin_order WHERE order_id=" + item3 + "") userInfo = cm.ExecQuery( "SELECT * FROM taojin_user_info WHERE puid='" + userOrder2[0][7] + "'") # 根据订单状态进行回复和结算奖金 if userOrder[0][7] == 4 or userOrder[0][7] == 1: # 已结算 self.changeInfoAlimama(userOrder2[0][7], userOrder[0]) up_set_sql = "UPDATE taojin_order SET status='2' WHERE order_id='" + str( item3) + "';" cm.ExecNonQuery(up_set_sql) elif userOrder[0][7] == 3: send_text = ''' ---------- 订单信息 ----------- 订单【%s】已失效 ''' % (item3) up_set_sql = "UPDATE taojin_order SET status='2' WHERE order_id='" + str( item3) + "';" cm.ExecNonQuery(up_set_sql) user = self.bot.friends().search( nick_name=userInfo[0][4])[0] user.send(send_text) else: userOrder = cm.ExecQuery( "SELECT * FROM taojin_order WHERE order_id=" + item3 + "") userInfo = cm.ExecQuery( "SELECT * FROM taojin_user_info WHERE puid='" + userOrder[0][7] + "'") send_text = ''' ---------订单消息---------- 订单【%s】返利失败 该笔订单非通过机器人购买 ''' % (item3) up_set_sql = "UPDATE taojin_order SET status='2' WHERE order_id='" + str( item3) + "';" cm.ExecNonQuery(up_set_sql) user = self.bot.friends().search( nick_name=userInfo[0][4])[0] user.send(send_text) time.sleep(7200) else: print('!!!! tb time not start, now time is %s .......' % nowtime) time.sleep(1800) continue
def getJd(self, raw, bot, msg, good_url): if config.get('SYS', 'jd') == 'no': text = ''' 一一一一系统信息一一一一 亲,暂不支持京东链接哦 ''' return text cm = ConnectMysql() try: # 用户第一次查询,修改备注 query_good = cm.ExecQuery("SELECT * FROM taojin_query_record WHERE puid='"+raw.sender.puid+"' AND bot_puid='"+bot.self.puid+"'") if query_good == (): se = re.compile('^(\d+)_(\d+)_\w_(\d)+$') if se.search(raw.sender.remark_name) == None: remarkName = self.ort.generateRemarkName(bot) split_arr2 = remarkName.split('_') new_remark_name2 = '%s%s%s%s%s%s%s' % (split_arr2[0], '_', split_arr2[1], '_', 'B', '_', split_arr2[3]) bot.core.set_alias(userName=raw.sender.user_name, alias=new_remark_name2) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name2+"' WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "'") else: split_arr = raw.sender.remark_name.split('_') new_remark_name = '%s%s%s%s%s%s%s' % (split_arr[0], '_', split_arr[1], '_', 'B', '_', split_arr[3]) bot.core.set_alias(userName=raw.sender.user_name, alias=new_remark_name) cm.ExecNonQuery("UPDATE taojin_user_info SET remarkname = '"+new_remark_name+"' WHERE puid='" + raw.sender.puid + "' AND bot_puid='" + bot.self.puid + "'") print('开始查询分享商品的信息......'+msg['Text']) bot_puid = bot.self.puid sku_arr = good_url.split('https://item.m.jd.com/product/') if sku_arr == None: if config.get('SYS', 'tl') == 'yes': msg_text = self.tu.tuling(msg) return msg_text else: return sku = sku_arr[1].split('.') res = self.get_good_link(sku[0]) if res['data']['shotCouponUrl'] == '': text = ''' 一一一一京东返利信息一一一一 【商品名】%s 【京东价】%s元 【返红包】%s元 返利链接:%s 获取返红包步骤: 1,点击商品链接并进行下单 2,下完单后复制订单号发给我 ''' % (res['logTitle'], res['logUnitPrice'], res['rebate'], res['data']['shotUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, skuid, type) VALUES('"+ bot.self.nick_name +"', '" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '0', '" + raw.sender.nick_name + "', '" + str(time.time()) + "', '"+ raw.sender.puid +"', '"+ bot_puid +"', '"+ res['skuid'] +"', '1')" cm.ExecNonQuery(insert_sql) return text else: text = ''' 一一一一京东返利信息一一一一 【商品名】%s 【京东价】%s元 【优惠券】%s元 【券后价】%s元 【返红包】%s元 领券链接:%s 获取返红包步骤: 1,复制本条消息打开淘宝领券 2,下完单后复制订单号发给我 ''' % ( res['logTitle'], res['logUnitPrice'], res['youhuiquan_price'], res['coupon_price'], res['rebate'], res['data']['shotCouponUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, skuid, type) VALUES('"+ bot.self.nick_name +"', '" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '" + res['coupon_price2'] + "', '" + raw.sender.nick_name + "', '" + str(time.time()) + "', '"+ raw.sender.puid +"', '"+ bot_puid +"', '"+ res['skuid'] +"', '1')" cm.ExecNonQuery(insert_sql) return text except Exception as e: trace = traceback.format_exc() self.logger.warning("error:{},trace:{}".format(str(e), trace)) text = ''' 一一一一 返利信息 一一一一 亲,当前商品暂无优惠券,建议您换一个商品试试呢,您也可以在下边的优惠券商城中查找哦 京东优惠券商城: '''+config.get('URL', 'jdshop')+''' 淘宝优惠券商城: '''+config.get('URL', 'tbshop')+''' 邀请好友得返利说明: '''+config.get('URL', 'lnvit')+''' ''' return text
def getGroupJd(self, bot, msg, good_url, raw): if config.get('SYS', 'jd') == 'no': text = ''' 一一一一系统信息一一一一 亲,暂不支持京东链接 ''' return text cm = ConnectMysql() try: wei_info = bot.core.search_chatrooms(userName=msg['FromUserName']) puid = raw.member.puid bot_puid = bot.self.puid sku_arr = good_url.split('https://item.m.jd.com/product/') if sku_arr == None: return sku = sku_arr[1].split('.') res = self.get_good_link(sku[0]) if res['data']['shotCouponUrl'] == '': text = ''' 一一一一京东返利信息一一一一 【商品名】%s 【京东价】%s元 【返红包】%s元 返利链接:%s 获取返红包步骤: 1,点击商品链接并进行下单 2,点击头像添加机器人好友 3,下完单后复制订单号发给我 ''' % (res['logTitle'], res['logUnitPrice'], res['rebate'], res['data']['shotUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, chatroom, skuid, type) VALUES('"+ bot.self.nick_name +"', '" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '0', '" + msg[ 'ActualNickName'] + "', '" + str(time.time()) + "', '"+ puid +"', '"+ bot_puid +"', '"+ wei_info['NickName'] +"', '"+ res['skuid'] +"', '1')" cm.ExecNonQuery(insert_sql) return text else: text = ''' 一一一一京东返利信息一一一一 【商品名】%s 【京东价】%s元 【优惠券】%s元 【券后价】%s元 【返红包】%s元 领券链接:%s 获取返红包步骤: 1,复制本条消息打开淘宝领券 2,点击头像添加机器人好友 3,下完单后复制订单号发给我 ''' % ( res['logTitle'], res['logUnitPrice'], res['youhuiquan_price'], res['coupon_price'], res['rebate'], res['data']['shotCouponUrl']) insert_sql = "INSERT INTO taojin_query_record(wx_bot, good_title, good_price, good_coupon, username, create_time, puid, bot_puid, chatroom, skuid, type) VALUES('"+ bot.self.nick_name +"', '" + \ res['logTitle'] + "', '" + str(res['logUnitPrice']) + "', '" + res['coupon_price2'] + "', '" + \ msg['ActualNickName'] + "', '" + str(time.time()) + "', '"+ puid +"', '"+ bot_puid +"', '"+ wei_info['NickName'] +"', '"+ res['skuid'] +"', '1')" cm.ExecNonQuery(insert_sql) return text except Exception as e: text = ''' 一一一一 返利信息 一一一一 亲,当前商品暂无优惠券,建议您换一个商品试试呢,您也可以在下边的优惠券商城中查找哦 京东优惠券商城: '''+config.get('URL', 'jdshop')+''' 淘宝优惠券商城: '''+config.get('URL', 'tbshop')+''' 邀请好友得返利说明: '''+config.get('URL', 'lnvit')+''' ''' return text