Esempio n. 1
0
 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)
Esempio n. 2
0
 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})
Esempio n. 3
0
    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)
Esempio n. 4
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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
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']})
Esempio n. 9
0
 def get_appointment_one(self):
     """获取单条订单"""
     if is_tourist():
         raise TOKEN_ERROR(u'请登录')
     data = parameter_required()
     if 'uctid' in data:
         uctid = data.get('uctid')
         order = self.strade.get_clean_order_by_uctid(uctid)
         if not order:
             raise NOT_FOUND(u'该订单不存在')
         order.UCTstatus = SERVER_STATUS.get(order.UCTstatus)
         sceid = order.SCEid
         cleaner_server = self.sserver.get_cleanerserver_by_sceid(sceid)
         order.fill('clener', 'type')
         order.fill(getattr(cleaner_server, 'SCMtitle', ''), 'name')
     elif 'uftid' in data:
         uftid = data.get('uftid')
         order = self.strade.get_fixer_order_by_uftid(uftid)
         if not order:
             raise NOT_FOUND(u'该订单不存在')
         order.UFTstatus = SERVER_STATUS.get(order.UFTstatus)
         order.fill('fixer', 'type')
         order.fill('邻家维修', 'name')
     elif 'umtid' in data:
         umtid = data.get('umtid')
         order = self.strade.get_mover_order_by_umtid(umtid)
         if not order:
             raise NOT_FOUND(u'该订单不存在')
         order.UMTstatus = SERVER_STATUS.get(order.UMTstatus)
         order.fill('mover', 'type')
         smsid = order.SMSid
         mover_server = self.sserver.get_mover_by_smsid(smsid)
         order.fill(getattr(mover_server, 'SMStitle', ''), 'name')
         order.fill('type', 'mover')
     else:
         return PARAMS_ERROR()
     if not is_admin():
         if request.user.id != order.USid:
             raise NOT_FOUND(u'它人订单')
     # 工作人员
     staff = {}
     stfid = order.STFid
     if stfid:
         staff = self.suser.get_staff_by_stfid(stfid).clean.add(
             'STFid', 'STFname')
     order.fill(staff, 'staff')
     return Success(u'获取订单成功', {'order': order})
Esempio n. 10
0
 def point_staff(self):
     """给订单指定工作人员"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('stfid', ))
     stfid = data.get('stfid')
     staff = self.suser.get_staff_by_stfid(stfid)
     if not staff:
         raise NOT_FOUND(u'不存在的工作人员')
     if staff.STFisblocked:
         raise NOT_FOUND(u'黑名单里的工作人员')
     response = {'stfid': stfid}
     # 如果是搬家服务
     if 'umtid' in data:
         umtid = data.get('umtid')
         mover_order = self.strade.get_mover_order_by_umtid(umtid)
         if mover_order.UMTstatus != 1:  # 只有等待服务的订单才可以制定
             raise PARAMS_ERROR(u'当前订单状态为{}, 只可以指定等待服务中的订单'.format(
                 SERVER_STATUS.get(mover_order.UMTstatus)))
         updated = self.strade.update_movertrade_detail_by_umtid(
             umtid, {'STFid': stfid})
         response['type'] = 'mover'
     elif 'uftid' in data:
         # 如果是维修
         uftid = data.get('uftid')
         fixer_order = self.strade.get_fixer_order_by_uftid(uftid)
         if fixer_order.UFTstatus != 1:
             raise PARAMS_ERROR(u'当前订单状态为{}, 只可以指定等待服务中的订单'.format(
                 SERVER_STATUS.get(fixer_order.UMTstatus)))
         updated = self.strade.update_fixerorder_detail_by_uftid(
             uftid, {'STFid': stfid})
         response['type'] = 'fixer'
     elif 'uctid' in data:
         # 如果是保洁
         uctid = data.get('uctid')
         cleaner_order = self.strade.get_clean_order_by_uctid(uctid)
         if cleaner_order.UCTstatus != 1:
             raise PARAMS_ERROR(u'当前订单状态为{}, 只可以指定等待服务中的订单'.format(
                 SERVER_STATUS.get(cleaner_order.UMTstatus)))
         updated = self.strade.update_cleanorder_detail_by_uctid(
             uctid, {'STFid': stfid})
         response['type'] = 'cleaner'
     else:
         # 其他 参数有误
         raise PARAMS_ERROR(u'订单参数有误')
     msg = u'更新成功' if updated else u'无此记录'
     return Success(msg, response)
Esempio n. 11
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})
Esempio n. 12
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})
Esempio n. 13
0
 def get_one_housekeeper(self):
     """获取一个管家"""
     data = parameter_required(('roid', ))
     # staff_list = self.suser.get_staff_list(level=0)  # level 0 表示管家
     # 暂定为随机获取一个管家
     self.sroom = SRoom()
     roid = data.get('roid')
     room = self.sroom.get_room_by_roid(roid)
     if not room:
         raise NOT_FOUND(u'房源不存在')
     stfid = room.STFid
     staff = self.suser.get_staff_by_stfid(stfid)
     if not staff:
         raise NOT_FOUND('未绑定管家')
     staff.clean.add('STFid', 'STFname', 'STFmobiel', 'STFgender')
     return Success(u'获取成功', {
         'housekeeper': staff
     })
Esempio n. 14
0
    def agree_cancle_fixer_order(self):
        """管理员同意执行退款"""
        if not is_admin():
            return TOKEN_ERROR(u'请使用管理员登录')
        data = parameter_required(('uftid', ))
        agree = int(data.get('agree', 1))
        uftid = data.get('uftid')
        order = self.strade.get_fixer_order_by_uftid(uftid)
        if not order:
            raise NOT_FOUND(u'不存在的订单')
        if order.UFTstatus != 3:
            raise PARAMS_ERROR(u'当前状态为{}'.format(
                SERVER_STATUS.get(order.UFTstatus, u'其他')))
        if not order.sn or not order.paytime:
            raise NOT_FOUND(u'未付款的订单')
        # 拒绝退款:
        if agree == 0:
            status = 1
            msg = u'已拒绝退款'
        # 同意退款
        else:
            status = 4
            msg = u'已同意退款'
            usid = order.USid
            user = self.suser.get_user_by_usid(usid)
            openid = user.WXopenid
            out_trade_no = order.sn
            total_fee = int(order.UFTprice * 100)
            # 调用退款
            try:
                self.pay.refund(out_trade_no=out_trade_no,
                                total_fee=total_fee,
                                refund_fee=total_fee,
                                op_user_id=openid,
                                out_refund_no=out_trade_no,
                                spbill_create_ip=request.remote_addr)
            except WeixinPayError as e:
                raise PARAMS_ERROR(u'签名错误')

        # 修改服务状态为退款中
        updated = self.strade.update_fixerorder_detail_by_uftid(
            uftid, {'UFTstatus': status})
        return Success(msg, {'uftid': uftid})
Esempio n. 15
0
 def get_subway_potion_by_lineid(self):
     """获取地铁线路的站点"""
     data = parameter_required(('line_id', ))
     line_id = data.get('line_id')
     line = self.scity.get_subwayline_by_lineid(line_id)
     if not line:
         raise NOT_FOUND(u'不存在的线路')
     positions = self.scity.get_subwayposition_by_line_id(line.subwaylineid)
     # 过滤空的地铁站
     positions = list(filter(lambda x: x.position, positions))
     return Success(u'获取站点信息成功', positions)
Esempio n. 16
0
 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]})
Esempio n. 17
0
 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
     })
Esempio n. 18
0
 def admin_login(self):
     """管理员登录"""
     data = parameter_required(('username', 'password'))
     username = data.get('username')
     password = data.get('password')
     admin = self.suser.verify_admin_login(username, password)
     if not admin:
         raise NOT_FOUND(u'用户名或者密码错误')
     level = admin.ADlevel  # 管理员等级
     token = usid_to_token(admin.ADid, 'Admin', level=level)
     return Success(u'获取token成功', {
         'token': token,
         'level': level
     })
Esempio n. 19
0
 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})
Esempio n. 20
0
 def update_cleanorder_status(self):
     """待改进"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('uctid', 'status'))
     status = data.get('status')
     uctid = data.get('uctid')
     cleaner_order = self.strade.get_clean_order_by_uctid(uctid)
     if not cleaner_order:
         raise NOT_FOUND()
     self._allow_order_status(cleaner_order.UCTstatus, int(status))
     updated = self.strade.update_cleanertrade_status(uctid, status)
     msg = u'修改成功'
     return Success(msg, {'uctid': uctid})
Esempio n. 21
0
 def update_moverorder_status(self):
     """更改订单状态就"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('umtid', 'status'))
     status = data.get('status')
     umtid = data.get('umtid')
     mover_order = self.strade.get_mover_order_by_umtid(umtid)
     if not mover_order:
         raise NOT_FOUND()
     self._allow_order_status(mover_order.UMTstatus, int(status))
     updated = self.strade.update_movertrade_status_by_umtid(umtid, status)
     msg = u'修改成功' if updated else u'无此记录'
     return Success(msg, {'umtid': umtid})
Esempio n. 22
0
 def update_fixorder_price(self):
     """修改维修价格"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('uftid', 'price'), others='ignore')
     uftid = data.get('uftid')
     fix_order = self.strade.get_fixer_order_by_uftid(uftid)
     if not fix_order:
         raise NOT_FOUND()
     if fix_order.UFTstatus != 0:
         raise PARAMS_ERROR(u'当前订单状态为{}, 只可以修改未付款的订单'.format(
             SERVER_STATUS.get(fix_order.UFTstatus)))
     updated = self.strade.update_fixerorder_detail_by_uftid(
         uftid, {'UFTprice': data.get('price')})
     return Success(u'修改成功', {'uftid': uftid})
Esempio n. 23
0
 def update_cleanerorder_price(self):
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('uctid', 'price'))
     price = data.get('price')
     uctid = data.get('uctid')
     cleaner_order = self.strade.get_clean_order_by_uctid(uctid)
     if not cleaner_order:
         raise NOT_FOUND()
     if cleaner_order.UCTstatus != 0:
         raise PARAMS_ERROR(u'当前订单状态为{}, 只可以修改未付款的订单'.format(
             SERVER_STATUS.get(cleaner_order.UCTstatus)))
     updated = self.strade.update_cleanorder_detail_by_uctid(
         uctid, {"UCTprice": price})
     return Success(u'修改成功', {'uctid': uctid})
Esempio n. 24
0
 def update_moverorder_price(self):
     """更新订单价格"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('umtid', 'price'))
     price = data.get('price')
     umtid = data.get('umtid')
     mover_order = self.strade.get_mover_order_by_umtid(umtid)
     if not mover_order:
         raise NOT_FOUND()
     if mover_order.UMTstatus != 0:
         raise PARAMS_ERROR(u'当前订单状态为{}, 只可以修改未付款的订单'.format(
             SERVER_STATUS.get(mover_order.UMTstatus)))
     updated = self.strade.update_movertrade_detail_by_umtid(
         umtid, {'UMTpreviewprice': price})
     return Success(u'修改成功', {'umtid': umtid})
Esempio n. 25
0
 def login(self):
     """登录, 没有用户则自动创建"""
     data = parameter_required(('phone', 'code', 'redirect'), others='ignore')
     phone = str(data.get('phone'))
     code = int(data.get('code'))
     redirect = data.get('redirect', HTTP_HOST)
     usercode = self.susercode.get_active_usercode_by_phone_code(phone, code)
     if not usercode:
         return NOT_FOUND(u'验证码已过期或不正确')
     user = self.suser.get_user_by_phone(phone)
     now_time = datetime.strftime(datetime.now(), format_for_db)
     if not user:  # 如果是新用户
         user_dict = {
             'usid': str(uuid.uuid4()),
             'USphone': str(phone),
             'UScreatetime': now_time,
             'USlastlogin': now_time
         }
         self.suser.add_model('User', user_dict)
         token = usid_to_token(user_dict['usid'])
         state = str(user_dict['usid']) + u'P' + redirect
         redirect_url = self.wxlogin.authorize(API_HOST + "/api/wechat/callback", WXSCOPE, state=state)
         return Success(u'注册成功', status=302, data={
             'token': token,
             'redirect_url': redirect_url
         })
     elif not user.WXopenid:  # 无用户资料
         token = usid_to_token(user.USid)
         state = str(user.USid) + u'P' + redirect
         redirect_url = self.wxlogin.authorize(API_HOST + "/api/wechat/callback", WXSCOPE, state=state)
         return Success(u'注册成功', status=302, data={
             'token': token,
             'redirect_url': redirect_url
         })
     else:  # 老用户
         # 如果是已经存在的用户则记录上次登录时间
         updated = self.suser.update_user_by_phone(phone, {
             'USlastlogin': now_time
         })
         token = usid_to_token(user.USid)
     return Success(u'获取token成功', {
         'token': token
     })
Esempio n. 26
0
 def get_detail_the_same_like_add(self):
     """房源信息接口2"""
     data = parameter_required(('roid', ))
     roid = data.get('roid')
     room = self.sroom.get_house_by_hoid(roid)
     if not room:
         raise NOT_FOUND(u'房源不存在')
     # room.fill(self.sroom.get_house_by_hoid(room.HOid), 'house')  # 楼层和规格
     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.ROface = FACE_CONFIG.get(room.ROface, u'未知')
     room.ROrenttype = RENT_TYPE.get(room.ROrenttype, u'未知')
     room.add('ROisdelete', 'ROcreatetime', 'ROcitynum')
     return Success(u'获取房源信息成功', room)
Esempio n. 27
0
 def update_bedroom(self):
     """更新卧室信息, 比如改为已租出, 或者价格之类"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('bbrid', ))
     bbrid = data.pop('bbrid')
     bedroom = self.sroom.get_bedroom_by_bbrid(bbrid)
     if not bedroom:
         raise NOT_FOUND(u'此卧室不存在')
     roid = bedroom.ROid
     if 'bbrshowprice' in data:
         # 需要改为未租出的状态
         self.sroom.update_bedroom_by_bbrid(
             bbrid, {
                 'BBRshowprice': data.get('bbrshowprice'),
                 'BBRshowpriceunit': data.get('bbrshowpriceunit', 'month'),
                 'BBRstatus': 2
             })
         userbedroom = self.sroom.update_roomates_info_by_bbrid(
             bbrid, {'UBBRstatus': 1})  # 同时需要更新卧室住户的状态
         msg = u'改为未入住成功'
     elif 'usgender' in data:
         # 需要改为入住状态
         self.sroom.update_bedroom_by_bbrid(bbrid, {"BBRstatus": 5})
         # 同时需要添加入住信息, 修改以往的入住信息为已搬(如果有)
         self.sroom.update_roomates_info_by_bbrid(bbrid, {'UBBRstatus': 1})
         model_dict = dict(UBBRid=str(uuid.uuid4()),
                           BBRid=bbrid,
                           USgender=data.get('usgender'))
         mod = dict(UserBedroomBehindRoom=model_dict)
         self.sroom.add_models(mod)
         msg = u'改为已入住成功'
     else:
         raise PARAMS_ERROR(u'缺少必要的参数')
     cache.delete('room_detail::{}'.format(roid))
     return Success(msg, {'bbrid': bbrid})
Esempio n. 28
0
 def update_room(self):
     """更新房源信息"""
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required(('roid', ))
     roid = data.get('roid')
     # 房源主体的参数
     # house信息
     # medias信息
     # tags
     # roomequi设备
     # 公寓信息
     house = data.pop('house', None)
     medias = data.pop('medias', [])
     tags = data.pop('tags', [])
     roomrequirment = data.pop('roomrequirment', None)
     room = self.sroom.get_room_by_roid(roid)
     if not room:
         raise NOT_FOUND(u'无此房源')
     room_data = {
         'ROname': data.get('roname'),
         'ROimage': data.get('roimage'),
         'ROareanum': data.get('roareanum'),
         'ROface': data.get('roface'),
         'ROarea': data.get('roarea'),
         'ROshowpriceunit': data.get('roshowpriceunit'),
         'ROrenttype': data.get('rorenttype'),
         'ROdecorationstyle': data.get('rodecorationstyle'),
         'ROshowprice': data.get('roshowprice'),
         'ROcitynum': data.get('rocitynum'),
         'ROsubwayaround': data.get('rosubwayaround'),
         'STFid': data.get('stfid')
     }
     room_data = {k: v for k, v in room_data.items() if v is not None}
     if not room_data:
         raise PARAMS_ERROR('修改room需要的参数缺失')
     room_updated = self.sroom.update_room_by_roid(roid, room_data)
     print('更新了room')
     if house:
         hoid = room.ROid
         houseinfo_required = ('hofloor', 'hototalfloor', 'hobedroomcount',
                               'hoparlorcount')
         parameter_required(houseinfo_required, datafrom=house)
         house_data = {
             'HOfloor': house.get('hofloor'),
             'HOtotalfloor': house.get('hototalfloor'),
             'HObedroomcount': house.get('hobedroomcount'),
             'HOparlorcount': house.get('hoparlorcount'),
         }
         house_updated = self.sroom.update_house_by_hoid(hoid, house_data)
     if medias:
         # 此处接受到的media数据是没有删除的和信添加的, 删除的将不会在传过来
         # 此处有点罗嗦, 只需删除原来的数据, 再重新添加即可
         deleted = self.sroom.delete_room_media_by_roid(roid)
         for new_media in medias:
             new_media['reid'] = str(uuid.uuid4())
             new_media['roid'] = roid
             self.sroom.add_model('RoomMedia', new_media)
             print('添加多媒体')
     if tags:
         # 删除原来的tag
         self.sroom.delete_tag_by_roid(roid)
         print('删除了原来的tag')
         mod = {}
         mod['RoomTag'] = []
         for tag in tags:
             tag['roid'] = roid
             tag['rtid'] = str(uuid.uuid4())
             mod['RoomTag'].append(tag)
         self.sroom.add_models(mod)
         print('添加tag')
     if roomrequirment:
         self.sroom.delete_room_equirment_by_roid(roid)
         print('删除了原来的设备')
         roomrequirment['roid'] = roid
         roomrequirment['reid'] = str(uuid.uuid4())
         self.sroom.add_model('RoomEquirment', roomrequirment)
         print('修改设备')
     if 'villegeid' in data:
         hoid = room.HOid
         # house = self.sroom.get_house_by_hoid(hoid)
         villege = self.sroom.get_villege_info_by_id(data.get('villegeid'))
         if not villege:
             raise PARAMS_ERROR(u'villege id有误')
         self.sroom.update_house_by_hoid(hoid,
                                         {'VIid': data.get('villegeid')})
     cache.delete('room_detail::{}'.format(roid))
     cache.delete("get_index_room_list_data")  # 删除缓存
     return Success(u'修改成功', {'roid': roid})