Example #1
0
def register(request):
    result = {'code': 100, 'log': 'register success'}
    re_data = None
    try:
        data = Checker.request(request, ['phone', 'name', 'sex', 'password', 'shop', 'time'])
        try:
            _ = BarberProxy(data['phone'])
        except BarberDoesNotExistError:
            BarbersManager.add_barber(phone=data['phone'], name=data['name'],
                                      sex=data['sex'], password=data['password'],
                                      shop=data['shop'], time_=data['time'])
        else:
            raise BarberHasRegister
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Example #2
0
def quick_appt(request):
    result = {'code': 100, 'log': '已将订单发送至理发师端'}
    re_data = None
    try:
        data = Checker.request(request, ['phone', 'name', 'longitude', 'latitude', 'sex'])
        try:
            _ = CustomerProxy(data['phone'])
        except CustomerDoesNotExistError:
            CustomersManager.add_customer(phone=data['phone'], name=data['name'], sex=data['sex'])
        order = OrdersManager.add_order(cus_phone=data['phone'])
        barbers, dis = BarbersManager.get_near_barber(longitude=float(data['longitude']),
                                                      latitude=float(data['latitude']), range_=1500)
        push_order_to_barber(order=order, barbers=barbers, dis_list=dis)
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Example #3
0
def normal_appt(request):
    result = {'code': 100, 'log': '返回理发师列表'}
    re_data = None
    try:
        data = Checker.request(request, ['longitude', 'latitude', 'date'])
        barbers, dis_list = BarbersManager.get_near_barber(longitude=float(data['longitude']),
                                                           latitude=float(data['latitude']), range_=1500)
        barbers = process_time(barbers=barbers, date=data['date'])
        l = len(barbers)
        for i in range(0, l):
            barbers[i]['distance'] = dis_list[i]
        barbers.sort(key=lambda d: d['distance'])
        if not barbers:
            raise NoBarberHasRegister
        re_data = barbers
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))