示例#1
0
def setHonorField(is_honor, id):
    mysql = Mysql_instance()
    sql = "update reward_course_config set is_honor='%s' where id ='%s'" % (
        is_honor, id)
    mysql.cursor.execute(sql)
    mysql.commit()
    mysql.close()
示例#2
0
def getRewardDataInfo(startDate, endDate):
    mysql = Mysql_instance()
    startDate = str(datetime.strptime(startDate, '%Y-%m-%d'))
    endDate = str(datetime.strptime(endDate, '%Y-%m-%d') + timedelta(1))
    sql = "select uid,nickname,key_code,reward_cost,reward_value,reward_time,deliver_time,card_no,card_pwd,status,reward_name,cost_type_name,cost_num from reward_record "\
          +"where reward_time >= '%s' and reward_time < '%s'"%(startDate,endDate)
    print '---------------------------'
    print sql
    print '---------------------------'
    mysql.cursor.execute(sql)
    res = mysql.cursor.fetchall()
    data = []
    for row in res:
        data.append({
            "uid": row[0],
            "nickname": row[1],
            "key_code": row[2],
            "reward_cost": round(float(row[3]) / 100, 2),
            "reward_value": round(float(row[4]) / 100, 2),
            "reward_time": str(row[5]),
            "deliver_time": str(row[6] or ""),
            "card_no": row[7] or "",
            "card_pwd": row[8] or "",
            "status": row[9],
            "reward_name": row[10],
            "cost_type_name": row[11],
            "cost_num": row[12],
        })
    mysql.close()
    return json.dumps({"count": len(data), "data": data})
示例#3
0
def updateCourseInfo(id, title, cost, price, item_id, cost_type, cost_num,
                     cost_type_name, icon, item_type, limit_price):
    mysql = Mysql_instance()
    sql = "update reward_course_config set title='%s',cost='%s',price='%s',item_id='%s',cost_type='%s',cost_num='%s',cost_type_name='%s',icon='%s',item_type='%s',limit_price='%s' where id='%s'" % (
        title, cost, price, item_id, cost_type, cost_num, cost_type_name, icon,
        item_type, limit_price, id)
    mysql.cursor.execute(sql)
    mysql.commit()
    mysql.close()
示例#4
0
def createRewardCourse(title, cost, price, item_id, cost_type, cost_num,
                       cost_type_name, icon, item_type, limit_price):
    mysql = Mysql_instance()
    cost = int(float(cost) * 100)
    price = int(float(price) * 100)
    sql = "insert into reward_course_config(title,cost,price,item_id,cost_type,cost_num,cost_type_name,icon,item_type,limit_price) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (
        title, cost, price, item_id, cost_type, cost_num, cost_type_name, icon,
        item_type, limit_price)
    mysql.cursor.execute(sql)
    mysql.commit()
    mysql.close()
示例#5
0
def getRewardUserInfo(key_code):
    sql = "select uid,nickname,card_no,card_pwd from reward_record where key_code='%s'" % key_code
    mysql = Mysql_instance()
    mysql.cursor.execute(sql)
    res = mysql.cursor.fetchone()
    return {
        "uid": res[0],
        "nickname": res[1],
        "card_no": res[2] or "",
        "card_pwd": res[3] or "",
        "key_code": key_code
    }
示例#6
0
def getThisRewardCourse(id):
    mysql = Mysql_instance()
    sql = "select title,cost,price,item_id,cost_type,cost_num,cost_type_name,icon,item_type,limit_price from reward_course_config where id='%s'" % id
    mysql.cursor.execute(sql)
    res = mysql.cursor.fetchone()
    return {
        "id": id,
        "title": res[0],
        "cost": res[1],
        "price": res[2],
        "item_id": res[3],
        "cost_type": res[4],
        "cost_num": res[5],
        "cost_type_name": res[6],
        "icon": res[7],
        "item_type": res[8],
        "limit_price": res[9],
    }
示例#7
0
def getRewardCourseInfo():
    mysql = Mysql_instance()
    sql = "select id,title,cost,price,item_id,cost_type,cost_num,cost_type_name,icon,item_type,limit_price,is_honor from reward_course_config"
    mysql.cursor.execute(sql)
    res = mysql.cursor.fetchall()
    data = []
    for row in res:
        data.append({
            "id": row[0],
            "title": row[1],
            "cost": round(float(row[2]) / 100, 2),
            "price": round(float(row[3]) / 100, 2),
            "item_id": row[4],
            "cost_type": row[5],
            "cost_num": row[6],
            "cost_type_name": row[7],
            "icon": row[8],
            "item_type": row[9],
            "limit_price": row[10],
            "is_honor": row[11],
        })
    return json.dumps({"count": len(data), "data": data})
示例#8
0
def sendReward(redis, key_code, card_no, card_pwd):
    mysql = Mysql_instance()
    # 有可能重复记录,所以获取是否第一次记录
    is_first_get = True
    sql_is_first_record = 'select * from reward_record where status = 1 and key_code = "%s"' % key_code
    mysql.cursor.execute(sql_is_first_record)
    is_first_res = mysql.cursor.fetchall()
    if len(is_first_res) > 0:
        is_first_get = False

    sql = "select status,item_id,uid,reward_value from reward_record where key_code = '%s'" % key_code
    mysql.cursor.execute(sql)
    res = mysql.cursor.fetchone()

    sql = "update reward_record set card_no = '%s',card_pwd = '%s' where key_code = '%s'" % (
        card_no, card_pwd, key_code)
    if res and res[0] == 0:
        now = str(datetime.now())
        if res[1] is not None:
            bag_redis.hdel('reward:%s:user:%s:keycode' % (res[1], res[2]),
                           res[3])
        sql = "update reward_record set card_no = '%s',card_pwd = '%s',status = 1,deliver_time = '%s' where key_code = '%s'" % (
            card_no, card_pwd, now, key_code)
    mysql.cursor.execute(sql)
    mysql.commit()
    mysql.close()
    # 金币追踪
    if is_first_get:
        record_player_balance_change(bag_redis,
                                     '',
                                     -1,
                                     0,
                                     0,
                                     59,
                                     extra1=key_code)
    return getRewardUserInfo(key_code)
示例#9
0
def delRewardCourse(id):
    mysql = Mysql_instance()
    sql = "delete from reward_course_config where id = '%s'" % id
    mysql.cursor.execute(sql)
    mysql.commit()
    mysql.close()