Ejemplo n.º 1
0
    def _get(self):
        goods_id = int(self.get_argument('goods_id', 0))
        if not goods_id:
            return self.render_html('app/alert.html', msg=u"请选择商品!")     
        
        service = GoodsService(GoodsInfo)
        goods = service.get(id=goods_id)
        if not goods:
            return self.render_html('app/alert.html', msg=u"该商品不存在!") 

        alert = None  
        num = int(self.get_argument('num', 1))
        if goods.number < num:
            alert = u"!库存不足!"
        
        address_id = int(self.get_argument('address_id', self.user.deliver_address_id))
        if not address_id:
            alert = u"!请先添加您的收货地址!"
        
        address = None
        address_service = UserDeliverAddressService(UserDeliverAddress)  
        ua = address_service.get(id = address_id, status=1)
        if ua:
            address = {'name':ua.name,'phone':ua.phone,'address':u'{0}{1}'.format(ua.region_name, ua.address)}
            if not self.check_region(goods_id, ua.region_id):
                alert = u"!该地区暂不支持购买!"
        else:
            alert = u"!请先添加您的收货地址!"       
                                  
        d = {}
        d['id'] = goods.id
        d['name'] = goods.name
        d['price'] = goods.price
        d['feed_day'] = goods.feed_day
        d['number'] = goods.number
        d['status'] = goods.status
        d['brief'] = goods.brief
        d['detail'] = goods.detail   
        d['type'] = goods.type
        
        d['avatar'] = ''
        if goods.avatar_id:
            avatar_service = AvatarService(AvatarInfo)
            avatar = avatar_service.get(id=goods.avatar_id)   
            d['avatar'] = os.path.join(settings.AVATAR_URL, avatar.filename) if avatar else ''
   
        d['address'] = address   
        d['alert'] = alert 
        d['attach'] = {'num':num, 'address_id':address_id}
        
        dis = self.get_discount(goods.id)
        d['last_price'] = goods.price * dis['discount'] if 'discount' in dis else goods.price
        d['dis_num'] = dis['num'] if 'num' in dis else 1
        d['dis_amount'] = dis['amount'] if 'amount' in dis else 0
        d['dis_desc'] = dis['desc'] if 'desc' in dis else ''
        
        d['amount'] = d['last_price'] * num - int(num/d['dis_num'])*d['dis_amount']
        d['discount'] = goods.price * num  - d['amount']
                    
        return self.render_html('app/buy_goods.html',**d)  
Ejemplo n.º 2
0
class GoodsDetailHandler(TornadoHttpHandler):   
    
    def __init__(self, *args, **kwargs):
        super(GoodsDetailHandler, self).__init__(*args, **kwargs)  
        
        self.goods_service = GoodsPictureService(GoodsPicture)
        self.avatar_service = AvatarService(AvatarInfo)

    @returns(need_login=True)  
    def _get(self):   
        goods_id = self.get_argument("goods_id")  
#         code = self.get_argument("code")  
        goods = GoodsService(GoodsInfo).get(id=int(goods_id)) 

        _, icon, big, pics = self.get_goods_pics(goods.avatar_id, goods.id)        
        gtype = constants.GOODS_TYPE[goods.type]
        return self.render_html('admin/goods_detail.html', 
                    **{'code':goods.code,'name':goods.name,'price':goods.price,'feed_day':goods.feed_day,
                       'number':goods.number,'brief':goods.brief,'detail':goods.detail,'id':goods.id,
                       'status':[u'正常',u'下架'][goods.status],'icon':icon, 'pics':pics, 'type':gtype, 'big':big})                

    def get_goods_pics(self, avatar_id, goods_id):
        avatar = self.avatar_service.get(id=avatar_id)
        icon = os.path.join(settings.AVATAR_URL, avatar.filename) if avatar else ''        
        
        big = None
        pics = []
        pictures = self.goods_service.gets(goods_id=goods_id)
        for pic in pictures:
            url = os.path.join(settings.GOODS_PICTURE_URL, pic.filename)
            if pic.type == 1:
                big = (pic.id, url)
            else:    
                pics.append((pic.id, url))  
        return avatar, icon, big, pics                
Ejemplo n.º 3
0
    def _get(self):        
        goods_id = int(self.get_argument('goods_id', 0))
        if not goods_id:
            return self.render_html('app/alert.html', msg=u"请选择商品!") 
        
        service = GoodsService(GoodsInfo)
        goods = service.get(id=goods_id)
        if not goods:
            return self.render_html('app/alert.html', msg=u"该商品不存在!") 
        
        d = {}
        d['id'] = goods.id
        d['name'] = goods.name
        d['price'] = goods.price
        d['feed_day'] = goods.feed_day
        d['number'] = goods.number
        d['status'] = goods.status
        d['brief'] = goods.brief
        d['detail'] = goods.detail   
        d['type'] = goods.type
        
        d['deliver_date'] = time_util.delta_str(delta=goods.feed_day + 1)
        
        d['avatar'] = ''
        if goods.avatar_id:
            avatar_service = AvatarService(AvatarInfo)
            avatar = avatar_service.get(id=goods.avatar_id)   
            d['avatar'] = os.path.join(settings.AVATAR_URL, avatar.filename) if avatar else ''

        detail_pic = ''
        pics = []
        pictures = GoodsPictureService(GoodsPicture).gets(goods_id=goods.id)
        for pic in pictures:
            url = os.path.join(settings.GOODS_PICTURE_URL, pic.filename)
            if pic.type == 1:
                detail_pic = url
            else:    
                pics.append( url)        
        
        d['detail_pic'] = detail_pic   
        d['pics'] = pics   
        
        dis = self.get_discount(goods.id)
        d['last_price'] = goods.price * dis['discount'] if 'discount' in dis else goods.price
        d['dis_desc'] = dis['desc'] if 'desc' in dis else ''
            
        return self.render_html('app/goods_detail.html',**d)  
Ejemplo n.º 4
0
 def upload_icon(self, body, goods_id, suffix):
     icon_id = int(time.time()*1000)
     file_name = str.format('{0}_{1}.{2}', str(goods_id), str(icon_id), suffix)
     fname = os.path.join(settings.AVATAR_PATH, file_name)
     with open(fname,'w+') as _f:
         _f.write(body)
         _f.close()
      
     avatar = AvatarInfo()
     avatar.id = icon_id
     avatar.filename = file_name
     avatar.type = suffix
     avatar.path = ""  
     
     aservice = AvatarService(AvatarInfo)
     aservice.insert(avatar)
     return icon_id 
Ejemplo n.º 5
0
 def _post(self):
     gtype = int(self.get_argument('gtype', 0))
     gtype_list = [gtype] if gtype != 0 else [1, 2, 3]        
     
     service = GoodsService(GoodsInfo)
     all_goods = service.cgets(status=0) 
     
     goods_list = []
     for goods in all_goods:
         if goods.number <= 0:
             continue
         if goods.type not in gtype_list:
             continue
         
         d = {}
         d['id'] = goods.id
         d['name'] = goods.name
         d['price'] = goods.price
         d['feed_day'] = goods.feed_day
         d['number'] = goods.number
         d['status'] = goods.status
         d['brief'] = goods.brief
         d['detail'] = goods.detail  
         d['type'] = goods.type 
         
         if goods.avatar_id:
             avatar_service = AvatarService(AvatarInfo)
             avatar = avatar_service.get(id=goods.avatar_id)   
             d['avatar'] = os.path.join(settings.AVATAR_URL, avatar.filename) if avatar else ''
         
         dis = self.get_discount(goods.id)
         d['last_price'] = goods.price * dis['discount'] if 'discount' in dis else goods.price
         d['dis_desc'] = dis['desc'] if 'desc' in dis else ''
         
         d['price_string'] = str(d['price'])
         d['last_price_string'] = str(d['last_price'])
             
         goods_list.append(d)  
     
     return Result(alert.SUCCESS, data=goods_list)()        
Ejemplo n.º 6
0
    def _get(self):
        user = self.user

        info = {}
        info['id'] = user.id
        info['account'] = user.account
        info['nickname'] = user.nickname
        info['phone'] = "{0}****{1}".format(user.phone[0:3], user.phone[7:])

        info['avatar'] = ''
        if user.avatar_id:
            avatar = AvatarService(AvatarInfo).get(id=user.avatar_id)
            info['avatar'] = os.path.join(settings.AVATAR_URL,
                                          avatar.filename) if avatar else ''

        return self.render_html('app/user_info.html', **info)
Ejemplo n.º 7
0
    def _post(self):
        status = int(self.get_argument('status', -1))
        status_list = [status] if status in [1, 2] else [1, 2, 3]

        user_goods_service = UserGoodsService(UserGoods)
        orders = user_goods_service.gets(user_id=self.user.id)

        order_list = []
        for order in orders:
            if order.status not in status_list:
                continue

            d = {}
            d['order_id'] = order.id
            d['user_id'] = order.user_id
            d['goods_id'] = order.goods_id
            d['goods_name'] = order.goods_name
            d['number'] = order.number
            d['feed_day'] = order.feed_day
            d['deliver_date'] = str(order.deliver_date).split()[0]
            #             d['create_date'] = order.create_date
            d['status'] = order.status

            goods = GoodsService(GoodsInfo).get(id=order.goods_id)
            d['brief'] = goods.brief
            d['type'] = goods.type

            d['avatar'] = ''
            if goods.avatar_id:
                avatar = AvatarService(AvatarInfo).get(id=goods.avatar_id)
                d['avatar'] = os.path.join(settings.AVATAR_URL,
                                           avatar.filename) if avatar else ''

            if order.status != 1:
                di = DeliverService(DeliverInfo).get(user_goods_id=order.id)
                if di:
                    d['deliver_date'] = str(di.create_date).split()[0]

            ftext, stext, after = self.get_text(order, d['deliver_date'],
                                                goods.type)
            d['ftext'] = ftext
            d['stext'] = stext
            d['after'] = after

            order_list.append(d)

        return Result(alert.SUCCESS, data=order_list[::-1])()
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(GoodsDetailHandler, self).__init__(*args, **kwargs)  
     
     self.goods_service = GoodsPictureService(GoodsPicture)
     self.avatar_service = AvatarService(AvatarInfo)
Ejemplo n.º 9
0
    def _get(self):
        order_id = int(self.get_argument('order_id', 0))
        if not order_id:
            return self.render_html('app/alert.html', msg=u"请选择订单!")

        user_goods_service = UserGoodsService(UserGoods)
        order = user_goods_service.get(id=order_id)
        if not order:
            return self.render_html('app/alert.html', msg=u"该订单不存在!")

        info = {}
        info['order_id'] = order.id
        info['code'] = order.code
        info['user_id'] = order.user_id
        info['goods_id'] = order.goods_id
        info['goods_name'] = order.goods_name
        info['number'] = order.number
        info['feed_day'] = order.feed_day
        info['deliver_date'] = str(order.deliver_date).split()[0]
        info['create_date'] = order.create_date
        info['status'] = order.status

        udas = UserDeliverAddressService(UserDeliverAddress)
        address = udas.get(id=order.deliver_address_id, status=1) or udas.get(
            id=order.deliver_address_id, status=0)

        info['name'] = address.name
        info['phone'] = address.phone
        info['address'] = u'{0}{1}'.format(address.region_name,
                                           address.address)
        info['zip_code'] = address.zip_code

        goods = GoodsService(GoodsInfo).get(id=order.goods_id)
        info['type'] = goods.type

        info['avatar'] = ''
        if goods.avatar_id:
            avatar = AvatarService(AvatarInfo).get(id=goods.avatar_id)
            info['avatar'] = os.path.join(settings.AVATAR_URL,
                                          avatar.filename) if avatar else ''

        info['goods_price'] = order.goods_price
        info['amount'] = 0
        info['pay_date'] = ''
        info['discount'] = 0
        pay = UserPayService(UserPay).get(user_goods_id=order_id)
        if pay:
            info['amount'] = pay.amount
            info['pay_date'] = pay.create_date
            info['discount'] = order.goods_price * order.number - pay.amount

        info['express_name'] = ''
        info['express_no'] = ''
        if order.status != 1:
            di = DeliverService(DeliverInfo).get(user_goods_id=order_id)
            if di:
                info['deliver_date'] = str(di.create_date).split()[0]
                info['express_name'] = di.express_name
                info['express_no'] = di.express_no

        ftext, stext, after = self.get_text(order, info['deliver_date'],
                                            goods.type)
        info['ftext'] = ftext
        info['stext'] = stext
        info['after'] = after

        return self.render_html('app/order_detail.html', **info)