def create(corp, name, product_ids=None): category_model = mall_models.ProductCategory.create( owner = corp.id, name = name, product_count = len(product_ids) if product_ids else 0 ) if product_ids: for product_id in product_ids: mall_models.CategoryHasProduct.create( product = product_id, category = category_model.id ) Category.update_product_count(category_model.id) msgutil.send_message( TOPIC['product'], 'add_products_to_category', { 'corp_id': corp.id, 'product_ids': product_ids, 'category_id': category_model.id } ) return Category.from_model({ "db_model": category_model })
def send_reject_product_message(product_name=None, reject_reason=None, customer_id=None, customer_name=None): """ 商品驳回 """ customer_id = customer_id if customer_id.startswith('wzc_') else '' msg_name = 'add_customer_news' data = { 'news': { 'author_username': '******', 'author_name': '机器人', 'title': '审核通知', 'summary': '商品审核未通过(已通过)', 'description': '商品名:%s,已被操作为:入库审核驳回,驳回原因:%s' % (product_name.encode('utf8'), reject_reason.encode('utf8')), 'customer_id': str(customer_id).encode('utf8'), 'customer_name': customer_name.encode('utf8') } } msgutil.send_message(topic_name, msg_name, data)
def process(data, recv_msg=None): """ 发货出货单的消息处理 """ corp_id = data['corp_id'] delivery_item_id = data['delivery_item_id'] to_status = data['to_status'] # 订阅快递推送 topic_name = TOPIC['base_service'] data = { "delivery_item_id": delivery_item_id, "corp_id": corp_id } msgutil.send_message(topic_name, 'notify_kuaidi_task', data) # 发送模板消息 topic_name = TOPIC['base_service'] data = { "corp_id": corp_id, "type": "delivery_item", "delivery_item_id": delivery_item_id, 'to_status': to_status } msgutil.send_message(topic_name, 'send_order_template_message_task', data)
def delete_verified_products(self, product_ids): """ 从商品池删除商品 @param product_ids: @return: """ if product_ids: #在product pool中删除 mall_models.ProductPool.update( display_index=NEW_PRODUCT_DISPLAY_INDEX, status=mall_models.PP_STATUS_DELETE).dj_where( product_id__in=product_ids, woid=self.corp_id).execute() #从分组中删除 self.corp.category_repository.delete_products_in_categories( product_ids) #对于代销商品,重新将其放回商品池 mall_models.ProductPool.update( status=mall_models.PP_STATUS_ON_POOL).dj_where( product_id__in=product_ids, woid=self.corp_id, type=mall_models.PP_TYPE_SYNC).execute() self.__compatible_delete_products(product_ids) topic_name = TOPIC['product'] msg_name = 'product_deleted' data = {"corp_id": self.corp.id, "product_ids": product_ids} msgutil.send_message(topic_name, msg_name, data) return True
def send_product_outgiving_message(corp_id, product_id): msgutil.send_message(TOPIC['product'], 'outgiving_product', { 'corp_id': corp_id, 'product_id': product_id }) print corp_id, 'send_outgiving_product_message...', product_id
def update(self, update_params): """ 更新积分规则 """ corp = CorporationFactory.get() member_models.IntegralStrategySettings.update( integral_each_yuan=update_params['integral_each_yuan'], be_member_increase_count=update_params['be_member_increase_count'], click_shared_url_increase_count=0, buy_award_count_for_buyer=update_params[ 'buy_award_count_for_buyer'], order_money_percentage_for_each_buy=update_params[ 'order_money_percentage_for_each_buy'], buy_via_shared_url_increase_count_for_author=0, buy_via_offline_increase_count_for_author=update_params[ 'buy_via_offline_increase_count_for_author'], buy_via_offline_increase_count_percentage_for_author=update_params[ 'buy_via_offline_increase_count_percentage_for_author'], use_ceiling=update_params['use_ceiling'], review_increase=update_params['review_increase']).dj_where( webapp_id=corp.webapp_id).execute() msg_name = 'webapp_owner_info_updated' topic_name = TOPIC['mall_config'] data = { "corp_id": corp.id, } msgutil.send_message(topic_name, msg_name, data)
def send_sync_product_message(product_name=None, platforms=[], customer_id=None, customer_name=None): """ 商品同步 """ customer_id = customer_id if customer_id.startswith('wzc_') else '' msg_name = 'add_customer_news' platforms_string = u'、'.join(platforms) data = { 'news': { 'author_username': '******', 'author_name': '机器人', 'title': '审核通知', 'summary': '商品审核已通过', 'description': '商品名:%s,已被操作为:已入库,已同步,同步同平台分别为:%s' % (product_name.encode('utf8'), platforms_string.encode('utf8')), 'customer_id': str(customer_id).encode('utf8'), 'customer_name': customer_name.encode('utf8') } } msgutil.send_message(topic_name, msg_name, data)
def send_stop_sell_product_message(product_name=None, stop_reason=None, customer_id=None, customer_name=None): """ 商品停售 """ customer_id = customer_id if customer_id.startswith('wzc_') else '' msg_name = 'add_customer_news' data = { 'news': { 'author_username': '******', 'author_name': '机器人', 'title': '停售通知', 'summary': '商品撤架停售', 'description': '商品名:%s,已被操作为:已入库,已停售,停售原因:%s' % (product_name.encode('utf8'), stop_reason.encode('utf8')), 'customer_id': str(customer_id).encode('utf8'), 'customer_name': customer_name.encode('utf8') } } msgutil.send_message(topic_name, msg_name, data)
def add_products(self, product_ids): """ 向分组中添加一组商品 先过滤出CategoryHasProduct表中已经存在的<category_id, product_id>对,只向表中添加新的<category_id, product_id>对 """ if product_ids: relations = mall_models.CategoryHasProduct.select().dj_where(product_id__in=product_ids, category_id=self.id) existed_product_ids = set([relation.product_id for relation in relations]) product_ids = set(product_ids) new_product_ids = product_ids - existed_product_ids if new_product_ids: for product_id in new_product_ids: mall_models.CategoryHasProduct.create( product = product_id, category = self.id ) Category.update_product_count(self.id) msgutil.send_message( TOPIC['product'], 'add_products_to_category', { 'corp_id': CorporationFactory.get().id, 'product_ids': list(new_product_ids), 'category_id': self.id } )
def create(self, args): name = args['name'] default_config = args['default_config'] is_enable_special_config = args.get('is_enable_special_config', False) special_configs = args['special_configs'] is_enable_free_config = args['is_enable_free_config'] free_configs = args['free_configs'] corp_id = self.corp.id postage_config = mall_models.PostageConfig.create( owner=corp_id, supplier_id=corp_id, name=name, first_weight=round(float(default_config.get('first_weight', 0.0)), 1), first_weight_price=round( float(default_config.get('first_weight_price', 0.0)), 2), added_weight=str( round(float(default_config.get('added_weight', 0.0)), 1)), added_weight_price=str( round(float(default_config.get('added_weight_price', 0.0)), 2)), is_enable_special_config=args['is_enable_special_config'], is_enable_free_config=args['is_enable_free_config'], is_used=False) if is_enable_special_config: for special_config in special_configs: special_config = mall_models.SpecialPostageConfig.create( owner=corp_id, postage_config=postage_config, destination=special_config.get('destinations', ''), first_weight=round( float(special_config.get('first_weight', 0.0)), 1), first_weight_price=round( float(special_config.get('first_weight_price', 0.0)), 2), added_weight=str( round(float(special_config.get('added_weight', 0.0)), 1)), added_weight_price=str( round( float(special_config.get('added_weight_price', 0.0)), 2))) if is_enable_free_config: for free_config in free_configs: free_config = mall_models.FreePostageConfig.create( owner=corp_id, postage_config=postage_config, destination=free_config.get('destinations', ''), condition=free_config.get('condition', 'count'), condition_value=free_config.get('value', '')) # 发送更新缓存的消息 msgutil.send_message(TOPIC['product'], 'postage_config_updated', { 'corp_id': corp_id, 'postage_config_id': postage_config.id }) return postage_config
def update(self, args): update_params = self.__build_update_params(args) corp = CorporationFactory.get() mall_models.MallConfig.update(**update_params).dj_where( owner_id=corp.id).execute() msgutil.send_message(TOPIC['product'], 'mall_config_updated', {'corp_id': corp.id})
def __send_message_to_topic(self): corp_id = CorporationFactory.get().id msg_name = 'webapp_owner_info_updated' topic_name = TOPIC['mall_config'] data = { "corp_id": corp_id, } msgutil.send_message(topic_name, msg_name, data)
def send_to_ding(text, cid): if settings.MODE == "deploy": uuid = 199597313 else: uuid = 80035247 data = {"uuid": uuid, "content": text} msgutil.send_message('notify', 'ding', data)
def __send_msg_to_topic(self, product_id, msg_name, category_id=0): topic_name = TOPIC['product'] data = { "product_id": product_id, "corp_id": self.corp.id, "category_id": category_id, } msgutil.send_message(topic_name, msg_name, data)
def put(args): order_id = args['order_id'] express_company_name = args['express_company_name'] express_number = args['express_number'] data_mns = [] data = { 'order_id': order_id, 'express_company_name': express_company_name, 'express_number': express_number } resp = Resource.use('zeus').put({ 'resource': 'mall.delivery', 'data': data }) errcode = SYSTEM_ERROR_CODE # 获取app_id传送到mns进行消息处理 pay_log = PayLog.from_order_id({"order_id": order_id}) if pay_log: app_id = pay_log.appid else: watchdog.info( "order paylog is not exits, delivery mns message send failed!! order_id:{}, msg:{}" .format(order_id, unicode_full_stack()), log_type='OPENAPI_ORDER') errcode = DELIVERY_ORDER_HAS_NO_PAYLOG return {'errcode': errcode, 'errmsg': code2msg[errcode]} topic_name = TOPIC['order'] data_mns['order_id'] = order_id data_mns['app_id'] = app_id or '' data_mns['express_company_name'] = express_company_name data_mns['express_number'] = express_number if resp: if resp['code'] == 200: if resp['data']['result'] == 'SUCCESS': errcode = SUCCESS_CODE data = {'errcode': errcode} msgutil.send_message(topic_name, 'delivery_item_shipped', data_mns) return data else: if resp['data']['msg'] == u'不能对当前订单发货': errcode = DELIVERY_ORDER_HAS_MULTIPLE_CHILD_ORDERS elif resp['data']['msg'] == u'订单状态已经改变': errcode = DELIVERY_ORDER_STATUS_ERROR elif resp['data']['msg'] == u'订单不存在': errcode = DELIVERY_ORDER_NOT_EXIST watchdog.info( "delivery failed!! errcode:{}, order_id:{}".format( errcode, order_id), log_type='OPENAPI_ORDER') if errcode == SYSTEM_ERROR_CODE: watchdog.error("delivery failed!! errcode:{}, msg:{}".format( errcode, unicode_full_stack()), log_type='OPENAPI_ORDER') return {'errcode': errcode, 'errmsg': code2msg[errcode]}
def handle(self, **options): """ 取消“团购”超时的未付款订单的 """ try: webapp_ids = [] relations = mall_models.OrderHasGroup.objects.filter( group_status=mall_models.GROUP_STATUS_ON) for relation in relations: if relation.webapp_id not in webapp_ids: webapp_ids.append(relation.webapp_id) webapp_id2user = dict([ (user_profile.webapp_id, user_profile.user) for user_profile in UserProfile.objects.filter( webapp_id__in=webapp_ids) ]) order_ids = [] orders = mall_models.Order.objects.filter( order_id__in=[r.order_id for r in relations], status=mall_models.ORDER_STATUS_NOT, created_at__lte=datetime.now() - timedelta(minutes=15)) for order in orders: try: update_order_status(webapp_id2user[order.webapp_id], 'cancel', order) relations.filter(order_id=order.order_id).update( group_status=mall_models.GROUP_STATUS_failure) logging.info(u"团购15分钟未支付订单order_id:%s取消成功" % order.order_id) order_ids.append(order.order_id) except: notify_msg = u"团购未支付订单{},取消失败, cause:\n{}".format( order.order_id, unicode_full_stack()) watchdog_error(notify_msg) continue watchdog_info({ 'hint': 'cancel_group_order_and_notify_pay', 'order_ids': 'order_ids', 'uuid': 'cancel_group_order_and_notify_pay' }) if not settings.IS_UNDER_BDD and order_ids: # BDD时不发消息 topic_name = "order-close" data = { "name": "cancel_group_order_and_notify_pay", "data": { "order_ids": order_ids } } msg_name = "cancel_order" msgutil.send_message(topic_name, msg_name, data) except: notify_msg = u"团购未支付订单取消失败, cause:\n{}".format( unicode_full_stack()) watchdog_error(notify_msg) print "success"
def create_default_webapp_config(self): """ 创建默认的WebappConfig对象 """ mall_config = mall_models.MallConfig.create(owner=self.corp.id, order_expired_day=24) msgutil.send_message(TOPIC['product'], 'mall_config_created', {'corp_id': self.corp.id}) return WebappConfig(mall_config)
def send_sync_product_message(product=None, user_id=None, image_paths=None): """ 首次同步商品信息 """ data = organize_product_message_info(product=product, user_id=user_id, image_paths=image_paths) msgutil.send_message(PRODUCT_TOPIC_NAME, PRODUCT_MSG_NAME, data)
def delete_category(self, category_id): mall_models.CategoryHasProduct.delete().dj_where( category=category_id).execute() mall_models.ProductCategory.delete().dj_where( owner_id=self.corp.id, id=category_id).execute() msgutil.send_message(TOPIC['product'], 'category_deleted', { 'category_id': category_id, 'corp_id': self.corp.id })
def send_product_change_reject_status(product=None, user_id=None, image_paths=None): """ 商品被入库驳回,用户重新提交审核,商品变为待入库状态 """ data = organize_product_message_info(product=product, user_id=user_id, image_paths=image_paths) msgutil.send_message(PRODUCT_TOPIC_NAME, PRODUCT_MSG_NAME, data)
def delete_postage_config(self, postage_config_id): """ 删除指定的postage config """ mall_models.PostageConfig.update(is_deleted=True).dj_where( id=postage_config_id, owner_id=self.corp.id).execute() msgutil.send_message(TOPIC['product'], 'postage_config_updated', { 'corp_id': self.corp.id, 'postage_config_id': postage_config_id })
def send_product_created_cache(product_id, product_name): """ 新增商品 """ msgutil.send_message(TOPIC['product'], 'new_product_enter_pool', { "product_id": product_id, 'name': product_name }) print 'send_sync_product_updated_message...', product_id
def __send_msg_to_topic(self, msg_name, from_status, to_status): topic_name = TOPIC['order'] data = { "order_id": self.id, "order_bid": self.bid, "corp_id": self.context['corp'].id, "from_status": mall_models.ORDER_STATUS2MEANINGFUL_WORD[from_status], "to_status": mall_models.ORDER_STATUS2MEANINGFUL_WORD[to_status] } msgutil.send_message(topic_name, msg_name, data)
def send_sync_weapp_account_change(product_id=None): """ 同步不同平台信息(如果取消同步了,也需要同步状态信息) """ data = { 'product_id': product_id, 'show_list': product_show_list(product_id=product_id), 'push_status': get_product_status(product_id=product_id) } msgutil.send_message(PRODUCT_TOPIC_NAME, PRODUCT_MSG_NAME, data)
def send_product_change(supplier_id, product_id): """ 商品创建、更新 """ msgutil.send_message( TOPIC['notify'], 'pre_product_update_ding', { 'uuid': DING_UUID['update_product'], 'supplier_id': supplier_id, 'product_id': product_id }) print supplier_id, 'send_product_change...', product_id
def set_used(self): """ 将当前postage config设置为"使用" """ corp_id = CorporationFactory.get().id mall_models.PostageConfig.update(is_used=False).dj_where(id__not=self.id, owner_id=corp_id).execute() mall_models.PostageConfig.update(is_used=True).dj_where(id=self.id).execute() msgutil.send_message( TOPIC['product'], 'postage_config_set_used', {'corp_id': corp_id, 'postage_config_id': self.id} )
def cleanup_cache(self): """ 有用 @return: """ openid = member_models.MemberHasSocialAccount.select().dj_where( member_id=self.id).first().account.openid # 先暂时使用mall_config主题,目的是为了省两块钱TODO topic_name = TOPIC['mall_config'] msg_name = 'member_info_updated' data = {"weapp_id": self.webapp_id, "openid": openid} msgutil.send_message(topic_name, msg_name, data)
def delete_property_value(self, property_value_id): """ 删除指定的商品规格属性的属性值 """ mall_models.ProductModelPropertyValue.update(is_deleted=True).dj_where( id=property_value_id).execute() # 发送更新缓存的消息 msgutil.send_message( TOPIC['product'], 'product_model_property_value_deleted', { 'corp_id': self.corp.id, 'product_model_property_value': property_value_id })
def add_property_value(self, name, pic_url): """ 向商品规格属性中添加一个property value(规格值) """ property_value = mall_models.ProductModelPropertyValue.create( property=self.id, name=name, pic_url=pic_url) msgutil.send_message( TOPIC['product'], 'product_model_property_value_created', { 'corp_id': CorporationFactory.get().id, 'product_model_property_value_id': property_value.id }) return property_value
def __send_msg_to_topic(self, msg_name, from_status, to_status): topic_name = TOPIC['delivery_item'] data = { "delivery_item_id": self.id, "delivery_item_bid": self.bid, "corp_id": self.context['corp'].id, "from_status": mall_models.ORDER_STATUS2MEANINGFUL_WORD[from_status], "to_status": mall_models.ORDER_STATUS2MEANINGFUL_WORD[to_status] } logging.info('send mns message:{}'.format(data)) msgutil.send_message(topic_name, msg_name, data)