def handle(self, *args, **options): """ 同步没有同步客户运费模板 """ postage_configs = postage_models.PostageConfig.objects.filter( is_deleted=False) relations = postage_models.PostageConfigRelation.objects.all() free_postage_configs = postage_models.FreePostageConfig.objects.all() special_postage_configs = postage_models.SpecialPostageConfig.objects.all( ) relation_postage_ids = [ relation.postage_config_id for relation in relations ] user_relations = account_models.AccountHasSupplier.objects.all() count = 0 for postage_config in postage_configs: if postage_config.id not in relation_postage_ids: user_relation = user_relations.filter( user_id=postage_config.owner_id).last() if user_relation: postage_params = new_config.organize_postage_config_params( postage_config=postage_config, user_relation=user_relation) resp, resp_data = sync_util.sync_zeus( params=postage_params, resource='mall.postage_config', method='put') free_configs = free_postage_configs.filter( postage_config_id=postage_config.id) if resp: count += 1 weapp_postage_config_id = resp_data.get( 'postage_config').get('id') postage_models.PostageConfigRelation.objects.create( postage_config_id=postage_config.id, weapp_config_relation_id=weapp_postage_config_id) for free_config in free_configs: params = new_config.organize_free_postage_config( weapp_postage_config_id=weapp_postage_config_id, free_postage=free_config) resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.free_postage_config', method='put') for special_postage in special_postage_configs: params = new_config.organize_special_postage_config( weapp_postage_config_id=weapp_postage_config_id, special_postage=special_postage) resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.special_postage_config', method='put') print 'postage config {} is ok!'.format( postage_config.id) print '>>>>>>>>>>>>>>>ALL is OK!<<<<<<<<<<<<<<<<<<<<' print '>>>>>>>>>>>>>>>count is {}!<<<<<<<<<<<<<<<<<<<<'.format(count)
def api_delete(request): label_id = request.POST.get('label_id', 0) response = create_response(500) try: if label_id != 0: models.LabelGroup.objects.filter(id=label_id).update(is_deleted=True) label_group_values = models.LabelGroupValue.objects.filter(property_id=label_id) label_group_values.update(is_deleted=True) product_models.ProductHasLabel.objects.filter(property_id=label_id).delete() catalog_models.ProductCatalogHasLabel.objects.filter(property_id=label_id).delete() response = create_response(200) relation = models.LabelGroupRelation.objects.filter(label_group_id=label_id).first() if relation: weapp_label_group_id = relation.weapp_label_group_id params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'product_label_group_id': weapp_label_group_id } # 先删除weapp的标签分组 resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_label_group', method='delete') if not resp: watchdog.error('sync_delete_label_group: %s failed' % label_id) # 同步删除标签 for label_group_value in label_group_values: value_relation = models.LabelGroupValueRelation.objects.filter(label_value_id=label_group_value.id).first() if not value_relation: continue params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'product_label_id': value_relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_label', method='delete') if not resp: watchdog.error('sync_delete_label_: %s failed' % label_group_value.id) # 将有这个标签的商品的标签去掉 params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_id': value_relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.disable_product_label', method='delete') if not resp: watchdog.error('sync_disable_product_label: %s failed' % label_group_value.id) # 将有这个标签的类目的标签删掉 params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_id': value_relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.classification_has_label', method='delete') except: msg = unicode_full_stack() watchdog.error(msg) response.innerErrMsg = msg return response.get_response()
def api_post(request): post = request.POST name = post.get('name') template_id = post.get('id') flag = post.get('flag', 'name') try: models.ProductLimitZoneTemplate.objects.filter(id=template_id).update(name=name) # 同步到weapp的参数 weapp_cities = [] weapp_provinces = [] if flag != 'name': selected_data = json.loads(post.get('selected_data', '')) provinces = selected_data.get('provinces') # 先删除 models.LimitTemplateHasZone.objects.filter(template_id=template_id).delete() # 创建模板的数据 bulk_create = [] for province in provinces: # 前段传递的数据如果是全选了省,那么cities是空的 cities = province.get('cities') weapp_provinces.append(str(province.get('provinceId'))) if not cities: bulk_create.append(models.LimitTemplateHasZone(template_id=template_id, province=province.get('provinceId'), )) else: bulk_create += [models.LimitTemplateHasZone(template_id=template_id, province=province.get('provinceId'), city=city.get('cityId')) for city in cities] weapp_cities += [str(city.get('cityId')) for city in cities] models.LimitTemplateHasZone.objects.bulk_create(bulk_create) # 同步更新到weapp relation = models.ProductLimitZoneTemplateRelation.objects.filter(template_id=template_id).first() if relation: params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'name': name, 'cities': ','.join(weapp_cities), 'template_id': relation.weapp_template_id, 'provinces': ','.join(weapp_provinces), 'flag': flag } sync_util.sync_zeus(params=params, resource='mall.product_limit_zone_template', method='post') response = create_response(200) except: msg = unicode_full_stack() watchdog.error('product_limit_zone.template_POST{}'.format(msg)) response = create_response(500) return response.get_response()
def api_post(request): postage_id = request.POST.get('postage_id', -1) # 必须在这里查,查之前用的模板 old_used_config = models.PostageConfig.objects.filter( owner_id=request.user.id, is_used=True).last() models.PostageConfig.objects.filter( is_used=True, owner_id=request.user.id).update(is_used=False) models.PostageConfig.objects.filter(id=postage_id).update(is_used=True) product_models.Product.objects.filter( owner_id=request.user.id, has_same_postage=True).update(postage_id=postage_id) new_use_config = models.PostageConfig.objects.filter( id=postage_id).last() user_relation = account_models.AccountHasSupplier.objects.filter( user_id=request.user.id).last() # 同步 if old_used_config and user_relation: params = organize_postage_config_params( postage_config=old_used_config, user_relation=user_relation) postage_config_relation = models.PostageConfigRelation.objects \ .filter(postage_config_id=old_used_config.id, ).last() params.update({ 'postage_config_id': postage_config_relation.weapp_config_relation_id, 'is_used': 'false' }) if postage_config_relation: sync_util.sync_zeus(params=params, resource='mall.postage_config', method='post') if new_use_config and user_relation: params = organize_postage_config_params( postage_config=new_use_config, user_relation=user_relation) postage_config_relation = models.PostageConfigRelation.objects \ .filter(postage_config_id=new_use_config.id, ).last() params.update({ 'postage_config_id': postage_config_relation.weapp_config_relation_id }) if postage_config_relation: sync_util.sync_zeus(params=params, resource='mall.postage_config', method='post') data = {'postageId': postage_id} response = create_response(200) response.data = data return response.get_response()
def api_put(request): post = request.POST name = post.get('name') db_model = None try: db_model = models.ProductLimitZoneTemplate.objects.create(name=name, owner_id=request.user.id) params = { 'name': name, 'owner_id': PRODUCT_POOL_OWNER_ID } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_limit_zone_template', method='put') if resp and resp_data: # 创建中间关系 models.ProductLimitZoneTemplateRelation.objects.create( template_id=db_model.id, weapp_template_id=resp_data.get('template').get('id') ) response = create_response(200) else: models.ProductLimitZoneTemplate.objects.filter(id=db_model).delete() response = create_response(500) except: msg = unicode_full_stack() watchdog.error('product_limit_zone.template_PUT{}'.format(msg)) if db_model: models.ProductLimitZoneTemplate.objects.filter(id=db_model.id).delete() response = create_response(500) return response.get_response()
def api_delete(request): post = request.POST template_id = post.get('id') try: # 判断是否有正在使用的 use_products = product_models.Product.objects.filter(limit_zone=template_id)\ .exclude(limit_zone_type=product_models.NO_LIMIT) # print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.' # print use_products.count() # print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.' if use_products.count() > 0: # data = { # 'msg': '还有正在使用该模板的商品,请先处理!' # } response = create_response(500) response.errMsg = '还有正在使用该模板的商品,请先处理!' return response.get_response() models.ProductLimitZoneTemplate.objects.filter(id=template_id).update(is_deleted=True) # 同步到weapp relation = models.ProductLimitZoneTemplateRelation.objects.filter(template_id=template_id).first() if relation: params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'template_id': relation.weapp_template_id } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_limit_zone_template', method='delete') response = create_response(200) except: msg = unicode_full_stack() watchdog.error('product_limit_zone.template_DELETE{}'.format(msg)) response = create_response(500) return response.get_response()
def api_post(request): label_id = request.POST.get('label_id', -1) name = request.POST.get('name', '') try: models.LabelGroup.objects.filter(id=int(label_id)).update( name= name ) response = create_response(200) relation = models.LabelGroupRelation.objects.filter(label_group_id=label_id).first() if relation: weapp_label_group_id = relation.weapp_label_group_id params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'name': name, 'product_label_group_id': weapp_label_group_id } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_label_group', method='post') if not resp: response = create_response(500) except: response = create_response(500) msg = unicode_full_stack() watchdog.error(msg) return response.get_response()
def update_product_store(product_2_weapp_product=None, products=None): """ 从weapp拿到库存后更新panda库存 """ weapp_product_ids = product_2_weapp_product.keys() params = {'product_ids': json.dumps(weapp_product_ids)} resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product', method='get') resp_products = [] if not resp_data else resp_data["products"] # 组装(panda商品idweapp规格名: 库存) panda_product_id_to_socks = {} for resp_product in resp_products: temp_models = resp_product.get('models') for temp_model in temp_models: panda_product_id = product_2_weapp_product.get( temp_model.get('product_id')) if not panda_product_id: panda_product_id = product_2_weapp_product.get( str(temp_model.get('product_id'))) temp_model_name = temp_model.get('name') panda_product_id_to_socks.update({ str(panda_product_id) + '#' + temp_model_name: temp_model.get('stocks') }) # 返回单规格的商品的库存id: store standard_product_to_store = {} # panda_product_model_name_to_stocks = {} panda_ids = product_2_weapp_product.values() for product in products: if product.id not in panda_ids: continue model_properties = get_weapp_model_properties(product=product) if len(model_properties) == 0: # 单规格 key = str(product.id) + '#standard' product_store = panda_product_id_to_socks.get(key) if product_store and int(product_store) != product.product_store: standard_product_to_store.update( {product.id: panda_product_id_to_socks.get(key)}) models.Product.objects.filter(id=product.id).update( product_store=panda_product_id_to_socks.get(key)) continue for _property in model_properties: key = str(product.id) + '#' + _property.get('name') stocks = panda_product_id_to_socks.get(key) if stocks and stocks != product.product_store: models.ProductModel.objects.filter(id=_property.get('panda_model_info_id'))\ .update(stocks=panda_product_id_to_socks.get(key)) return standard_product_to_store
def api_delete(request): postage_id = request.POST.get('postage_id', -1) models.PostageConfig.objects.filter(id=postage_id).update( is_deleted=True) data = {'postageId': postage_id} # 同步 user_relation = account_models.AccountHasSupplier.objects.filter( user_id=request.user.id).last() relation = models.PostageConfigRelation.objects.filter( postage_config_id=postage_id).last() if relation and user_relation: params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'postage_config_id': relation.weapp_config_relation_id, 'supplier_id': user_relation.supplier_id } sync_util.sync_zeus(params=params, resource='mall.postage_config', method='delete') response = create_response(200) response.data = data return response.get_response()
def api_put(request): label_id = request.POST.get('label_id', -1) label_value = request.POST.get('label_value', '') try: if label_id != -1: label_group_relation = models.LabelGroupRelation.objects.filter( label_group_id=label_id).first() if label_group_relation: db_model = models.LabelGroupValue.objects.create( property_id=label_id, name=label_value) response = create_response(200) params = { 'name': label_value, 'owner_id': PRODUCT_POOL_OWNER_ID, 'product_label_group_id': label_group_relation.weapp_label_group_id } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.product_label', method='put') if resp and resp_data: models.LabelGroupValueRelation.objects.create( label_value_id=db_model.id, weapp_label_value_id=resp_data.get('label').get( 'id')) else: response = create_response(500) models.LabelGroupValue.objects.filter( id=db_model.id).update(is_deleted=True) else: response = create_response(500) else: response = create_response(500) except: response = create_response(500) msg = unicode_full_stack() watchdog.error(msg) return response.get_response()
def api_put(request): try: label_group = models.LabelGroup.objects.create( user_id= request.user.id ) params = { 'owner_id': PRODUCT_POOL_OWNER_ID, } resp, resp_data = sync_util.sync_zeus(params=params, resource='mall.product_label_group', method='put') if not resp or not resp_data: models.LabelGroup.objects.filter(id=label_group.id).update(is_deleted=True) response = create_response(500) else: models.LabelGroupRelation.objects.create( label_group_id=label_group.id, weapp_label_group_id=resp_data.get('group').get('id') ) response = create_response(200) except: response = create_response(500) msg = unicode_full_stack() watchdog.error(msg) return response.get_response()
def api_put(request): """ 保存分类跟标签的对应关系 """ select_catalog_labels = request.POST.get('select_catalog_labels', '') catalog_id = request.POST.get('catalog_id', -1) product_id = int(request.POST.get('product_id', -1)) select_catalog_labels = json.loads(select_catalog_labels) if len(select_catalog_labels) > 0: catalog_label_create = [] product_label_create = [] label_ids = [] for select_catalog_label in select_catalog_labels: value_ids = [] select_value_ids = select_catalog_label['valueIds'] label_ids += select_value_ids property_id = select_catalog_label['propertyId'] for value_id in select_value_ids: value_ids.append(str(value_id)) str_value_ids = ','.join(value_ids) #分类配置标签 catalog_label_create.append( catalog_models.ProductCatalogHasLabel( catalog_id=catalog_id, label_ids=str_value_ids, property_id=property_id)) #商品配置标签 product_label_create.append( product_models.ProductHasLabel(product_id=product_id, label_ids=str_value_ids, property_id=property_id)) if product_id == -1: # 类目下的标签 catalog_relation = catalog_models.ProductCatalogRelation.objects.filter( catalog_id=catalog_id).first() # label_ids = [] # label_ids = select_catalog_labels[0].get('valueIds') label_relations = models.LabelGroupValueRelation.objects.filter( label_value_id__in=label_ids) weapp_classification_id = catalog_relation.weapp_catalog_id params = { 'label_ids': json.dumps([ relation.weapp_label_value_id for relation in label_relations ]), 'classification_id': weapp_classification_id, 'owner_id': PRODUCT_POOL_OWNER_ID } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.classification_has_label', method='post') if resp: # 分类关联标签 catalog_models.ProductCatalogHasLabel.objects.filter( catalog_id=catalog_id).delete() catalog_models.ProductCatalogHasLabel.objects.bulk_create( catalog_label_create) else: response = create_response(500) return response.get_response() else: product_relation = product_models.ProductHasRelationWeapp.objects.filter( product_id=product_id).first() if product_relation: weapp_product_id = product_relation.weapp_product_id # label_ids = select_catalog_labels[0].get('valueIds') label_relations = models.LabelGroupValueRelation.objects.filter( label_value_id__in=label_ids) params = { 'product_id': weapp_product_id, 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_ids': json.dumps([ relation.weapp_label_value_id for relation in label_relations ]), } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.product_has_label', method='post') if resp: # 商品关联标签 product_models.ProductHasLabel.objects.filter( product_id=product_id).delete() product_models.ProductHasLabel.objects.bulk_create( product_label_create) print product_label_create, select_catalog_labels print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' else: response = create_response(500) return response.get_response() else: product_models.ProductHasLabel.objects.filter( product_id=product_id).delete() product_models.ProductHasLabel.objects.bulk_create( product_label_create) else: if product_id != -1: product_models.ProductHasLabel.objects.filter( product_id=product_id).delete() product_models.ProductHasLabel.objects.create( product_id=product_id, label_ids='', property_id=-1) # 同步到weapp product_relation = product_models.ProductHasRelationWeapp.objects.filter( product_id=product_id).first() if product_relation: weapp_product_id = product_relation.weapp_product_id params = { 'product_id': weapp_product_id, 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_ids': '', } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.product_has_label', method='post') else: # 更新类目的标签 catalog_models.ProductCatalogHasLabel.objects.filter( catalog_id=catalog_id).delete() # 同步到weapp catalog_relation = catalog_models.ProductCatalogRelation.objects.filter( catalog_id=catalog_id).first() if catalog_relation: weapp_classification_id = catalog_relation.weapp_catalog_id params = { 'label_ids': '', 'classification_id': weapp_classification_id, 'owner_id': PRODUCT_POOL_OWNER_ID } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.classification_has_label', method='post') response = create_response(200) return response.get_response()
def api_post(request): postage_id = int(request.POST.get('postage_id', -1)) postage_name = request.POST.get('postage_name', '') default_postages = json.loads(request.POST.get('default_postages')) special_postages = json.loads(request.POST.get('special_postages')) free_postages = json.loads(request.POST.get('free_postages')) models.PostageConfig.objects.filter( id=postage_id, is_deleted=False).update( name=postage_name, first_weight=default_postages[0].get('firstWeight'), first_weight_price=default_postages[0].get('firstWeightPrice'), added_weight=default_postages[0].get('addedWeight'), added_weight_price=default_postages[0].get('addedWeightPrice'), is_enable_special_config=True if special_postages else False, is_enable_free_config=True if free_postages else False, is_enable_added_weight=True if default_postages[0].get('addedWeight') > 0 else False, ) #特殊地区运费配置 models.SpecialPostageConfig.objects.filter( postage_config_id=postage_id).delete() if special_postages: special_postage_create = [] for special_postage in special_postages: selected_ids = [ str(selected_id) for selected_id in special_postage['selectedIds'] ] special_postage_create.append( models.SpecialPostageConfig( owner=request.user, postage_config_id=postage_id, first_weight=special_postage['firstWeight'], added_weight=special_postage['addedWeight'], first_weight_price=special_postage['firstWeightPrice'], added_weight_price=special_postage['addedWeightPrice'], destination=','.join(selected_ids))) models.SpecialPostageConfig.objects.bulk_create( special_postage_create) #包邮配置 models.FreePostageConfig.objects.filter( postage_config_id=postage_id).delete() if free_postages: free_postage_create = [] for free_postage in free_postages: selected_ids = [ str(selected_id) for selected_id in free_postage['selectedIds'] ] free_postage_create.append( models.FreePostageConfig( owner=request.user, postage_config_id=postage_id, condition=free_postage['condition'], condition_value=free_postage['conditionValue'], destination=','.join(selected_ids))) models.FreePostageConfig.objects.bulk_create(free_postage_create) # 同步 postage_config = models.PostageConfig.objects.filter( id=postage_id).first() user_relation = account_models.AccountHasSupplier.objects.filter( user_id=request.user.id).last() if postage_config and user_relation: params = organize_postage_config_params( postage_config=postage_config, user_relation=user_relation) postage_config_relation = models.PostageConfigRelation.objects\ .filter(postage_config_id=postage_config.id,).last() params.update(postage_config_id=postage_config_relation. weapp_config_relation_id) resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.postage_config', method='post') weapp_config_relation_id = postage_config_relation.weapp_config_relation_id if resp: special_params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'postage_config_id': weapp_config_relation_id } sync_util.sync_zeus(params=special_params, resource='mall.special_postage_config', method='delete') if special_postages: for special_postage in special_postage_create: params = organize_special_postage_config( weapp_postage_config_id=weapp_config_relation_id, special_postage=special_postage) sync_util.sync_zeus( params=params, resource='mall.special_postage_config', method='put') if free_postages: free_params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'postage_config_id': weapp_config_relation_id } sync_util.sync_zeus(params=free_params, resource='mall.free_postage_config', method='delete') for free_postage in free_postage_create: params = organize_free_postage_config( weapp_postage_config_id=weapp_config_relation_id, free_postage=free_postage) sync_util.sync_zeus( params=params, resource='mall.free_postage_config', method='put') response = create_response(200) return response.get_response()
def api_put(request): postage_name = request.POST.get('postage_name', '') default_postages = json.loads(request.POST.get('default_postages')) special_postages = json.loads(request.POST.get('special_postages')) free_postages = json.loads(request.POST.get('free_postages')) postage_config = models.PostageConfig.objects.create( owner=request.user, name=postage_name, first_weight=default_postages[0].get('firstWeight'), first_weight_price=default_postages[0].get('firstWeightPrice'), added_weight=default_postages[0].get('addedWeight'), added_weight_price=default_postages[0].get('addedWeightPrice'), is_enable_special_config=True if special_postages else False, is_enable_free_config=True if free_postages else False, is_enable_added_weight=True if default_postages[0].get('addedWeight') > 0 else False, is_used=False) if special_postages: #特殊地区运费配置 special_postage_create = [] for special_postage in special_postages: selected_ids = [ str(selected_id) for selected_id in special_postage['selectedIds'] ] special_postage_create.append( models.SpecialPostageConfig( owner=request.user, postage_config=postage_config, first_weight=special_postage['firstWeight'], added_weight=special_postage['addedWeight'], first_weight_price=special_postage['firstWeightPrice'], added_weight_price=special_postage['addedWeightPrice'], destination=','.join(selected_ids))) models.SpecialPostageConfig.objects.bulk_create( special_postage_create) if free_postages: #包邮配置 free_postage_create = [] for free_postage in free_postages: selected_ids = [ str(selected_id) for selected_id in free_postage['selectedIds'] ] free_postage_create.append( models.FreePostageConfig( owner=request.user, postage_config=postage_config, condition=free_postage['condition'], condition_value=free_postage['conditionValue'], destination=','.join(selected_ids))) models.FreePostageConfig.objects.bulk_create(free_postage_create) # 同步 if postage_config: user_relation = account_models.AccountHasSupplier.objects.filter( user_id=request.user.id).last() if user_relation: params = organize_postage_config_params( postage_config=postage_config, user_relation=user_relation) resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.postage_config', method='put') if not resp: models.PostageConfig.objects.filter( id=postage_config.id).delete() response = create_response(500) return response.get_response() else: # 存储模板的中间关系 weapp_postage_config = resp_data.get('postage_config') models.PostageConfigRelation.objects.create( postage_config_id=postage_config.id, weapp_config_relation_id=weapp_postage_config.get( 'id')) # 同步特殊运费和普通运费 if special_postages: for special_postage in special_postage_create: params = organize_special_postage_config( weapp_postage_config_id=weapp_postage_config. get('id'), special_postage=special_postage) sync_util.sync_zeus( params=params, resource='mall.special_postage_config', method='put') if free_postages: for free_postage in free_postage_create: params = organize_free_postage_config( weapp_postage_config_id=weapp_postage_config. get('id'), free_postage=free_postage) sync_util.sync_zeus( params=params, resource='mall.free_postage_config', method='put') response = create_response(200) return response.get_response()
def api_delete(request): label_value_id = request.POST.get('label_value_id', 0) response = create_response(500) try: if label_value_id != 0: label_group_values = models.LabelGroupValue.objects.filter( id=label_value_id) label_group_values.update(is_deleted=True) product_has_labels = product_models.ProductHasLabel.objects.filter( property_id=label_group_values[0].property_id, label_ids__icontains=label_value_id) product_catalog_has_labels = catalog_models.ProductCatalogHasLabel.objects.filter( property_id=label_group_values[0].property_id, label_ids__icontains=label_value_id) for product_has_label in product_has_labels: label_ids = [ str(label_id) for label_id in product_has_label.label_ids.split(',') ] if str(label_value_id) in label_ids: label_ids.remove(str(label_value_id)) if label_ids: product_models.ProductHasLabel.objects.filter( id=product_has_label.id).update( label_ids=','.join(label_ids)) else: product_models.ProductHasLabel.objects.filter( id=product_has_label.id).delete() for product_catalog_has_label in product_catalog_has_labels: label_ids = [ str(label_id) for label_id in product_catalog_has_label.label_ids.split(',') ] if str(label_value_id) in label_ids: label_ids.remove(str(label_value_id)) if label_ids: catalog_models.ProductCatalogHasLabel.objects.filter( id=product_catalog_has_label.id).update( label_ids=','.join(label_ids)) else: catalog_models.ProductCatalogHasLabel.objects.filter( id=product_catalog_has_label.id).delete() response = create_response(200) relation = models.LabelGroupValueRelation.objects.filter( label_value_id=label_value_id).first() if relation: params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'product_label_id': relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.product_label', method='delete') if not resp: watchdog.error('sync_delete_label_: %s failed' % label_value_id) # 将有这个标签的商品的标签去掉 params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_id': relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.disable_product_label', method='delete') if not resp: watchdog.error( 'sync_disable_product_label: %s failed' % label_value_id) # 将有这个标签的类目的标签删掉 params = { 'owner_id': PRODUCT_POOL_OWNER_ID, 'label_id': relation.weapp_label_value_id } resp, resp_data = sync_util.sync_zeus( params=params, resource='mall.classification_has_label', method='delete') except: msg = unicode_full_stack() response.innerErrMsg = msg watchdog.error(msg) return response.get_response()