Esempio n. 1
0
    def post(self):
        if self.arg.pic_url_list:
            pic_url_list = ','.join([
                i[len(ImageHost):]
                for i in trans.to_list(self.arg.pic_url_list)
            ])
        else:
            pic_url_list = ''

        response = publish_goods(shop_id=self.arg.shop_id,
                                 category_id=self.arg.category_id,
                                 description=self.arg.description,
                                 detail=self.arg.detail,
                                 bar_code=self.arg.bar_code,
                                 price=self.arg.price,
                                 promotion_price=self.arg.promotion_price,
                                 remark=self.arg.remark,
                                 brand_name=self.arg.brand_name,
                                 basic_info=self.arg.basic_info,
                                 pic_url_list=pic_url_list)
        response['is_sendall'] = False
        if self.arg.is_sendall == 1 or self.arg.is_sendall == '1' or self.arg.is_sendall is True:
            desc_fansmessageconfig_mass(self.arg.shop_id)
            fans = get_shop_fans(self.arg.shop_id)['fans']
            fans_ids = [i['user_id'] for i in fans]

            push_time = datetime.datetime.now()

            msg = loader.load("good.html").generate(
                description=self.arg.description,
                price=self.arg.price,
                promotion_price=self.arg.promotion_price,
                imgs=[i for i in trans.to_list(self.arg.pic_url_list)])
            dbsession = DBSession()
            FD_T_Fansmessage.post(dbsession=dbsession,
                                  shop_id=self.arg.shop_id,
                                  user_id=-1,
                                  message=msg,
                                  push_time=push_time)
            dbsession.commit()
            dbsession.close()

            http_client = AsyncHTTPClient()
            params = ""
            for i in fans_ids:
                params += "uid=%s&" % i
            url = "%s/chat/%s/fans/message/?" % (CONFIG.FD_CHAT_SERVER,
                                                 self.arg.shop_id) + params
            http_client.fetch(HTTPRequest(url=url, method='POST', body=msg))

            response['is_sendall'] = True

        self.write(response)
Esempio n. 2
0
def modify_shop_info(shop_id,
                     brand_name=None,
                     shop_name=None,
                     business_hours=None,
                     telephone_no=None,
                     city_id=None,
                     district_id=None,
                     business_area=None,
                     address=None,
                     longitude=None,
                     latitude=None,
                     pic_url_list=None,
                     category_list=None):
    session = DBSession()
    try:
        shop = session.query(FD_T_Shop).filter(
            FD_T_Shop.shop_id == shop_id).one()
        if brand_name:
            shop.brand_name = brand_name
        if shop_name:
            shop.shop_name = shop_name
        if business_hours:
            shop.business_hours = business_hours
        if telephone_no:
            shop.telephone_no = telephone_no
        if city_id:
            shop.city_id = city_id
        if district_id:
            shop.district_id = district_id
        if business_area:
            shop.business_area = business_area
        if address:
            shop.address = address
        if longitude:
            shop.longitude = longitude
        if latitude:
            shop.latitude = latitude
        if pic_url_list:
            shop.pic_url_list = pic_url_list
        if category_list:
            shop.category_list = str(to_list(
                str(category_list))[0]) + ',' + ','.join(
                    get_shop_all_category(int(shop_id)))

        GEO().update(shop.shop_id, trans.to_list(shop.category_list),
                     shop.city_id, float(shop.longitude), float(shop.latitude))

        session.commit()
        return dict(is_success=True, shop_id=shop.shop_id)
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code,
                    des=MTERROR.MultipleResultsFound.des)
Esempio n. 3
0
 def dict(self):
     return {
         'user_id':
         self.user_id,
         'name':
         self.name,
         'gender':
         self.gender,
         'birthday':
         self.birthday.strftime('%Y-%m-%d %H:%M:%S:%f')
         if self.birthday else None,
         'mcode':
         self.mcode,
         'qrcode':
         self.qrcode,
         'phone_no':
         self.phone_no,
         'email':
         self.email,
         'portrait_url': [
             OSS_URL_PRIFIX + i for i in trans.to_list(self.portrait_url)
             if i
         ],
         'city_id':
         self.city_id
     }
Esempio n. 4
0
 def get(self):
     """
     get goods, status could be -2~2, or multipuls with dot like 1,2
     """
     status = trans.to_list(self.arg.status)
     response = get_goods_list_by_shop(int(self.arg.shop_id), int(self.arg.offset), int(self.arg.limit),
                                       status=self.arg.status)
     self.write(response)
Esempio n. 5
0
 def get(self):
     """
     get goods, status could be -2~2, or multipuls with dot like 1,2
     """
     status = trans.to_list(self.arg.status)
     response = get_goods_list_by_shop(int(self.arg.shop_id),
                                       int(self.arg.offset),
                                       int(self.arg.limit),
                                       status=self.arg.status)
     self.write(response)
Esempio n. 6
0
def modify_shop_info(shop_id, brand_name=None, shop_name=None, business_hours=None, telephone_no=None,
                     city_id=None, district_id=None, business_area=None, address=None,
                     longitude=None, latitude=None, pic_url_list=None, category_list=None):
    session = DBSession()
    try:
        shop = session.query(FD_T_Shop).filter(FD_T_Shop.shop_id == shop_id).one()
        if brand_name:
            shop.brand_name = brand_name
        if shop_name:
            shop.shop_name = shop_name
        if business_hours:
            shop.business_hours = business_hours
        if telephone_no:
            shop.telephone_no = telephone_no
        if city_id:
            shop.city_id = city_id
        if district_id:
            shop.district_id = district_id
        if business_area:
            shop.business_area = business_area
        if address:
            shop.address = address
        if longitude:
            shop.longitude = longitude
        if latitude:
            shop.latitude = latitude
        if pic_url_list:
            shop.pic_url_list = pic_url_list
        if category_list:
            shop.category_list = str(to_list(str(category_list))[0]) + ',' + ','.join(
                get_shop_all_category(int(shop_id)))

        GEO().update(shop.shop_id, trans.to_list(shop.category_list), shop.city_id, float(shop.longitude),
                     float(shop.latitude))

        session.commit()
        return dict(is_success=True,
                    shop_id=shop.shop_id)
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code, des=MTERROR.MultipleResultsFound.des)
Esempio n. 7
0
 def dict(self):
     return {
         'user_id': self.user_id,
         'name': self.name,
         'gender': self.gender,
         'birthday': self.birthday.strftime('%Y-%m-%d %H:%M:%S:%f') if self.birthday else None,
         'mcode': self.mcode,
         'qrcode': self.qrcode,
         'phone_no': self.phone_no,
         'email': self.email,
         'portrait_url': [OSS_URL_PRIFIX + i for i in trans.to_list(self.portrait_url) if i],
         'city_id': self.city_id
     }
Esempio n. 8
0
    def post(self):
        if self.arg.pic_url_list:
            pic_url_list = ','.join([i[len(ImageHost):] for i in trans.to_list(self.arg.pic_url_list)])
        else:
            pic_url_list = ''

        response = publish_goods(shop_id=self.arg.shop_id, category_id=self.arg.category_id,
                                 description=self.arg.description, detail=self.arg.detail, bar_code=self.arg.bar_code,
                                 price=self.arg.price,
                                 promotion_price=self.arg.promotion_price, remark=self.arg.remark,
                                 brand_name=self.arg.brand_name, basic_info=self.arg.basic_info,
                                 pic_url_list=pic_url_list)
        response['is_sendall'] = False
        if self.arg.is_sendall == 1 or self.arg.is_sendall == '1' or self.arg.is_sendall is True:
            desc_fansmessageconfig_mass(self.arg.shop_id)
            fans = get_shop_fans(self.arg.shop_id)['fans']
            fans_ids = [i['user_id'] for i in fans]

            push_time = datetime.datetime.now()

            msg = loader.load("good.html").generate(description=self.arg.description, price=self.arg.price,
                                                    promotion_price=self.arg.promotion_price,
                                                    imgs=[i for i in trans.to_list(self.arg.pic_url_list)])
            dbsession = DBSession()
            FD_T_Fansmessage.post(dbsession=dbsession, shop_id=self.arg.shop_id, user_id=-1, message=msg,
                                  push_time=push_time)
            dbsession.commit()
            dbsession.close()

            http_client = AsyncHTTPClient()
            params = ""
            for i in fans_ids:
                params += "uid=%s&" % i
            url = "%s/chat/%s/fans/message/?" % (CONFIG.FD_CHAT_SERVER, self.arg.shop_id) + params
            http_client.fetch(HTTPRequest(url=url, method='POST', body=msg))

            response['is_sendall'] = True

        self.write(response)
Esempio n. 9
0
def get_shops_limit(offset, limit):
    session = DBSession()
    total_num = session.query(FD_T_Shop).count()
    shops = session.query(FD_T_Shop).all()[offset: offset + limit]
    return dict(total_num=total_num,
                shops=[dict(shop_id=shop.shop_id,
                            shop_name=shop.shop_name,
                            qrcode=shop.qrcode,
                            business_hours=shop.business_hours,
                            telephone_no=shop.telephone_no,
                            city_id=shop.city_id,
                            district_id=shop.district_id,
                            business_area=shop.business_area,
                            address=shop.address,
                            longitude=float(shop.longitude),
                            latitude=float(shop.latitude),
                            pic_url_list=[ImageHost + i for i in trans.to_list(shop.pic_url_list)],
                            category_list=shop.pic_url_list) for shop in shops])
Esempio n. 10
0
def get_shops_limit(offset, limit):
    session = DBSession()
    total_num = session.query(FD_T_Shop).count()
    shops = session.query(FD_T_Shop).all()[offset:offset + limit]
    return dict(total_num=total_num,
                shops=[
                    dict(shop_id=shop.shop_id,
                         shop_name=shop.shop_name,
                         qrcode=shop.qrcode,
                         business_hours=shop.business_hours,
                         telephone_no=shop.telephone_no,
                         city_id=shop.city_id,
                         district_id=shop.district_id,
                         business_area=shop.business_area,
                         address=shop.address,
                         longitude=float(shop.longitude),
                         latitude=float(shop.latitude),
                         pic_url_list=[
                             ImageHost + i
                             for i in trans.to_list(shop.pic_url_list)
                         ],
                         category_list=shop.pic_url_list) for shop in shops
                ])
Esempio n. 11
0
def shenhe(shop_id):
    dbsession = DBSession()
    geo = GEO()
    shopaccount = dbsession.query(FD_T_Shopaccount).filter(
        FD_T_Shopaccount.shop_id == shop_id).one()

    shopaccount.service_deadline = datetime.datetime.now(
    ) + datetime.timedelta(days=365)
    shopaccount.service_status = 2
    shop = dbsession.query(FD_T_Shop).filter(
        FD_T_Shop.shop_id == shop_id).one()

    fansmsgconfig = dbsession.query(FD_T_Fansmessageconfig).filter(
        FD_T_Fansmessageconfig.shop_id == shop_id).one()
    fansmsgconfig.current_p2p_count = 30
    fansmsgconfig.p2p_remain_count = 30
    fansmsgconfig.next_p2p_count = 30
    fansmsgconfig.current_mass_count = 10
    fansmsgconfig.mass_remain_count = 10
    fansmsgconfig.next_mass_count = 10

    dbsession.add(fansmsgconfig)

    # start send pass message
    shop = dbsession.query(FD_T_Shop).filter(
        FD_T_Shop.shop_id == shop_id).one()
    shopname = shop.shop_name
    pass_message(shopname, shopaccount.contact_phone_no)
    # end send pass message

    dbsession.commit()

    geo.insert(shop_id,
               [int(i) for i in trans.to_list(shop.category_list) if i],
               int(shop.city_id), float(shop.longitude), float(shop.latitude))

    dbsession.close()
Esempio n. 12
0
def shenhe(shop_id):
    dbsession = DBSession()
    geo = GEO()
    shopaccount = dbsession.query(FD_T_Shopaccount).filter(FD_T_Shopaccount.shop_id == shop_id).one()

    shopaccount.service_deadline = datetime.datetime.now() + datetime.timedelta(days=365)
    shopaccount.service_status = 2
    shop = dbsession.query(FD_T_Shop).filter(FD_T_Shop.shop_id == shop_id).one()

    fansmsgconfig = dbsession.query(FD_T_Fansmessageconfig).filter(FD_T_Fansmessageconfig.shop_id == shop_id).one()
    fansmsgconfig.current_p2p_count = 30
    fansmsgconfig.p2p_remain_count = 30
    fansmsgconfig.next_p2p_count = 30
    fansmsgconfig.current_mass_count = 10
    fansmsgconfig.mass_remain_count = 10
    fansmsgconfig.next_mass_count = 10

    dbsession.add(fansmsgconfig)

    # start send pass message
    shop = dbsession.query(FD_T_Shop).filter(FD_T_Shop.shop_id == shop_id).one()
    shopname = shop.shop_name
    pass_message(shopname, shopaccount.contact_phone_no)
    # end send pass message

    dbsession.commit()

    geo.insert(
        shop_id,
        [int(i) for i in trans.to_list(shop.category_list) if i],
        int(shop.city_id),
        float(shop.longitude),
        float(shop.latitude),
    )

    dbsession.close()
Esempio n. 13
0
                            promotion_price=float(i.promotion_price) if i.promotion_price else None)
                       for i in goods])


def get_fans_all_msg(shop_id, user_id):
    dbsession = DBSession()
    try:
        v = dbsession.query(FD_T_Visitedshop).filter(FD_T_Visitedshop.shop_id == shop_id,
                                                     FD_T_Visitedshop.user_id == user_id).one()
        u = dbsession.query(FD_T_User).filter(FD_T_User.user_id == user_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code, des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code, des=MTERROR.NoResultFound.des, is_success=False)
    except Exception, e:
        return dict(error_code=MTERROR.UnKnowError.code, des=str(e), is_success=False)
    res = get_customer_favorite_goods_in_shop(shop_id, user_id)
    user_name = u.name
    user_visit_num = v.visit_count
    user_favorite_num = res.get('total_num')
    last_visit_time = v.dict().get('last_visit_time')
    goods = res.get('goods')
    for good in goods:
        good['pic_url_list'] = [ImageHost + i for i in trans.to_list(good['pic_url_list'])]

    return dict(user_name=user_name,
                user_visit_num=user_visit_num,
                user_favorite_num=user_favorite_num,
                last_visit_time=last_visit_time,
                goods=goods)
Esempio n. 14
0
 except MultipleResultsFound, e:
     return dict(error_code=MTERROR.MultipleResultsFound.code,
                 des=MTERROR.MultipleResultsFound.des,
                 is_success=False)
 except NoResultFound, e:
     return dict(error_code=MTERROR.NoResultFound.code,
                 des=MTERROR.NoResultFound.des,
                 is_success=False)
 except Exception, e:
     return dict(error_code=MTERROR.UnKnowError.code,
                 des=str(e),
                 is_success=False)
 goods = shop.goods
 goods_list = [
     dict(goods_id=i.goods_id,
          category_list=trans.to_list(i.category_list),
          description=i.description,
          detail=i.detail,
          bar_code=i.bar_code,
          price=str(i.price) if i.price else None,
          promotion_price=str(i.promotion_price)
          if i.promotion_price else None,
          pic_url_list=trans.to_list(i.pic_url_list),
          brand_name=i.brand_name,
          basic_info=i.basic_info,
          shop_ip=i.shop_id,
          publish_time=i.publish_time.strftime('%Y-%m-%d %H:%M:%S'),
          favorite_num=get_goods_favorite(i.goods_id)['total_num'],
          status=i.status) for j, i in enumerate(goods)
     if str(i.status) in status
 ]
Esempio n. 15
0
        return dict(error_code=MTERROR.MultipleResultsFound.code,
                    des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code,
                    des=MTERROR.NoResultFound.des,
                    is_success=False)
    except Exception, e:
        return dict(error_code=MTERROR.UnKnowError.code,
                    des=str(e),
                    is_success=False)
    goods = shop.goods
    categorys = set()
    for good in goods:
        if int(good.status) == 1:
            for i in trans.to_list(good.category_list):
                categorys.add(i)
                categorys.add(str(category_get_father_category(i)))
    return list(categorys)


def category_get_father_category(category_id):
    session = DBSession()
    try:
        category = session.query(FD_T_Goodscategory).filter(
            FD_T_Goodscategory.id == category_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code,
                    des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
Esempio n. 16
0
        u = dbsession.query(FD_T_User).filter(
            FD_T_User.user_id == user_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code,
                    des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code,
                    des=MTERROR.NoResultFound.des,
                    is_success=False)
    except Exception, e:
        return dict(error_code=MTERROR.UnKnowError.code,
                    des=str(e),
                    is_success=False)
    res = get_customer_favorite_goods_in_shop(shop_id, user_id)
    user_name = u.name
    user_visit_num = v.visit_count
    user_favorite_num = res.get('total_num')
    last_visit_time = v.dict().get('last_visit_time')
    goods = res.get('goods')
    for good in goods:
        good['pic_url_list'] = [
            ImageHost + i for i in trans.to_list(good['pic_url_list'])
        ]

    return dict(user_name=user_name,
                user_visit_num=user_visit_num,
                user_favorite_num=user_favorite_num,
                last_visit_time=last_visit_time,
                goods=goods)
Esempio n. 17
0
def get_shop_all_category(shop_id):
    session = DBSession()
    try:
        shop = session.query(FD_T_Shop).filter(FD_T_Shop.shop_id == shop_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code, des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code, des=MTERROR.NoResultFound.des, is_success=False)
    except Exception, e:
        return dict(error_code=MTERROR.UnKnowError.code, des=str(e), is_success=False)
    goods = shop.goods
    categorys = set()
    for good in goods:
        if int(good.status) == 1:
            for i in trans.to_list(good.category_list):
                categorys.add(i)
                categorys.add(str(category_get_father_category(i)))
    return list(categorys)


def category_get_father_category(category_id):
    session = DBSession()
    try:
        category = session.query(FD_T_Goodscategory).filter(FD_T_Goodscategory.id == category_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code, des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code, des=MTERROR.NoResultFound.des, is_success=False)
    except Exception, e:
Esempio n. 18
0
 def put(self, goods_id):
     pic_url_list = [
         i[len(ImageHost):] for i in trans.to_list(self.arg.pic_url_list)
     ]
     response = set_goods_img(goods_id, ','.join(pic_url_list))
     self.write(response)
Esempio n. 19
0

def get_goods_list_by_shop(shop_id, offset, limit, status):
    session = DBSession()
    try:
        shop = session.query(FD_T_Shop).filter(FD_T_Shop.shop_id == shop_id).one()
    except MultipleResultsFound, e:
        return dict(error_code=MTERROR.MultipleResultsFound.code, des=MTERROR.MultipleResultsFound.des,
                    is_success=False)
    except NoResultFound, e:
        return dict(error_code=MTERROR.NoResultFound.code, des=MTERROR.NoResultFound.des, is_success=False)
    except Exception, e:
        return dict(error_code=MTERROR.UnKnowError.code, des=str(e), is_success=False)
    goods = shop.goods
    goods_list = [dict(goods_id=i.goods_id,
                       category_list=trans.to_list(i.category_list),
                       description=i.description,
                       detail=i.detail,
                       bar_code=i.bar_code,
                       price=str(i.price) if i.price else None,
                       promotion_price=str(i.promotion_price) if i.promotion_price else None,
                       pic_url_list=trans.to_list(i.pic_url_list),
                       brand_name=i.brand_name,
                       basic_info=i.basic_info,
                       shop_ip=i.shop_id,
                       publish_time=i.publish_time.strftime('%Y-%m-%d %H:%M:%S'),
                       favorite_num=get_goods_favorite(i.goods_id)['total_num'],
                       status=i.status) for j, i in enumerate(goods) if str(i.status) in status]
    goods_list = sorted(goods_list, key=lambda x: x['publish_time'], reverse=True)
    total_num = len(goods_list)
    goods_list = goods_list[int(offset): int(offset) + int(limit)]
Esempio n. 20
0
 def put(self, goods_id):
     pic_url_list = [i[len(ImageHost):] for i in trans.to_list(self.arg.pic_url_list)]
     response = set_goods_img(goods_id, ','.join(pic_url_list))
     self.write(response)