예제 #1
0
    def post(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        access_token = self.get_secure_cookie("access_token")
        ops = self.get_ops_info()

        _title = self.get_argument("title", "")
        _bk_img_url = self.get_argument("bk_img_url", "")
        _category = self.get_argument("category", "")
        _location = self.get_argument("location", "")
        _distance = self.get_argument("distance", "")
        _strength = self.get_argument("strength", "")
        _scenery = self.get_argument("scenery", "")
        _road_info = self.get_argument("road_info", "")
        _kickoff = self.get_argument("kickoff", "")

        logging.debug("got param title %r", _title)

        _id = str(uuid.uuid1()).replace('-', '')
        logging.info("create triprouter _id %r", _id)
        triprouters = {"_id":_id, "vendor_id":vendor_id,
                "title":_title, "bk_img_url":_bk_img_url, "category":_category, "location":_location,
                "distance":_distance, "strength":_strength, "scenery":_scenery, "road_info":_road_info,
                "kickoff":_kickoff, "score":10, "open":False}

        trip_router_dao.trip_router_dao().create(triprouters);

        article = {'_id':_id ,'title':_title, 'subtitle':_location, 'img':_bk_img_url,'paragraphs':''}
        self.create_article(article)

        self.redirect('/vendors/' + vendor_id + '/trip_router')
예제 #2
0
    def post(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r ~~~~~~in uri", vendor_id)
        logging.info("got trip_router_id %r @@@@@@in uri", trip_router_id)

        ops = self.get_ops_info()

        _title = self.get_argument("title", "")
        _bk_img_url = self.get_argument("bk_img_url", "")
        _category = self.get_argument("category", "")
        _location = self.get_argument("location", "")
        _distance = self.get_argument("distance", "")
        _strength = self.get_argument("strength", "")
        _scenery = self.get_argument("scenery", "")
        _road_info = self.get_argument("road_info", "")
        _kickoff = self.get_argument("kickoff", "")

        logging.info("update triprouter _id %r", trip_router_id)
        json = {"_id":trip_router_id, "vendor_id":vendor_id,
                "title":_title, "bk_img_url":_bk_img_url, "category":_category, "location":_location,
                "distance":_distance, "strength":_strength, "scenery":_scenery, "road_info":_road_info,
                "kickoff":_kickoff, "score":10}

        trip_router_dao.trip_router_dao().update(json)

        self.redirect('/vendors/' + vendor_id + '/trip_router/' + trip_router_id + '/edit/step1')
예제 #3
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip_router_id %r in uri", trip_router_id)

        ops = self.get_ops_info()
        access_token = self.get_access_token()

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

        # create new triprouter
        _triprouterty_id = str(uuid.uuid1()).replace('-', '')
        _timestamp = time.time()
        _json = {"_id":_triprouterty_id, "vendor_id":vendor_id,
                "title":triprouter['title'],
                "bk_img_url":triprouter['bk_img_url'],
                "category":triprouter['category'],
                "location":triprouter['location'],
                "distance":triprouter['distance'],
                "strength":triprouter['strength'],
                "scenery":triprouter['scenery'],
                "road_info":triprouter['road_info'],
                "kickoff":triprouter['kickoff'],
                "open":False,
                "score":10}

        trip_router_dao.trip_router_dao().create(_json)
        article = self.get_article(trip_router_id)
        if article:
            # 再创建一个新的article
            article = {'_id':_triprouterty_id, 'title':triprouter['title'], 'subtitle':triprouter['location'], 'img':triprouter['bk_img_url'],'paragraphs':_paragraphs}
            self.create_article(article)

        self.redirect('/vendors/' + ops['club_id'] + '/trip_router')
예제 #4
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip-router_id %r in uri", trip_router_id)

        ops = self.get_ops_info()

        trip_router_dao.trip_router_dao().delete(trip_router_id)

        self.redirect('/vendors/' + vendor_id + '/trip_router')
예제 #5
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip-router_id %r in uri", trip_router_id)

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

        access_token = self.get_secure_cookie("access_token")
        ops = self.get_ops_info()

        self.unpublish_article(trip_router_id)

        json = {"_id":trip_router_id, "open":False}
        trip_router_dao.trip_router_dao().updateOpenStatus(json)

        self.redirect('/vendors/' + vendor_id + '/trip_router')
예제 #6
0
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        tasks = task_dao.task_dao().query_by_vendor(vendor_id)

        for task in tasks:
            task['create_time'] = timestamp_datetime(task['create_time'])
            trip_router_id = task['triprouter']
            logging.info("got trip_router_id>>>>>>>>>> %r in uri",
                         trip_router_id)
            triprouter = trip_router_dao.trip_router_dao().query(
                trip_router_id)
            task['title'] = triprouter['title']
            task['bk_img_url'] = triprouter['bk_img_url']
            for category in categorys:
                if category['_id'] == task['category']:
                    task['category'] = category['title']
                    break

        counter = self.get_counter(vendor_id)
        self.render('vendor/task-list.html',
                    vendor_id=vendor_id,
                    ops=ops,
                    counter=counter,
                    tasks=tasks)
예제 #7
0
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        # categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        triprouters = trip_router_dao.trip_router_dao().query_by_open(vendor_id)
        triprouters_share = triprouter_share_dao.triprouter_share_dao().query_by_vendor(vendor_id)

        # 在所有开放的线路中剔除掉自己开放的
        for triprouter in triprouters:
            if(triprouter['vendor_id'] == vendor_id):
                triprouters.remove(triprouter)
                break

        # 加share属性,区别一个自己是否已经分享了别人开放的这个线路
        for triprouter in triprouters:
            club = club_dao.club_dao().query(triprouter['vendor_id'])
            triprouter['club']= club['club_name']
            triprouter['share'] = False

            for triprouter_share in triprouters_share:
                if(triprouter['_id']==triprouter_share['triprouter']):
                    triprouter['share'] = True
                    break

        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-share.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouters=triprouters)
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        account_id = self.get_secure_cookie("account_id")
        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        personal_tasks = personal_task_dao.personal_task_dao().query_by_vendor_account(vendor_id,account_id)

        for personal_task in personal_tasks:
            personal_task['create_time'] = timestamp_datetime(personal_task['create_time'])

            task_id = personal_task['task_id']
            task = task_dao.task_dao().query(task_id)

            trip_router_id = task['triprouter']
            triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

            personal_task['title'] = triprouter['title']
            personal_task['bk_img_url'] = triprouter['bk_img_url']
            for category in categorys:
                if category['_id'] == task['category']:
                    personal_task['category'] = category['title']
                    break

        self.render('wx/my-tasks.html',
                vendor_id=vendor_id,
                tasks=personal_tasks)
예제 #9
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip-router_id %r in uri", trip_router_id)

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

        access_token = self.get_secure_cookie("access_token")
        ops = self.get_ops_info()

        json = {"_id":trip_router_id, "open":True}
        trip_router_dao.trip_router_dao().updateOpenStatus(json)

        ids = {'ids':['b0569f58144f11e78d3400163e023e51']}
        self.update_article_categories(trip_router_id, ids)
        self.publish_article(trip_router_id)

        self.redirect('/vendors/' + vendor_id + '/trip_router')
    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')
예제 #11
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)
        evaluations = evaluation_dao.evaluation_dao().query_by_triprouter(trip_router_id)
        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-evallist.html',
                vendor_id=vendor_id,
                ops=ops,
                triprouter=triprouter,
                counter=counter,
                evaluations=evaluations)
예제 #12
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip-router_id %r in edit step1", trip_router_id)

        ops = self.get_ops_info()

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)
        categorys = category_dao.category_dao().query_by_vendor(vendor_id)

        counter = self.get_counter(vendor_id)

        self.render('vendor/trip-router-edit-step1.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouter=triprouter, categorys=categorys)
예제 #13
0
    def post(self,vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip_router_id %r in uri", trip_router_id)

        access_token = self.get_secure_cookie("access_token")
        ops = self.get_ops_info()

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

        content = self.get_argument("content","")
        logging.info("got content %r", content)

        article = {'_id':trip_router_id ,'title':triprouter['title'], 'subtitle':triprouter['location'], 'img':triprouter['bk_img_url'],'paragraphs':content}
        self.update_article(article)

        self.redirect('/vendors/' + vendor_id + '/trip_router/' + trip_router_id + '/edit/step2')
예제 #14
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip-router_id %r in uri", trip_router_id)

        ops = self.get_ops_info()

        # 设置别人开放的线路为自己所用
        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)
        club = club_dao.club_dao().query(triprouter['vendor_id'])

        _id = str(uuid.uuid1()).replace('-', '')
        json = {"_id":_id, "triprouter":trip_router_id,
                "share":True,"vendor_id":vendor_id, "bk_img_url":triprouter['bk_img_url'],
                "title":triprouter['title'],"club":club['club_name'],"score":triprouter['score']}

        triprouter_share_dao.triprouter_share_dao().create(json)

        self.redirect('/vendors/' + vendor_id + '/trip_router/share')
예제 #15
0
    def get(self, vendor_id):

        # _array = trip_router_dao.trip_router_dao().query_by_open(vendor_id)
        triprouters_me = trip_router_dao.trip_router_dao().query_by_vendor(
            vendor_id)
        triprouters_share = triprouter_share_dao.triprouter_share_dao(
        ).query_by_vendor(vendor_id)

        # 处理一下自己线路
        for triprouter in triprouters_me:
            club = club_dao.club_dao().query(triprouter['vendor_id'])
            triprouter['club'] = club['club_name']
            triprouter['share'] = False

        _array = triprouters_me + triprouters_share

        self.render('wx/triprouter-index.html',
                    vendor_id=vendor_id,
                    triprouters=_array)
예제 #16
0
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()
        logging.info("got ops %r in uri", ops)

        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        triprouters = trip_router_dao.trip_router_dao().query_by_vendor(vendor_id)

        for triprouter in triprouters:
            for category in categorys:
                if category['_id'] == triprouter['category']:
                    triprouter['category'] = category['title']
                    break
        logging.info("got triprouter %r in uri", triprouters)

        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-list.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouters=triprouters)
예제 #17
0
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        triprouters_me = trip_router_dao.trip_router_dao().query_by_vendor(vendor_id)
        triprouters_share = triprouter_share_dao.triprouter_share_dao().query_by_vendor(vendor_id)

        # 处理一下自己线路
        for triprouter in triprouters_me:
            club = club_dao.club_dao().query(triprouter['vendor_id'])
            triprouter['club'] = club['club_name']
            triprouter['share'] = False

        triprouters = triprouters_me + triprouters_share

        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-use.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouters=triprouters)
예제 #18
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got trip_router_id %r in edit step2", trip_router_id)

        access_token = self.get_secure_cookie("access_token")
        ops = self.get_ops_info()

        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

        article = self.get_article(trip_router_id)
        if not article:
            article = {'_id':trip_router_id ,'title':triprouter['title'], 'subtitle':triprouter['location'], 'img':triprouter['bk_img_url'],'paragraphs':''}
            self.create_article(article)

        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-edit-step2.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouter=triprouter,
                travel_id=trip_router_id,
                article=article)
예제 #19
0
    def get(self, vendor_id, trip_router_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        activitys = activity_dao.activity_dao().query_by_triprouter(trip_router_id)
        triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)
        for activity in activitys:
            activity['begin_time'] = timestamp_date(float(activity['begin_time'])) # timestamp -> %m/%d/%Y
            for category in categorys:
                if category['_id'] == activity['category']:
                    activity['category'] = category['title']
                    break

        counter = self.get_counter(vendor_id)
        self.render('vendor/trip-router-activitylist.html',
                vendor_id=vendor_id,
                ops=ops,
                counter=counter,
                triprouter=triprouter,
                activitys=activitys)
예제 #20
0
    def post(self, vendor_id):

        triprouters = self.get_argument("triprouters", [])
        _triprouter_ids = JSON.loads(triprouters)
        for trip_router_id in _triprouter_ids:
            trip_router = trip_router_dao.trip_router_dao().query(
                trip_router_id)
            _id = str(uuid.uuid1()).replace('-', '')
            _timestamp = time.time()
            _category = trip_router['category']
            _title = trip_router['title']
            _json = {
                "_id": _id,
                "title": _title,
                "vendor_id": vendor_id,
                "triprouter": trip_router_id,
                "category": _category,
                "create_time": _timestamp
            }
            task_dao.task_dao().create(_json)

        self.redirect('/vendors/' + vendor_id + '/setup/task')
예제 #21
0
    def get(self, vendor_id):
        logging.info("got vendor_id %r in uri", vendor_id)

        ops = self.get_ops_info()

        tasks = task_dao.task_dao().query_by_vendor(vendor_id)
        trip_routers = trip_router_dao.trip_router_dao().query_by_vendor(
            vendor_id)
        # 从所有线路里分离出没被选中任务的
        for task in tasks:
            task_trip_router = task['triprouter']
            for trip_router in trip_routers:
                trip_router_id = trip_router['_id']
                if (task_trip_router == trip_router_id):
                    trip_routers.remove(trip_router)
                    break

        counter = self.get_counter(vendor_id)
        self.render('vendor/task-create.html',
                    vendor_id=vendor_id,
                    ops=ops,
                    counter=counter,
                    triprouters=trip_routers)
    def get(self, vendor_id, account_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got account_id %r in uri", account_id)

        ops = self.get_ops_info()
        access_token = self.get_access_token()

        url = API_DOMAIN + "/api/clubs/"+vendor_id+"/users/" + account_id
        http_client = HTTPClient()
        headers = {"Authorization":"Bearer " + access_token}
        response = http_client.fetch(url, method="GET", headers=headers)
        logging.info("got response.body %r", response.body)
        data = json_decode(response.body)
        _customer_profile = data['rs']

        _contacts = contact_dao.contact_dao().query_by_account(vendor_id, account_id)

        access_token = self.get_access_token()

        params = {"filter":"account", "account_id":account_id, "page":1, "limit":20,}
        url = url_concat(API_DOMAIN + "/api/orders", params)
        http_client = HTTPClient()
        headers = {"Authorization":"Bearer " + access_token}
        response = http_client.fetch(url, method="GET", headers=headers)
        logging.info("got response.body %r", response.body)
        data = json_decode(response.body)
        rs = data['rs']
        orders = rs['data']

        for order in orders:
            # 下单时间,timestamp -> %m月%d 星期%w
            order['create_time'] = timestamp_datetime(float(order['create_time']))
            # 合计金额
            order['amount'] = float(order['amount']) / 100
            order['actual_payment'] = float(order['actual_payment']) / 100

        # 取任务
        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        personal_tasks = personal_task_dao.personal_task_dao().query_by_vendor_account(vendor_id,account_id)
        logging.info("got personal_tasks============ %r in uri", len(personal_tasks))

        for personal_task in personal_tasks:
            personal_task['create_time'] = timestamp_datetime(personal_task['create_time'])

            task_id = personal_task['task_id']
            task = task_dao.task_dao().query(task_id)

            trip_router_id = task['triprouter']
            triprouter = trip_router_dao.trip_router_dao().query(trip_router_id)

            personal_task['title'] = triprouter['title']
            personal_task['bk_img_url'] = triprouter['bk_img_url']
            for category in categorys:
                if category['_id'] == task['category']:
                    personal_task['category'] = category['title']
                    break

        counter = self.get_counter(vendor_id)
        self.render('vendor/customer-profile.html',
                access_token=access_token,
                vendor_id=vendor_id,
                ops=ops,
                account_id=account_id,
                counter=counter,
                profile=_customer_profile,
                contacts=_contacts, orders=orders, tasks =personal_tasks)
예제 #23
0
    def get(self, vendor_id, triprouter_id):
        logging.info("got vendor_id %r in uri", vendor_id)
        logging.info("got triprouter_id %r in uri", triprouter_id)

        _triprouter = trip_router_dao.trip_router_dao().query(triprouter_id)

        # 详细介绍 判断是否有article_id
        try:
            _triprouter['article_id']
        except:
            _triprouter['article_id'] = ''

        if (_triprouter['article_id'] != ''):

            url = "http://" + STP + "/blogs/my-articles/" + _triprouter[
                'article_id'] + "/paragraphs"
            http_client = HTTPClient()
            response = http_client.fetch(url, method="GET")
            logging.info("got response %r", response.body)
            _paragraphs = json_decode(response.body)

            _triprouter_desc = ""
            for _paragraph in _paragraphs:
                if _paragraph["type"] == 'raw':
                    _triprouter_desc = _paragraph['content']
                    break
            _triprouter_desc = _triprouter_desc.replace('&', "").replace(
                'mdash;', "").replace('<p>', "").replace("</p>", " ").replace(
                    "<section>", "").replace("</section>",
                                             " ").replace("\n", " ")
            _triprouter['desc'] = _triprouter_desc + '...'

        else:
            _triprouter['desc'] = '...'

        # 相关活动
        categorys = category_dao.category_dao().query_by_vendor(vendor_id)
        activitys = activity_dao.activity_dao().query_by_triprouter(
            triprouter_id)
        for activity in activitys:
            activity['begin_time'] = timestamp_date(
                float(activity['begin_time']))  # timestamp -> %m/%d/%Y
            activity['end_time'] = timestamp_date(float(
                activity['end_time']))  # timestamp -> %m/%d/%Y
            for category in categorys:
                if category['_id'] == activity['category']:
                    activity['category'] = category['title']
                    break

        wx_app_info = vendor_wx_dao.vendor_wx_dao().query(vendor_id)
        wx_app_id = wx_app_info['wx_app_id']
        logging.info("got wx_app_id %r in uri", wx_app_id)
        wx_app_secret = wx_app_info['wx_app_secret']
        wx_notify_domain = wx_app_info['wx_notify_domain']

        logging.info("------------------------------------uri: " +
                     self.request.uri)
        _access_token = getAccessTokenByClientCredential(
            wx_app_id, wx_app_secret)
        _jsapi_ticket = getJsapiTicket(_access_token)
        _sign = Sign(_jsapi_ticket, wx_notify_domain + self.request.uri).sign()
        logging.info("------------------------------------nonceStr: " +
                     _sign['nonceStr'])
        logging.info("------------------------------------jsapi_ticket: " +
                     _sign['jsapi_ticket'])
        logging.info("------------------------------------timestamp: " +
                     str(_sign['timestamp']))
        logging.info("------------------------------------url: " +
                     _sign['url'])
        logging.info("------------------------------------signature: " +
                     _sign['signature'])

        # _logined = False
        # wechat_open_id = self.get_secure_cookie("wechat_open_id")
        # if wechat_open_id:
        #     _logined = True

        _account_id = self.get_secure_cookie("account_id")

        self.render('wx/triprouter-info.html',
                    vendor_id=vendor_id,
                    triprouter=_triprouter,
                    activitys=activitys,
                    wx_app_id=wx_app_secret,
                    wx_notify_domain=wx_notify_domain,
                    sign=_sign,
                    account_id=_account_id)