예제 #1
0
    def list(self):
        """拼团/商品列表"""
        args = request.args.to_dict()
        now = datetime.datetime.now()
        option = args.get('option')
        gpstatus = args.get('gpstatus')
        starttime, endtime = args.get('starttime', '2019-01-01') or '2019-01-01', args.get('endtime', '2100-01-01') or '2100-01-01'
        if is_admin() or is_supplizer():
            return self._back_group_product_list(gpstatus, starttime, endtime)

        if str(option) == 'my':
            my_group = []
            if common_user():
                my_group = self._filter_joined_group().all_with_page()
            list(map(lambda x: self._fill_single_group(x), my_group))
            return Success(data=my_group)

        elif str(option) == 'all':
            all_group = self._filter_not_joined_group().all_with_page()
            list(map(lambda x: self._fill_single_group(x), all_group))
            return Success(data=all_group)

        my_group = []
        if common_user():
            my_group = self._filter_joined_group().distinct().limit(2).all()

        list(map(lambda x: self._fill_single_group(x), my_group))

        all_group = self._filter_not_joined_group().distinct().limit(2).all()

        list(map(lambda x: self._fill_single_group(x), all_group))

        group_goods = GroupGoodsProduct.query.filter(GroupGoodsProduct.isdelete == False,
                                                     GroupGoodsProduct.GPstatus == ApplyStatus.agree.value,
                                                     GroupGoodsProduct.GPday == now.date()
                                                     ).order_by(GroupGoodsProduct.createtime.desc()).all_with_page()
        for gp in group_goods:
            gp.hide('SUid', 'PRid', 'GPfreight')
            product = Products.query.filter(Products.PRid == gp.PRid, Products.isdelete == False).first()
            if not product:
                continue
            gps_list = GroupGoodsSku.query.filter_by(GPid=gp.GPid, isdelete=False).all()
            gpsku_price = [gps.SKUPrice for gps in gps_list]
            gp.fill('gpstatus_en', ApplyStatus(gp.GPstatus).name)
            gp.fill('gpstatus_zh', ApplyStatus(gp.GPstatus).zh_value)
            gp.fill('prmainpic', product['PRmainpic'])
            gp.fill('prtitle', product.PRtitle)
            gp.fill('gpdeposit', max(gpsku_price))

        res = {'my_group': my_group,
               'all_group': all_group,
               'group_goods': group_goods
               }

        return Success(data=res)
예제 #2
0
    def list(self):
        """商品列表"""
        args = parameter_required()
        prtitle = args.get('prtitle')
        ipstatus = args.get('status')
        try:
            ipstatus = getattr(ApplyStatus, ipstatus).value
        except Exception as e:
            current_app.logger.error(
                'integral list status error : {}'.format(e))
            ipstatus = None
        integral_balance = 0
        if common_user():
            ipstatus = ApplyStatus.agree.value
            user = User.query.filter_by_(USid=request.user.id).first()
            integral_balance = getattr(user, 'USintegral', 0)
        elif is_tourist():
            ipstatus = ApplyStatus.agree.value

        filter_args = [
            IntegralProduct.isdelete == False,
            IntegralProduct.IPstatus == ipstatus, Products.isdelete == False,
            Products.PRstatus == ProductStatus.usual.value
        ]
        if is_supplizer():
            filter_args.append(Products.CreaterId == request.user.id),
        if prtitle:
            filter_args.append(Products.PRtitle.ilike('%{}%'.format(prtitle)))
        ips = IntegralProduct.query.outerjoin(
            Products, Products.PRid == IntegralProduct.PRid).filter_(
                *filter_args).order_by(
                    IntegralProduct.createtime.desc()).all_with_page()
        for ip in ips:
            pr = Products.query.filter(Products.PRid == ip.PRid).first()
            pb = ProductBrand.query.filter(
                ProductBrand.PBid == pr.PBid).first()
            ip.fill('prtitle', pr.PRtitle)
            ip.fill('prmainpic', pr['PRmainpic'])
            ip.fill('ipstatus_zh', ApplyStatus(ip.IPstatus).zh_value)
            ip.fill('ipstatus_en', ApplyStatus(ip.IPstatus).name)
            ip.fill('pbname', pb.PBname)

        res = dict(product=ips)
        if common_user() or is_tourist():
            cfg = ConfigSettings()
            rule = cfg.get_item('integralrule', 'rule')
            integral = dict(balance=integral_balance, rule=rule)
            res['integral'] = integral
        return Success(data=res)
예제 #3
0
 def award_detail(self):
     """查看申请详情"""
     data = parameter_required(('fmfaid', ))
     fmfaid = data.get('fmfaid')
     apply = FreshManFirstApply.query.filter(
         FreshManFirstApply.isdelete == False,
         FreshManFirstApply.FMFAid == fmfaid).first_('该申请不存在')
     apply.fill('FMFAstatus_zh', ApplyStatus(apply.FMFAstatus).zh_value)
     if apply.FMFAfrom == ApplyFrom.platform.value:
         admin = Admin.query.filter(Admin.ADid == apply.SUid).first()
         admin.hide('ADfirstpwd', 'ADpassword')
         apply.fill('from_admin', admin)
     else:
         supplizer = Supplizer.query.filter(
             Supplizer.SUid == apply.SUid).first()
         supplizer.hide('SUpassword')
         apply.fill('from_supplizer', supplizer)
     apply_product = FreshManFirstProduct.query.filter(
         FreshManFirstProduct.FMFAid == apply.FMFAid).first()
     apply_product.PRattribute = json.loads(apply_product.PRattribute)
     apply.fill('product', apply_product)
     apply_skus = FreshManFirstSku.query.filter(
         FreshManFirstSku.FMFPid == apply_product.FMFPid).all()
     for apply_sku in apply_skus:
         sku = ProductSku.query.filter(
             ProductSku.SKUid == apply_sku.SKUid).first()
         sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
         apply_product.fill('apply_sku', apply_sku)
         apply_sku.fill('sku', sku)
     return Success('获取成功', apply)
예제 #4
0
    def _back_box_product_list(mbastatus, starttime, endtime):
        filter_args = []
        try:
            mbastatus = getattr(ApplyStatus, mbastatus).value
        except Exception:
            mbastatus = None
        if isinstance(mbastatus, int):
            filter_args.append(MagicBoxApply.MBAstatus == mbastatus)
        if is_supplizer():
            filter_args.append(MagicBoxApply.SUid == request.user.id)

        mbas = MagicBoxApply.query.filter(
            MagicBoxApply.isdelete == False, MagicBoxApply.MBAday >= starttime,
            MagicBoxApply.MBAday <= endtime, *filter_args).order_by(
                MagicBoxApply.createtime.desc()).all_with_page()
        for mba in mbas:
            mba.hide('SUid', 'MBAfreight')
            product = Products.query.filter(
                Products.PRid == mba.PRid, Products.isdelete == False).first()
            pbname = db.session.query(ProductBrand.PBname).filter_by_(
                isdelete=False, PBid=product.PBid).scalar()
            mba.fill('pbname', pbname)
            mba.Gearsone = json.loads(mba.Gearsone)
            mba.Gearstwo = json.loads(mba.Gearstwo)
            mba.Gearsthree = json.loads(mba.Gearsthree)
            mba.fill('mbastatus_en', ApplyStatus(mba.MBAstatus).name)
            mba.fill('mbastatus_zh', ApplyStatus(mba.MBAstatus).zh_value)
            if not product:
                continue
            mbs_list = MagicBoxApplySku.query.filter(
                MagicBoxApplySku.isdelete == False,
                MagicBoxApplySku.MBAid == mba.MBAid).all()
            for mbs in mbs_list:
                product_sku = ProductSku.query.filter_by(
                    SKUid=mbs.SKUid, isdelete=False).first()
                if not product_sku:
                    continue
                mbs.fill(
                    'skuattritedetail',
                    json.loads(getattr(product_sku, 'SKUattriteDetail', '')))
            mba.fill('skus', mbs_list)
            mba.fill('prtitle', product.PRtitle)
            mba.fill('prmainpic', product['PRmainpic'])
        return Success(data=mbas)
예제 #5
0
    def get_list(self):

        aca_list = ActivationCodeApply.query.filter(
            ActivationCodeApply.USid == request.user.id, ActivationCodeApply.isdelete == False).all()

        for aca in aca_list:
            aca.hide('USid')
            aca.fill('acaapplystatus', ApplyStatus(aca.ACAapplyStatus).name)
            aca.fill('acaapplystatus_zh', ApplyStatus(aca.ACAapplyStatus).zh_value)
            if aca.ACAapplyStatus == ApplyStatus.reject.value:
                reason = ApprovalNotes.query.filter(
                    Approval.AVcontent == aca.ACAid,
                    Approval.PTid == 'toactivationcode',
                    ApprovalNotes.AVid == Approval.AVid
                ).order_by(ApprovalNotes.createtime.desc()).first()
                if not reason:
                    continue
                aca.fill('acareason', reason.ANabo)

        return Success('获取申请列表成功', data=aca_list)
예제 #6
0
 def list_apply(self):
     """查看申请列表"""
     if not is_supplizer() and not is_admin():
         raise AuthorityError()
     form = ListFreshmanFirstOrderApply().valid_data()
     starttime, endtime = form.starttime.data, form.endtime.data
     suid = form.suid.data
     if is_supplizer():
         suid = request.user.id
     adid = form.adid.data
     status = form.status.data
     query = FreshManFirstApply.query.filter(
         FreshManFirstApply.isdelete == False)
     if suid:
         query = query.filter(
             FreshManFirstApply.SUid == suid,
             FreshManFirstApply.FMFAfrom == ApplyFrom.supplizer.value)
     if adid:
         query = query.filter(
             FreshManFirstApply.SUid == adid,
             FreshManFirstApply.FMFAfrom == ApplyFrom.platform.value)
     if status is not None:
         query = query.filter(FreshManFirstApply.FMFAstatus == status)
     applys = query.filter(
         FreshManFirstApply.FMFAstartTime >= starttime,
         FreshManFirstApply.FMFAendTime <= endtime).order_by(
             FreshManFirstApply.createtime.desc()).all_with_page()
     for apply in applys:
         # 状态中文
         apply.fill('FMFAstatus_zh', ApplyStatus(apply.FMFAstatus).zh_value)
         # 商品
         fresh_product = FreshManFirstProduct.query.filter(
             FreshManFirstProduct.isdelete == False,
             FreshManFirstProduct.FMFAid == apply.FMFAid,
         ).first()
         apply.fill('fresh_product', fresh_product)
         # 活动sku
         freshsku = FreshManFirstSku.query.filter(
             FreshManFirstSku.isdelete == False,
             FreshManFirstSku.FMFPid == fresh_product.FMFPid).all()
         fresh_product.fill('sku', freshsku)
         # 申请人
         if apply.FMFAfrom == ApplyFrom.supplizer.value:
             supplizer = Supplizer.query.filter(
                 Supplizer.SUid == apply.SUid).first()
             apply.fill('from_supplizer', supplizer)
         elif apply.FMFAfrom == ApplyFrom.platform.value:
             admin = Admin.query.filter(Admin.ADid == apply.SUid).first()
             admin.hide('ADfirstpwd', 'ADpassword')
             apply.fill('from_admin', admin)
     return Success(data=applys)
예제 #7
0
    def _back_group_product_list(self, gpstatus, starttime, endtime):
        filter_args = []
        try:
            gpstatus = getattr(ApplyStatus, gpstatus).value
        except Exception:
            gpstatus = None
        if isinstance(gpstatus, int):
            filter_args.append(GroupGoodsProduct.GPstatus == gpstatus)

        if is_supplizer():
            filter_args.append(GroupGoodsProduct.SUid == request.user.id)

        group_goods = GroupGoodsProduct.query.filter(GroupGoodsProduct.isdelete == False,
                                                     GroupGoodsProduct.GPday >= starttime,
                                                     GroupGoodsProduct.GPday <= endtime,
                                                     *filter_args
                                                     ).order_by(GroupGoodsProduct.createtime.desc()).all_with_page()
        for gp in group_goods:
            gp.hide('SUid', 'GPfreight')
            product = Products.query.filter(Products.PRid == gp.PRid, Products.isdelete == False).first()
            pbname = db.session.query(ProductBrand.PBname).filter_by_(isdelete=False, PBid=product.PBid).scalar()
            gp.fill('pbname', pbname)
            if not product:
                continue
            gps_list = GroupGoodsSku.query.filter_by(GPid=gp.GPid, isdelete=False).all()
            for gps in gps_list:
                product_sku = ProductSku.query.filter_by(SKUid=gps.SKUid, isdelete=False).first()
                if not product_sku:
                    continue
                gps.fill('skuattritedetail', json.loads(getattr(product_sku, 'SKUattriteDetail', '')))
            gp.fill('skus', gps_list)
            gp.fill('gpstatus_en', ApplyStatus(gp.GPstatus).name)
            gp.fill('gpstatus_zh', ApplyStatus(gp.GPstatus).zh_value)
            gp.fill('prmainpic', product['PRmainpic'])
            gp.fill('prtitle', product.PRtitle)
        return Success(data=group_goods)
예제 #8
0
    def _fill_tlp(self, tlp, tla):
        if not tlp:
            return
        product = Products.query.filter(Products.PRid == tlp.PRid,
                                        Products.isdelete == False).first()
        if not product:
            current_app.logger.info('·商品已删除 prid = {}'.format(tlp.PRid))
        if isinstance(product.PRattribute, str):
            product.PRattribute = json.loads(product.PRattribute)
        if isinstance(getattr(product, 'PRremarks', None) or '{}', str):
            product.PRremarks = json.loads(
                getattr(product, 'PRremarks', None) or '{}')

        pb = ProductBrand.query.filter_by(PBid=product.PBid,
                                          isdelete=False).first()

        images = ProductImage.query.filter(
            ProductImage.PRid == product.PRid,
            ProductImage.isdelete == False).order_by(
                ProductImage.PIsort).all()
        product.fill('images', images)
        product.fill('brand', pb)
        tls_list = TimeLimitedSku.query.filter_by(TLPid=tlp.TLPid,
                                                  isdelete=False).all()
        skus = list()
        sku_value_item = list()
        # 预计佣金
        comm = Commision.query.filter(Commision.isdelete == False).first()
        try:
            commision = json.loads(comm.Levelcommision)
            level1commision = commision[0]  # 一级分销商
            planetcommision = commision[-1]  # 平台收费比例
        except ValueError:
            current_app.logger.info('ValueError error')
        except IndexError:
            current_app.logger.info('IndexError error')

        preview_get = []
        for tls in tls_list:
            sku = ProductSku.query.filter_by(SKUid=tls.SKUid,
                                             isdelete=False).first()
            if not sku:
                current_app.logger.info('该sku已删除 skuid = {0}'.format(
                    tls.SKUid))
                continue
            # sku.hide('SKUprice')
            # sku.hide('SKUstock')
            sku.fill('tlsprice', tls.SKUprice)
            sku.fill('tlsstock', tls.TLSstock)
            preview_get.append(
                self._commision_preview(price=tls.SKUprice,
                                        planet_rate=planetcommision,
                                        planet_and_user_rate=sku.SkudevideRate
                                        or planetcommision,
                                        current_user_rate=level1commision))
            if isinstance(sku.SKUattriteDetail, str):
                sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
            sku_value_item.append(sku.SKUattriteDetail)
            skus.append(sku)
        product.fill('profict', min(preview_get))
        if not skus:
            current_app.logger.info('该申请的商品没有sku prid = {0}'.format(
                product.PRid))
            return
        product.fill('skus', skus)
        sku_value_item_reverse = []
        for index, name in enumerate(product.PRattribute):
            value = list(
                set([attribute[index] for attribute in sku_value_item]))
            value = sorted(value)
            temp = {'name': name, 'value': value}
            sku_value_item_reverse.append(temp)
        product.fill('SkuValue', sku_value_item_reverse)
        product.fill('tlastarttime', tla.TLAstartTime)
        product.fill('tlaendtime', tla.TLAendTime)
        product.fill('tlpprice', tlp.PRprice)
        product.fill('tlpid', tlp.TLPid)
        product.fill('tlpcreatetime', tlp.createtime)
        product.fill('tlastatus_zh', ApplyStatus(tlp.TLAstatus).zh_value)
        product.fill('tlastatus_en', ApplyStatus(tlp.TLAstatus).name)
        product.fill('tlastatus', tlp.TLAstatus)
        month_sale = db.session.query(
            ProductMonthSaleValue.PMSVfakenum).filter_by_(
                PRid=tlp.PRid).order_by(
                    ProductMonthSaleValue.createtime.desc(),
                    origin=True).first()
        current_app.logger.info('get_mouth_sale_value: {}'.format(month_sale))
        month_sale = month_sale[0] if month_sale else random.randint(15, 100)
        product.fill('prsalesvalue', month_sale)

        return product
예제 #9
0
    def __fill_integral(self, startid, contentid):
        start_model = Supplizer.query.filter_by_(SUid=startid).first() or Admin.query.filter_by_(ADid=startid).first()
        ip = IntegralProduct.query.filter_by(IPid=contentid, isdelete=False).first()

        product = Products.query.filter(
            Products.PRid == ip.PRid, Products.isdelete == False).first()
        if not product:
            current_app.logger.info('·商品已删除 prid = {}'.format(ip.PRid))
        product.fields = ['PRid', 'PRtitle', 'PRstatus', 'PRmainpic', 'PRattribute', 'PRdesc', 'PRdescription',
                          'PRlinePrice']
        if isinstance(product.PRattribute, str):
            product.PRattribute = json.loads(product.PRattribute)
        if isinstance(getattr(product, 'PRremarks', None) or '{}', str):
            product.PRremarks = json.loads(getattr(product, 'PRremarks', None) or '{}')

        pb = ProductBrand.query.filter_by(PBid=product.PBid, isdelete=False).first()
        pb.fields = ['PBname', 'PBid']

        images = ProductImage.query.filter(
            ProductImage.PRid == product.PRid, ProductImage.isdelete == False).order_by(
            ProductImage.PIsort).all()
        [img.hide('PRid') for img in images]
        product.fill('images', images)
        product.fill('brand', pb)
        ips_list = IntegralProductSku.query.filter_by(IPid=ip.IPid, isdelete=False).all()
        skus = list()
        sku_value_item = list()
        for ips in ips_list:
            sku = ProductSku.query.filter_by(SKUid=ips.SKUid, isdelete=False).first()
            if not sku:
                current_app.logger.info('该sku已删除 skuid = {0}'.format(ips.SKUid))
                continue
            sku.hide('SKUstock', 'SkudevideRate', 'PRid', 'SKUid')
            sku.fill('skuprice', ips.SKUprice)
            sku.fill('ipsstock', ips.IPSstock)
            sku.fill('ipsid', ips.IPSid)

            if isinstance(sku.SKUattriteDetail, str):
                sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
            sku_value_item.append(sku.SKUattriteDetail)
            skus.append(sku)
        if not skus:
            current_app.logger.info('该申请的商品没有sku prid = {0}'.format(product.PRid))
            return
        product.fill('skus', skus)
        sku_value_item_reverse = []
        for index, name in enumerate(product.PRattribute):
            value = list(set([attribute[index] for attribute in sku_value_item]))
            value = sorted(value)
            temp = {
                'name': name,
                'value': value
            }
            sku_value_item_reverse.append(temp)
        product.fill('skuvalue', sku_value_item_reverse)
        product.fill('ipstatus_zh', ApplyStatus(ip.IPstatus).zh_value)
        product.fill('ipstatus_en', ApplyStatus(ip.IPstatus).name)
        product.fill('ipstatus', ip.IPstatus)
        product.fill('ipprice', ip.IPprice)
        product.fill('iprejectreason', ip.IPrejectReason)
        product.fill('ipsaleVolume', ip.IPsaleVolume)
        product.fill('ipid', ip.IPid)
        product.fill('ipfreight', 0)  # 运费目前默认为0

        return start_model, product
예제 #10
0
    def list(self):
        """查看自己的申请列表"""
        if is_supplizer():
            suid = request.user.id
        elif is_admin():
            suid = None
        else:
            raise AuthorityError()
        data = parameter_required()
        mbastatus = data.get('mbastatus', 'all')
        if str(mbastatus) == 'all':
            mbastatus = None
        else:
            mbastatus = getattr(ApplyStatus, mbastatus).value
        starttime, endtime = data.get('starttime', '2019-01-01'), data.get(
            'endtime', '2100-01-01')
        out_stocks_query = OutStock.query.join(
            MagicBoxApply, MagicBoxApply.OSid == OutStock.OSid).group_by(
                OutStock.OSid).order_by(MagicBoxApply.MBAstarttime.desc(),
                                        MagicBoxApply.createtime.desc())
        if suid:
            out_stocks_query = out_stocks_query.filter(
                MagicBoxApply.SUid == suid)
        out_stocks = out_stocks_query.all()
        award_list = []
        for out_stock in out_stocks:
            awards = MagicBoxApply.query.filter(
                MagicBoxApply.isdelete == False,
                MagicBoxApply.OSid == out_stock.OSid).filter_(
                    MagicBoxApply.MBAstatus == mbastatus,
                    MagicBoxApply.MBAstarttime >= starttime,
                    MagicBoxApply.MBAstarttime <= endtime).all()
            for award in awards:
                award.fill('skustock', out_stock.OSnum)
            award_list.extend(awards)

        for award in award_list:
            award.Gearsone = json.loads(award.Gearsone)
            award.Gearstwo = json.loads(award.Gearstwo)
            award.Gearsthree = json.loads(award.Gearsthree)
            sku = ProductSku.query.filter_by(SKUid=award.SKUid).first()
            award.fill('skupic', sku['SKUpic'])
            product = Products.query.filter_by(PRid=award.PRid).first()
            award.fill('prtitle', product.PRtitle)
            award.fill('prmainpic', product['PRmainpic'])
            brand = ProductBrand.query.filter_by(PBid=product.PBid).first()
            award.fill('pbname', brand.PBname)
            award.fill('mbastatus_zh', ApplyStatus(award.MBAstatus).zh_value)
            if award.MBAfrom == ApplyFrom.supplizer.value:
                sup = Supplizer.query.filter_by(SUid=award.SUid).first()
                name = getattr(sup, 'SUname', '')
            elif award.MBAfrom == ApplyFrom.platform.value:
                admin = Admin.query.filter_by(ADid=award.SUid).first()
                name = getattr(admin, 'ADname', '')
            else:
                name = ''
            award.fill('authname', name)
            award.fill('createtime', award.createtime)

        # 筛选后重新分页
        page = int(data.get('page_num', 1)) or 1
        count = int(data.get('page_size', 15)) or 15
        total_count = len(award_list)
        if page < 1:
            page = 1
        total_page = int(total_count / int(count)) or 1
        start = (page - 1) * count
        if start > total_count:
            start = 0
        if total_count / (page * count) < 0:
            ad_return_list = award_list[start:]
        else:
            ad_return_list = award_list[start:(page * count)]
        request.page_all = total_page
        request.mount = total_count
        return Success(data=ad_return_list)
예제 #11
0
    def _fill_mba(self, mba):
        product = Products.query.filter(
            Products.PRid == mba.PRid,
            Products.isdelete == False).first_('商品已下架')
        product.fields = [
            'PRid', 'PRtitle', 'PRprice', 'PRlinePrice', 'PRsalesValue',
            'PRstatus', 'PRmainpic', 'PRattribute', 'PRdesc', 'PRdescription'
        ]
        if isinstance(product.PRattribute, str):
            product.PRattribute = json.loads(product.PRattribute)
        if isinstance(getattr(product, 'PRremarks', None) or '{}', str):
            product.PRremarks = json.loads(
                getattr(product, 'PRremarks', None) or '{}')
        pb = ProductBrand.query.filter_by(PBid=product.PBid,
                                          isdelete=False).first()
        pb.fields = ['PBname', 'PBid']

        images = ProductImage.query.filter(
            ProductImage.PRid == product.PRid,
            ProductImage.isdelete == False).order_by(
                ProductImage.PIsort).all()
        [img.hide('PRid') for img in images]
        product.fill('images', images)
        product.fill('brand', pb)

        mbs_list = MagicBoxApplySku.query.filter_by(isdelete=False,
                                                    MBAid=mba.MBAid).all()
        depost_price = []
        skus = []
        sku_value_item = []
        for mbs in mbs_list:
            depost_price.append([
                round(float(mbs.LowestPrice), 2),
                round(float(mbs.HighestPrice), 2)
            ])
            sku = ProductSku.query.filter_by(SKUid=mbs.SKUid,
                                             isdelete=False).first()
            if not sku:
                current_app.logger.error('该商品sku已删除 skuid = {0}'.format(
                    mbs.SKUid))
                continue
            sku.hide('SKUstock', 'SkudevideRate', 'PRid')
            sku.fill('skuprice', mbs.SKUprice)
            sku.fill('mbsstock', mbs.MBSstock)
            sku.fill('mbsid', mbs.MBSid)
            sku.fill('highestprice', mbs.HighestPrice)
            sku.fill('lowestprice', mbs.LowestPrice)

            if isinstance(sku.SKUattriteDetail, str):
                sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
            sku_value_item.append(sku.SKUattriteDetail)
            skus.append(sku)
        if not skus:
            current_app.logger.error('该申请的商品没有sku prid = {0}'.format(
                product.PRid))
            return
        product.fill('skus', skus)
        sku_value_item_reverse = []
        for index, name in enumerate(product.PRattribute):
            value = list(
                set([attribute[index] for attribute in sku_value_item]))
            value = sorted(value)
            temp = {'name': name, 'value': value}
            sku_value_item_reverse.append(temp)
        product.fill('skuvalue', sku_value_item_reverse)
        product.fill('mbastatus', mba.MBAstatus)
        product.fill('mbastatus_en', ApplyStatus(mba.MBAstatus).name)
        product.fill('mbastatus_zh', ApplyStatus(mba.MBAstatus).zh_value)
        product.fill('mbadeposit', min(depost_price)[0])  # 押金
        product.fill('purchaseprice', min(depost_price)[1])  # 可购价
        product.fill('mbaid', mba.MBAid)
        product.fill('mbaday', mba.MBAday)
        product.fill('mbarejectreason', mba.MBArejectReason)
        product.fill('mbafreight', mba.MBAfreight)
        gearone = gearone_str = geartwo = geartwo_str = gearthree = gearthree_str = None
        if isinstance(mba.Gearsone, str):
            gearone = json.loads(mba.Gearsone)
            gearone_str = f'礼盒A:随机减少{gearone[0]}元'
        if isinstance(mba.Gearstwo, str):
            geartwo = json.loads(mba.Gearstwo)
            geartwo_str = f'礼盒B:随机减少{geartwo[0]}元或增加{geartwo[1]}元'
        if isinstance(mba.Gearsthree, str):
            gearthree = json.loads(mba.Gearsthree)
            gearthree_str = f'礼盒C:随机减少{gearthree[0]}元或增加{gearthree[1]}元'
        product.fill('gearsone', gearone)
        product.fill('gearone_str', gearone_str)
        product.fill('gearstwo', geartwo)
        product.fill('geartwo_str', geartwo_str)
        product.fill('gearsthree', gearthree)
        product.fill('gearthree_str', gearthree_str)
        return product
예제 #12
0
    def _fill_gp(self, gp, gg=None):
        product = Products.query.filter(Products.PRid == gp.PRid, Products.isdelete == False).first_('商品已下架')
        product.fields = ['PRid', 'PRtitle', 'PRprice', 'PRlinePrice', 'PRsalesValue', 'PRstatus', 'PRmainpic',
                          'PRattribute', 'PRdesc', 'PRdescription']
        if isinstance(product.PRattribute, str):
            product.PRattribute = json.loads(product.PRattribute)
        if isinstance(getattr(product, 'PRremarks', None) or '{}', str):
            product.PRremarks = json.loads(getattr(product, 'PRremarks', None) or '{}')

        pb = ProductBrand.query.filter_by(PBid=product.PBid, isdelete=False).first()
        pb.fields = ['PBname', 'PBid']

        images = ProductImage.query.filter(
            ProductImage.PRid == product.PRid, ProductImage.isdelete == False).order_by(
            ProductImage.PIsort).all()
        [img.hide('PRid') for img in images]
        product.fill('images', images)
        product.fill('brand', pb)
        gps_list = GroupGoodsSku.query.filter_by(GPid=gp.GPid, isdelete=False).all()
        gpsku_price = []
        skus = []
        sku_value_item = []
        for gps in gps_list:
            gpsku_price.append(round(float(gps.SKUPrice), 2))
            sku = ProductSku.query.filter_by(SKUid=gps.SKUid, isdelete=False).first()
            if not sku:
                current_app.logger.info('该sku已删除 skuid = {0}'.format(gps.SKUid))
                continue
            sku.hide('SKUstock', 'SkudevideRate', 'PRid')
            sku.fill('skuprice', gps.SKUPrice)
            sku.fill('gsstock', gps.GSstock)
            sku.fill('gsid', gps.GSid)

            if isinstance(sku.SKUattriteDetail, str):
                sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
            sku_value_item.append(sku.SKUattriteDetail)
            skus.append(sku)
        if not skus:
            current_app.logger.info('该申请的商品没有sku prid = {0}'.format(product.PRid))
            return
        product.fill('skus', skus)
        sku_value_item_reverse = []
        for index, name in enumerate(product.PRattribute):
            value = list(set([attribute[index] for attribute in sku_value_item]))
            value = sorted(value)
            temp = {
                'name': name,
                'value': value
            }
            sku_value_item_reverse.append(temp)
        product.fill('skuvalue', sku_value_item_reverse)
        product.fill('gpstatus_zh', ApplyStatus(gp.GPstatus).zh_value)
        product.fill('gpstatus_en', ApplyStatus(gp.GPstatus).name)
        product.fill('gpstatus', gp.GPstatus)
        product.fill('gpdeposit', max(gpsku_price))  # 显示的押金
        product.fill('gprejectreason', gp.GPrejectReason)
        product.fill('gpid', gp.GPid)
        product.fill('gpday', gp.GPday)
        product.fill('gpfreight', gp.GPfreight)  # 运费目前默认为0
        # if not gg:
        #     gg_query = GuessGroup.query.filter(GuessGroup.isdelete == False,
        #                                        GuessGroup.GPid == gp.GPid,
        #                                        GuessGroup.GGendtime >= datetime.datetime.now(),
        #                                        GuessGroup.GGstatus == GuessGroupStatus.pending.value)
        #     if common_user():
        #         gg_query = gg_query.outerjoin(GuessRecord, GuessRecord.GGid == GuessGroup.GGid
        #                                       ).filter(GuessRecord.isdelete == False,
        #                                                GuessRecord.USid == request.user.id,
        #                                                GuessRecord.GRstatus == GuessRecordStatus.valid.value)
        #     gg = gg_query.first()

        if common_user() or is_tourist():
            headers, numbers = self._fill_number_and_headers(gg)
            status = getattr(gg, 'GGstatus', None)
            ggstatus_zh = GuessGroupStatus(status).zh_value if isinstance(status, int) else None
            tradeprice = None
            if gg and status == GuessGroupStatus.completed.value:
                tradeprice = db.session.query(OrderMain.OMtrueMount).outerjoin(
                    GuessRecord, GuessRecord.OMid == OrderMain.OMid
                ).filter(OrderMain.isdelete == False, GuessRecord.isdelete == False, GuessRecord.GGid == gg.GGid,
                         OrderMain.USid == request.user.id, GuessRecord.GRstatus == GuessRecordStatus.valid.value,
                         ).scalar() if common_user() else None
                ggstatus_zh = '本期正确结果: {}'.format(gg.GGcorrectNum) if common_user() else ggstatus_zh

            guess_group = {'ggid': getattr(gg, 'GGid', None),
                           'ggstatus': status,
                           'ggstatus_en': GuessGroupStatus(status).name if isinstance(status, int) else None,
                           'ggstatus_zh': ggstatus_zh,
                           'headers': headers,
                           'numbers': numbers,
                           'tradeprice': tradeprice,
                           'rules': db.session.query(Activity.ACdesc
                                                     ).filter_by_(ACtype=ActivityType.guess_group.value).scalar()
                           }
            product.fill('guess_group', guess_group)
            have_paid = self.verify_have_paid(gp, gg)
            usid = request.user.id if common_user() else None
            joined = self._already_joined(gg, usid)
            if gg and gg.GGstatus != GuessGroupStatus.pending.value:
                have_paid = True
                joined = True
            product.fill('topaydeposit', bool(not have_paid))
            product.fill('joined', bool(joined))
        return product