def add_bedroom(self): """添加卧室, 以及卧室入住信息""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('roid', 'bbrnum'), forbidden=('bbrid', 'bbrstatus')) room = self.sroom.get_room_by_roid(data.get('roid')) mod = {} data['bbrid'] = str(uuid.uuid4()) mod['BedroomBehindRoom'] = data if not room: raise NOT_FOUND(u'不存在的房源id') if 'bbrshowprice' in data: # 卧室未租出 data['BBRstatus'] = 2 elif 'usgender' in data: # 已经租出 data['BBRstatus'] = 5 mod['UserBedroomBehindRoom'] = { 'UBBRid': str(uuid.uuid4()), 'BBRid': data['bbrid'], 'USgender': data.get('usgender') } else: raise PARAMS_ERROR(u'缺少必要的参数') self.sroom.add_models(mod) cache.delete('room_detail::{}'.format(data.get('roid'))) return Success(u'添加成功', {'bbrid': data['bbrid']})
def cleaner_appiontment(self): """清洁服务预约""" if is_admin(): raise TOKEN_ERROR(u'普通用户才可以预约') if is_tourist(): raise TOKEN_ERROR(u'请登录后预约') required = ('sceid', 'uctpreviewstarttime', 'uctaddr', 'uctpreviewlastingtime', 'uctphone', 'uctprice', 'uctlocation') data = parameter_required(required, others='ignore') cleaner_exists = self.sserver.get_cleanerserver_by_sceid( data.get('sceid')) if not cleaner_exists: raise NOT_FOUND(u'不存在的清洁服务') data['uctphone'] = data.get('uctphone').strip() validate_phone(data.get('uctphone')) self._allow_starttime(data.get('uctpreviewstarttime')) data['uctid'] = str(uuid.uuid4()) data['usid'] = request.user.id data['UCTcreatetime'] = datetime.strftime(datetime.now(), format_for_db) uctlocation = data.get('uctlocation') data['Citynum'] = BdMap(uctlocation).city_id # 获取城市id modelbean_dict = self.sserver.add_model( 'UserCleanTrade', data, ['UCTpreviewstarttime', 'UCTid']) modelbean_dict['name'] = cleaner_exists.SCMtitle return Success(u'预约成功', modelbean_dict)
def user_cancle_fixer_order(self): """用户取消维修订单""" if is_tourist(): return TOKEN_ERROR(u'请先登录') if is_admin(): return TOKEN_ERROR(u'请使用普通用户登录') data = parameter_required(('uftid', )) uftid = data.get('uftid') usid = request.user.id order = self.strade.get_fixer_order_by_uftid(uftid) if not order: raise NOT_FOUND(u'没有该订单') if order.USid != usid: # 判断订单是否是该用户的 raise NOT_FOUND(u'他人订单') if order.UFTstatus == 0: # 如果订单状态是未付款 canceled = self.strade.update_fixerorder_detail_by_uftid( uftid, { 'UFTstatus': 5 # 交易关闭 }) msg = u'操作完成' if canceled else u'无此记录' elif order.UFTstatus == 1: # 订单状态是付款成功后的等待服务 apply_forrefund = self.strade.update_fixerorder_detail_by_uftid( uftid, { 'UFTstatus': 3 # 申请退款中 }) msg = u'操作完成' if apply_forrefund else u'无此记录' elif order.UFTstatus == 3: raise PARAMS_ERROR(u'正在申请退款中') elif order.UFTstatus == 4: raise PARAMS_ERROR(u'退款中') else: raise PARAMS_ERROR(u'服务已完成或已关闭') return Success(msg, {'uftid': uftid})
def add_providehouse_apply(self): """申请提交房源""" if is_admin(): return TOKEN_ERROR(u'普通用户才可以申请') if is_tourist(): return TOKEN_ERROR(u'请登录后申请') data = parameter_required( ('phacity', 'phavillege', 'phaphone', 'phaname'), others='ignore') validate_phone(data.get('phaphone')) usid = request.user.id already_apply = self.strade.get_provide_appy_by_usid_village( usid, data.get('phavillege')) if already_apply: last_applytime = datetime.strptime(already_apply.PHAcreatetime, format_for_db) seconds = (datetime.now() - last_applytime).total_seconds() if seconds < 600: # 短时间内重复提交不记录 return Success(u'申请成功, 等待管家回电') data['usid'] = usid data['PHAcreatetime'] = datetime.strftime(datetime.now(), format_for_db) data['PHAid'] = str(uuid.uuid4()) self.strade.add_model('ProvideHouseApply', data) return Success(u'申请成功, 等待管家回电')
def mover_appointment(self): """搬家预约""" if is_admin(): return TOKEN_ERROR(u'普通用户才可以预约') if is_tourist(): return TOKEN_ERROR(u'请登录后预约') required = ('smsid', 'umtstarttime', 'umtmoveoutaddr', 'umtmoveinaddr', 'umtmoveoutlocation', 'umtmoveinlocation', 'umtphone', 'umtpreviewprice') data = parameter_required(required, others='allow') # 是否存在这个服务 mover_exsits = self.sserver.get_mover_by_smsid(data.get('smsid')) if not mover_exsits: raise NOT_FOUND(u'不存在服务{}'.format(data.get('smsid'))) data['umtphone'] = data['umtphone'].strip() validate_phone(data.get('umtphone')) self._allow_starttime(data.get('umtstarttime')) data['UMTid'] = str(uuid.uuid4()) data['usid'] = request.user.id data['UMTcreatetime'] = datetime.strftime(datetime.now(), format_for_db) umtmoveoutlocation = data.get('umtmoveoutlocation') data['Citynum'] = BdMap(umtmoveoutlocation).city_id model_bean_dict = self.strade.add_model('UserMoveTrade', data, ['UMTstarttime', 'UMTid']) model_bean_dict['name'] = mover_exsits.SMStitle return Success(u'预约成功', model_bean_dict)
def update_staff(self): """修改工作人员信息""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') json_data = parameter_required(('stfid', ), others='allow') stfid = json_data.get('stfid') data = { 'STFname': json_data.get('stfname'), 'STFmobiel': json_data.get('stfmobiel'), 'STFphone': json_data.get('stfphone'), 'STFaddress': json_data.get('stfaddress'), 'STFgender': json_data.get('stfgender'), 'STFlevel': json_data.get('stflevel'), 'ADaddressnum': json_data.get('adaddressnum'), 'APid': json_data.get('apid'), 'ADdesc': json_data.get('addesc'), 'STFisblocked': json_data.get('stfisblocked'), } data = { k: v for k, v in data.items() if v is not None } staff = self.suser.update_staff_info(stfid, data) if not staff: return Success(u'无此记录', { 'stfid': stfid }) else: return Success(u'修改成功', { 'stfid': stfid })
def pay_for_service(self): data = parameter_required() if is_tourist(): raise TOKEN_ERROR() if is_admin(): raise AUTHORITY_ERROR(u'请使用普通用户登陆') usid = request.user.id user = self.suser.get_user_by_usid(usid) openid = user.WXopenid if 'umtid' in data: umtid = data.get('umtid') usermoverorder = self.strade.get_mover_order_by_umtid(umtid) if not usermoverorder or usermoverorder.UMTstatus != 0: raise NOT_FOUND() total_fee = usermoverorder.UMTpreviewprice out_trade_no = self.pay.nonce_str self.strade.update_movertrade_detail_by_umtid( umtid, {'sn': out_trade_no}) body = u'邻家搬家' attach = u'mover' elif 'uctid' in data: uctid = data.get('uctid') user_clean_order = self.strade.get_clean_order_by_uctid(uctid) if not user_clean_order or user_clean_order.UCTstatus != 0: raise NOT_FOUND() total_fee = user_clean_order.UCTprice out_trade_no = self.pay.nonce_str self.strade.update_cleanorder_detail_by_uctid( uctid, {'sn': out_trade_no}) body = u'cleaner' attach = u'cleaner' elif 'uftid' in data: uftid = data.get('uftid') user_fixer_order = self.strade.get_fixer_order_by_uftid(uftid) if not user_fixer_order or user_fixer_order.UFTstatus != 0: raise NOT_FOUND() total_fee = user_fixer_order.UFTprice out_trade_no = self.pay.nonce_str self.strade.update_fixerorder_detail_by_uftid( uftid, {'sn': out_trade_no}) body = u'fixer' attach = u'fixer' else: raise PARAMS_ERROR() try: total_fee *= 100 raw = self.pay.jsapi(trade_type="JSAPI", openid=openid, body=body, out_trade_no=out_trade_no, total_fee=int(total_fee), attach=attach, spbill_create_ip=request.remote_addr) res = dict(raw) res['paySign'] = res.get('sign') except WeixinPayError as e: return SYSTEM_ERROR(e.message) return Success(res)
def delete_guide(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('cgid', )) cgid = data.get('cgid') deleted = self.sroom.update_guide(cgid, {'CGisdelete': True}) msg = u'删除成功' if deleted else u'无此记录' return Success(msg, {'cgid': cgid})
def cancle_hot_city(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('city_id', )) city_id = data.get('city_id') updated = self.scity.update_room_open_city(city_id, {'ishot': False}) msg = u'更新成功' if updated else u'该成功暂未开通服务' return Success(msg, {'city_id': city_id})
def update_villeginfo(self): """修改小区信息""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('id', )) updated = self.sroom.update_villege_info(data.get('id'), data) msg = u'更新成功' if updated else u'无此记录' return Success(msg, {'id': data.get('id')})
def add_room(self): """添加房源""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') required = ('roname', 'roimage', 'roareanum', 'roface', 'roarea', 'roshowprice', 'roshowpriceunit', 'rorenttype', 'rodecorationstyle', 'rocitynum', 'roareanum', 'rosubwayaround', 'house', 'villegeid', 'medias', 'stfid') data = parameter_required(required, forbidden=( 'roid', 'hoid', )) house = data.pop('house', None) medias = data.pop('medias', []) tags = data.pop('tags', []) roomrequirment = data.pop('roomrequirment', None) # 是否存在小区 villege = self.sroom.get_villege_info_by_id(data.get('villegeid')) if not villege: raise NOT_FOUND(u'请添加小区信息') # 初始化添加参数 mod = {} roid = str(uuid.uuid4()) create_time = datetime.strftime(datetime.now(), format_for_db) house['hoid'] = data['hoid'] = data['roid'] = roid # 添加房源 data['ROcreatetime'] = create_time data['ROdistance'] = villege.subway_primary data['ROaroundequirment'] = villege.around data['ROsubwayposionname'] = villege.position mod['Room'] = data # 添加媒体 try: map(lambda x: x.setdefault('roid', roid), medias) map(lambda x: x.setdefault('reid', str(uuid.uuid4())), medias) mod['RoomMedia'] = medias except Exception as e: raise PARAMS_ERROR(u'medias参数有误') # 添加house houseinfo_required = ('hofloor', 'hototalfloor', 'hobedroomcount', 'hoparlorcount') parameter_required(houseinfo_required, datafrom=house) house['VIid'] = data.get('villegeid') mod['House'] = house # 添加tag try: map(lambda x: x.setdefault('roid', roid), tags) map(lambda x: x.setdefault('rtid', str(uuid.uuid4())), tags) mod['RoomTag'] = tags except Exception as e: raise PARAMS_ERROR(u'tags参数有误') # 添加设备: if roomrequirment: roomrequirment['roid'] = roid roomrequirment['reid'] = str(uuid.uuid4()) mod['RoomEquirment'] = roomrequirment self.sroom.add_models(mod) return Success(u'添加成功', {'roid': roid})
def add_customerguide(self): """添加入住指南""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('cgtitle', 'cgtext', 'cgsort'), forbidden=('cgid', )) data['cgid'] = str(uuid.uuid4()) added = self.sroom.add_model('CustomerGuide', data) return Success(u'添加成功', {'cgid': data.get('cgid')})
def del_room_opencity(self): """取消房源开放城市""" if not is_admin(): raise TOKEN_ERROR(u'请使管理员登录') data = parameter_required(('city_id', )) city_id = data.get('city_id') deleted = self.scity.delete_roomoppencity(city_id) msg = u'取消房源服务成功' if deleted else u'无此记录' return Success(msg, {'city_id': city_id})
def delete_bedroom(self): """删除卧室""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('bbrid', )) deleted = self.sroom.update_bedroom_by_bbrid(data.get('bbrid'), {'BBRisdelete': 1}) msg = u'删除成功' if deleted else u'无此记录' return Success(msg, {'bbrid': data.get('bbrid')})
def add_homestay_banner(self): """添加民宿页的轮播图""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('hsbimage', 'hsbsort'), others='ignore') data['hsbid'] = str(uuid.uuid4()) model_bean = self.sroom.add_model('HomeStayBanner', data) cache.delete('home_stay_banner') return Success(u'添加成功', {'hsbid': data['hsbid']})
def delete_joinroom_banner(self): """删除友家轮播图""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('jrbid', )) jrbid = data.get('jrbid') joinroom = self.sroom.delete_joinroom_banner(jrbid) msg = u'删除成功' if joinroom else u'要删除的对象不存在' return Success(msg, {'jrbid': jrbid})
def delete_provide_house(self): """删除房源删除""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('phaid', )) phaid = data.get('phaid') deleted = self.strade.updaet_provideapply(phaid, {'PAHisdelete': True}) msg = u'删除成功' if deleted else u'无此记录' return Success(msg, {'phaid': phaid})
def get_list(self): # todo 位置, 地铁, 附近 args = request.args.to_dict() args_dict = {} if not args: args = {} args_dict['page'] = int(args.get('page', 1)) # 页码 args_dict['count'] = int(args.get('count', 15)) # 取出条数 # 租赁方式, 合租整租公寓民宿 args_dict['type'] = args.get('type') # 装修风格 0 毛坯, 1简装, 2: 精装, 3: 豪华 style = args.get('style').split('|') if 'style' in args else [] # 租金 args_dict['lowprice'] = args.get('lowprice') args_dict['highprice'] = args.get('highprice') # 朝向 face=1|2|3 ==> [1, 2, 3] face_args = args.get('face').split('|') if 'face' in args else [] # 展现方式 image or video args_dict['show_type'] = args.get('show_type') # 房型 一室,二室,三室,五室以上 args_dict['bed_count'] = args.get('bed_count').split( '|') if 'bed_count' in args else None # 城市编号 args_dict['city_id'] = args.get('city_id') # 区 args_dict['area_id'] = args.get('area_id') # 地铁 args_dict['subway'] = args.get('subway') # 小区 args_dict['villege'] = args.get('villege') print(args_dict) admin = True if is_admin() else None args_dict = {k: v for k, v in args_dict.items() if v is not None} room_detail_list = self.sroom.get_room_list_filter(args_dict, admin, style=style, face_args=face_args) request.subway = args.get('subway') map(self._fill_detail_for_list, room_detail_list) map(self._fill_house_info, room_detail_list) # 楼层和规格 map(lambda x: x.fill( self.sroom.get_tags_by_roid(x.ROid), 'tags', hide=('ROid', )), room_detail_list) # 填充tag信息 map(lambda x: x.fill(self.sindex.is_room_showinindex_by_roid(x.ROid), 'show_index'), room_detail_list) # 是否显示在首页 for room in room_detail_list: if room.ROdistance in ['无', u'无']: room.fill(None, 'ROdistance') page_count = getattr(request, 'page_count') all_count = getattr(request, 'all_count') data = Success(u'获取房源列表成功', data=room_detail_list, page_count=page_count, all_count=all_count) return data
def delete_server_index_show(self): """删除首页显示的服务""" if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('sisid', )) server_index_show = self.sindex.delete_server_index_show(data.get('sisid')) message = u'删除成功' if server_index_show else u'要删除的对象不存在' return Success(message, { 'sisid': data.get('sisid') })
def update_provide_house_status(self): """更新设置申请列表的状态""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('phaid', 'pahstatus')) phaid = data.get('phaid') updated = self.strade.updaet_provideapply( phaid, {'PAHstatus': data.get('pahstatus')}) msg = u'修改成功' if updated else u'无此记录' return Success(msg, {'phaid': phaid})
def delete_homestay_banner(self): """删除民宿页的轮播图""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('hsbid', )) hsbid = data.get('hsbid') homestaybanner = self.sroom.delete_homestay_banner(hsbid) cache.delete('home_stay_banner') msg = u'删除成功' if homestaybanner else u'要删除的对象不存在' return Success(msg, {'hsbid': hsbid})
def delete_complaint(self): """删除投诉""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('usercomplaintid', )) cid = data.get('usercomplaintid') deleted = self.strade.update_somplaint_by_complaintid( cid, {'UserComplaintisdelete': True}) msg = u'删除成功' if deleted else u'无此记录' return Success(msg, {'usercomplaintid': cid})
def delete_room_show_by_roid(self): if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('roid', )) room_index_show = self.sindex.delete_room_show_by_roid(data.get('roid')) cache.delete("get_index_room_list_data") # 删除缓存 message = u'取消成功' if room_index_show else u'要取消的房源不在首页' return Success(message, { 'roid': data.get('roid') })
def add_banner(self): """新建轮播图, 必要的参数: 图片地址, 顺序标志, 链接""" if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('ibimage', 'iblink', 'ibsort'), others='ignore') data['IBid'] = str(uuid.uuid4()) self.sindex.add_model('IndexBanner', data) return Success(u'添加成功', { 'ibid': data['IBid'] })
def delete_banner_show(self): """删除轮播""" if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('ibid', )) banner = self.sindex.delete_banner_show_by_ibid(data.get('ibid')) message = u'删除成功' if banner else u'要删除的元素不存在' return Success(message, { 'ibid': data.get('ibid') })
def add_server_index(self): """新建首页显示的服务项目""" if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('sisimage', 'sislink', 'sissort'), others='ignore') data['SISid'] = str(uuid.uuid4()) self.sindex.add_model('ServerIndexShow', data) return Success(u'添加成功', { 'sisid': data['SISid'] })
def delete_room_show(self): """删除首页显示的整租或合租房源""" if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('risid', )) room_index_show = self.sindex.delete_room_show_by_risid(data.get('risid')) cache.delete("get_index_room_list_data") # 删除缓存 message = u'删除成功' if room_index_show else u'要删除的对象不存在' return Success(message, { 'risid': data.get('risid') })
def add_room_show(self): """新建首页显示的合租整租公寓民宿, 必要的参数 房源id, type, 和顺序: """ if not is_admin(): raise AUTHORITY_ERROR('请使用管理员登录') data = parameter_required(('roid', 'rotype', 'rosort'), others='ignore') data['RISid'] = str(uuid.uuid4()) self.sindex.add_model('RoomIndexShow', data) cache.delete("get_index_room_list_data") # 删除缓存 return Success(u'添加成功', { 'risid': data['RISid'] })
def update_complaint(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('usercomplaintid', 'status')) status = data.get('status') if str(status) not in ['1', '0']: raise PARAMS_ERROR(u'status参数不合法') comlain = self.strade.update_somplaint_by_complaintid( data.get('usercomplaintid'), {'UserComplaintstatus': status}) if not comlain: raise NOT_FOUND(u'修改失败') return Success(u'修改成功', {'status': COMPLAIN_STATUS[status]})
def get_complaint_list(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') args = request.args.to_dict() page = int(args.get('page', 1)) count = int(args.get('count', 15)) status = args.get('status') complain_list = self.strade.get_complaint_list(page, count, status) map( lambda x: setattr(x, 'UserComplaintstatus', COMPLAIN_STATUS[ x.UserComplaintstatus]), complain_list) return Success(u'获取投诉列表成功', complain_list)