Esempio n. 1
0
def add(img: str,
        name: str = '',
        title: str = '',
        receive_text: str = None,
        custom_style: str = None):
    uuid = shortuuid.uuid()
    coupon = {
        'uuid': uuid,
        'name': name,
        'img': img,
        'title': title,
        'receive_text': receive_text,
        'custom_style': custom_style
    }
    db.execute(Coupon.insert().values(**coupon))
    return uuid
def add(cid: int, tel: str):
    coupon_res = coupon.get_by_id(cid)
    if not coupon_res:
        raise error.CouponNotFoundError(cid)
    telephone = {'tel': tel, 'coupon_id': cid}
    result = db.execute(Telephone.insert().values(**telephone))
    return result.inserted_primary_key
Esempio n. 3
0
def inc_submit(cid: str, value: int = 1):
    exp = Coupon.update().values(
        submit_count=Coupon.c.submit_count.op('+')(value)).where(
            Coupon.c.uuid == cid)
    result = db.execute(exp)
    view = result.last_updated_params()
    result.close()
    return view
Esempio n. 4
0
def get_all():
    exp = select([Coupon])
    result = db.execute(exp)
    coupons = result.fetchall()
    result.close()
    return coupons
Esempio n. 5
0
def get_by_uuid(uuid: str):
    exp = select([Coupon]).where(Coupon.c.uuid == uuid)
    result = db.execute(exp)
    coupon = result.fetchone()
    result.close()
    return coupon
Esempio n. 6
0
def get_by_id(cid: int):
    exp = select([Coupon]).where(Coupon.c.id == cid)
    result = db.execute(exp)
    coupon = result.fetchone()
    result.close()
    return coupon
Esempio n. 7
0
def edit(cid: str, **kwargs):
    db.execute(Coupon.update().values(**kwargs).where(cid == Coupon.c.uuid))
    return cid