Beispiel #1
0
def process_time(*, barbers: [BarberProxy], date: str) -> [dict]:  # 最好做一个testing
    Checker.appt_date(date)
    re_barbers = []
    for barber in barbers:
        bar_time = barber.time.split('-')
        start = date + ';' + bar_time[0] + '-' + bar_time[0]
        end = date + ';' + bar_time[-1] + '-' + bar_time[-1]
        orders = OrdersManager.get_by_time(start=start, end=end)

        #
        his_order = [order for order in orders if order.bar_phone == barber.phone]
        #
        for order in his_order:
            ord_time = order.time.split(';')[1].split('-')
            if not ord_time[0] in bar_time:
                bar_time.append(ord_time[0])
            else:
                bar_time.remove(ord_time[0])
            if not ord_time[1] in bar_time:
                bar_time.append(ord_time[1])
            else:
                bar_time.remove(ord_time[1])
            bar_time.sort()
        time_ = ''
        for t in bar_time:
            time_ += t
            time_ += '-'
        time_ = time_[:-1]
        b = barber.get_dict()
        b['time'] = time_
        re_barbers.append(b)
    return re_barbers
Beispiel #2
0
 def bar_phone(self, phone):
     Checker.phone(phone)
     try:
         self.__order.ord_barber_id = Barber.objects.get(bar_phone=phone)
         self.__order.save()
     except Barber.DoesNotExist:
         raise BarberDoesNotExistError
Beispiel #3
0
 def add_customer(cls, *, phone: str, name: str, sex: str):  # 如何防止重复
     try:
         _ = CustomerProxy(phone)
     except CustomerDoesNotExistError:
         Checker.phone(phone).name(name).sex(sex)
         customer = Customer()
         customer.cus_name, customer.cus_phone, customer.cus_sex = name, phone, sex
         customer.save()
Beispiel #4
0
    def add_barber(cls, *, phone, password, name, sex, shop, time_):
        try:
            barber = Barber()
            Checker.phone(phone).password(password).name(name).sex(sex).shop_name(shop).time_set(time_)
            para = (phone, password, name, sex, Shop.objects.get(shop_name=shop), time_)

            (barber.barber_phone, barber.barber_pass, barber.barber_name,
             barber.barber_sex, barber.barber_shop_id, barber.free_time) = para

            barber.save()
        except Shop.DoesNotExist:
            raise ShopDoesNotExistError
Beispiel #5
0
 def get_near_barber(cls, *, longitude, latitude, range_):
     Checker.latitude(latitude).longitude(longitude)
     barbers = Barber.objects.all()
     d = lambda barber_: distance(latitude_1=latitude, longitude_1=longitude,
                                  latitude_2=barber_.barber_shop_id.shop_lati,
                                  longitude_2=barber_.barber_shop_id.shop_long)
     barbers_in_range, dis_list = [], []
     for barber in barbers:
         temp = d(barber)
         if temp < range_:
             barbers_in_range.append(BarberProxy.get_by_object(barber))
             dis_list.append(temp)
     return barbers_in_range, dis_list
Beispiel #6
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))
Beispiel #7
0
 def update(self, bar_phone, time_, accepted, hairstyle=None, remark=None):
     try:
         Checker.phone(bar_phone).appt_time(time_)  # ??
         self.__order.ord_barber_id = Barber.objects.get(barber_phone=bar_phone)
         self.__order.ord_time = time_
         self.__order.ord_is_acc = accepted
         if remark:
             Checker.remark(remark)
             self.__order.ord_remark = remark
         if hairstyle:
             self.__order.ord_hairstyle_id = Hairstyle.objects.get(hairstyle_name=hairstyle)
         self.__order.save()
         return self
     except Barber.DoesNotExist:
         raise BarberDoesNotExistError
     except Hairstyle.DoesNotExist:
         raise HairstyleDoesNotExistError
Beispiel #8
0
def get_barber(request):
    result = {'code': 100, 'log': '返回请求理发师信息'}
    re_data = None
    try:
        data = Checker.request(request, ['phone', 'date'])
        re_data = process_time(barbers=[BarberProxy(data['phone'])], date=data['date'])[0]
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Beispiel #9
0
def update_sex(request):
    result = {'code': 100, 'log': "Customer's sex update success!"}
    re_data = None
    try:
        data = Checker.request(request, ['phone', 'sex'])
        CustomerProxy(phone=data['phone']).sex = data['sex']
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Beispiel #10
0
def is_register(request):
    result = {'code': 100, 'log': '用户已注册,返回用户信息'}
    re_data = None
    try:
        data = Checker.request(request, ['phone'])
        customer = CustomerProxy(data['phone'])
        re_data = customer.get_dict()
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
Beispiel #11
0
 def add_order(cls, *, cus_phone, bar_phone=None, time_=None, accepted=None, hairstyle=None, remark=None):
     try:
         Checker.phone(cus_phone)
         order = Order()
         order.ord_cus_id = Customer.objects.get(cus_phone=cus_phone)
         if bar_phone:
             Checker.phone(bar_phone)
             order.ord_barber_id = Barber.objects.get(barber_phone=bar_phone)
         if time_:
             Checker.appt_time(time_)  #
             order.ord_time = time_
         if accepted is not None:
             order.ord_is_acc = accepted
         if hairstyle:
             order.ord_hairstyle_id = Hairstyle.objects.get(hairstyle_name=hairstyle)
         if remark:
             order.ord_remark = remark
         order.save()
         return OrderProxy.get_by_object(order)
     except Customer.DoesNotExist:
         raise CustomerDoesNotExistError
     except Barber.DoesNotExist:
         raise BarberDoesNotExistError
     except Hairstyle.DoesNotExist:
         raise HairstyleDoesNotExistError
Beispiel #12
0
def process_time(*, barbers: [BarberProxy], date: str) -> [dict]:
    """
    生成理发师的空闲时间
    :param barbers:BarberProxy类对象列表
    :param date: 给定日期,格式2014.06.18
    :return:
    """
    Checker.appt_date(date)
    re_barbers = []
    for barber in barbers:
        bar_time = barber.time.split("-")
        start = date + ";" + bar_time[0] + "-" + bar_time[0]
        end = date + ";" + bar_time[-1] + "-" + bar_time[-1]
        orders = OrdersManager.get_by_time(start=start, end=end)

        #
        his_order = [order for order in orders if order.bar_phone == barber.phone]
        #
        for order in his_order:
            ord_time = order.time.split(";")[1].split("-")
            if not ord_time[0] in bar_time:
                bar_time.append(ord_time[0])
            else:
                bar_time.remove(ord_time[0])
            if not ord_time[1] in bar_time:
                bar_time.append(ord_time[1])
            else:
                bar_time.remove(ord_time[1])
            bar_time.sort()
        time_ = ""
        for t in bar_time:
            time_ += t
            time_ += "-"
        time_ = time_[:-1]
        b = barber.get_dict()
        b["time"] = time_
        re_barbers.append(b)
    return re_barbers
Beispiel #13
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))
Beispiel #14
0
def update_profile(request):
    result = {'code': 100, 'log': '返回所需要的信息'}
    re_data = None
    try:
        data = Checker.request(request, ['phone'])
        customer = CustomerProxy(phone=data['phone'])
        customer.profile = 'profile/customer/' + customer.phone + '.png'
        re_data = {'key': customer.profile,
                   'bucket_name': 'jianyue-img',
                   'access_key_id': 'DS1sGprn39SnhFDV',
                   'access_key_secret': 'dFmlLMHapOfyUKTDeeUFCp7M64U1aD',
                   }
    except JianyueError as e:
        result = e.info
    finally:
        result['data'] = re_data
        return HttpResponse(encode(result))
    #return HttpResponse(encode(result))
Beispiel #15
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))
Beispiel #16
0
 def set_appt_time(self, time_):
     #理发师设置自己的可预约时间
     Checker.time_set(time_)  # 检查设置的预约时间是否合法
     self.__barber.free_time = time_
     self.__barber.save()
Beispiel #17
0
 def phone(self, phone_):
     Checker.phone(phone_)
     self.__shop.shop_phone = phone_
     self.__shop.save()
Beispiel #18
0
 def profile(self, image):
     Checker.profile(image)
     self.__barber.barber_profile = image
     self.__barber.save()
Beispiel #19
0
 def time(self, time_):
     Checker.time_set(time_)
     self.__barber.free_time = time_
     self.__barber.save()
Beispiel #20
0
 def phone(self, phone_):
     Checker.phone(phone_)
     self.__barber.barber_phone = phone_
     self.__barber.save()
Beispiel #21
0
 def sex(self, sex_):
     Checker.sex(sex_)
     self.__barber.barber_sex = sex_
     self.__barber.save()
Beispiel #22
0
 def name(self, name_):
     Checker.name(name_)
     self.__customer.cus_name = name_
     self.__customer.save()
Beispiel #23
0
 def phone(self, phone_):
     Checker.phone(phone_)
     self.__customer.cus_phone = phone_
     self.__customer.save()
Beispiel #24
0
 def sex(self, sex_):
     Checker.sex(sex_)
     self.__customer.cus_sex = sex_
     self.__customer.save()
Beispiel #25
0
 def profile(self, image):
     Checker.profile(image)
     self.__customer.cus_profile = image
     self.__customer.save()
Beispiel #26
0
 def latitude(self, latitude_):
     Checker.latitude(latitude_)
     self.__shop.shop_lati = latitude_
     self.__shop.save()
Beispiel #27
0
 def remark(self, remark_):
     Checker.remark(remark_)
     self.__order.ord_remark = remark_
     self.__order.save()
Beispiel #28
0
 def time(self, time_):
     Checker.appt_time(time_)
     self.__order.ord_time = time_
     self.__order.save()
Beispiel #29
0
 def name(self, name_):
     Checker.name(name_)
     self.__barber.barber_name = name_
     self.__barber.save()
Beispiel #30
0
 def longitude(self, longitude_):
     Checker.longitude(longitude_)
     self.__shop.shop_long = longitude_
     self.__shop.save()