示例#1
0
 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})
示例#2
0
 def get_detail(self):
     """房源详细信息"""
     data = parameter_required(('roid', ))
     roid = data.get('roid')
     room = cache.get('room_detail::{}'.format(roid))
     if not room:
         room = self.sroom.get_room_by_roid(roid)
         if not room:
             raise NOT_FOUND(u'房源不存在')
         self._fill_house_info(room)  # 楼层和规格
         self._fill_roomate_info(room)  # 室友信息
         room.fill(self.sroom.get_room_equirment_by_roid(room.ROid),
                   'equirment',
                   hide=('IConid', 'REid', 'ROid'))
         room.fill(self.sroom.get_room_media_by_roid(room.ROid), 'media')
         room.fill(self.scity.get_city_by_city_id(room.ROcitynum), 'city')
         room.fill(self.scity.get_areainfo_by_id(room.ROareanum), 'area')
         room.ROface = FACE_CONFIG.get(room.ROface, u'未知')
         room.ROrenttype = RENT_TYPE.get(room.ROrenttype, u'未知')
         room.fill(self.sroom.get_tags_by_roid(roid),
                   'tags',
                   hide=('ROid', ))  # 填充tag信息
         self._fix_villege_subway_info(room)
         room.add('ROisdelete', 'ROcreatetime', 'ROcitynum')
         cache.set('room_detail::{}'.format(roid), room)
     return Success(u'获取房源信息成功', room)
示例#3
0
文件: CTrade.py 项目: haobin12358/zr
 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)
示例#4
0
 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']})
示例#5
0
文件: CTrade.py 项目: haobin12358/zr
 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)
示例#6
0
文件: CTrade.py 项目: haobin12358/zr
 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'申请成功, 等待管家回电')
示例#7
0
文件: CTrade.py 项目: haobin12358/zr
 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})
示例#8
0
文件: Cpay.py 项目: haobin12358/zr
 def check_refund(self):
     """查询是否退款"""
     # if not is_admin():
     #     raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required()
     if 'umtid' in data:
         umtid = data.get('umtid')
         order = self.strade.get_mover_order_by_umtid(umtid)
         if not order or order.UMTstatus != 4:
             raise NOT_FOUND()
         pass
     elif 'uctid' in data:
         uctid = data.get('uctid')
         order = self.strade.get_clean_order_by_uctid(uctid)
         if not order or order.UCTstatus != 4:
             raise NOT_FOUND()
     elif 'uftid' in data:
         uftid = data.get('uftid')
         order = self.strade.get_fixer_order_by_uftid(uftid)
         if not order or order.UFTstatus != 4:
             raise NOT_FOUND()
     else:
         raise PARAMS_ERROR()
     sn = order.sn
     try:
         res = self.pay.refund_query(out_trade_no=sn)
     except WeixinPayError as e:
         raise SYSTEM_ERROR(e.message)
     return Success(data=res)
示例#9
0
 def weixin_callback():
     """通过code, 获取用户信息"""
     args = parameter_required(('code', ))
     code = args.get('code')
     try:
         data = wxlogin.access_token(code)
         print(data)
         data = wxlogin.user_info(data.access_token, data.openid)
         state = args.get('state').split('P')
         usid = state[0]
         redirect_url = state[1]
         to_model = {
             'UScity': data.get('city'),
             'WXopenid': data.get('openid'),
             'WXnickname': data.get('nickname'),
             'USnickname': data.get('nickname'),
             'USheader': data.get('headimgurl'),
             'WXprovice': data.get('province')
         }
         to_model['USgender'] = 0 if data.get('sex') == 1 else 1
         suser = SUser()
         updated = suser.update_user_by_usid(usid, to_model)
         return redirect(redirect_url)
     except WeixinLoginError as e:
         current_app.logger.error(request.url)
         # raise PARAMS_ERROR(u'登录出现错误')
         return redirect(HTTP_HOST)
示例#10
0
文件: CUser.py 项目: haobin12358/zr
 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
         })
示例#11
0
文件: Cpay.py 项目: haobin12358/zr
    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)
示例#12
0
 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')})
示例#13
0
 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})
示例#14
0
 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})
示例#15
0
 def get_guide(self):
     data = parameter_required(('cgid', ))
     cgid = data.get('cgid')
     guide = self.sroom.get_guide_by_cgid(cgid)
     if not guide:
         raise NOT_FOUND(u'不存在的指南')
     guide.hide('CGisdelete')
     return Success(u'获取指南成功', {'guide': guide})
示例#16
0
文件: CUser.py 项目: haobin12358/zr
 def get_code(self):
     """发送验证码"""
     data = parameter_required(('phone', ))
     phone = validate_phone(data.get('phone'))
     send = Thread(target=self._async_send_code, args=(phone, ))
     send.start()
     message = u'获取成功'
     return Success(message)
示例#17
0
文件: CTrade.py 项目: haobin12358/zr
 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})
示例#18
0
 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})
示例#19
0
 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']})
示例#20
0
 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')})
示例#21
0
 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})
示例#22
0
 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')})
示例#23
0
文件: CTrade.py 项目: haobin12358/zr
 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})
示例#24
0
文件: CTrade.py 项目: haobin12358/zr
 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})
示例#25
0
 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})
示例#26
0
 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')     
     })
示例#27
0
 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']
     })
示例#28
0
 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']
     })
示例#29
0
 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')
     })
示例#30
0
 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')
     })