示例#1
0
 def login(self):
     """
     :return:
     """
     url = config.host + '/sys/login'
     method = 'POST'
     headers = {
         "Connection": "keep-alive",
         "Accept": "application/json, text/javascript, */*; q=0.01",
         "X-Requested-With": "XMLHttpRequest",
         "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
     }
     data = {
         "loginName": str(self.account),
         "bossId": "",
         "loginPassword": config.account.get(str(self.account)),
         "loginType": "password",
         "verifyCode": "",
         "userMobile": ""
     }
     # logger.info(r)
     response = self._request.go(method, url, header=headers, data=data)
     if response.status_code != 200:
         logger.error('login failed' + response.text)
         # logger.info(rds.hget(self.session_id))
         exit()
     cookie_dict = requests.utils.dict_from_cookiejar(response.cookies)
     for key, value in cookie_dict.items():
         _cookie = '\"' + str(key) + '=' + str(value) + '\"'
     rds.hset(self.session_id, 'cookie', str(_cookie))
示例#2
0
 def publish(self, stage_type):
     url = config.host + '/order/addConsignorOrder/addOrderForSeniorConsignor'
     method = 'POST'
     cookie = rds.hget(self.session_id, 'cookie')
     headers = {
         "Connection": "keep-alive",
         "Accept": "application/json, text/javascript, */*; q=0.01",
         "X-Requested-With": "XMLHttpRequest",
         "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
         "Cookie": cookie
     }
     response = self._request.go(method=method, url=url, header=headers, data=stage_type)
     order_id = response.json().get('orderId')
     rds.hset(self.session_id, 'orderId', order_id)
示例#3
0
 def multi_cargo(self, user_cargo=None, user_weight=None):
     # 多货物随机组合
     _user_cargo_list = ['矿渣粉', '无烟煤', '笔记本电脑'
                         ] if not user_cargo else user_cargo
     _cargo_list = random.sample(_user_cargo_list,
                                 config.MULTI_CARGO_NUMBER)
     cargo_list = []
     for c in _cargo_list:
         _cargo = self._get_cargo_status_by_name(c)
         cargo_list.append(_cargo)
     cargo_info = utils.cargo_publish_info(cargo_list, user_weight)
     rds.hset(self.session_id, 'cargo',
              json.dumps(cargo_info, ensure_ascii=False))
     return cargo_info
示例#4
0
 def special_cargo_with_insurance(self,
                                  user_cargo: list = None,
                                  user_weight: list = None):
     # 随机正常货物
     _user_cargo_list = ['工字钢'] if not user_cargo else user_cargo
     cargo_select = random.choice(_user_cargo_list)
     _cargo_select_list = [cargo_select]
     _cargo = self._get_cargo_status_by_name(cargo_select)
     if _cargo['STATE'] != '1':
         raise ValueError('货物未审核通过')
     cargo_list = [_cargo]
     insurance = self._insurance_calculate(_cargo_select_list)
     if not insurance[cargo_select]['cargo_insurance']:
         raise ValueError('货物为不保货物')
     if not insurance[cargo_select]['transport_insurance']:
         raise ValueError('货物为单一险种货物')
     cargo_info = utils.cargo_publish_info(cargo_list, user_weight)
     rds.hset(self.session_id, 'cargo',
              json.dumps(cargo_info, ensure_ascii=False))
     return cargo_info
示例#5
0
    def __call__(self, designCarrier: bool = False, carrier_list: list = None):
        if str(self._real_designate_flag) == '1':
            self.designate_info[
                'designCarrier'] = "1" if designCarrier else "0"
        if designCarrier:
            if str(self._advanced_designate_flag) == '1':
                self.designate_info['advanceRatioSelect'] = "50"

        if not carrier_list:
            rds.hset(self.session_id, 'designate', str(self.designate_info))
            return self.designate_info
        else:
            _carrier_mobile_list = []
            _carrier_userid_list = []
            _carrier_name_list = []
            _carrier_user_type_list = []
            _carrier_exist_list = []
            for u in carrier_list:
                user = utils.get_user_by_serial_number(u)
                _carrier_mobile_list.append(user.get('CONTACTER_PHONE'))
                _carrier_userid_list.append(str(user.get('USER_ID')))
                _carrier_name_list.append(user.get('CONTACTER'))
                _carrier_user_type_list.append(user.get('USER_TYPE'))
                _carrier_exist_list.append('0')
            self.designate_info['appointCarrierMobiles'] = ','.join(
                _carrier_mobile_list)
            self.designate_info['appointCarrierUserIds'] = ','.join(
                _carrier_userid_list)
            self.designate_info['appointCarrierNames'] = ','.join(
                _carrier_name_list)
            self.designate_info['appointCarrierUserTypes'] = ','.join(
                _carrier_user_type_list)
            self.designate_info['appointCarrierIfExists'] = '.'.join(
                _carrier_exist_list)
            rds.hset(self.session_id, 'designate', str(self.designate_info))
            return self.designate_info
示例#6
0
    def snatch_order_consignor_insurance(self,
                                         mode: str = 'publish',
                                         freight_type: int = 1,
                                         user_quote: float = None,
                                         user_cargoMoney: float = None):
        """
        :param freight_type:
        :param mode:
        :param user_quote:
        :param user_cargoMoney:
        :return:
        普通货-抢单-自主保险:保险在发布节点确认。创建stage时将保险写入redis
        """
        publish_param = self._order_publish_type(mode)

        _cargoMoney = random.randint(5000, 15000)
        _quote = round(random.triangular(100, 200, 100), 3)
        _cargoCategory = self._cargo.get('cargoCategory', None)[0]

        if _cargoCategory == '1':
            _orderWeight = self._cargo.get('orderWeight', None)
            if _orderWeight:
                total_weight = float(sum(_orderWeight))
            else:
                raise ValueError("未获取到货物的计量")
        elif _cargoCategory == '2':
            _orderVolume = self._cargo.get('orderVolume', None)
            if _orderVolume:
                total_weight = float(sum(_orderVolume))
            else:
                raise ValueError('未获取到货物的计量')
        else:
            raise ValueError('未获取到货物的cargoCategory')
        cargoMoney = _cargoMoney if not user_cargoMoney else user_cargoMoney

        quote = _quote if not user_quote else user_quote
        if freight_type == 1:
            _allMoney = round(quote * total_weight, 3)
        elif freight_type == 2:
            _allMoney = quote
        else:
            raise ValueError('freight_type只能时1或者2')

        _insurance_param = {
            "havePolicy": "1",
            "cargo_list": self._cargo.get('orderName'),
            "cargoMoney": cargoMoney,
            "weight": total_weight,
            "totalMoney": str(_allMoney / 1.06382978),
            "giftMoney": float(self._common.get('giftMoney'))
        }
        insurance = get_insurance(**_insurance_param)

        order_type = {
            "orderModel": "0",
            "freightType": str(freight_type),
            "chooseRadio": "1",
            "havePolicy": "1",
            "orderMark": "",
            "cargoMoney": str(cargoMoney),
            "weight": str(total_weight),
            "quote": str(quote),
            "consignorNoTaxMoney": str(quote / 1.06382978),
            "allMoney": str(_allMoney),
            "cargoValueLimitation":
            float(insurance.get('CARGO_VALUE_LIMITATION')),
            "cargoValueOverLimit": insurance.get('CARGO_VALUE_OVER_LIMIT',
                                                 '0'),
            "blockMoney": str(self.blockMoney),
            "prompt": "普通货-抢单-单价-自主保险"
        }
        publish_param.update(order_type)
        rds.hset(self.session_id, 'insurance', str(insurance))
        rds.hset(self.session_id, 'publish_param', str(publish_param))
        return publish_param
示例#7
0
    def bidding_order_consignor_insurance(self,
                                          mode: str = 'publish',
                                          freight_type: int = 1,
                                          user_cargoMoney: float = None):
        """
        :param freight_type:
        :param mode:
        :param user_cargoMoney:
        :return:
        普通货-竞价-自主保险:保险根据货物类型确认。创建stage时将保险写入redis
        """
        publish_param = self._order_publish_type(mode)
        _cargoMoney = random.randint(5000, 15000)

        _cargoCategory = self._cargo.get('cargoCategory', None)[0]
        if _cargoCategory == '1':
            _orderWeight = self._cargo.get('orderWeight', None)
            if _orderWeight:
                total_weight = float(sum(_orderWeight))
            else:
                raise ValueError("未获取到货物的计量")
        elif _cargoCategory == '2':
            _orderVolume = self._cargo.get('orderVolume', None)
            if _orderVolume:
                total_weight = float(sum(_orderVolume))
            else:
                raise ValueError('未获取到货物的计量')
        else:
            raise ValueError('未获取到货物的cargoCategory')
        cargoMoney = _cargoMoney if not user_cargoMoney else user_cargoMoney

        _insurance_param = {
            "havePolicy": "1",
            "cargo_list": self._cargo.get('orderName'),
            "cargoMoney": cargoMoney,
            "weight": total_weight,
            "totalMoney": "",
            "giftMoney": float(self._common.get('giftMoney'))
        }
        insurance = get_insurance(**_insurance_param)

        order_type = {
            "orderModel": "1",
            "freightType": str(freight_type),
            "chooseRadio": "1",
            "havePolicy": "1",
            "orderMark": "",
            "cargoMoney": str(cargoMoney),
            "weight": str(total_weight),
            "quote": "",
            "consignorNoTaxMoney": "",
            "allMoney": "",
            "cargoValueLimitation":
            float(insurance.get('CARGO_VALUE_LIMITATION')),
            "cargoValueOverLimit": insurance.get('CARGO_VALUE_OVER_LIMIT',
                                                 '0'),
            "blockMoney": "300.001",
            "prompt": "普通货-抢单-包车价-自主保险"
        }
        publish_param.update(order_type)
        rds.hset(self.session_id, 'insurance', str(insurance))
        rds.hset(self.session_id, 'publish_param', str(publish_param))
        return publish_param
示例#8
0
 def __get__(self, instance, owner):
     oil = instance._oil(**self._setter)
     rds.hset(instance.session_id, 'oil', json.dumps(oil, ensure_ascii=False))
     return oil
示例#9
0
 def __get__(self, instance, owner):
     _designate = instance._designate(**self._setter)
     rds.hset(instance.session_id, 'designate', json.dumps(_designate, ensure_ascii=False))
     return _designate
示例#10
0
 def __get__(self, instance: object, owner):
     _common = instance._common(**self._setter)
     rds.hset(instance.session_id, 'common', json.dumps(_common, ensure_ascii=False))
     return _common
示例#11
0
 def __get__(self, instance, owner):
     _receipt = instance._receipt(**self._setter)
     rds.hset(instance.session_id, 'receipt', json.dumps(_receipt, ensure_ascii=False))
     return _receipt
示例#12
0
 def carrier_create(self):
     carrier = utils.get_user_by_serial_number(self._account)
     carrier_user_id = carrier.get('USER_ID')
     rds.hset(self.session_id, 'carrier_user_id', carrier_user_id)
     return Carrier(self.session_id, carrier_user_id, self._account)
示例#13
0
 def owner_create(self):
     consignor = utils.get_user_by_serial_number(self._account)
     consignor_user_id = consignor.get('USER_ID')
     rds.hset(self.session_id, 'consignor_user_id', consignor_user_id)
     return Owner(self.session_id, self._account, consignor_user_id)