Ejemplo n.º 1
0
 def get(self, *args, **kwargs):
     shop_id = ObjectId(self.get_argument('id'))
     shop = yield self.shop_model.GetShopFromId(shop_id)
     shop_data = yield BuildShopData().BuildShopDeatil(shop)
     areas_full = yield BuildAreaData().BuildAreasWithSchools(
         self.current_user)
     school_of_shop = yield self.school_model.GetSchoolFromId(
         shop['school_district'])
     if not school_of_shop:
         school_of_shop = {}
     data = {
         'shop': shop_data,
         'areas': {
             'full':
             json.dumps(areas_full),
             'choosed':
             json.dumps({
                 'area': school_of_shop.get('region', ''),
                 'province': school_of_shop.get('province', ''),
                 'city': school_of_shop.get('city', ''),
                 'campus': school_of_shop.get('name', '')
             })
         },
         'shop_add': False
     }
     self.render('detail_page_shop_edit.html', data=data)
Ejemplo n.º 2
0
 def get(self, *args, **kwargs):
     shop_id = ObjectId(self.get_argument('id'))
     shop = yield self.shop_model.GetShopFromId(shop_id)
     if shop['school_name'] == 'kkyzh' and not 'sa' in self.current_user[
             'roles']:
         raise gen.Return(None)
     shop_data = yield BuildShopData().BuildShopDeatil(shop)
     data = {'shop': shop_data}
     self.render('detail_page_shop.html', data=data)
Ejemplo n.º 3
0
    def get(self, *args, **kwargs):
        table_type = self.get_argument('type')

        kwargs = {'user': self.current_user}

        data = {}
        if table_type == 'role_list':
            if not 'RoleRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = BuildRoleData().BuildTableFrame()
        elif table_type == 'member_list':
            if not 'UserRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildUserData().BuildTableFrame(**kwargs)
        elif table_type == 'campus_list':
            if not 'SchoolRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildSchoolData().BuildTableFrame(**kwargs)
        elif table_type == 'order_list':
            if not 'OrderRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildOrderData().BuildTableFrame(**kwargs)
        elif table_type == 'item_list':
            if not 'ItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = BuildItemData().BuildTableFrame(**kwargs)
        elif table_type == 'shop_list':
            if not 'ShopRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildShopData().BuildTableFrame(**kwargs)
        elif table_type == 'courier_list':
            if not 'CourierRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildCourierData().BuildTableFrame(**kwargs)
        elif table_type == 'task_list':
            if not 'TaskRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildTaskData().BuildTableFrame(**kwargs)
        elif table_type == 'withdraw_list':
            if not 'WithdrawRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildWithdrawData().BuildTableFrame(**kwargs)
        elif table_type == 'expenses_list':
            if not 'ExpendRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildExpendData().BuildTableFrame(**kwargs)

        table_to_render = {
            'role_list': 'table_role.html',
            'item_list': 'table_role.html',
            'campus_list': 'table_campus.html'
        }.get(table_type, 'table.html')

        self.render(table_to_render, data=data)
Ejemplo n.º 4
0
    def get(self, *args, **kwargs):
        if not 'ShopRead' in self.current_user['privileges']:
            raise PermissionDeny()

        shop_id = ObjectId(self.get_argument('shop_id'))
        faked_category_id = self.get_argument('id', None)
        if not faked_category_id or faked_category_id == '0':
            self.write('')
            raise gen.Return(None)
        faked_category = settings.item.GetCategoryFromId(faked_category_id)
        if not faked_category:
            self.write('')
            raise gen.Return(None)

        data_items = yield BuildShopData().BuildShopItems(shop_id, faked_category['name'])

        data = {
            'items': data_items,
            'shop_id': shop_id
        }
        self.render('detail_page_shop_edit_items_content.html', data=data)
Ejemplo n.º 5
0
    def post(self, *args, **kwargs):
        region = self.get_argument('area')
        province = self.get_argument('province')
        city = self.get_argument('city')
        campus = self.get_argument('campus')

        areas_full = yield BuildAreaData().BuildAreasWithSchools(self.current_user)
        data = {
            'flag': 'ok',
            'message': u'',
            'areas': {
                'full': json.dumps(areas_full)
            }
        }

        if u'全部' in region or u'全部' in province or u'全部' in city or u'全部' in campus:
            data['flag'] = 'error'
            data['message'] = u'添加店铺失败:未选择校区'
            self.render('detail_page_shop_edit.html', data=data)
            raise gen.Return(None)

        shop_data = yield BuildShopData().BuildShopFromRequest(self)
        shop_data['created_time'] = int(time.time()*1000)
        shop_data['image_id'] = self.GetShopImageId(shop_data['type'])

        school = yield self.school_model.GetSchoolFromName(campus)
        available_couriers = yield self.courier_model.GetCouriersFromDistrictId(school['_id'])
        if not available_couriers:
            shop_data['status'] = 'closed'

        result = yield self.shop_model.insert(shop_data)
        if result:
            self.redirect('/shop_detail?id=%s' % result)
        else:
            data['flag'] = 'error'
            data['message'] = u'添加店铺失败'
            self.render('detail_page_shop_edit.html', data=data)
Ejemplo n.º 6
0
    def get(self, *args, **kwargs):
        type = self.get_argument('type')
        page = int(self.get_argument('page', 1))
        filter_type = self.get_argument('filter_type', '')
        filter_value = self.get_argument('filter_value', '')
        filter_status = self.get_argument('filter_status', '')
        filter_time_start = self.get_argument('filter_datestart', None)
        filter_time_end = self.get_argument('filter_dateend', None)
        area = self.get_argument('area', '')
        province = self.get_argument('province', '')
        city = self.get_argument('city', '')
        campus = self.get_argument('campus', '')

        if not area or u'全部' in area:
            area = self.current_user['region']
        if not province or u'全部' in province:
            province = self.current_user['province']
        if not city or u'全部' in city:
            city = self.current_user['city']
        if not campus or u'全部' in campus:
            campus = self.current_user['school_name']

        if filter_time_start:
            dt = datetime.datetime.utcfromtimestamp(int(filter_time_start)/1000)
            filter_time_start = int(time.mktime(dt.timetuple())) * 1000
        if filter_time_end:
            dt = datetime.datetime.utcfromtimestamp(int(filter_time_end)/1000) + datetime.timedelta(days=1)
            filter_time_end = int(time.mktime(dt.timetuple())) * 1000

        kwargs = {
            'page': page,
            'filter_type': filter_type,
            'filter_value': filter_value,
            'filter_status': filter_status,
            'filter_time_start': filter_time_start,
            'filter_time_end': filter_time_end,
            'area': area,
            'province': province,
            'city': city,
            'campus': campus
        }

        data = {}
        if type == 'role_list':
            if not 'RoleRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildRoleData().BuildTableContent(**kwargs)
        elif type == 'member_list':
            if not 'UserRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildUserData().BuildTableContent(**kwargs)
        elif type == 'campus_list':
            if not 'SchoolRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildSchoolData().BuildTableContent(**kwargs)
        elif type == 'order_list':
            if not 'OrderRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildOrderData().BuildTableContent(**kwargs)
        elif type == 'item_list':
            if not 'ItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildItemData().BuildTableContent(**kwargs)
        elif type == 'shop_list':
            if not 'ShopRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildShopData().BuildTableContent(**kwargs)
        elif type == 'courier_list':
            if not 'CourierRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildCourierData().BuildTableContent(**kwargs)
        elif type == 'task_list':
            if not 'TaskRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildTaskData().BuildTableContent(**kwargs)
        elif type == 'withdraw_list':
            if not 'WithdrawRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildWithdrawData().BuildTableContent(**kwargs)
        elif type == 'expenses_list':
            if not 'ExpendRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildExpendData().BuildTableContent(**kwargs)

        self.render('table_content.html', data=data)
Ejemplo n.º 7
0
    def post(self, *args, **kwargs):
        if not 'ShopUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        shop_id = ObjectId(self.get_argument('shop_id'))
        faked_category_id = self.get_argument('id')
        hardcoded_category = settings.item.GetCategoryFromId(faked_category_id)

        selected_items = {}
        for k,v in self.request.arguments.items():
            m = re.findall('.*_(.*)_checked', k)
            if m:
                selected_items[m[0]] = {}
        for k,v in self.request.arguments.items():
            m = re.findall('.*_(.*)_price', k)
            if m and m[0] in selected_items:
                selected_items[m[0]]['price'] = int(decimal.Decimal(v[0])*100)

        condition = {
            'shop_id': shop_id,
            'name': hardcoded_category['name']
        }
        category = yield self.category_model.find_one(condition)
        if not category and selected_items:
            category_data = {
                'shop_id': shop_id,
                'name': hardcoded_category['name'],
                'priority': hardcoded_category['priority']
            }
            new_category_id = yield self.category_model.insert(category_data)
            category = yield self.category_model.find_one({'_id': new_category_id})

        condition = {
            '_id': {  '$in': [ObjectId(_) for _ in selected_items] }
        }
        selected_repo_items = yield self.item_repo_model.find(condition).to_list(None)
        selected_item_numbers = [_['number'] for _ in selected_repo_items]

        condition = {
            'category': hardcoded_category['name']
        }
        all_repo_items = yield self.item_repo_model.find(condition).to_list(None)
        all_repo_item_numbers = [_['number'] for _ in all_repo_items]

        on_sale_items_condition = {
            'shop_id': shop_id,
            'category': category['_id'],
            'status': 'on_sale',
            'old': { '$exists': False }
        }
        current_shop_on_sale_items = yield self.item_model.find(on_sale_items_condition).to_list(None)
        go_off_shelves_item_numbers = [
            i['id']
            for i in current_shop_on_sale_items
                if i ['id'] in all_repo_item_numbers and not i['id'] in selected_item_numbers
        ]

        condition = {
            'shop_id': shop_id,
            'category': category['_id'],
            'old': { '$exists': False },
            'id': { '$in': go_off_shelves_item_numbers }
        }
        updater = {
            '$set': { 'status': 'off_shelves' }
        }
        result = yield self.item_model.update(condition, updater, multi=True)
        logging.info('[ShopEditItemsContent] ' + self.current_user.get('name','') + ' off_shelves: ' + str(go_off_shelves_item_numbers))

        # current_shop_on_sale_item_numbers = [_['id'] for _ in current_shop_on_sale_items]
        for item in selected_repo_items:
            condition = {
                'shop_id': shop_id,
                'category': category['_id'],
                'id': item['number'],
                'name': item['name']
            }
            updater = {
                '$set': {
                    'status': 'on_sale',
                    'price': selected_items[str(item['_id'])]['price'],
                    'priority': item['priority'],
                    'image_id': item['image_id'],
                    'description': item.get('description', '')
                }
            }

            if 'limit' in item:
                updater['$set']['special_price'] = item['special_price']
                updater['$set']['limit'] = item['limit']

            result = yield self.item_model.update(condition, updater, upsert=True)

        data_items = yield BuildShopData().BuildShopItems(shop_id, category['name'])
        data = {
            'items': data_items,
            'shop_id': shop_id,
            'flag': 'ok',
            'message': u'修改成功'
        }
        self.render('detail_page_shop_edit_items_content.html', data=data)
Ejemplo n.º 8
0
    def post(self, *args, **kwargs):
        shop_id = ObjectId(self.get_argument('id'))
        shop_data = yield BuildShopData().BuildShopFromRequest(self)

        if shop_data['status'] == 'open':
            shop = yield self.shop_model.GetShopFromId(shop_id)
            school = yield self.school_model.GetSchoolFromId(
                shop['school_district'])
            available_couriers = yield self.courier_model.GetCouriersFromDistrictId(
                school['_id'])
            if not available_couriers:
                del shop_data['status']
                shop = yield self.shop_model.GetShopFromId(shop_id)
                shop_data = yield BuildShopData().BuildShopDeatil(shop)
                areas_full = yield BuildAreaData().BuildAreasWithSchools(
                    self.current_user)
                school_of_shop = yield self.school_model.GetSchoolFromId(
                    shop['school_district'])
                if not school_of_shop:
                    school_of_shop = {}
                data = {
                    'shop': shop_data,
                    'areas': {
                        'full':
                        json.dumps(areas_full),
                        'choosed':
                        json.dumps({
                            'area':
                            school_of_shop.get('region', ''),
                            'province':
                            school_of_shop.get('province', ''),
                            'city':
                            school_of_shop.get('city', ''),
                            'campus':
                            school_of_shop.get('name', '')
                        })
                    }
                }
                data['flag'] = 'error'
                data['message'] = '没有工作的速递员,不能营业'
                self.render('detail_page_shop_edit.html', data=data)
                raise gen.Return(None)

        result = yield self.shop_model.UpdateShop(shop_id, shop_data)
        success = result['updatedExisting'] and result['ok'] == 1

        if success:
            self.redirect('/shop_detail?id=%s' % shop_id)
        else:
            shop = yield self.shop_model.GetShopFromId(shop_id)
            shop_data = yield BuildShopData().BuildShopDeatil(shop)
            areas_full = yield BuildAreaData().BuildAreasWithSchools(
                self.current_user)
            school_of_shop = yield self.school_model.GetSchoolFromId(
                shop['school_district'])
            if not school_of_shop:
                school_of_shop = {}
            data = {
                'shop': shop_data,
                'areas': {
                    'full':
                    json.dumps(areas_full),
                    'choosed':
                    json.dumps({
                        'area': school_of_shop.get('region', ''),
                        'province': school_of_shop.get('province', ''),
                        'city': school_of_shop.get('city', ''),
                        'campus': school_of_shop.get('name', '')
                    })
                }
            }
            data['flag'] = 'error'
            data['message'] = '修改学校资料失败'
            self.render('detail_page_shop_edit.html', data=data)