def sync_order(): global modian_handler my_logger.info('同步订单') for modian in global_config.MODIAN_ARRAY: pro_id = modian.group_account_id orders = modian_handler.get_all_orders(modian) for order in orders: user_id = order['user_id'] nickname = order['nickname'] pay_time = order['pay_time'] backer_money = order['backer_money'] oid = uuid.uuid3(uuid.NAMESPACE_OID, str(user_id) + pay_time) # print('oid: %s', oid) rst = mysql_util.select_one( """ select * from `order` where id='%s' """, (str(oid), )) if len(rst) == 0: my_logger.info('该订单不在数据库中') # 每次需要更新一下昵称 mysql_util.query(""" INSERT INTO `supporter` (`id`, `name`) VALUES (%s, '%s') ON DUPLICATE KEY UPDATE `name`='%s' """ % (user_id, nickname, nickname)) mysql_util.query(""" INSERT INTO `order` (`id`, `supporter_id`, `backer_money`, `pay_time`, `pro_id`) VALUES ('%s', %s, %s, '%s', %s); """ % (oid, user_id, backer_money, pay_time, pro_id)) msg = '【机器人补播报】感谢 %s 支持了%s元, %s\n' % ( nickname, backer_money, util.random_str(global_config.MODIAN_POSTSCRIPTS)) # QQHandler.send_to_groups(['483548995'], msg) modian_handler.order_queues[modian.group_account_id].add(oid)
def evolution(self, raw_list, user_id, pay_time): """ 进化(吞噬) :param raw_list: 原材料,只能为同等级的材料 :return: """ if (not raw_list) or len(raw_list) == 0: logger.exception('原材料为空!') raise RuntimeError('原材料列表为空') raw_material_level = raw_list[0].level if raw_material_level + 1 not in self.cards.keys(): logger.info('已经是最高级的卡牌,不能合成') return None logger.info('删除原材料') # 删除原材料 for raw_material in raw_list: mysql_util.query(""" UPDATE `draw_record` SET is_valid=0 WHERE id=%s """, (raw_material.id,)) # 从高1级的卡中获得一张 new_card = util.choice(self.cards[raw_material_level + 1]) logger.debug('合成的新卡: %s' % new_card) mysql_util.query(""" INSERT INTO `draw_record` (`supporter_id`, `card_id`, `draw_time`, `is_valid`) VALUES (%s, %s, %s, %s) """, (user_id, new_card.id, pay_time, 1)) logger.info('合卡完成')
def draw_missed_cards(self, modian_id, score=10): """ 补抽卡 :param modian_id: :param score: 抽卡消耗的积分数量 :return: """ logger.info('积分抽卡,modian_id:{}, score:{}'.format(modian_id, score)) import time if score < 15: return '消耗的积分必须要大于等于15!' if score % 15 != 0: return '消耗的积分必须是15的倍数!' current_score = int(self.get_current_score(modian_id)) if current_score < score: return '桃叭ID:{}的当前积分: {},少于需要消耗的积分: {},不能补抽!'.format(modian_id, current_score, score) else: result = '桃叭ID:{},积分抽卡,当前积分-{}\n'.format(modian_id, score) mysql_util.query(""" INSERT INTO `t_card_score` (`modian_id`, `score`) VALUES (%s, %s) """, (modian_id, -1 * score)) money = int(score // 10) * 10.17 result += self.draw(modian_id, '补抽用户', money, util.convert_timestamp_to_timestr(int(time.time() * 1000))) return result
def save_character(character): """ 将更新后的任务保存到数据库 :param character: :return: """ my_logger.debug('将更新后的任务保存到数据库') mysql_util.query( """ UPDATE `t_character` SET `name`=%s, `prop1`=%s, `prop2`=%s, `prop3`=%s, `prop4`=%s, `prop5`=%s WHERE `modian_id`=%s """, (character.name, character.prop1, character.prop2, character.prop3, character.prop4, character.prop5, character.id))
def save_event(modian_id, event_id, event_remark): """ 保存事件到数据库 :param modian_id :param event_id :param event_remark :return: """ my_logger.debug('保存事件到数据库') mysql_util.query( """ INSERT INTO `t_event` (`modian_id`, `event_id`, `event_remark`) VALUES (%s, %s, %s) """, (modian_id, event_id, event_remark))
def save_character(character): """ 将更新后的任务保存到数据库 :param character: :return: """ my_logger.debug('将更新后的任务保存到数据库') mysql_util.query( """ UPDATE `t_character` SET `name`=%s, `prop1`=%s, `prop2`=%s, `prop3`=%s, `prop4`=%s, `prop5`=%s, `num_of_fragment`=%s, `loc_x`=%s, `loc_y`=%s WHERE `modian_id`=%s """, (character.name, character.prop1, character.prop2, character.prop3, character.prop4, character.prop5, character.num_of_fragment, character.current_point.x, character.current_point.y, character.id))
def abc(self, backer_money, user_id): print('backer_money: %s, user_id: %s' % (backer_money, user_id)) seats = [] standings = [] wannengs = [] ticket_num = modian_300_performance_handler.get_draw_tickets_num(backer_money) for i in range(ticket_num): if len(self.current_available_seats) > 0: seat_number = modian_300_performance_handler.draw_tickets(self.current_available_seats) if seat_number != -1: self.current_available_seats.remove(seat_number) mysql_util.query(""" INSERT INTO `seats_record` (`seats_type`, `modian_id`, `seats_number`) VALUES (%s, %s, %s) """, (1, user_id, seat_number)) seats.append(seat_number) elif len(self.current_available_standings) > 0: standing_number = modian_300_performance_handler.draw_standing_tickets(self.current_available_standings) if standing_number != -1: self.current_available_standings.remove(standing_number) mysql_util.query(""" INSERT INTO `seats_record` (`seats_type`, `modian_id`, `seats_number`) VALUES (%s, %s, %s) """, (2, user_id, standing_number)) standings.append(Standing(standing_number)) else: wanneng_number = modian_300_performance_handler.draw_wanneng_tickets() mysql_util.query(""" INSERT INTO `seats_record` (`seats_type`, `modian_id`, `seats_number`) VALUES (%s, %s, %s) """, (3, user_id, wanneng_number)) wannengs.append(Wanneng(wanneng_number)) if len(seats) == 0 and len(standings) == 0 and len(wannengs) == 0: report_message = '抱歉,本次抽选未中T_T\n' else: report_message = '您参与的FXF48公演抽选成功!\n' idx = 1 if len(seats) > 0: for seat in seats: # seat_o = modian_300_performance_handler.convert_number_to_seats(seat) seat_o = modian_300_performance_handler.seat_number_to_date_dict[seat] report_message += '%d. 公演日期: %d年%d月%d日, 座位号: %s排%s号' % ( idx, seat_o.year, seat_o.month, seat_o.day, seat_o.row, seat_o.col) # 特殊座位 if seat in modian_300_performance_handler.special_seats_wording.keys(): report_message += ', \n【奖励】%s' % modian_300_performance_handler.special_seats_wording[seat] report_message += '\n' idx += 1 if len(standings) > 0: for standing in standings: report_message += '%d. 站票: %03d\n' % (idx, standing.number) idx += 1 if len(wannengs) > 0: for wanneng in wannengs: report_message += '%d. 万能票%03d: 可小窗联系@OFJ,您可获得一张自己指定座位号的门票【注:票面将会标有"复刻票"字样,10排17除外】\n' % ( idx, wanneng.number) idx += 1 report_message += '\n' print (report_message)
def create_character(modian_id, modian_name): """ 创建人物 :return: """ my_logger.info('创建人物, modian_id: %s' % modian_id) # 随机生成属性 prop1 = random.randint(40, 70) prop2 = random.randint(30, 60) prop3 = random.randint(5, 20) prop4 = random.randint(0, 50) prop5 = random.randint(30, 50) mysql_util.query( """ INSERT INTO `t_character` (`modian_id`, `name`, `prop1`, `prop2`, `prop3`, `prop4`, `prop5`) VALUES (%s, %s, %s, %s, %s, %s, %s) """, (modian_id, modian_name, prop1, prop2, prop3, prop4, prop5)) intro_words = [ "樱桃树绽放出粉红的花朵,当微风吹过的时候,花瓣便在树枝上轻轻抖动,在这段沿盘山的小路上走来一位魔法师,胸前的徽章上似乎是一只小熊猫,那是【{}】。" .format(modian_name), "一道高大的身影出现在城堡正门前,遮住了门外照进的阳光,他似乎抬头望向了“瘦夫人”的画像,“吾【{}】,请问此处可是“葛绿元少”?”". format(modian_name), "纯血即是正义!我是高贵!纯真!有抱负的【{}】,“丝来特别灵”是我的目标".format(modian_name), "“啊啊啊啊啊”伴随着一阵高昂的惨叫声,“啦闻唠嗑”的塔楼上方划过一道骑着扫帚的身影。那是!恐高症的【{}】".format( modian_name), "窗外,一阵急促的扑打翅膀的声音传来,一只猫头鹰停在了窗台前,它伸出了左爪将一封有着红色蜡封和盾牌纹章的羊皮信放在了窗台上。【{}】拿起了这封信。" .format(modian_name) ] # 随机挑选一个出场方式 intro = util.choice(intro_words) report_str = '%s\n' % intro[0] report_str += '【%s】的魔法世界开启, 属性:\n攻: %s, 防: %s, 气: %s, 运: %s, 魅力: %s\n' % ( modian_name, prop1, prop2, prop3, prop4, prop5) return report_str
def plus_shuihui_points(amount, pro_id, order_id, user_id): """ 水灰应援会链接的得分计算方式 10元=2.5积分,100元=26积分 :param amount: :param pro_id :param order_id: :param user_id: :return: """ my_logger.info('[水灰PK]pro_id: %s, 集资金额: %s, order_id: %s, user_id: %s' % (pro_id, amount, order_id, user_id)) points = 0 if amount < TEN: points = 0 elif amount < ONE_HUNDRED: points = int(amount // TEN) * 2.5 else: points = int(amount // ONE_HUNDRED) * 26 + int(amount % ONE_HUNDRED // TEN) * 2.5 my_logger.info('[水灰PK]加分数量: %s' % points) # 存入数据库 mysql_util.query(""" insert into `point_detail` (`order_id`, `pro_id`, `point`) VALUES (%s, %s, %s) """, (order_id, pro_id, points)) return points
def plus_fxf_yby_points(amount, pro_id, order_id, user_id): """ FXF和YBY链接的每次集资得分计算方式 10元=1积分,100元=11积分 :param amount: :param pro_id :param order_id: :param user_id: :return: """ my_logger.info('[水灰PK]pro_id: %s, 集资金额: %s, order_id: %s, user_id: %s' % (pro_id, amount, order_id, user_id)) points = 0 if amount < TEN: points = 0 elif amount < ONE_HUNDRED: points = int(amount // TEN) else: points = int(amount // ONE_HUNDRED) * 11 + int(amount % ONE_HUNDRED // TEN) my_logger.info('[水灰PK]加分数量: %s' % points) # 存入数据库 mysql_util.query(""" insert into `point_detail` (`order_id`, `pro_id`, `point`) VALUES (%s, %s, %s) """, (order_id, pro_id, points)) return points
def create_character(modian_id): """ 创建人物 :return: """ my_logger.info('创建人物, modian_id: %s' % modian_id) # 随机姓名 random_name = TOTAL_NAMES.pop() my_logger.debug('随机姓名: %s' % random_name) # 随机生成属性 prop1 = random.randint(40, 70) prop2 = random.randint(30, 60) prop3 = random.randint(5, 20) prop4 = random.randint(0, 50) prop5 = random.randint(30, 50) mysql_util.query( """ INSERT INTO `t_character` (`modian_id`, `name`, `prop1`, `prop2`, `prop3`, `prop4`, `prop5`) VALUES (%s, %s, %s, %s, %s, %s, %s) """, (modian_id, random_name, prop1, prop2, prop3, prop4, prop5)) intro_words = [ "郁雷之声渐响,轰轰不绝。河海尚远,而耳中尽是浪涛之声。 似有一名字伴雷声入耳,仔细辨来,名为:【{}】。".format( random_name), "湖山深处,但见竹木阴森,苍翠重叠,不雨而润,不烟而晕, 晨雾朦胧处现一少年,“在下【{}】,请问此处可是星梦谷?”".format( random_name), "月照竹林风飞叶,竹影之下见刀光。小侠籍籍无名,仅有此片竹林识得其名为【{}】".format(random_name), "嗖的一声,一支羽箭从山坳后射了出来,呜呜声响,划过长空,【{}】松开弓弦,雁落平沙。".format(random_name), "灯宵月夕,雪际花时,市集喧闹却也听得句柔声细语:“这文书写有【{}】之名,可是你掉的?”".format(random_name) ] # 随机挑选一个出场方式 intro = util.choice(intro_words) report_str = '%s\n' % intro[0] report_str += '%s的武侠世界开启, 属性:\n攻: %s, 防: %s, 气: %s, 运: %s, 魅力: %s\n' % ( random_name, prop1, prop2, prop3, prop4, prop5) return report_str
def minus_points(amount, order_id, pro_id): """ 捣蛋组扣分 10.17得到小锤子 积分-1 101.7得到南瓜鬼脸 积分-10 111.1 捣蛋一次 积分-12 捣蛋失败 积分+1 概率20%(暂定) 捣蛋大成功 积分额外-3 概率10%(暂定) :param amount: :return: """ my_logger.info('捣蛋组扣分, 金额: %s' % amount) num_of_hummer = 0 num_of_pumpkin_grimace = 0 num_of_treat = 0 if amount < HUMMER_AMOUNT: points = 0 return points, '' elif HUMMER_AMOUNT <= amount < PUMPKIN_GRIMACE_AMOUNT: num_of_hummer = int(amount // HUMMER_AMOUNT) points = num_of_hummer * HUMMER_POINTS elif PUMPKIN_GRIMACE_AMOUNT <= amount < TREAT_AMOUNT: num_of_pumpkin_grimace = int(amount // PUMPKIN_GRIMACE_AMOUNT) num_of_hummer = int((amount % PUMPKIN_GRIMACE_AMOUNT) // HUMMER_AMOUNT) points = num_of_pumpkin_grimace * PUMPKIN_GRIMACE_POINTS + num_of_hummer * HUMMER_POINTS else: num_of_treat = int(amount // TREAT_AMOUNT) num_of_pumpkin_grimace = int( (amount % TREAT_AMOUNT) // PUMPKIN_GRIMACE_AMOUNT) num_of_hummer = int( (amount % TREAT_AMOUNT % PUMPKIN_GRIMACE_AMOUNT) // HUMMER_AMOUNT) points = num_of_treat * TREAT_POINTS \ + num_of_pumpkin_grimace * PUMPKIN_GRIMACE_POINTS \ + num_of_hummer * HUMMER_POINTS my_logger.info('扣分数量: %s' % points) report = '获得' report += '【小锤子】*%s, ' % num_of_hummer if num_of_hummer > 0 else '' report += '【南瓜鬼脸】*%s, ' % num_of_pumpkin_grimace if num_of_pumpkin_grimace > 0 else '' report += '【捣蛋】*%s, ' % num_of_treat if num_of_treat > 0 else '' report += '\n' if num_of_hummer > 0: report += '[CQ:image,file=%s]' % HUMMER_IMG if num_of_pumpkin_grimace > 0: report += '[CQ:image,file=%s]' % PUMPKIN_GRIMACE_IMG if num_of_treat > 0: report += '[CQ:image,file=%s]' % TREAT_IMG candidate = ['捣蛋失败', '捣蛋大成功', '无'] weight = [10, 20, 70] weight2 = [10, 15, 75] if 10.17 <= amount < 101.7: idx = util.weight_choice(candidate, weight) elif amount >= 101.7: idx = util.weight_choice(candidate, weight2) else: idx = -1 bonus_report = '' if idx == 0: # 捣蛋失败 if 10.17 <= amount < 101.7: # 10.17-101.7, 积分清零 points = 0 bonus_report += '很不幸,捣蛋失败,本次获取的积分清零T_T' elif amount >= 101.7: # 多于101.7,积分减半 points = int(points // 2) bonus_report += '很不幸,捣蛋失败,本次获取的积分减半T_T' elif idx == 1: # 捣蛋大成功,本次积分翻倍 points *= 2 bonus_report += '恭喜,捣蛋大成功,本次获取的积分加倍' else: pass if len(bonus_report) > 0: report += bonus_report report += '本次减分:%s\n' % -points # 存入数据库 mysql_util.query( """ insert into `point_detail` (`order_id`, `pro_id`, `point`) VALUES (%s, %s, %s) """, (order_id, pro_id, points)) return points, report
def draw(self, user_id, nickname, backer_money, pay_time): logger.info('抽卡: user_id: %s, nickname: %s, backer_money: %s, pay_time: %s', user_id, nickname, backer_money, pay_time) # 计算抽卡张数 card_num = self.compute_draw_nums(backer_money) if card_num == 0: logger.info('集资未达到标准,无法抽卡') return '' logger.info('共抽卡%d张', card_num) rst = {} rst_type = {} rst_level = {} level_list = [CardLevel.R, CardLevel.SR, CardLevel.SSR, CardLevel.UR] type_dict = { # CardType.STAR: '星组', # CardType.MOON: '月组', # CardType.SUN: '日组', CardType.NORMAL: '普通', CardType.SPECIAL: '活动限定' } # 获取此ID已抽中的全部卡牌 rst_tmp = mysql_util.select_all(""" SELECT distinct(`card_id`) from `draw_record` where supporter_id="%s" """, (user_id,)) card_has = set() # 该用户已经拥有的卡片 card_new = set() # 该用户收集到的新卡 if rst_tmp and len(rst_tmp) > 0: for tmp in rst_tmp: card_has.add(tmp[0]) logger.debug('摩点ID: {}, 当前拥有的卡片: {}'.format(user_id, card_has)) score_add = 0 insert_sql = 'INSERT INTO `draw_record` (`supporter_id`, `card_id`, `draw_time`, `backer_money`) VALUES ' flag = False for no in range(card_num): # 先判断能否抽中卡,如果抽不中,直接跳过 # draw_rst = self.can_draw() # if not draw_rst: # continue flag = True # 卡片类型 idx = util.weight_choice(level_list, self.weights) card_type = level_list[idx] # 在对应卡片类型中,抽出一张卡 card = util.choice(self.cards[card_type])[0] logger.debug('抽出的卡: %s' % card) if card.id in card_has: logger.debug('卡片{}已经拥有,积分+1') # 如果已经拥有该卡片,积分+1 score_add += 1 else: card_new.add(card.id) card_has.add(card.id) # card = self.base_cards[card_index] insert_sql += """("%s", %s, '%s', %s),""" % (user_id, card.id, pay_time, backer_money) # 此种类型的卡如果已经达到了1张,则将该卡片从卡池中移除 # if card.id in ACTIVITY_CARD_ID: # rst2 = mysql_util.select_one(""" # SELECT count(*) from `draw_record` WHERE `card_id` = %s # """, (card.id,)) # if rst2: # if rst2[0] == 1: # if card in self.cards[card.level]: # self.cards[card.level].remove(card) if card in rst: rst[card] += 1 else: rst[card] = 1 if card.level not in rst_level: rst_level[card.level] = [] if card not in rst_level[card.level]: rst_level[card.level].append(card) if card.type0 not in rst_type: rst_type[card.type0] = [] if card not in rst_type[card.type0]: rst_type[card.type0].append(card) print(insert_sql[:-1]) logger.debug(insert_sql[:-1]) logger.debug('摩点ID: {}, 抽到的新卡片: {}'.format(user_id, card_new)) img_flag = True img_report = '' report = '恭喜抽中:\n' card_new_list = [] # 用来发图的 if CardLevel.UR in rst_level and len(rst_level[CardLevel.UR]) > 0: report += '【UR】: ' for card in rst_level[CardLevel.UR]: # report += '{}-{}*{}, '.format(type_dict[card.type0], card.name, rst[card]) new_flag = '' if card.id in card_new: new_flag = emojis.encode('(:new:)') card_new_list.append(self.cards_single[card.id]) report += '{}*{}{}, '.format(card.name, rst[card], new_flag) if img_flag: if len(card_new_list) > 0: img = util.choice(card_new_list)[0] else: img = util.choice(rst_level[CardLevel.UR])[0] img_report = '[CQ:image,file={}]\n'.format(img.url) img_flag = False report += '\n' if CardLevel.SSR in rst_level and len(rst_level[CardLevel.SSR]) > 0: report += '【SSR】: ' for card in rst_level[CardLevel.SSR]: # report += '{}-{}*{}, '.format(type_dict[card.type0], card.name, rst[card]) new_flag = '' if card.id in card_new: new_flag = emojis.encode('(:new:)') card_new_list.append(self.cards_single[card.id]) report += '{}*{}{}, '.format(card.name, rst[card], new_flag) if img_flag: if len(card_new_list) > 0: img = util.choice(card_new_list)[0] else: img = util.choice(rst_level[CardLevel.SSR])[0] img_report = '[CQ:image,file={}]\n'.format(img.url) img_flag = False report += '\n' if CardLevel.SR in rst_level and len(rst_level[CardLevel.SR]) > 0: report += '【SR】: ' for card in rst_level[CardLevel.SR]: # report += '{}{}*{}, '.format(type_dict[card.type0], card.sub_id, rst[card]) # report += '{}-{}*{}, '.format(type_dict[card.type0], card.name, rst[card]) new_flag = '' if card.id in card_new: new_flag = emojis.encode('(:new:)') card_new_list.append(self.cards_single[card.id]) report += '{}*{}{}, '.format(card.name, rst[card], new_flag) if img_flag: if len(card_new_list) > 0: img = util.choice(card_new_list)[0] else: img = util.choice(rst_level[CardLevel.SR])[0] img_report = '[CQ:image,file={}]\n'.format(img.url) img_flag = False report += '\n' if CardLevel.R in rst_level and len(rst_level[CardLevel.R]) > 0: report += '【R】: ' for card in rst_level[CardLevel.R]: # report += '{}{}*{}, '.format(type_dict[card.type0], card.sub_id, rst[card]) # report += '{}-{}*{}, '.format(type_dict[card.type0], card.name, rst[card]) new_flag = '' if card.id in card_new: new_flag = emojis.encode('(:new:)') card_new_list.append(self.cards_single[card.id]) report += '{}*{}{}, '.format(card.name, rst[card], new_flag) if img_flag: if len(card_new_list) > 0: img = util.choice(card_new_list)[0] else: img = util.choice(rst_level[CardLevel.R])[0] img_report = '[CQ:image,file={}]\n'.format(img.url) img_flag = False report += '\n' report += img_report if flag: # 如果一张都没有抽中,就不执行sql语句 mysql_util.query(insert_sql[:-1]) # 积分保存到数据库 if score_add > 0: mysql_util.query(""" INSERT INTO `t_card_score` (`modian_id`, `score`) VALUES (%s, %s) """, (user_id, score_add)) report += '通过重复卡获取积分: {}\n'.format(score_add) report += '当前积分为: {}\n'.format(self.get_current_score(user_id)) logger.debug(report) return report
def parse_order_details(self, orders, modian_entity): if len(self.order_queues[modian_entity.pro_id]) == 0 and len( orders) == 0: my_logger.debug('订单队列为空') return jiebang_activities = global_config.MODIAN_JIEBANG_ACTIVITIES[ modian_entity.pro_id] flag_activities = global_config.MODIAN_FLAG_ACTIVITIES[ modian_entity.pro_id] count_flag_activities = global_config.MODIAN_COUNT_FLAG_ACTIVITIES[ modian_entity.pro_id] # 查询集资情况 target, current, pro_name, backer_count = self.get_current_and_target( modian_entity) project_info = '当前进度: %s元, 目标金额: %s元' % (current, target) modian_entity.current = current modian_entity.title = pro_name modian_entity.target = target modian_entity.support_num = backer_count my_logger.debug('size of order %s queue: %s', modian_entity.pro_id, len(self.order_queues[modian_entity.pro_id])) for order in orders: user_id = order['user_id'] nickname = order['nickname'] pay_time = order['pay_time'] backer_money = order['backer_money'] oid = uuid.uuid3(uuid.NAMESPACE_OID, str(user_id) + pay_time) my_logger.debug('oid: %s', oid) if oid in self.order_queues[modian_entity.pro_id]: continue my_logger.debug('项目%s队列长度: %s', modian_entity.pro_id, len(self.order_queues[modian_entity.pro_id])) # 每次需要更新一下昵称 try: # supporter = Supporter(id=user_id, name=nickname) # self.alchemy_session.merge(supporter) mysql_util.query( """ INSERT INTO `supporter` (`id`, `name`) VALUES (%s, %s) ON DUPLICATE KEY UPDATE `name`=%s """, (user_id, nickname, nickname)) except Exception as e: my_logger.exception(e) try: # 创建对象 # modian_order = ModianOrder(id=str(oid), supporter_id=user_id, backer_money=backer_money, pay_time=pay_time, # pro_id=modian_entity.pro_id) # self.alchemy_session.merge(modian_order) mysql_util.query( """ INSERT INTO `order` (`id`,`supporter_id`,`backer_money`,`pay_time`, `pro_id`) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE `id`=%s """, (str(oid), user_id, backer_money, pay_time, modian_entity.pro_id, str(oid))) except Exception as e: my_logger.exception(e) msg = '感谢 %s(%s) 支持了%s元, %s\n' % ( nickname, user_id, backer_money, util.random_str(global_config.MODIAN_POSTSCRIPTS)) daka_rank, support_days = self.find_user_daka_rank( user_id, modian_entity.pro_id) if daka_rank != -1 and support_days: msg += '当前项目已打卡%s天\n' % support_days if modian_entity.need_display_rank is True: jizi_rank, backer_money = self.find_user_jizi_rank( user_id, modian_entity.pro_id) if jizi_rank != -1: msg += '当前项目已集资%s元, 排名: %s' % (backer_money, jizi_rank) else: pass # 统计当前人数 msg += '当前集资人数: %s\n' % backer_count # 抽卡播报 card_report = '' if global_config.MODIAN_CARD_DRAW: card_report = self.card_draw_handler.draw( user_id, nickname, backer_money, pay_time) '''接棒相关''' my_logger.debug('接棒情况更新') for jiebang in jiebang_activities: # if jiebang.start_time > time.time(): # continue my_logger.debug('接棒活动详情: 【%s】', jiebang.name) my_logger.debug('集资金额: %s, 接棒最小金额: %s', backer_money, jiebang.min_stick_amount) if backer_money >= jiebang.min_stick_amount: stick_num = util.compute_stick_num( jiebang.min_stick_amount, backer_money) jiebang.current_stick_num += stick_num jiebang.last_record_time = util.convert_timestamp_to_timestr( int(time.time() * 1000)) # 数据库也要更新 try: mysql_util.query( """ UPDATE jiebang SET `current_stick_num`=%s, `last_record_time`=%s WHERE `name`=%s """, (jiebang.current_stick_num, jiebang.last_record_time, jiebang.name)) except Exception as e: my_logger.error('更新接棒数据失败') my_logger.exception(e) my_logger.debug('数据库接棒数据更新完成') test_msg = '' if jiebang.need_detail == 1: test_msg = '【%s】, 当前第%s棒, 目标%s棒\n' \ % (jiebang.name, jiebang.current_stick_num, jiebang.target_stick_num) elif jiebang.need_detail == 0: test_msg = '【%s】\n' % jiebang.name elif jiebang.need_detail == 2: test_msg = '【%s】, 当前第%s棒\n' \ % (jiebang.name, jiebang.current_stick_num) elif jiebang.need_detail == 3: if stick_num > 1: test_msg = '抽奖号: {}~{}\n'.format( jiebang.current_stick_num - stick_num + 1, jiebang.current_stick_num) else: test_msg = '抽奖号: {}\n'.format( jiebang.current_stick_num) my_logger.debug(test_msg) if len(test_msg) > 0: msg += test_msg QQHandler.send_to_groups(['483548995'], test_msg) '''金额类flag相关''' my_logger.debug('flag情况更新') flag_test_msgs = '' for flag in flag_activities: my_logger.debug('Flag活动详情: %s', flag.name) my_logger.debug('Flag金额: %s, 结束时间: %s', flag.target_flag_amount, flag.end_time) diff = flag.target_flag_amount - current test_msgs = '【%s】, 目标金额: %s元, ' % (flag.name, flag.target_flag_amount) if diff > 0: test_msgs += '距离目标还差%s元\n' % round(diff, 2) flag_test_msgs += test_msgs else: test_msgs += '已经达成目标\n' my_logger.debug(flag_test_msgs) if len(flag_test_msgs) > 0: QQHandler.send_to_groups(['483548995'], flag_test_msgs) # msg += flag_test_msgs '''人头类flag相关''' my_logger.debug('人头flag情况更新') count_flag_test_msgs = '' for flag in count_flag_activities: my_logger.debug('人头Flag活动详情: %s', flag.name) my_logger.debug('人头Flag目标: %s, 开始时间: %s, 结束时间: %s', flag.target_flag_amount, flag.start_time, flag.end_time) target = flag.target_flag_amount # 统计当前人数 rst = mysql_util.select_one( """ select count(distinct(`supporter_id`)) from `order` where `pro_id` = %s and `pay_time` <= %s and `pay_time` >= %s """, (modian_entity.pro_id, flag.end_time, flag.start_time)) # 目标人数为0,代表特殊类flag,只报人数 if target == 0: count_flag_test_msgs += '【%s】, 当前人数: %s ' % (flag.name, rst[0]) else: count_flag_test_msgs += '【%s】, 当前人数: %s, 目标人数: %s ' % ( flag.name, rst[0], flag.target_flag_amount) my_logger.debug(count_flag_test_msgs) if len(count_flag_test_msgs) > 0: QQHandler.send_to_groups(['483548995'], count_flag_test_msgs) # msg += flag_test_msgs msg += '%s\n集资项目: %s\n链接: %s\n' % (project_info, pro_name, modian_entity.link) # msg += jizi_pk_report my_logger.info(msg) if global_config.USING_COOLQ_PRO is True: my_logger.debug('使用酷Q PRO发送图片') msg += '\n[CQ:image,file=http://wx1.sinaimg.cn/large/439a9f3fgy1fpllweknr6j201i01g0lz.jpg]\n' # if global_config.MODIAN_NEED_DISPLAY_PK: # msg += self.pk_modian_activity() QQHandler.send_to_groups(modian_entity.broadcast_groups, msg) if card_report: QQHandler.send_to_groups(modian_entity.broadcast_groups, card_report) # QQHandler.send_to_groups(['483548995'], card_report) self.order_queues[modian_entity.pro_id].add(oid) # 更新接棒的数据库 try: my_logger.debug('更新接棒活动信息:') for jiebang in jiebang_activities: my_logger.debug( 'current_stick_num: %s, last_record_time: %s, name: %s', jiebang.current_stick_num, jiebang.last_record_time, jiebang.name) mysql_util.query( """ UPDATE jiebang SET current_stick_num=%s WHERE name=%s """, (jiebang.current_stick_num, jiebang.name)) except Exception as e: my_logger.exception(e)
def parse_order_details(self, orders, taoba_entity): my_logger.debug('taoba_entity: {}'.format(taoba_entity.taoba_id)) my_logger.debug('keys: {}'.format(self.order_queues.keys())) if len(self.order_queues[taoba_entity.taoba_id]) == 0 and len( orders) == 0: my_logger.debug('订单队列为空') return jiebang_activities = global_config.MODIAN_JIEBANG_ACTIVITIES[ taoba_entity.taoba_id] flag_activities = global_config.MODIAN_FLAG_ACTIVITIES[ taoba_entity.taoba_id] count_flag_activities = global_config.MODIAN_COUNT_FLAG_ACTIVITIES[ taoba_entity.taoba_id] # 查询集资情况 pro_name, current, backer_count = self.get_current_and_target( taoba_entity) project_info = '当前进度: %s元' % current taoba_entity.current = current taoba_entity.title = pro_name # group_account_entity.target = target taoba_entity.support_num = backer_count my_logger.debug('size of order %s queue: %s', taoba_entity.taoba_id, len(self.order_queues[taoba_entity.taoba_id])) for order in orders: user_id = order['userid'] nickname = order['nickname'] pay_time = util.convert_timestamp_to_timestr(order['addtime'] * 1000) single_price = order['amount'] pay_amount = order['nums'] backer_money = single_price listid = int(order['id']) my_logger.debug('oid: %s', listid) if listid in self.order_queues[taoba_entity.taoba_id]: continue my_logger.debug('项目%s队列长度: %s', taoba_entity.taoba_id, len(self.order_queues[taoba_entity.taoba_id])) # 每次需要更新一下昵称 try: mysql_util.query( """ INSERT INTO `supporter` (`id`, `name`) VALUES (%s, %s) ON DUPLICATE KEY UPDATE `id`=%s """, (user_id, nickname, user_id)) except Exception as e: my_logger.exception(e) try: # 创建对象 mysql_util.query( """ INSERT INTO `order` (`id`,`supporter_id`,`backer_money`,`pay_time`, `pro_id`) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE `id`=%s """, (str(listid), user_id, backer_money, pay_time, taoba_entity.taoba_id, str(listid))) except Exception as e: my_logger.exception(e) msg = '感谢 %s(%s) 支持了%s元, %s\n' % ( nickname, user_id, backer_money, util.random_str(global_config.MODIAN_POSTSCRIPTS)) # daka_rank, support_days = self.find_user_daka_rank(user_id, group_account_entity.pro_id) # if daka_rank != -1 and support_days: # msg += '当前项目已打卡%s天\n' % support_days # if group_account_entity.need_display_rank is True: # jizi_rank, backer_money = self.find_user_jizi_rank(user_id, group_account_entity.pro_id) # if jizi_rank != -1: # msg += '当前项目已集资%s元, 排名: %s' % (backer_money, jizi_rank) # else: # pass # 统计当前人数 count = mysql_util.select_one( """ SELECT COUNT(distinct(`supporter_id`)) FROM `order` WHERE `pro_id`=%s """, (taoba_entity.taoba_id, )) backer_count = count[0] msg += '当前集资人数: %s\n' % backer_count # 抽卡播报 card_report = '' if global_config.MODIAN_CARD_DRAW: card_report = self.card_draw_handler.draw( user_id, nickname, backer_money, pay_time) '''接棒相关''' my_logger.debug('接棒情况更新') for jiebang in jiebang_activities: # if jiebang.start_time > time.time(): # continue my_logger.debug('接棒活动详情: 【%s】', jiebang.name) my_logger.debug('集资金额: %s, 接棒最小金额: %s', backer_money, jiebang.min_stick_amount) if backer_money >= jiebang.min_stick_amount: stick_num = util.compute_stick_num( jiebang.min_stick_amount, backer_money) jiebang.current_stick_num += stick_num jiebang.last_record_time = util.convert_timestamp_to_timestr( int(time.time() * 1000)) # 数据库也要更新 try: mysql_util.query( """ UPDATE jiebang SET `current_stick_num`=%s, `last_record_time`=%s WHERE `name`=%s """, (jiebang.current_stick_num, jiebang.last_record_time, jiebang.name)) except Exception as e: my_logger.error('更新接棒数据失败') my_logger.exception(e) my_logger.debug('数据库接棒数据更新完成') test_msg = '' if jiebang.need_detail == 1: test_msg = '【%s】, 当前第%s棒, 目标%s棒\n' \ % (jiebang.name, jiebang.current_stick_num, jiebang.target_stick_num) elif jiebang.need_detail == 0: test_msg = '【%s】\n' % jiebang.name elif jiebang.need_detail == 2: test_msg = '【%s】, 当前第%s棒\n' \ % (jiebang.name, jiebang.current_stick_num) elif jiebang.need_detail == 3: if stick_num > 1: test_msg = '抽奖号: {}~{}\n'.format( jiebang.current_stick_num - stick_num + 1, jiebang.current_stick_num) else: test_msg = '抽奖号: {}\n'.format( jiebang.current_stick_num) my_logger.debug(test_msg) if len(test_msg) > 0: msg += test_msg # QQHandler.send_to_groups(['483548995'], test_msg) '''金额类flag相关''' my_logger.debug('flag情况更新') flag_test_msgs = '' for flag in flag_activities: my_logger.debug('Flag活动详情: %s', flag.name) my_logger.debug('Flag金额: %s, 结束时间: %s', flag.target_flag_amount, flag.end_time) diff = flag.target_flag_amount - current test_msgs = '【%s】, 目标金额: %s元, ' % (flag.name, flag.target_flag_amount) if diff > 0: test_msgs += '距离目标还差%s元\n' % round(diff, 2) flag_test_msgs += test_msgs else: test_msgs += '已经达成目标\n' my_logger.debug(flag_test_msgs) if len(flag_test_msgs) > 0: pass # QQHandler.send_to_groups(['483548995'], flag_test_msgs) # msg += flag_test_msgs '''人头类flag相关''' my_logger.debug('人头flag情况更新') count_flag_test_msgs = '' for flag in count_flag_activities: my_logger.debug('人头Flag活动详情: %s', flag.name) my_logger.debug('人头Flag目标: %s, 开始时间: %s, 结束时间: %s', flag.target_flag_amount, flag.start_time, flag.end_time) target = flag.target_flag_amount # 统计当前人数 rst = mysql_util.select_one( """ select count(distinct(`supporter_id`)) from `order` where `pro_id` = %s and `pay_time` <= %s and `pay_time` >= %s """, (taoba_entity.taoba_id, flag.end_time, flag.start_time)) # 目标人数为0,代表特殊类flag,只报人数 if target == 0: count_flag_test_msgs += '【%s】, 当前人数: %s ' % (flag.name, rst[0]) else: count_flag_test_msgs += '【%s】, 当前人数: %s, 目标人数: %s ' % ( flag.name, rst[0], flag.target_flag_amount) my_logger.debug(count_flag_test_msgs) if len(count_flag_test_msgs) > 0: # QQHandler.send_to_groups(['483548995'], count_flag_test_msgs) pass # msg += flag_test_msgs msg += '%s\n集资项目: %s\n集资方式: %s\n' % (project_info, pro_name, taoba_entity.link) # msg += jizi_pk_report # if global_config.MODIAN_NEED_DISPLAY_PK: # msg += self.pk_modian_activity() if global_config.USING_COOLQ_PRO is True: my_logger.debug('使用酷Q PRO发送图片') msg += '\n[CQ:image,file={}]\n'.format(taoba_entity.qrcode) # QQHandler.send_to_groups(taoba_entity.broadcast_groups, msg) if card_report: pass # QQHandler.send_to_groups(taoba_entity.broadcast_groups, card_report) # QQHandler.send_to_groups(['483548995'], card_report) # 集五福 # wufu_report = modian_wufu_handler.draw(user_id, nickname, backer_money, pay_time) # if wufu_report: # QQHandler.send_to_groups(group_account_entity.broadcast_groups, wufu_report) self.order_queues[taoba_entity.taoba_id].add(listid) # 更新接棒的数据库 try: my_logger.debug('更新接棒活动信息:') for jiebang in jiebang_activities: my_logger.debug( 'current_stick_num: %s, last_record_time: %s, name: %s', jiebang.current_stick_num, jiebang.last_record_time, jiebang.name) mysql_util.query( """ UPDATE jiebang SET current_stick_num=%s WHERE name=%s """, (jiebang.current_stick_num, jiebang.name)) except Exception as e: my_logger.exception(e)
def plus_points(amount, order_id, pro_id): """ 发糖组加分 10.17得到棒棒糖 积分+1 48 得到糖罐 积分+5 101.7得到狐狸玩偶 积分+10 过期的棒棒糖 积分-1 概率20%(暂定) Fxf的啵啵 积分+3 概率10%(暂定) :param amount: :return: """ my_logger.info('发糖组加分,金额: %s元' % amount) num_of_fox_doll = 0 num_of_sugar_bowl = 0 num_of_lollipop = 0 if amount < LOLLIPOP_AMOUNT: points = 0 return points, '' elif LOLLIPOP_AMOUNT <= amount < SUGAR_BOWL_AMOUNT: num_of_lollipop = int(amount // LOLLIPOP_AMOUNT) points = num_of_lollipop * LOLLIPOP_POINTS elif SUGAR_BOWL_AMOUNT <= amount < FOX_DOLL_AMOUNT: num_of_sugar_bowl = int(amount // SUGAR_BOWL_AMOUNT) num_of_lollipop = int((amount % SUGAR_BOWL_AMOUNT) // LOLLIPOP_AMOUNT) points = num_of_sugar_bowl * SUGAR_BOWL_POINTS + num_of_lollipop * LOLLIPOP_POINTS else: num_of_fox_doll = int(amount // FOX_DOLL_AMOUNT) num_of_sugar_bowl = int( (amount % FOX_DOLL_AMOUNT) // SUGAR_BOWL_AMOUNT) num_of_lollipop = int( (amount % FOX_DOLL_AMOUNT % SUGAR_BOWL_AMOUNT) // LOLLIPOP_AMOUNT) points = num_of_fox_doll * FOX_DOLL_POINTS + num_of_sugar_bowl * SUGAR_BOWL_POINTS + num_of_lollipop * LOLLIPOP_POINTS my_logger.info('加分数量: %s' % points) report = '获得' report += '【棒棒糖】*%s, ' % num_of_lollipop if num_of_lollipop > 0 else '' report += '【糖罐】*%s, ' % num_of_sugar_bowl if num_of_sugar_bowl > 0 else '' report += '【狐狸玩偶】*%s, ' % num_of_fox_doll if num_of_fox_doll > 0 else '' if num_of_lollipop > 0: report += '[CQ:image,file=%s]' % LOLLIPOP_IMG if num_of_sugar_bowl > 0: report += '[CQ:image,file=%s]' % SUGAR_BOWL_IMG if num_of_fox_doll > 0: report += '[CQ:image,file=%s]' % FOX_DOLL_IMG report += '\n' candidate = ['过期的棒棒糖', 'FXF的啵啵', '无'] weight = [10, 20, 70] weight2 = [10, 15, 75] if 10.17 <= amount < 101.7: idx = util.weight_choice(candidate, weight2) elif amount >= 101.7: idx = util.weight_choice(candidate, weight) else: idx = -1 bonus_report = '' if idx == 0: # 过期的棒棒糖 if 10.17 <= amount < 101.7: # 10.17-101.7, 积分清零 points = 0 bonus_report += '很不幸,你获得了【过期的棒棒糖】,本次获取的积分清零T_T' elif amount >= 101.7: # 多于101.7,积分减半 points = int(points // 2) bonus_report += '很不幸,你获得了【过期的棒棒糖】,本次获取的积分减半T_T' elif idx == 1: # FXF的啵啵,本次积分翻倍 points *= 2 bonus_report += '恭喜,你获得了【FXF的啵啵】,本次获取的积分加倍' else: pass if bonus_report: report += bonus_report report += '本次加分:%s\n' % points # 存入数据库 mysql_util.query( """ insert into `point_detail` (`order_id`, `pro_id`, `point`) VALUES (%s, %s, %s) """, (order_id, pro_id, points)) return points, report
def update_modian_conf(): global modian_handler time0 = time.time() my_logger.info('读取摩点配置') ConfigReader.read_conf() # modian_json = json.load(open("data/modian.json", encoding='utf8')) # modian_json = json.load(open("data/weixin_group_account.json", encoding='utf8')) modian_json = json.load(open("data/taoba_account.json", encoding='utf8')) modian_handler.login(modian_json['taoba_account'], modian_json['taoba_passwd']) global_config.MODIAN_POSTSCRIPTS = modian_json['modian_postscripts'] # 摩点集资PK链接数组初始化 global_config.MODIAN_NEED_DISPLAY_PK = modian_json[ 'modian_need_display_pk'] for modian_pk_j in modian_json['modian_pk_activities']: global_config.MODIAN_PK_ARRAY.append(modian_pk_j) # 是否需要开启抽卡功能 global_config.MODIAN_CARD_DRAW = modian_json['modian_need_card_draw'] # global_config.MODIAN_300_ACTIVITY = modian_json['modian_300_activity'] # 需要适应同时开多个链接的情况 global_config.MODIAN_ARRAY = [] for modian_j in modian_json['monitor_activities']: # if modian_j['modian_need_display_rank'] is False: # modian = ModianEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], False, # modian_j['broadcast_groups']) # modian = GroupAccountEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], # modian_j['broadcast_groups'], modian_j['qrcode']) modian = TaoBaEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], modian_j['broadcast_groups'], modian_j['qrcode']) # elif modian_j['wds_need_display_rank'] is True: # modian = ModianEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], True, # modian_j['broadcast_groups']) global_config.MODIAN_ARRAY.append(modian) modian_handler.taoba_project_array = global_config.MODIAN_ARRAY # modian_handler.init_order_queues() modian_handler.card_draw_handler.read_config() global_config.JIZI_NOTIFY_GROUPS = ConfigReader.get_property( 'qq_conf', 'jizi_notify_groups').split(';') modian_groups = global_config.JIZI_NOTIFY_GROUPS modian_handler.group_account_notify_groups = modian_groups my_logger.debug('JIZI_NOTIFY_GROUPS: %s, length: %d', ','.join(global_config.JIZI_NOTIFY_GROUPS), len(modian_handler.group_account_notify_groups)) my_logger.debug('读取正在进行中的flag活动') global_config.MODIAN_FLAG_ACTIVITIES = {} flag_json = json.load(open('data/modian_flag.json', encoding='utf8'))['activities'] for modian in global_config.MODIAN_ARRAY: pro_id = modian.taoba_id global_config.MODIAN_FLAG_ACTIVITIES[pro_id] = [] for activity in flag_json: pro_id = activity['pro_id'] end_time = activity['end_time'] if util.convert_timestr_to_timestamp(end_time) > time.time(): flag = ModianFlagEntity(activity['flag_name'], activity['pro_id'], activity['target_flag_amount'], activity['end_time'], activity['remark']) global_config.MODIAN_FLAG_ACTIVITIES[int(pro_id)].append(flag) my_logger.debug('MODIAN_FLAG_ACTIVITIES: %s', global_config.MODIAN_FLAG_ACTIVITIES) my_logger.debug('读取正在进行的人头flag活动') global_config.MODIAN_COUNT_FLAG_ACTIVITIES = {} count_flag_json = json.load( open('data/modian_count_flag.json', encoding='utf8'))['activities'] for modian in global_config.MODIAN_ARRAY: pro_id = modian.taoba_id global_config.MODIAN_COUNT_FLAG_ACTIVITIES[pro_id] = [] for activity in count_flag_json: pro_id = activity['pro_id'] start_time = activity['start_time'] end_time = activity['end_time'] if util.convert_timestr_to_timestamp( start_time) >= util.convert_timestr_to_timestamp(end_time): my_logger.error('人头类flag,起始时间大于结束时间!') raise RuntimeError('起始时间大于结束时间') time0 = time.time() if util.convert_timestr_to_timestamp( end_time) > time0 > util.convert_timestr_to_timestamp( start_time): flag = ModianCountFlagEntity(activity['flag_name'], activity['pro_id'], activity['target_flag_amount'], activity['start_time'], activity['end_time'], activity['remark']) global_config.MODIAN_COUNT_FLAG_ACTIVITIES[int(pro_id)].append( flag) my_logger.debug('MODIAN_COUNT_FLAG_ACTIVITIES: %s', global_config.MODIAN_COUNT_FLAG_ACTIVITIES) # 接棒活动更新,读取json文件中的内容,更新到数据库中 my_logger.debug('接棒活动更新,读取json文件中的内容,更新到数据库中') jiebang_json = json.load(open('data/modian_jiebang.json', encoding='utf8'))['activities'] # conn = sqlite3.connect('data/modian.db', check_same_thread=False) for activity in jiebang_json: end_time = activity['end_time'] my_logger.debug('活动结束时间: {}; 当前时间:{}'.format( util.convert_timestr_to_timestamp(end_time), time.time())) if util.convert_timestr_to_timestamp(end_time) < time.time(): my_logger.debug('活动结束时间早于当前时间,跳过') continue name = activity['jiebang_name'] try: # cursor = conn.cursor() # c = cursor.execute(""" # select * from jiebang WHERE name=? # """, (name, )) # rst = c.fetchall() rst = mysql_util.select_one( """ select * from jiebang WHERE name=%s """, (name, )) my_logger.debug(rst) if rst is not None: my_logger.debug('DB中有相应的接棒活动') else: my_logger.debug('DB中没有对应的接棒活动,需要创建') mysql_util.query( """ INSERT INTO jiebang (name, pro_id, current_stick_num, start_time, end_time, target_stick_num, min_stick_amount, need_detail) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """, (name, activity['pro_id'], 0, activity['start_time'], activity['end_time'], activity['target_stick_num'], activity['min_stick_amount'], activity['need_detail'])) # conn.commit() # else: # raise RuntimeError('接棒活动名称错误!') except Exception as e: my_logger.error('读取mysql出现错误') my_logger.exception(e) # finally: # cursor.close() # 读取正在进行中的接棒活动 my_logger.debug('读取正在进行中的接棒活动') global_config.MODIAN_JIEBANG_ACTIVITIES = {} for modian in global_config.MODIAN_ARRAY: pro_id = modian.taoba_id global_config.MODIAN_JIEBANG_ACTIVITIES[pro_id] = [] try: # cursor = conn.cursor() rst = mysql_util.select_all( """ SELECT name, pro_id, current_stick_num, last_record_time, start_time, end_time, target_stick_num, min_stick_amount, need_detail FROM jiebang where pro_id=%s and end_time >= NOW() and current_stick_num < target_stick_num """, (pro_id, )) if rst: for jiebang in rst: my_logger.debug('jiebang name: {}'.format( str(jiebang[0], encoding='utf-8'))) # 修正当前棒数 my_logger.info('修正接棒棒数') real_stick_num = 0 rst0 = mysql_util.select_all( """ SELECT backer_money FROM `order` WHERE pro_id = %s and backer_money >= %s and pay_time >= %s and pay_time <= %s """, (pro_id, jiebang[7], jiebang[4], jiebang[5])) my_logger.debug( """ SELECT backer_money FROM `order` WHERE pro_id = %s and backer_money >= %s and pay_time >= %s and pay_time <= %s """ % (pro_id, jiebang[7], jiebang[4], jiebang[5])) my_logger.debug(rst0) if rst0: for order in rst0: my_logger.debug('order: {}'.format(order[0])) real_stick_num += int(order[0] // jiebang[7]) my_logger.info('记录棒数: {}, 实际棒数: {}'.format( jiebang[2], real_stick_num)) mysql_util.query( """ UPDATE jiebang SET current_stick_num = %s WHERE name = %s """, (real_stick_num, jiebang[0])) my_logger.debug( 'jiebang: %s, %s, %s, %s, %s, %s, %s, %s, %s', jiebang[0], jiebang[1], jiebang[2], jiebang[3], jiebang[4], jiebang[5], jiebang[6], jiebang[7], jiebang[8]) jiebang_entity = ModianJiebangEntity( str(jiebang[0], encoding='utf-8'), jiebang[1], jiebang[2], jiebang[3], jiebang[4], jiebang[5], jiebang[6], jiebang[7], jiebang[8]) jiebang_entity.current_stick_num = real_stick_num my_logger.info('修正完成') global_config.MODIAN_JIEBANG_ACTIVITIES[pro_id].append( jiebang_entity) except Exception as e: my_logger.error('读取正在进行中的接棒活动出现错误!') my_logger.exception(e) # finally: # cursor.close() my_logger.debug(global_config.MODIAN_JIEBANG_ACTIVITIES) # conn.close() my_logger.debug('读取摩点配置耗时: %s秒', time.time() - time0) modian_handler.init_order_queues()