Exemple #1
0
 def update_shoppingcart(self):
     """购物车添加或者修改"""
     if is_tourist():
         return TOKEN_ERROR  # token无效或者未登录的用户
     data = request.json
     scid = data.get('scid')  # 如果是scid则是修改
     pskid = data.get('pskid')
     scnums = data.get('num')
     update_nums = data.get('update_num')
     if not scnums and not update_nums:
         raise PARAMS_MISS()
     if not pskid:
         raise PARAMS_MISS()
     productsku = self.sproductskukey.get_psk_by_pskid(pskid)
     if not productsku:
         raise NOT_FOUND(u'sku不存在')
     usid = request.user.id
     cart = self.sshoppingcart.get_shoppingcar_by_usidandpskid(usid, pskid)
     # 如果是已经存在的购物车
     if cart:
         scid = cart.SCid
         if update_nums:
             scnums = cart.SCnums + update_nums
         elif scnums:
             scnums = scnums
         if scnums < 1:
             # 删除
             return self.delete_shoppingcart(scid)
         self.sshoppingcart.update_shoppingcart(cart, scnums)
     # 创建
     else:
         if update_nums:
             scnums = update_nums
         elif scnums:
             scnums = scnums
         if scnums < 1:
             return self.delete_shoppingcart(scid)
         psk = self.sproductskukey.get_psk_by_pskid(pskid)
         if not psk:
             raise SYSTEM_ERROR('不存在的商品')
         prid = psk.PRid
         cartdict = {
             'USid': usid,
             'PSKid': pskid,
             'SCnums': scnums,
             'PRid': prid
         }
         if scid:
             self.sshoppingcart.update_shoppingcat_by_scid(scid, cartdict)
         else:
             scid = str(uuid.uuid4())
             cartdict['SCid'] = scid
             dict_add_models('ShoppingCart', cartdict)
     data = import_status('update_cart_success', 'OK')
     data['data'] = {
         'scid': scid
     }
     return data
Exemple #2
0
 def get_one_by_productid(self):
     logger.info(request.detail)
     args = request.args.to_dict()
     prid = args.get('productid')
     usid = request.user.id
     if not prid:
         raise PARAMS_MISS()
     product = self.sproduct.get_product_by_productid(prid)
     if not product:
         raise NOT_FOUND(u"无此商品")
     # 是管理员或客服则显示全部信息
     if is_admin() or is_customerservice():
         product.fields = product.all
         print '是管理员或客服'
     else:
         # 如果是游客, 或者是未购买开店大礼包的普通用户
         if is_tourist() or is_ordirnaryuser():
             print '是游客或者普通用户'
             product = self.trans_product_for_fans(product)
         else:  # 合伙人(即已购买开店大礼包的用户)
             print '合伙人'
             product = self.trans_product_for_shopkeeper(product)
         product = self.fill_product_nums(product)
     # 填充一些都需要的信息
     self.fill_product_alreadylike(product, usid)
     self.fill_images(product)
     self.fill_prtarget(product)
     self.fill_product_sku_key(product)
     self.fill_product_sku_value(product)
     self.sproduct.update_view_num(product.PRid)
     data = import_status('get_product_success', 'OK')
     data['data'] = product
     return data
Exemple #3
0
 def get_comment_list(self):
     """获取评论列表"""
     try:
         args = request.args.to_dict()
         acid = args.get('acid')
         if not acid:
             raise PARAMS_MISS(u'必要的参数缺失: acid;')
         reply = True if args.get('reply') else False
         page = int(args.get('page', 1))  # 页码
         # start = int(args.get('start', 0))  # 起始位置
         count = int(args.get('count', 15))  # 取出条数
         # if not start:
         #     start = (page -1) * count
         comment_list = self.sactivitycomment.get_comment_by_activity_id(
             acid, page, count, reply)
         # end = start + count
         # len_comment_list = len(comment_list)
         # if end > len_comment_list:
         #     end = len_comment_list
         # comment_list = comment_list[start: end]
         map(self.fill_user, comment_list)
         map(self.fill_comment_apply_for, comment_list)
         data = import_status('get_acvity_comment_list_success', 'OK')
         data['data'] = comment_list
         return data
     except Exception as e:
         generic_log(e)
         raise e
Exemple #4
0
    def set_schedual_show(self):
        """设置个人主页升级进度显示(vip数据统计), 素材圈显示, 待评价"""
        if not is_admin():
            raise TOKEN_ERROR(u'请使用管理员登录')
        # data = parameter_required(u'vip_match', u'material', u'wait_apply')
        data = request.json
        paras_list = ['vip_match', 'material', 'wait_apply']
        if not data or not filter(lambda x: x in paras_list, data):
            raise PARAMS_MISS()
        if 'vip_match' in data:  # vip进度, 写在model里
            vip_match_show = False if str(
                data.get('vip_match')) == '1' else True
            updated = self.spartnermatch.update_partner_match(
                1,
                {  # 更改: 这里的level没有用
                    'PSIMisclose': vip_match_show
                })
        if 'material' in data:  # 素材圈是否显示, 写在model里
            material_show = False if str(data.get('material')) == '1' else True
            updated = self.stopnav.update_topnav_by_tnidorname(
                data={'Tisdelete': material_show}, name='素材圈')

        if 'wait_apply' in data:  # 写在配置文件里
            wait_apply_show = data.get('wait_apply')
            wait_apply_show = '0' if str(wait_apply_show) == '0' else '1'
            Partner().set_item('show', 'wait_apply', wait_apply_show)
        msg = 'update_success'
        data = import_status(msg, "OK")
        return data
Exemple #5
0
 def update_status(self):
     # if not is_admin():
     #     raise TOKEN_ERROR
     parameter_required('coid', 'cotreatstatus')
     data = request.json
     logger.debug('get update complain status %s', data)
     complain = self.scomplain.get_complain_by_coid(data.get("coid"))
     if not complain:
         raise PARAMS_MISS('params coid is not right')
     if not re.match(r'^[0-2]$', str(data.get("cotreatstatus"))):
         raise PARAMS_MISS('params cotreatstatus is not right')
     cotreatstatus = int(data.get("cotreatstatus"))
     if cotreatstatus <= complain.COtreatstatus:
         raise PARAMS_MISS('params cotreatstatus is not right')
     update_result = self.scomplain.update_complain(
         data.get("coid"), {"COtreatstatus": cotreatstatus})
     if not update_result:
         raise SYSTEM_ERROR(u"服务器繁忙")
     return import_status('update_complain_success', "OK")
Exemple #6
0
 def upload_static_image(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'权限不足')
     logger.debug('get args is %s', request.args.to_dict())
     filetype = request.args.to_dict().get('filetype')
     from WeiDian.config.enums import staticimage
     if filetype not in staticimage:
         raise PARAMS_MISS('filetype is not right')
     url = BaseFile().upload_file("", "", staticimage.get(filetype))
     res = import_status("save_photo_success", "OK")
     res['data'] = url
     return res
Exemple #7
0
 def add_one(self):
     """添加推荐"""
     # 此处无需添加图片, 关联商品id即可
     if not is_admin():
         return AUTHORITY_ERROR(u'当前非管理员权限')
     data = request.json
     logger.debug("data is %s", data)
     parameter_required('PRid_list')
     now_time = datetime.strftime(datetime.now(), format_for_web_second)
     restarttime = get_db_time_str(data.get('REstarttime',
                                            now_time))  # 上线时间, 默认当前时间
     restarttime_str_to_time = datetime.strptime(restarttime, format_for_db)
     days_later = datetime.strftime(
         restarttime_str_to_time + timedelta(days=7), format_for_web_second)
     reendtime = get_db_time_str(data.get('REendtime',
                                          days_later))  # 推荐下线时间, 默认7天以后
     relikefakenum = data.get('RElikenum', 0)  # 喜欢数
     refakeviewnum = data.get('REviewnum', 0)  # 浏览数
     prid_list = data.get('PRid_list')
     if not prid_list:
         raise PARAMS_MISS(u'缺失PRid_list')
     reid = str(uuid.uuid4())
     try:
         re_info = {
             # 'REid': reid,
             # 'SUid': request.user.id,
             'RElikefakenum': relikefakenum,
             'REfakeviewnum': refakeviewnum,
             'REstarttime': restarttime,
             'REendtime': reendtime,
         }
         update_info = self.srecommend.update_recommend_by_reid
     except Exception as e:
         logger.debug("add Recommend error")
         raise SYSTEM_ERROR(u'添加Recommend错误')
     try:
         for item in prid_list:
             add_model(
                 'RecommendProduct', **{
                     'REid': reid,
                     'PRid': item.get('PRid'),
                     'RPid': str(uuid.uuid4()),
                     'RPsort': item.get('RPsort')
                 })
     except Exception as e:
         logger.debug("add recommondproduct list error")
         raise SYSTEM_ERROR(u'添加每日推荐商品RecommendProduct内容出错')
     response_make_recommend = import_status('add_recommend_success', 'OK')
     response_make_recommend['data'] = {
         'reid': reid,
     }
     return response_make_recommend
Exemple #8
0
def parameter_required(*required):
    """
    验证缺失的参数
    :param required:必须的参数列表
    :return:传入的参数
    """

    body_data = request.json or {}
    query_data = request.args.to_dict() or {}
    total_date = dict(body_data, **query_data)
    # data.update(query_data)

    if not total_date:
        raise PARAMS_MISS(u'未传入参数')
    if required:
        missed = filter(lambda x: x not in total_date, required)

        if missed:
            missed_params = '/'.join(missed)
            if isinstance(missed_params, str):
                missed_params = missed_params.decode("utf8")
            logger.debug('missed params is %s', missed_params)
            raise PARAMS_MISS(u'必要参数缺失: ' + missed_params)
    return body_data
Exemple #9
0
 def add_comment(self):
     """添加评论数据"""
     if is_tourist():
         return AUTHORITY_ERROR(u'未登录')
     data = parameter_required(u'ACtext')
     acid = data.get('acid')
     acoid = data.get('acoid')
     usid = request.user.id
     actext = data.get('ACtext')
     # 添加评论
     if acid:
         activity = self.sactivity.get_activity_by_acid(acid)
         if not activity:
             raise NOT_FOUND(u'推文不存在')
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'USid': usid,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     # 如果是添加回复
     elif acoid:
         if not is_admin():
             raise TOKEN_ERROR(u'请使用管理员回复')
         comment = self.sactivitycomment.get_comment_by_acoid(acoid)
         if not comment:
             raise NOT_FOUND(u'不存在的评论')
         acid = comment.ACid
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'ACOparentid': acoid,
             'USid': request.user.id,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     else:
         raise PARAMS_MISS(u'请指定回复类型')
     self.sactivity.add_model('ActivityComment', **model_data)
     data = import_status('add_activity_comment_success', 'OK')
     data['data'] = {'acoid': model_data['ACOid']}
     return data
Exemple #10
0
    def add_image(self):
        if not is_admin():
            return AUTHORITY_ERROR(u"权限不足")
        # parameter_required(*self.add_image_params)
        data = request.json
        adimage_list_web = data.get("adimage", [])
        if not adimage_list_web:
            raise PARAMS_MISS('adimage')
        for adimage_web in adimage_list_web:
            aitype = int(adimage_web.get("aitype"))
            if not adimage_web.get("aiimage") or not (0 <= aitype < 15):
                continue
            adimage = {
                'AIimage': adimage_web.get("aiimage"),
                'AItype': adimage_web.get("aitype"),
                'AIsize': adimage_web.get("aisize"),
                'ACid': adimage_web.get("acid"),
            }

            adimage_list = self.sadimage.get_image_by_aitype(aitype)
            if aitype != 10:
                if adimage_list:
                    update_result = self.sadimage.update_image(
                        adimage_list[0].AIid, adimage)
                    if not update_result:
                        raise SYSTEM_ERROR(u"数据更新异常")
                else:
                    adimage['AIid'] = str(uuid.uuid1())
                    self.sadimage.add_model("AdImage", **adimage)

            else:
                if len(adimage_list) == 3:
                    adimage['AIcreatetime'] = get_db_time_str()
                    update_result = self.sadimage.update_image(
                        adimage_list[1].AIid, adimage)
                    if not update_result:
                        raise SYSTEM_ERROR(u"数据更新异常")
                else:
                    adimage['AIid'] = str(uuid.uuid1())
                    self.sadimage.add_model("AdImage", **adimage)

        return import_status('save_photo_success', 'OK')
Exemple #11
0
    def get_comment_with_apply(self):
        """获取推文的评论列表(评论回复嵌套)"""
        try:
            args = request.args.to_dict()
            acid = args.get('acid')
            if not acid:
                raise PARAMS_MISS(u'必要的参数缺失: acid;')
            page = int(args.get('page', 1))  # 页码
            count = int(args.get('count', 15))  # 取出条数
            comment_list = self.sactivitycomment.get_comment_by_activity_id(
                acid, page, count)
            for comment in comment_list:
                self.fill_user(comment)
                comment.ACOcreatetime = get_web_time_str(comment.ACOcreatetime)
                replys = self.sactivitycomment.get_apply_by_acoid(
                    comment.ACOid)
                if replys:
                    for reply in replys:
                        comment.fill(replys, 'reply')
                        reply.hide('USid')
                        # 改: 所有的回复都是管理员回复
                        admin_user = self.ssuperuser.get_one_super_by_suid(
                            reply.USid)
                        if admin_user:
                            user = admin_user
                            admin_user.fill(0, 'robot')
                            user.hide('SUid')
                        else:
                            user = {'name': u'运营人员', 'robot': 1}
                        reply.ACOcreatetime = get_web_time_str(
                            reply.ACOcreatetime)
                        reply.fill(user, 'user')

            data = import_status('get_acvity_comment_list_success', 'OK')
            data['data'] = comment_list
            data["count"] = request.all_count
            data["page_count"] = request.page_count
            return data
        except Exception as e:
            generic_log(e)
            raise e
Exemple #12
0
    def get_activity_list_by_actitle(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u'当前非管理员权限')
        args = request.args.to_dict()
        logger.debug('get arsgs %s', args)
        actitle = args.get("actitle")
        hmtype = args.get('hmtype', 3)
        if str(hmtype) not in self.hmsk_type:
            raise PARAMS_MISS(u"参数错误")

        from WeiDian.config.enums import HMSkipType
        topnav = self.stopnav.get_topnav_by_name(HMSkipType.get(str(hmtype)))
        acfilter = {
            Activity.ACtitle.contains(actitle),
            Activity.ACtext.contains(actitle)
        }
        activity_list = self.sactivity.get_activity_by_filter(
            acfilter, topnav.TNid)
        res = import_status("add_activity_success", "OK")
        res['data'] = activity_list
        return res
Exemple #13
0
    def update_product_image(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u'权限不足')

        data = parameter_required('productid', 'images')
        logger.debug('get update_product_image data %s', data)
        product = self.sproduct.get_product_by_productid(data.get("productid"))
        if not product:
            raise PARAMS_MISS(u"商品不存在或已删除")
        # for image in data.get("images"):
        #     primage = self.sproductimage.get_images_by_prid_pisort(product.PRid, image.get('pisort', 0))
        #     if primage:
        #         update_result = self.sproductimage.update_image(
        #             primage.PIid, {"PIurl": image.get("piurl"), "PIexist": image.get("piexist", 1)})
        #         if not update_result:
        #             logger.error('update product image error, sort is %s', image.get("pisort", 0))
        #             raise SYSTEM_ERROR(u"数据库异常")
        #     else:
        #         self.sproductimage.add_model("ProductImage", **{
        #             "PIid": str(uuid.uuid1()),
        #             "PRid": product.PRid,
        #             "PIurl": image.get("piurl"),
        #             "PIsort": image.get("pisort", 0),
        #             "PIexist": image.get("piexist", 1),
        #         })
        self.sproductimage.update_image_by_prid(product.PRid, {"PIexist": 0})
        for image in data.get('images'):
            self.sproductimage.add_model(
                "ProductImage", **{
                    "PIid": str(uuid.uuid1()),
                    "PRid": product.PRid,
                    "PIurl": image.get("piurl"),
                    "PIsort": image.get("pisort", 0),
                    "PIexist": image.get("piexist", 1),
                })

        return import_status('update_product_image_success', 'OK')
Exemple #14
0
 def shelves_product(self):
     """状态改成0 上架  1下架"""
     if not is_admin():
         return AUTHORITY_ERROR(u'权限不足')
     data = parameter_required('productid')
     prstatus = data.get("prstatus", 1)
     logger.debug('get prestatus. %s', prstatus)
     logger.debug('get productid. %s', data.get('productid'))
     if not re.match(r'^[0-2]$', str(prstatus)):
         raise PARAMS_MISS(u'prstatus, 参数异常')
     prstatus = int(prstatus)
     prstatus = 0 if int(prstatus) else 1
     product = self.sproduct.get_product_by_productid(data.get('productid'))
     logger.debug('get product %s', product)
     if not product and prstatus != 1:
         return import_status('no_product', 'OK')
     update_result = self.sproduct.update_product_by_productid(
         data.get('productid'), {
             "PRstatus": prstatus,
             'PRmodifytime': get_db_time_str()
         })
     if not update_result:
         raise SYSTEM_ERROR(u'服务器繁忙')
     return import_status('update_product_success', 'OK')
Exemple #15
0
    def get_all(self):
        """获取条件下的所有活动
        """
        if is_tourist():
            return AUTHORITY_ERROR(u"未登录")
        args = request.args.to_dict()
        logger.info("this is get all activity args %s", args)
        parameter_required(u'tnid')
        tnid = args.get('tnid')  # 导航id
        suid = args.get('suid')  # 管理员id
        lasting = args.get('lasting', 'true')  # 是否正在进行的活动
        acid = args.get("acid")
        if not acid:
            acid = None
        start = int(args.get('start', 0))  # 起始位置
        count = int(args.get('count', 5))  # 取出条数
        page = (args.get('page'))
        # 过滤跳转类型
        skiptype = args.get('skiptype')
        if skiptype is None:
            settings = Partner()
            skiptype = settings.get_item('skip', 'skip_type')  # 配置文件中的过滤条件(默认)
        if skiptype == 'all':
            skiptype = None
        # 分页
        if not page:
            page = int(math.floor(start / count) + 1)
        if not (tnid or suid):
            raise PARAMS_MISS(u"参数缺失")
        try:
            topnav = self.stopnav.get_topnav_by_tnid(tnid)
            if not topnav:
                raise NOT_FOUND(u'无此tnid')
            if topnav.TNtype == 2 and str(tnid) != '1':  # '1'为每日十荐页tnid
                skiptype = 0
            print(skiptype)

            now_time = None

            if str(lasting) == 'true':
                now_time = datetime.strftime(datetime.now(), format_for_db)
            activity_list = self.sactivity.get_activity_by_topnavid(
                tnid, page, count, skiptype, acid, suid, now_time)
            logger.info("get activity_list success")

            # if suid:
            #     activity_list = self.sactivity.get_activity_by_suid(suid, page, count)
            # if not activity_list:
            #     raise SYSTEM_ERROR(u'数据库错误')

            for activity in activity_list:
                self.sactivity.update_view_num(activity.ACid)
                self.fill_detail(activity)
                self.fill_like_num(activity)
                self.fill_type(activity)
                activity.fill(activity.AClinkvalue, 'aclinkvalue')
                if activity.ACSkipType == 0:
                    self.fill_comment_two(activity)
                    activity.fill('none_skip', 'skip_type')
                    activity.fill('无跳转类型', 'zh_skip_type')
                elif activity.ACSkipType == 1:
                    baid = activity.AClinkvalue
                    activity.fill('bigactivity', 'skip_type')
                    activity.fill('专题', 'zh_skip_type')
                    bigactivity = self.sbigactivity.get_one_big_act(baid)
                    if not bigactivity:
                        # raise NOT_FOUND()
                        pass
                    else:
                        bigactivity_type = bigactivity.BAtype
                        big_activity_content = {'type': bigactivity_type}
                        big_activity_content.setdefault(
                            'baid', bigactivity.BAid)
                        # 图片类型专题
                        if bigactivity_type == 0:
                            big_activity_content.setdefault(
                                'baimage', bigactivity.BAlongimg)  # 返回字段不修改
                            big_activity_content.setdefault(
                                'baid', bigactivity.BAid)
                        activity.fill(big_activity_content, 'bigactivity')
                elif activity.ACSkipType == 2:
                    self.fill_soldnum(activity)
                    self.fill_product(activity)
                    activity.fill('product', 'skip_type')
                    activity.fill('商品', 'zh_skip_type')
                activity.ACstarttime = get_web_time_str(activity.ACstarttime)
                activity.ACendtime = get_web_time_str(activity.ACendtime)

            data = import_status("get_activity_list_success", "OK")
            data["count"] = request.all_count
            data["page_count"] = request.page_count
            data["data"] = activity_list
            return data
        except Exception as e:
            logger.exception("get activity error")
            generic_log(e)
            return e
Exemple #16
0
 def update_product_relate_bigactivity(self):
     """商品池修改商品与专题的关联"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
     data = request.json
     logger.debug("update product relate bigactivity data is %s", data)
     pbid = data.get('pbid')
     baid = data.get('baid')
     prid = data.get('prid')
     option = data.get('option')
     if not re.match(r'^[0-2]$', str(option)):
         raise PARAMS_MISS(u'option 参数异常')
     if baid == '':
         raise PARAMS_MISS(u'baid 参数异常')
     elif baid not in self.empty:
         bigact = self.sbigactivity.get_one_big_act(baid)
         if not bigact:
             raise NOT_FOUND(u'输入的关联专题不存在')
     if prid == '':
         raise PARAMS_MISS(u'prid 参数异常')
     elif prid not in self.empty:
         product = self.sproduct.get_product_by_prid(prid)
         if not product:
             raise NOT_FOUND(u'商品信息不存在')
     if str(option) == '0':  # 0 删除
         parameter_required('pbid')
         # 操作记录
         pbinfo = self.sproduct.get_single_productbigactivity_by_filter(
             {'PBid': pbid})
         if pbinfo:
             self.__make_product_recording(pbinfo.PRid, pbinfo.BAid,
                                           u'解除专题关联')
         del_info = self.sproduct.del_productbigactivity_by_filter(
             {'PBid': pbid})
         if not del_info:
             raise NOT_FOUND(u'错误,未找到要删除的关联专题')
     elif str(option) == '1':  # 1 添加
         parameter_required('prid', 'baid')
         prbaid_list = self.sproduct.get_product_baid_by_prid(prid)
         if prbaid_list:
             logger.debug("exist prbaid count is %s", len(prbaid_list))
             if len(prbaid_list) >= 3:
                 raise SYSTEM_ERROR(u'每个商品最多只能关联三个专题')
             for prbaid in prbaid_list:
                 if baid == prbaid.BAid:
                     raise SYSTEM_ERROR(u'已与此专题进行过关联')
         pbid = str(uuid.uuid1())
         self.sproduct.add_model(
             'ProductBigActivity', **{
                 'PBid': pbid,
                 'PRid': prid,
                 'BAid': baid
             })
         # 操作记录
         self.__make_product_recording(prid, baid, u'添加专题关联')
     elif str(option) == '2':  # 2 修改
         parameter_required('pbid', 'baid')
         pbact = self.sproduct.update_productbigactivity_by_filter(
             {'PBid': pbid}, {'BAid': baid})
         if not pbact:
             raise NOT_FOUND(u'修改失败')
         # 操作记录
         pbinfo = self.sproduct.get_single_productbigactivity_by_filter(
             {'PBid': pbid})
         if pbinfo:
             self.__make_product_recording(pbinfo.PRid, baid, u'修改专题关联')
     response = import_status("update_success", "OK")
     response['data'] = {'pbid': pbid}
     return response
Exemple #17
0
 def update_product_relate_prtarget(self):
     """商品池修改商品与模块的关联"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
     data = request.json
     logger.debug("update product relate prtarget data is %s", data)
     prid = data.get('prid')
     prtargets = data.get('prtarget')
     if prtargets:
         if len(prtargets) > 3:
             raise SYSTEM_ERROR(u'每个商品最多只能关联三个模块')
         ptid = str(uuid.uuid1())
         if '101' in prtargets:
             del_info = self.sproduct.del_product_target_by_filter(
                 {"PRid": prid})
             logger.debug(
                 "del prtarget relation success before add operation, del count: %s",
                 del_info)
             self.sproduct.add_model(
                 "ProductTarget", **{
                     'PTid': ptid,
                     'PRid': prid,
                     'PRtarget': '101'
                 })
             # 操作记录
             self.__make_product_recording(prid, prid, u'更改为大礼包商品')
         else:
             topnav_list = self.stopnav.get_all_tnid()
             tnid_list = []
             [tnid_list.append(topnav.TNid) for topnav in topnav_list]
             with self.sproduct.auto_commit() as session:
                 model_beans = []
                 for targetid in prtargets:
                     if str(targetid) not in tnid_list:
                         raise PARAMS_MISS(u'prtarget参数错误,未找到要关联的模块')
                     prtarget_dict = dict(PTid=str(uuid.uuid4()),
                                          PRid=prid,
                                          PRtarget=targetid)
                     prtarget_info = ProductTarget.create(prtarget_dict)
                     model_beans.append(prtarget_info)
                     # 操作记录
                     self.__make_product_recording(prid, targetid,
                                                   u'更改模块关联')
                 session.query(ProductTarget).filter(
                     ProductTarget.PRid == prid).delete()
                 session.add_all(model_beans)
     elif prtargets == []:
         # 操作记录
         try:
             target_info = self.sproduct.get_product_target_by_prid(prid)
             if target_info:
                 for tgid in target_info:
                     self.__make_product_recording(prid, tgid.PRtarget,
                                                   u'解除模块关联')
         except Exception as e:
             logger.exception("not found prtargetid ,error is %s", e)
             self.__make_product_recording(prid, prid, u'解除模块关联')
         del_info = self.sproduct.del_product_target_by_filter(
             {"PRid": prid})
         logger.debug("del prtarget relation success this is none list: %s",
                      del_info)
     response = import_status("update_success", "OK")
     response['data'] = {'prid': prid}
     return response
Exemple #18
0
 def shelf_product_and_claim_act(self):
     """商品上下架/删除商品/推文认领"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
     data = request.json
     logger.debug("shelf product and claim act data is %s", data)
     prid = data.get('prid')
     parameter_required('prid')
     shelf = data.get('shelf')  # 0 下架 1 上架
     claim = data.get('claim')  # 0 取消认领 1 认领推文
     prdel = data.get('prdel')  # 1 删除
     modifyid = None
     if shelf not in self.empty and claim not in self.empty:
         raise PARAMS_MISS(u'参数错误,只能进行一项操作')
     pr_info = self.sproduct.get_product_by_prid(prid)
     if not pr_info:
         raise NOT_FOUND(u'无该商品信息')
     if pr_info.PRisdelete == True:
         raise NOT_FOUND(u'数据错误,该商品已被删除')
     if shelf not in self.empty:
         if not re.match(r'^[0-1]$', str(shelf)):
             raise PARAMS_MISS(u'shelf, 参数异常')
         if pr_info.PRstatus == int(shelf):
             raise SYSTEM_ERROR(u'已完成上/下架操作')
         upinfo = self.sproduct.update_product_info_by_filter(
             {'PRid': prid}, {
                 'PRmodifytime': get_db_time_str(),
                 'PRstatus': int(shelf)
             })
         if not upinfo:
             raise SYSTEM_ERROR(u'更新数据错误')
         # 操作日志
         shelf_operation = u'上架商品' if str(shelf) == '1' else u'下架商品'
         self.__make_product_recording(prid, prid, shelf_operation)
     if claim not in self.empty:
         if not re.match(r'^[0-1]$', str(claim)):
             raise PARAMS_MISS(u'claim, 参数异常')
         if pr_info.SUmodifyid:
             if pr_info.SUmodifyid != request.user.id:
                 raise SYSTEM_ERROR(u'该推文已被其他运营认领')
             else:
                 if str(claim) == '1':
                     raise SYSTEM_ERROR(u'您已完成认领')
         else:
             if str(claim) == '0':
                 raise SYSTEM_ERROR(u'您没有认领该商品的关联推文,不能进行解除操作')
         modifyid = request.user.id if str(claim) == '1' else None
         upinfo = self.sproduct.update_product_info_by_filter(
             {'PRid': prid}, {
                 'PRmodifytime': get_db_time_str(),
                 'SUmodifyid': modifyid
             })
         if not upinfo:
             raise SYSTEM_ERROR(u'更新数据错误')
         # 操作日志
         operation = u'认领推文' if str(claim) == '1' else u'解除推文认领'
         self.__make_product_recording(prid, prid, operation)
     if prdel not in self.empty:
         if str(prdel) == '1':
             update_result = self.sproduct.update_product_info_by_filter(
                 {'PRid': prid}, {
                     "PRisdelete": True,
                     'PRmodifytime': get_db_time_str()
                 })
             if not update_result:
                 raise SYSTEM_ERROR(u'删除数据错误')
             # 操作日志
             self.__make_product_recording(prid, prid, u'删除商品')
     response = import_status("update_success", "OK")
     response['data'] = {'prid': prid, 'claimid': modifyid or ''}
     return response