def fill(self, obj, name, hide=None, fields=None, allow_none=True): """简化control层代码: room.fill(self.sroom.get_house_by_hoid(room.HOid), 'house') 等同于: room.house = self.sroom.get_house_by_hoid(room.HOid) room.add('house') 或者: map(lambda x: x.fill(self.sroom.get_house_by_hoid(x.HOid), 'house', hide=('VIid',)), room_detail_list) """ if not obj and not allow_none: msg = u'关联的对象不存在:' + name raise NOT_FOUND(msg) if hide: if isinstance(obj, list): map(lambda x: x.hide(*hide), obj) else: if obj: obj.hide(*hide) if fields: if isinstance(obj, list): map(lambda x: x.clean.add(*fields), obj) else: obj.fields = fields setattr(self, name, obj) return self.add(name)
def get_one_or_default_address(self): if is_tourist(): raise TOKEN_ERROR(u'未登录') uaid = request.args.to_dict().get('uaid') usid = request.user.id logger.debug("get uaid is %s", uaid) if uaid is not None: uafilter = {'UAid': uaid} else: uafilter = {'USid': usid, 'UAdefault': True, 'UAisdelete': False} default_address = self.suesraddress.get_one_or_default_address( uafilter) if not default_address: any_address = self.suesraddress.get_first_no_default_address(usid) if not any_address: raise NOT_FOUND(u'该用户未设置地址信息') address = default_address or any_address if address: logger.info("get address success, now to fill detail") addressinfoes = self.suesraddress.get_addressinfo_by_areaid( address.areaid) for addressinfo in addressinfoes: address.addressinfo = addressinfo address.add("addressinfo") response = import_status("messages_get_item_ok", "OK") response['data'] = address return response
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
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
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
def del_exist_tags(self): if not is_admin(): raise AUTHORITY_ERROR(u'非管理员权限') atid = request.json.get('atid') logger.debug("del exist tags data is %s", request.data) del_info = self.stags.del_exist_tags(atid) if not del_info: raise NOT_FOUND(u"无删除内容") response = import_status("delete_success", "OK") response['data'] = {'atid': atid} return response
def del_comment_admin(self): if not is_admin(): raise AUTHORITY_ERROR(u'当前非管理员') data = request.json acoid = data.get('acoid') logger.debug('del comment data is %s', data) up_info = self.sactivitycomment.delete_comment_by_acoid(acoid) if not up_info: raise NOT_FOUND(u'要删除的数据不存在') data = import_status("delete_success", "OK") data['acoid'] = acoid return data
def del_rewardpacket(self): """删除优惠券集合""" if not is_admin(): raise AUTHORITY_ERROR(u'非管理员权限') data = request.json logger.debug("del reward packet id is %s", data) rptid = data.get('rptid') del_info = self.sraward.update_reward_packet({'RPTid': rptid}, {'RPTisdelete': True}) self.sraward.del_packet_contact({'RPTid': rptid}) if not del_info: raise NOT_FOUND(u'删除失败') data = import_status("delete_success", "OK") data['data'] = {'rptid': rptid} return data
def fill_transfer_detail(self, raward): from WeiDian.service.SUser import SUser if hasattr(raward, 'RFstatus'): reward_info = self.sraward.get_raward_by_id(raward.RAid) # if reward_info.RAtransfer == False: # raise SYSTEM_ERROR(u'信息错误,该券不能被赠送') if not re.match(r'^[0-2]$', str(raward.RFstatus)): raise SYSTEM_ERROR(u'优惠券转赠状态异常') if raward.RFstatus == 0: presenter = SUser().get_user_by_user_id(raward.RFfrom) recipient = SUser().get_user_by_user_id(raward.USid) if not presenter or not recipient: raise NOT_FOUND(u'转赠信息不正确') if raward.USid == request.user.id: usheader = presenter.USheader remarks = '由{0}赠送'.format((presenter.USname).encode('utf8')) tag = '赠送' transfer_valid = True elif raward.RFfrom == request.user.id: usheader = recipient.USheader remarks = '已赠送给{0}'.format((recipient.USname).encode('utf8')) tag = '赠送' transfer_valid = False elif raward.RFstatus == 1: recipient = SUser().get_user_by_user_id(raward.USid) presenter = SUser().get_user_by_user_id(raward.RFfrom) if raward.USid == request.user.id: usheader = presenter.USheader remarks = '因领取后{0}小时未使用已退还给{1}'.format(reward_info.RAtransfereffectivetime, (presenter.USname).encode('utf8')) tag = '已退回' transfer_valid = False elif raward.RFfrom == request.user.id: usheader = recipient.USheader remarks = '{0}领取后{1}小时未使用还回'.format((recipient.USname).encode('utf8'), reward_info.RAtransfereffectivetime) tag = '已还回' transfer_valid = True elif raward.RFstatus == 2: recipient = SUser().get_user_by_user_id(raward.USid) usheader = recipient.USheader remarks = '{0}已使用'.format(str(recipient.USname)) tag = '已使用' transfer_valid = False raward.fill(transfer_valid, 'transfer_valid') raward.fill(usheader, 'usheader') raward.fill(remarks, 'remarks') raward.fill(tag, 'tag') return raward
def get_like_list(self): """获取用户的收藏列表""" if is_tourist(): return TOKEN_ERROR(u'未登录') args = request.args.to_dict() logger.debug("get like list args is %s", args) parameter_required("page_size", "page_num") page_num = args.get("page_num") page_size = args.get("page_size") page_num = 1 if not page_num else int(page_num) page_size = 5 if not page_size else int(page_size) try: productlike_list = self.sproductlike.get_productlike_list_by_usid( request.user.id, page_num, page_size) if not productlike_list: raise NOT_FOUND(u'用户无收藏信息') logger.info("get product like list success") map(self.fill_productinfo, productlike_list) # 获取转发数 from WeiDian.service.SActivity import SActivity from WeiDian.service.SActivityFoward import SActivityFoward total_forward = 0 for prlike in productlike_list: forward_act = SActivity().get_acid_by_filterid({ 'AClinkvalue': prlike.PRid, 'ACSkipType': 2, }) for act in forward_act: forward_num = SActivityFoward().get_fowardnum_by_acid( act.ACid) total_forward = total_forward + forward_num prlike.forwardnum = total_forward prlike.add("forwardnum") prlikecount = self.sproductlike.get_prlike_count_by_usid( request.user.id) data = import_status("get_product_like_success", "OK") data["count"] = prlikecount data["data"] = productlike_list return data except Exception as e: logger.exception("get product like error") raise SYSTEM_ERROR(u'收藏信息不存在')
def user_receive_reward(self): """用户自己领取页面内的优惠券""" if is_tourist(): raise TOKEN_ERROR(u'未登录') data = request.json parameter_required('raid') logger.debug("user recevive data is", data) usid = request.user.id raid = data.get('raid') # 判断发放的优惠券是否还有领取数量 hang_out = self.sraward.is_hand_out({'RAid': raid}) if hang_out: if hang_out.RTcount <= 0: raise NOT_FOUND(u'该优惠券已领取完毕') else: self.sraward.update_is_hand_out({'RAid': hang_out.RAid}, {'RTcount': hang_out.RTcount - 1}) # 判断用户是否已持有 is_hold = self.sraward.is_user_hold_reward({'USid': usid, 'RAid': raid}) if is_hold: logger.info("The user already has this type of reward ") reward_info = self.sraward.get_raward_by_id(raid) urid = is_hold.URid if is_hold.RAnumber < reward_info.RAmaxholdnum: self.sraward.update_user_reward({'RAid': raid}, {'RAnumber': is_hold.RAnumber + 1}) else: raise PARAMS_REDUNDANCE(u'已拥有该券最大可持有数量') else: logger.info("New reward to user") urid = str(uuid.uuid1()) self.sraward.add_model('UserRaward', **{ 'URid': urid, 'USid': usid, 'RAid': raid, }) data = import_status("receive_reward_success", "OK") data['data'] = {'urid': urid } return data
def superadmin_to_update_others(self): if not is_superadmin(): raise AUTHORITY_ERROR(u'当前非超管权限') data = request.json logger.debug("update admin data is %s", data) parameter_required('suid') suid = data.get('suid') password = data.get('password') sulevel = data.get("sulevel") sulevel = 1 if not sulevel else int(sulevel) if sulevel not in [0, 1]: raise PARAMS_ERROR(u'sulevel参数错误') change_suser = self.ssuperuser.get_one_super_by_suid(suid) if not change_suser: raise NOT_FOUND(u'要修改的信息不存在') upinfo = { "SUid": suid, "SUname": data.get("suname"), "SUheader": data.get("suheader"), "SUlevel": sulevel, "SUidfreeze": data.get("suisfreeze"), "SUisdelete": data.get("suisdelete") } upinfo = {k: v for k, v in upinfo.items() if v not in self.empty} if password: if len(password) < 4: raise PARAMS_ERROR(u'密码长度低于4位') zh_pattern = re.compile(u'[\u4e00-\u9fa5]+') match = zh_pattern.search(password) if match: raise PARAMS_ERROR(u'密码包含中文字符') pwdhashed = generate_password_hash(password) upinfo["SUpassword"] = pwdhashed changed = self.ssuperuser.update_info(suid, upinfo) if not changed: raise SYSTEM_ERROR(u"修改信息不存在") response = import_status("update_superinfo_success", "OK") response['data'] = {'suid': suid} return response
def update_sku_price(self): """更新sku里的售价/进价/利润""" if not is_admin(): raise AUTHORITY_ERROR(u'请使用管理员账号重新登录') data = request.json pskid = data.get('pskid') parameter_required('pskid') logger.debug("update sku price data is %s", data) sku_info = self.sproductskukey.get_psk_by_pskid(pskid) if not sku_info: raise NOT_FOUND(u'没有找到相应的sku') price_dict = { "PSKprice": data.get('pskprice'), "PSKprofict": data.get('pskprofict'), "PSKpurchase": data.get('pskpurchase') } price_dict = { k: v for k, v in price_dict.items() if v not in self.empty } if price_dict not in self.empty: up_info = self.sproductskukey.update_sku_price_by_filter( {'PSKid': pskid}, price_dict) if not up_info: raise SYSTEM_ERROR(u'更新数据错误') # 操作日志 operation_dict = { "PSKprice": u'更新售价', "PSKprofict": u'更新利润', "PSKpurchase": u'更新进货价' } if price_dict not in self.empty: for i in price_dict.keys(): self.__make_product_recording(sku_info.PRid, sku_info.PSskuid, operation_dict[i]) response = import_status("update_success", "OK") response['data'] = {'pskid': pskid} return response
def update_reward(self): """更换优惠券集合或删除""" if not is_admin(): raise AUTHORITY_ERROR(u'非管理员权限') data = request.json logger.debug("update or del reward id is %s", data) raid = data.get('raid') raisdelete = data.get('raisdelete') rptid = data.get('rptid') if raisdelete: upinfo = self.sraward.update_reward({'RAid': raid}, {'RAisdelete': raisdelete}) if not upinfo: raise NOT_FOUND(u'删除失败') elif rptid is not None: self.sraward.del_packet_reward(raid) if rptid: self.sraward.add_model('RewardPacketContact', **{ 'RPCid': str(uuid.uuid1()), 'RAid': raid, 'RPTid': rptid }) data = import_status("update_success", "OK") data['data'] = {'raid': raid} return data
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
def give_reward_to_others(self): """转赠优惠券(暂时用不到)""" if is_tourist(): raise TOKEN_ERROR(u'未登录') data = request.json usid = data.get('usid') urid = data.get('urid') # 在自己的普通券表中拥有 is_own_hold = self.sraward.is_user_hold_reward({'USid': request.user.id, 'URid': urid}) # 送出去过,但是已退回,可以继续转赠 is_own_gift_hold = self.sraward.is_user_hold_reward_in_gift({'RFfrom': request.user.id, 'RFid': urid, 'RFstatus': 1}) if is_own_hold: raid = is_own_hold.RAid elif is_own_gift_hold: raid = is_own_gift_hold.RAid else: raise NOT_FOUND(u'用户无此优惠券') reward_info = self.sraward.get_raward_by_id(raid) if reward_info.RAtransfer == False: raise SYSTEM_ERROR(u'该券不允许转赠') return_time = reward_info.RAtransfereffectivetime # 转赠有效时间,退回时间 # 已经赠送了该券给接收者,接收者还没用,且未到退回时间 is_recivice_gift_hold = self.sraward.is_user_hold_reward_in_gift({'RAid': raid, 'USid': usid, 'RFstatus': 0, 'RFfrom': request.user.id}) if is_recivice_gift_hold: raise SYSTEM_ERROR(u'您已赠送过该券给用户') # 接收者已经拥有其他人送的该券, 不影响, 忽略 # is_recivice_hold_from_other = self.sraward.is_user_hold_reward({'USid': usid, 'RAid': raid}) # 接收者原来已经拥有此券了 is_recivice_hold = self.sraward.is_user_hold_reward({'RAid': raid}) if is_own_gift_hold: up_reward_info = self.sraward.update_reward_transfer_info({'RFfrom': request.user.id, 'RFid': urid, 'RFstatus': 1}, {'USid':usid, 'RFstatus': 0}) if not up_reward_info: raise SYSTEM_ERROR(u'再次转送失败') if is_own_hold and is_recivice_hold: if is_own_hold.RAnumber > 0 and is_recivice_hold.RAnumber < reward_info.RAmaxholdnum: logger.info("The user already has this type of reward ") update_reward = self.sraward.update_user_reward({'URid': is_own_hold.URid}, {'RAnumber': is_own_hold.RAnumber - 1}) # self.sraward.update_user_reward({'RAid': raid}, {'RAnumber': is_recivice_hold.RAnumber + 1}) rfid = str(uuid.uuid1()) self.sraward.add_model('RewardTransfer', **{ 'RFid': rfid, 'USid': usid, 'RAid': raid, 'URFrom': request.user.id, 'RAnumber': 1, 'RFendtime': (datetime.now() + timedelta(hours=int(return_time))).strftime(format_for_db), 'RFstatus': 0 }) if not update_reward: raise PARAMS_ERROR(u'更新参数错误') else: raise NOT_FOUND(u'您已没有可赠送数量或赠送用户已拥有该券最大可持有数') elif is_own_hold and not is_recivice_hold: if is_own_hold.RAnumber > 0: logger.info("New reward to user") rfid = str(uuid.uuid1()) self.sraward.add_model('RewardTransfer', **{ 'RFid': rfid, 'USid': usid, 'RAid': raid, 'URFrom': request.user.id, 'RAnumber': 1, 'RFendtime': (datetime.now() + timedelta(hours=int(return_time))).strftime(format_for_db), 'RFstatus': 0 }) else: raise NOT_FOUND(u'您已没有可赠送的数量') else: raise NOT_FOUND(u'您已没有可赠送的数量') data = import_status("give_to_others_success", "OK") data['data'] = {'urid': urid} return data
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
def get_one_reward(self): """获取单张优惠券详情""" if is_tourist(): raise TOKEN_ERROR(u'未登录') # parameter_required('raid') args = request.args.to_dict() raid = args.get('raid') urid = args.get('urid') logger.debug("get reward info is %s", args) if urid: # 是赠送者原表里的 is_presenter_own_hold = self.sraward.is_user_hold_reward({'URid': urid}) # 在赠送者转赠表中,送出去过,已退回,可以继续转赠 is_presenter_gift_hold = self.sraward.is_user_hold_reward_in_gift( {'RFid': urid, 'RFstatus': 1}) if is_presenter_own_hold: raid = is_presenter_own_hold.RAid reward = self.sraward.get_raward_by_id(raid) reward_detail = self.fill_reward_detail(reward) is_presenter_own_hold.fill(reward_detail, 'reward_detail') elif is_presenter_gift_hold: raid = is_presenter_gift_hold.RAid gift = self.fill_transfer_detail(is_presenter_gift_hold) gift_detail = self.sraward.get_raward_by_id(raid) gift_detail = self.fill_reward_detail(gift_detail) # 检验转赠券在各情况下的有效性 gift_detail.valid = gift_detail.valid and gift.transfer_valid gift.fill(gift_detail, 'reward_detail') gift.RFcreatetime = get_web_time_str(gift.RFcreatetime) gift.RFendtime = get_web_time_str(gift.RFendtime) gift_dict = { 'urid': gift.RFid, 'usid': gift.USid, 'raid': gift.RAid, 'ranumber': gift.RAnumber, 'urcreatetime': gift.RFcreatetime, 'reendtime': gift.RFendtime, 'rffrom': gift.RFfrom, 'rfstatus': gift.RFstatus, 'urusetime': gift.RFusetime, 'remarks': gift.remarks, 'tag': gift.tag, 'usheader': gift.usheader, 'reward_detail': gift.reward_detail } else: raise NOT_FOUND(u'无此转赠优惠券信息') reward_detail = is_presenter_own_hold or gift_dict else: reward_info = self.sraward.get_raward_by_id(raid) if not reward_info: raise NOT_FOUND(u'无此券信息') reward_detail = self.fill_reward_detail(reward_info) presenter = self.suser.get_user_by_user_id(request.user.id) data = import_status("messages_get_item_ok", "OK") data['usname'] = presenter.USname data['usheader'] = presenter.USheader data['data'] = reward_detail return data
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