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 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 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_complaint(self): if is_admin(): raise TOKEN_ERROR(u'只有普通用户才可是投诉') if is_tourist(): raise TOKEN_ERROR(u'请登录后投诉') data = parameter_required(('usercomplainttext', 'usercomplaintaddress', 'usercomplaintphone'), others='ignore') validate_phone(data.get('usercomplaintphone')) data['usid'] = request.user.id data['UserComplaintid'] = str(uuid.uuid4()) data['UserComplaintcreatetime'] = datetime.strftime( datetime.now(), format_for_db) self.strade.add_model('UserComplaint', data) return Success(u'投诉成功')
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 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 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 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 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 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 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 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_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_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 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)
def add_room_opencity(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('city_id', )) city_id = data.get('city_id') room_city = self.scity.is_room_open_city(city_id) if room_city: raise PARAMS_ERROR(u'重复添加') data['rcid'] = str(uuid.uuid4()) added = self.scity.add_model('RoomCity', data) return Success(u'添加房源开放城市成功', {'city_id': city_id})
def post(self): if not is_admin(): raise TOKEN_ERROR('请使用管理员登录') data = parameter_required(('password', )) hash_pass = generate_password_hash(data.get('password')) admin = self.suser.update_admin_by_adid(request.user.id, { 'ADpassword':hash_pass }) return jsonify({ 'message': '修改成功', 'status': 200 })
def delete_staff(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('stfid',)) stfid = data.get('stfid') staff = self.suser.delete_staff_by_stfid(stfid) if not staff: return Success(u'无此记录', { 'stfid': stfid }) return Success(u'删除成功', { 'stfid': stfid })
def delete_room(self): """删除房源""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('roid', )) roid = data.get('roid') deleted = self.sroom.delete_room_by_roid(roid) # 同时取消在首页的显示 self.sindex.delete_room_show_by_roid(roid) cache.delete('room_detail::{}'.format(roid)) cache.delete("get_index_room_list_data") # 删除缓存 msg = u'删除成功' if deleted else u'无此记录' return Success(msg, {'roid': roid})
def fixer_appiontment(self): """维修预约""" if is_admin(): return TOKEN_ERROR(u'只有普通用户才可以预约') if is_tourist(): return TOKEN_ERROR(u'请登录后预约') required = ('uftaddr', 'uftstarttime', 'uftphone', 'uftlocation') forbidden = ('usid', 'uftstatus') data = parameter_required(required, forbidden=forbidden) data['uftphone'] = data.get('uftphone').strip() validate_phone(data.get('uftphone')) self._allow_starttime(data.get('uftstarttime')) data['UFTid'] = str(uuid.uuid4()) data['usid'] = request.user.id data['UFTcreatetime'] = datetime.strftime(datetime.now(), format_for_db) uftlocation = data.get('uftlocation') data['Citynum'] = BdMap(uftlocation).city_id # 获取城市id model_bean_dict = self.sserver.add_model('UserFixerTrade', data, ['UFTid', 'UFTstarttime']) model_bean_dict['name'] = u'维修预约' return Success(u'预约成功', model_bean_dict)
def get_staff_by_id(self): if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('stfid', )) staff = self.suser.get_staff_by_stfid(data.get('stfid')) if not staff: raise NOT_FOUND(u'无记录') staff.all.hide('STFisdelete') setattr(staff, 'STFlevel', STAFF_TYPE.get(staff.STFlevel, u'其他')) setattr(staff, 'STFgender', GENDER_CONFIG.get(staff.STFgender, u'未知')) return Success(u'获取成功', { 'staff': staff })
def update_fixerorder_status(self): """更新维修订单状态, 订单状态先使用随意改变的""" if not is_admin(): raise TOKEN_ERROR(u'请使用管理员登录') data = parameter_required(('uftid', 'status')) uftid = data.get('uftid') fix_order = self.strade.get_fixer_order_by_uftid(uftid) if not fix_order: raise NOT_FOUND() status = data.get('status') self._allow_order_status(fix_order.UFTstatus, int(status)) updated = self.strade.update_fixertrade_status_by_utfid(uftid, status) msg = u'修改成功' return Success(msg, {'uftid': uftid})