def post(self, vendor_id, order_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got order_id %r in uri", order_id)

        order_dao.order_dao().delete(order_id)

        num = order_dao.order_dao().count_not_review_by_vendor(vendor_id)
        budge_num_dao.budge_num_dao().update({"_id": vendor_id, "order": num})

        self.finish("ok")
    def get(self, vendor_id, order_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got order_id %r in uri", order_id)

        _timestamp = time.time()
        json = {
            "_id": order_id,
            "last_update_time": _timestamp,
            "review": True
        }
        order_dao.order_dao().update(json)

        self.check_order(order_id)
        self.counter_decrease(vendor_id, "activity_order")

        self.finish("ok")
    def post(self, vendor_id, order_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got order_id %r in uri", order_id)
        _content = self.get_argument("content", "")
        _score = self.get_argument("score", "")
        if _score :
            _score = int(_score)
        else :
            _score = 0

        order = order_dao.order_dao().query(order_id)
        activity_id = order['activity_id']
        activity = activity_dao.activity_dao().query(activity_id)
        triprouter_id = activity['triprouter']

        # 更新订单状态
        json = {'_id':order_id, 'status': ORDER_STATUS_BF_COMMENT}
        order_dao.order_dao().update(json)

        # 创建新的评论
        _id = str(uuid.uuid1()).replace('-', '')
        json = {"_id":_id, "vendor_id":vendor_id,
                "content":_content, "score":_score,
                 "activity":activity_id, "triprouter":triprouter_id}
        evaluation_dao.evaluation_dao().create(json)
        logging.info("create eval _id %r", _id)

        # 更新线路表的评分 先取出该线路的所有评分算平均值后更新
        triprouter = trip_router_dao.trip_router_dao().query(triprouter_id)
        evaluations = evaluation_dao.evaluation_dao().query_by_triprouter(triprouter_id)

        total_score = 0
        total_time = 0

        for evaluation in evaluations:
            total_score = total_score + evaluation['score']
            total_time = total_time + 1
        new_score = math.ceil(float(total_score) / total_time)
        logging.info("create new score %r", new_score)

        _json = {"_id":triprouter_id, "score":int(new_score)}

        trip_router_dao.trip_router_dao().update(_json)

        self.redirect('/bf/wx/vendors/' + vendor_id + '/pc')
    def get(self, vendor_id, order_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got order_id %r in uri", order_id)

        _order = order_dao.order_dao().query(order_id)

        self.render('wx/myorder-evaluate.html',
                vendor_id=vendor_id,
                order=_order)
    def get(self, vender_id):
        account_id = self.get_argument("account_id")
        logging.info("got _account_id %r", account_id)
        sBefore = self.get_argument("before", "")
        if sBefore != "":
            iBefore = float(datetime_timestamp(sBefore))
        else:
            iBefore = time.time()
        logging.info("got iBefore>>>> %r in uri", iBefore)
        _orders = order_dao.order_dao().query_pagination_by_account(
            account_id, iBefore, PAGE_SIZE_LIMIT)
        for order in _orders:
            _activity = activity_dao.activity_dao().query(order['activity_id'])
            order['activity_title'] = _activity['title']
            order['create_time'] = timestamp_datetime(order['create_time'])
            logging.info("got activity_title %r", order['activity_title'])
            order['activity_begin_time'] = timestamp_datetime(
                _activity['begin_time'])
            order['activity_distance'] = _activity['distance']
            order['activity_status'] = _activity['status']

            order_fees = []
            for ext_fee_id in order['ext_fees']:
                for template in _activity['ext_fee_template']:
                    if ext_fee_id == template['_id']:
                        json = {
                            "_id": ext_fee_id,
                            "name": template['name'],
                            "fee": template['fee']
                        }
                        order_fees.append(json)
                        break
            order['fees'] = order_fees

            order_insurances = []
            for insurance_id in order['insurances']:
                _insurance = insurance_template_dao.insurance_template_dao(
                ).query(insurance_id)
                order_insurances.append(_insurance)
            order['insurances'] = order_insurances

            _cret = cret_dao.cret_dao().query_by_account(
                order['activity_id'], order['account_id'])
            if _cret:
                logging.info("got _cret_id %r", _cret['_id'])
                order['cret_id'] = _cret['_id']
            else:
                order['cret_id'] = None

        _json = json_encode(_orders)
        self.write(_json)
        self.finish()
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        # _session_ticket = self.get_secure_cookie("session_ticket")

        _keys = self.get_argument("keysValue", "")
        _type = self.get_argument("searchType", "")

        if (_type == 'order'):
            _array = order_dao.order_dao().query_by_order_keys(
                vendor_id, _keys)
        elif (_type == 'title'):
            _array = apply_dao.apply_dao().query_by_title_keys(
                vendor_id, _keys)
        elif (_type == 'nickname'):
            _array = order_dao.order_dao().query_by_nickname_keys(
                vendor_id, _keys)
        elif (_type == 'date'):
            keys_array = _keys.split('~')
            begin_keys = float(date_timestamp(keys_array[0]))
            end_keys = float(date_timestamp(keys_array[1]))
            logging.info("got begin_keys>>>>>>>>>>> %r in uri", begin_keys)
            logging.info("got end_keys>>>>>>>>>>> %r in uri", end_keys)
            _array = order_dao.order_dao().query_by_time_keys(
                vendor_id, begin_keys, end_keys)
        else:
            _array = []

        if (_array):
            for order in _array:
                _activity = activity_dao.activity_dao().query(
                    order['activity_id'])
                order['activity_title'] = _activity['title']
                # order['activity_amount'] = _activity['amount']
                if not order['base_fees']:
                    order['activity_amount'] = 0
                else:
                    for base_fee in order['base_fees']:
                        # 价格转换成元
                        order['activity_amount'] = float(base_fee['fee']) / 100

                logging.info("got activity_title %r", order['activity_title'])
                order['create_time'] = timestamp_datetime(order['create_time'])

                customer_profile = vendor_member_dao.vendor_member_dao(
                ).query_not_safe(vendor_id, order['account_id'])

                if (customer_profile):
                    try:
                        customer_profile['account_nickname']
                    except:
                        customer_profile['account_nickname'] = ''
                    try:
                        customer_profile['account_avatar']
                    except:
                        customer_profile['account_avatar'] = ''

                    order['account_nickname'] = customer_profile[
                        'account_nickname']
                    order['account_avatar'] = customer_profile[
                        'account_avatar']
                else:
                    order['account_nickname'] = ''
                    order['account_avatar'] = ''

                try:
                    order['bonus']
                except:
                    order['bonus'] = 0
                # 价格转换成元
                order['bonus'] = float(order['bonus']) / 100
                try:
                    order['prepay_id']
                except:
                    order['prepay_id'] = ''
                try:
                    order['transaction_id']
                except:
                    order['transaction_id'] = ''
                try:
                    order['payed_total_fee']
                except:
                    order['payed_total_fee'] = 0

                for ext_fee in order['ext_fees']:
                    # 价格转换成元
                    ext_fee['fee'] = float(ext_fee['fee']) / 100

                for insurance in order['insurances']:
                    # 价格转换成元
                    insurance['fee'] = float(insurance['fee']) / 100

                for _voucher in order['vouchers']:
                    # 价格转换成元
                    _voucher['fee'] = float(_voucher['fee']) / 100

                _cret = cret_dao.cret_dao().query_by_account(
                    order['activity_id'], order['account_id'])
                if _cret:
                    logging.info("got _cret_id %r", _cret['_id'])
                    order['cret_id'] = _cret['_id']
                else:
                    order['cret_id'] = None

                # order['activity_amount'] = float(_activity['amount']) / 100
                if not order['base_fees']:
                    order['activity_amount'] = 0
                else:
                    for base_fee in order['base_fees']:
                        # 价格转换成元
                        order['activity_amount'] = float(base_fee['fee']) / 100

                order['total_amount'] = float(order['total_amount']) / 100
                order['payed_total_fee'] = float(
                    order['payed_total_fee']) / 100

        _json = json_encode(_array)
        logging.info("got _json %r", _json)
        self.write(JSON.dumps(_json, default=json_util.default))
        self.finish()