Пример #1
0
def submit_order(request):
    result = {'code': 100, 'log': '已通知理发师'}
    re_data = None
    try:
        data = Checker.request(request, ['barphone', 'cusphone', 'cusname', 'sex',
                                         'time', 'distance', 'hairstyle', 'remark'])
        #try:
        #    _ = CustomerProxy(data['cusphone'])
        #except CustomerDoesNotExistError:
        CustomersManager.add_customer(phone=data['cusphone'], name=data['cusname'], sex=data['sex'])

        #time_conflict(phone=data['cusphone'], time_=data['time'])  # ??
        order_clash(bar_phone=data['barphone'], time_=data['time'])
        time_ = calculate_order_time(hairstyle=data['hairstyle'], time_=data['time'])

        order = OrdersManager.add_order(cus_phone=data['cusphone'], bar_phone=data['barphone'],
                                        time_=time_, hairstyle=data['hairstyle'],
                                        remark=data['remark'], accepted=True).get_dict()
        order.pop('accepted')
        push_msg(alias=order['barphone'], msg=order)
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Пример #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))