Example #1
0
 def get_categoreis_for_api(cls):
     data_dict = dict()
     categorie_type = cls.objects.filter(
         ~Q(categorie_type=None),
         status='normal').values('categorie_type').annotate(
             c=Count('categorie_type'))
     for i in categorie_type:
         temp = cls.objects.filter(
             categorie_type=i['categorie_type']).values(
                 'categorie_id', 'categorie_name', 'photo_id')
         temp = list(temp)
         for j in temp:
             j['image_path'] = common.build_photo_url(
                 j['photo_id'], pic_version='thumbicon', cdn=True)
         data_dict[i['categorie_type']] = temp
     obj = cls.objects.filter(is_hot=True, status='normal').values(
         'categorie_id', 'categorie_name', 'photo_id')
     if obj:
         obj = list(obj)
         for j in obj:
             j['image_path'] = common.build_photo_url(
                 j['photo_id'], pic_version='thumbicon', cdn=True)
         data_dict['热门分类'] = obj
     data_dict['热门品牌'] = Brands.get_all_brand_dict_for_api()
     return data_dict
Example #2
0
 def get_campaigns_by_l_and_d(cls, location, datetime):
     data_list = cls.objects.filter(location=location,
                                    start_time__lte=datetime,
                                    end_time__gte=datetime).values()
     for i in data_list:
         i['campaigns_photo'] = common.build_photo_url(
             i['campaigns_photo_id'], pic_version='title', cdn=True)
         i['title_photo'] = common.build_photo_url(i['title_photo_id'],
                                                   pic_version='title',
                                                   cdn=True)
     return list(data_list)
Example #3
0
def item_image_manage(request):
    if request.method == "GET":
        item_id = request.GET.get('item_id')
        item_image_list = item_models.ItemImages.get_item_images_by_itemid(
            item_id)
        item_info_image = item_models.ItemImages.get_item_info_images_by_itemid(
            item_id)
        item_obj = item_models.Items.get_item_by_id(item_id)
        item_image_dict = {}
        if item_image_list:
            for i in item_image_list:
                if "title" not in item_image_dict:
                    item_image_dict['title'] = [{
                        'image_path':
                        common.build_photo_url(i['photo_id'],
                                               pic_version='title'),
                        'image_id':
                        i['image_id']
                    }]
                else:
                    item_image_dict["title"].append({
                        'image_path':
                        common.build_photo_url(i['photo_id'],
                                               pic_version='title'),
                        'image_id':
                        i['image_id']
                    })
        if item_info_image:
            if "item" not in item_image_dict:
                item_image_dict['item'] = [{
                    'image_path':
                    common.build_photo_url(item_info_image['photo_id'],
                                           pic_version='item'),
                    'image_id':
                    item_info_image['image_id']
                }]
            else:
                item_image_dict["item"].append({
                    'image_path':
                    common.build_photo_url(i['photo_id'], pic_version='item'),
                    'image_id':
                    i['image_id']
                })
        return my_render(
            request,
            'item/a_item_image_manage.html',
            item_image_dict=item_image_dict,
            item_obj=item_obj,
        )
Example #4
0
 def get_comment_image_obj_by_id(cls, comment_id, for_api=False):
     image_list = cls.objects.filter(comment_id=comment_id,
                                     status='normal').values()
     if image_list:
         image_list = list(image_list)
         if for_api:
             for i in image_list:
                 i['image_path'] = common.build_photo_url(
                     i['photo_id'], pic_version='title', cdn=True)
         else:
             for i in image_list:
                 i['image_path'] = common.build_photo_url(
                     i['photo_id'], pic_version='title')
         return image_list
     else:
         return None
Example #5
0
 def get_all_brand_dict_for_api(cls):
     all_data = cls.objects.filter(status='normal', is_hot=True).values(
         'brand_id', 'cn_name', 'photo_id')
     all_data = list(all_data)
     for i in all_data:
         i['image'] = common.build_photo_url(i['photo_id'],
                                             pic_version="thumbicon",
                                             cdn=True)
     return all_data
Example #6
0
 def get_user_order_by_member_id(cls, member_id, current_page,
                                 order_status):
     order_num_list = cls.objects.filter(member_id=member_id, status='normal'). \
         values('order_num').annotate(c = Count('order_num')).order_by('-pk')
     p = Paginator(order_num_list, 10)
     if int(current_page) > p.num_pages:
         return list()
     order_num_list = p.page(current_page).object_list
     data_list = list()
     for i in order_num_list:
         order_num = i['order_num']
         if order_status:
             obj = cls.objects.filter(order_num=order_num,
                                      order_status=order_status,
                                      status="normal").values()
         else:
             obj = cls.objects.filter(order_num=order_num,
                                      status="normal").values()
         if obj:
             recv_addr = get_model_dict_by_pk(RecvAddr,
                                              obj.first()['recv_addr_id'])
             data_dict = {
                 'order_num':
                 i['order_num'],
                 'recv_addr':
                 recv_addr,
                 'member_message':
                 obj.first()['member_message'],
                 'all_price':
                 0,
                 'create_time':
                 common.parse_timestamps(obj.first()['create_time']),
                 'order_status':
                 dict(cls.status_choices)[obj.first()['order_status']],
                 'goods':
                 list()
             }
             for j in obj:
                 item = item_models.Items.get_item_by_id(j['item_id'])
                 image_path = common.build_photo_url(item.photo_id,
                                                     cdn=True)
                 data_dict['goods'].append({
                     'image_path': image_path,
                     'item_name': j['item_name'],
                     'item_count': j['item_count'],
                     'item_id': j['item_id'],
                     'price': j['price'],
                 })
                 data_dict['all_price'] += float(j['price']) * int(
                     j['item_count'])
             data_list.append(data_dict)
         else:
             return list()
     return data_list
Example #7
0
 def get_user_order_by_order_num(cls, order_num, order_status=None):
     if order_status is not None:
         obj = cls.objects.filter(order_num=order_num,
                                  order_status=order_status,
                                  status="normal").values()
     else:
         obj = cls.objects.filter(order_num=order_num,
                                  status="normal").values()
     recv_addr = get_model_dict_by_pk(RecvAddr, obj[0]['recv_addr_id'])
     data_dict = {
         'order_num': order_num,
         'member_message': obj.first()['member_message'],
         'create_time': common.parse_timestamps(obj.first()['create_time']),
         'order_status':
         dict(cls.status_choices)[obj.first()['order_status']],
         'recv_addr': recv_addr,
         'goods': list()
     }
     data_dict['all_price'] = 0
     for i in obj:
         item = item_models.Items.get_item_by_id(i['item_id'])
         if item:
             image_path = common.build_photo_url(item.photo_id, cdn=True)
             data_dict['goods'].append({
                 'image_path':
                 image_path,
                 'item_name':
                 i['item_name'],
                 'item_count':
                 i['item_count'],
                 'item_id':
                 i['item_id'],
                 'price':
                 i['price'],
                 'order_status':
                 dict(cls.status_choices)[i['order_status']],
             })
             data_dict['all_price'] += float(i['price']) * int(
                 i['item_count'])
         else:
             data_dict['goods'].append({
                 'item_name':
                 i['item_name'] + '(商品已经下架)',
                 'item_count':
                 i['item_count'],
                 'price':
                 i['price'],
                 'order_status':
                 dict(cls.status_choices)[i['order_status']],
             })
             data_dict['all_price'] += float(i['price']) * int(
                 i['item_count'])
     return data_dict
Example #8
0
 def get_item_dict_by_barcode_api(cls, item_barcode):
     data_dict = dict()
     model = cls.objects.filter(item_barcode=item_barcode,
                                status='normal').last()
     if not model:
         return None
     model = model_to_dict(model)
     data_dict['item_name'] = model.get('item_name')
     data_dict['specifications_type'] = model.get('capacity') if model.get(
         'capacity') else '无规格信息'
     data_dict['thumbicon'] = common.build_photo_url(model.get('photo_id'),
                                                     cdn=True)
     data_dict['item_barcode'] = model.get('item_barcode')
     return data_dict
Example #9
0
 def get_items_list_for_api(cls, current_page):
     '请求商品列表接口'
     item_obj = cls.objects.filter(status='normal').order_by('-item_id')
     p = Paginator(item_obj, 15)
     current_page = int(current_page)
     if current_page > p.num_pages:
         return list()
     items_list = p.page(current_page).object_list.values(
         'item_id', "item_name", "price", "stock_count", "photo_id")
     items_list = list(items_list)
     for i in items_list:
         i['item_thumbicon'] = common.build_photo_url(i['photo_id'],
                                                      cdn=True)
     return items_list
Example #10
0
 def get_user_order_list(cls, current_page, search_value=None):
     data_list = get_data_list(cls, current_page, search_value=search_value)
     data_list = data_list.values('order_num').annotate(
         c=Count('order_num'))
     my_list = list()
     for i in data_list:
         order_num = i['order_num']
         obj = cls.objects.filter(order_num=order_num,
                                  status="normal").values()
         if obj:
             recv_addr = get_model_dict_by_pk(RecvAddr,
                                              obj.first()['recv_addr_id'])
             data_dict = {
                 'member_id':
                 obj.first()['member_id'],
                 'order_num':
                 i['order_num'],
                 'recv_addr':
                 recv_addr,
                 'member_message':
                 obj.first()['member_message'],
                 'all_price':
                 0,
                 'create_time':
                 common.parse_timestamps(obj.first()['create_time']),
                 'order_status':
                 dict(cls.status_choices)[obj.first()['order_status']],
                 'goods':
                 list()
             }
             for j in obj:
                 item = item_models.Items.get_item_by_id(j['item_id'])
                 photo_id = item.photo_id if item else None
                 image_path = common.build_photo_url(photo_id, cdn=True)
                 data_dict['goods'].append({
                     'image_path': image_path,
                     'item_name': j['item_name'],
                     'item_count': j['item_count'],
                     'price': j['price'],
                 })
                 data_dict['all_price'] += float(j['price']) * int(
                     j['item_count'])
             my_list.append(data_dict)
         else:
             return list()
     return my_list
Example #11
0
 def get_items_by_categorie_id(cls, data_id, filter_type, order_by,
                               current_page):
     if filter_type == 'categorie_id':
         item_obj = cls.objects. \
             filter(categorie_id = data_id, status = 'normal').order_by(order_by)
     else:
         item_obj = cls.objects. \
             filter(brand_id = data_id, status = 'normal').order_by(order_by)
     p = Paginator(item_obj, 15)
     if int(current_page) > p.num_pages:
         return list()
     items_list = list(
         p.page(current_page).object_list.values('item_id', "item_name",
                                                 "price", "stock_count",
                                                 "photo_id"))
     for i in items_list:
         i['image'] = common.build_photo_url(i['photo_id'],
                                             pic_version='thumbicon',
                                             cdn=True)
     return items_list
Example #12
0
 def get_items_by_campaign_id(cls, campaign_id, current_page):
     '''
     获取活动商品列表
     '''
     item_id_list = ad_models.CampaignItems.get_all_item_id_list_by_campaign_id(
         campaign_id)
     item_obj = cls.objects.filter(status='normal',
                                   item_id__in=item_id_list).values(
                                       'item_id', "item_name", "price",
                                       "stock_count", "photo_id",
                                       "brand_id").order_by('-item_id')
     if not item_obj:
         return list()
     p = Paginator(item_obj, 15)
     current_page = int(current_page)
     if current_page > p.num_pages:
         return list()
     items_list = p.page(current_page).object_list
     items_list = list(items_list)
     for i in items_list:
         i['item_thumbicon'] = common.build_photo_url(i['photo_id'],
                                                      cdn=True)
     data_dict = dict()
     for i in items_list:
         brand_obj = Brands.get_brand_by_id(i['brand_id'])
         if brand_obj:
             if brand_obj.cn_name not in data_dict:
                 data_dict[brand_obj.cn_name] = []
                 data_dict[brand_obj.cn_name].append(i)
             else:
                 data_dict[brand_obj.cn_name].append(i)
         else:
             if '' not in data_dict:
                 data_dict[''] = []
                 data_dict[''].append(i)
             else:
                 data_dict[''].append(i)
     new_data_list = list()
     for i in data_dict:
         new_data_list.append({'title': i, 'list': data_dict[i]})
     return new_data_list
Example #13
0
def get_item_info_list(request):
    return_value = {
        'status': 'error',
        'message': ''
    }
    if  request.method == 'POST':
        data = json.loads(request.body)
        data_list = list()
        item_id_list = data.get('item_id_list')
        for i in item_id_list:
            item_obj = item_models.get_model_obj_by_pk(
                item_models.Items,
                i
            )
            if item_obj:
                item_dict = model_to_dict(item_obj)
                item_dict['item_name'] = item_dict['item_name'] \
                    if item_dict['status'] == 'normal' else item_dict['item_name'] + '(该商品已经下架)'
                item_dict['image_path'] = common.build_photo_url(item_dict['photo_id'], cdn=True)
                data_list.append(item_dict)
        
        return_value['status'] = 'success'
        return_value['data'] = data_list
        return JsonResponse(return_value)
Example #14
0
def item_code(request, qr_code):
    return_value = {
        'status': 'error',
        'message': '',
    }
    # qr_code = request.GET.get('qr_code')
    if not (len(qr_code) == 9 and qr_code.startswith('U')):
        return_value['message'] = '商品码格式错误'
        return JsonResponse(return_value)

    qr_code_obj = order_models.ItemQRCode.get_qr_code_obj_by_qr_code(qr_code)
    if not qr_code_obj:
        return_value['message'] = '没有记录'
        return JsonResponse(return_value)
    qr_code_obj.search_count += 1
    qr_code_obj.save()
    batch_qr_code_id = qr_code_obj.batch_qr_code_id
    batch_qr_code_obj = order_models.get_model_obj_by_pk(
        order_models.BatchQrCode, batch_qr_code_id)
    if not qr_code_obj.stock_batch_count_id and batch_qr_code_obj.recv_code:
        recv_addr = order_models.Recv.get_recv_addr_by_recv_code(
            batch_qr_code_obj.recv_code)
        date = batch_qr_code_obj.create_time
        date = lib_data.parse_timestamps(date)
        member_obj = member_models.Member.get_member_by_id(
            batch_qr_code_obj.create_member)
        if member_obj:
            is_admin = member_obj.is_admin
            action = "出库扫码" if is_admin else '店铺扫码'
        else:
            action = '店铺扫码'
        return_value['data'] = [
            {
                "action": action,
                "to": recv_addr,
                "date": date
            },
        ]
        return_value["status"] = "success"
        return JsonResponse(return_value)
    elif not qr_code_obj.stock_batch_count_id and not batch_qr_code_obj.recv_code:
        return_value['messge'] = "该二维码未绑定"
        return JsonResponse(return_value)
    stock_batch_count_id = qr_code_obj.stock_batch_count_id
    obj = order_models.get_model_obj_by_pk(
        order_models.StockBatchCount,
        stock_batch_count_id,
    )
    item_obj = item_models.Items.get_item_obj_by_barcode(obj.item_barcode)
    item_name = '未查询到相关商品信息'
    brand_name = '未查询到相关品牌信息'
    item_photo = common.build_photo_url(None, pic_version='title', cdn=True)
    if item_obj:
        item_name = item_obj.item_name
        brand_id = item_obj.brand_id
        item_photo = common.build_photo_url(item_obj.photo_id,
                                            pic_version='title',
                                            cdn=True)
        if brand_id:
            brand_obj = item_models.Brands.get_brand_by_id(brand_id)
            brand_name = brand_obj.cn_name if brand_obj else brand_name
    stock_batch_dict = order_models.StockBatch.get_stock_dict_by_stock_batch_id(
        obj.stock_batch_id)
    recv_code = stock_batch_dict.get('recv_code')
    recv_addr = order_models.Recv.get_recv_addr_by_recv_code(recv_code)
    date = stock_batch_dict.get('create_time')
    date = lib_data.parse_timestamps(date)
    member_obj = member_models.Member.get_member_by_id(
        stock_batch_dict.get('create_user'))
    if member_obj:
        is_admin = member_obj.is_admin
        action = "出库扫码" if is_admin else '店铺扫码'
    else:
        action = '店铺扫码'
    return_value['data'] = [
        {
            "action": action,
            "to": recv_addr,
            "date": date,
            'item_name': item_name,
            'brand_name': brand_name,
            'image': item_photo,
        },
    ]
    return_value["status"] = "success"
    return JsonResponse(return_value)
Example #15
0
def get_item_info(request, item_id):
    return_value = {
        'status': 'error',
        'message': ''
    }
    openid = request.COOKIES.get('openid')
    member = member_models.Member.get_member_by_wx_openid(openid) if openid is not None else None
    if  request.method == 'GET':
        item_obj = item_models.get_model_obj_by_pk(
            item_models.Items,
            item_id
        )
        if item_obj:
            item_dict = model_to_dict(item_obj)
            item_image = list(
                item_models. \
                    ItemImages.get_item_images_by_itemid(item_dict['item_id'])
            )
            item_info_image = item_models.ItemImages. \
                get_item_info_images_by_itemid(item_dict['item_id'])
            if item_image:
                for i in item_image:
                    i['image_path'] = common.build_photo_url(
                        i['photo_id'],
                        pic_version="title",
                        cdn=True
                    )
                item_dict['item_image'] = item_image
            else:
                item_dict['item_image'] = [common.build_photo_url(
                        None,
                        pic_version="title",
                        cdn=True
                    ),]
            
            if item_info_image:
                item_info_image['image_path'] = common.build_photo_url(
                    item_info_image['photo_id'],
                    pic_version="item",
                    cdn=True
                )
                item_dict['item_info_image'] = item_info_image
            else:
                item_dict['item_info_image'] = common.build_photo_url(
                    None,
                    pic_version="item",
                    cdn=True
                )
            item_dict['item_thumbicon'] = common.build_photo_url(
                item_dict.get('photo_id'),
                pic_version="thumbicon",
                cdn=True
            )
            categories = item_models.Categories.get_categorie_by_id(item_dict['categorie_id'])
            item_dict['categorie_name'] = categories.categorie_name if categories else ''
            brand = item_models.Brands.get_brand_by_id(item_dict['brand_id'])
            item_dict['brand_name'] = brand.cn_name if brand else ''
            item_dict['specifications_type'] = dict(
                item_models.Items.specifications_type_choices
            )[item_dict['specifications_type_id']] if item_dict['specifications_type_id'] else ''
            if member:
                b = member_models.UserCollectionItem. \
                    user_has_collection_item(member.member_id, item_dict['item_id'])
                item_dict['has_collection'] = b
            else:
                item_dict['has_collection'] = False
            item_comment_list = item_models.ItemComments. \
                get_item_comment_by_item_id(item_dict['item_id'], 1, 'all')
            item_dict['item_comment_list'] = item_comment_list[0:3]
            return_value['status'] = 'success'
            return_value['data'] = item_dict
            return JsonResponse(return_value)
        else:
            return_value['message'] = "无次商品信息"
            return JsonResponse(return_value)
Example #16
0
def get_thumbicon_by_id(photo_id):
    return common.build_photo_url(photo_id)