Example #1
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'TALKBOT'):
            raise web.seeother('/')
        user_data = web.input(page='0', news_title='')
        render = helper.create_render()

        if not user_data['page'].isdigit():
            return render.info('参数错误!')

        conditions = {}

        news_title = user_data.news_title.strip()
        if news_title != '':
            conditions = {
                {
                    'news_title': {
                        '$regex':
                        u'%s.*' %
                        (news_title.replace('*', '\\*').replace('?', '\\?')),
                        '$options':
                        'i'
                    }
                },
            }

        # 分页获取数据
        db_sku = db.index_news.find(conditions,
                                    sort=[('available', -1),
                                          ('news_title', 1)],
                                    limit=PAGE_SIZE,
                                    skip=int(user_data['page']) * PAGE_SIZE)

        num = db_sku.count()
        if num % PAGE_SIZE > 0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE

        return render.index_news(helper.get_session_uname(),
                                 helper.get_privilege_name(), db_sku,
                                 range(0, num), news_title,
                                 int(user_data['page']))
Example #2
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'TALKBOT'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(rule_id='')

        if user_data.rule_id == '':
            return render.info('参数错误!')

        db.bayes.delete_one({'_id': ObjectId(user_data.rule_id)})

        # 刷新分词字典
        db.sys_refs.update_one({'name': 'dict_update'},
                               {'$set': {
                                   'last_tick': int(time.time())
                               }},
                               upsert=True)

        return render.info('成功删除!', '/plat/bayes')
Example #3
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'DATA_MODIFY'):
            raise web.seeother('/')

        render = helper.create_render(plain=True)
        param = web.input(page_id='')

        r1 = db.pages.find_one({'_id': ObjectId(param['page_id'])})
        if r1 is None:
            return json.dumps({'ret': -2, 'msg': 'page_id参数错误'})

        #r2 = db.nodes.find({'page_id':param['page_id']})

        #data=[x for x in r2]
        data = []

        return render.page_map(helper.get_session_uname(),
                               helper.get_privilege_name(), data,
                               param['page_id'], r1['page_code'],
                               r1['page_name'])
Example #4
0
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')

        mch_id = helper.get_session_mch_id()
        render = helper.create_render()
        user_data = web.input(obj_id='')

        obj_data = { 'obj_id' : 'n/a'}

        if user_data.obj_id != '': 
            db_obj=db.obj_store.find_one({'obj_id':user_data.obj_id, 'mch_id':mch_id})
            if db_obj!=None:
                # 已存在的obj
                obj_data = db_obj

        db_topic = db.topic_store.find({'mch_id':mch_id})

        return render.obj_store_edit(helper.get_session_uname(), helper.get_privilege_name(), 
            obj_data, db_topic)
Example #5
0
    def GET(self):
        if not logged(helper.PRIV_ADMIN):
            raise web.seeother('/')

        render = create_render()

        db_sys = db.user.find_one({'uname': 'settings'})
        if db_sys != None:
            return render.sys_setting(session.uname,
                                      user_level[session.privilege], db_sys)
        else:
            db.user.insert_one({
                'uname': 'settings',
                'signup': 0,
                'login': 0,
                'pk_count': 1,
                'wt_count': 1,
                'sa_count': 1
            })
            return render.info('如果是新系统,请重新进入此界面。', '/')
Example #6
0
    def GET(self):
        if helper.logged(helper.PRIV_USER, 'POS_INVENTORY'):
            render = helper.create_render()
            user_data = web.input(product_id='')

            if user_data.product_id == '':
                return render.info('错误的参数!')

            # 查找shop
            db_shop = helper.get_shop_by_uid()

            # 查找店面信息
            db_shop2 = helper.get_shop(db_shop['shop'])
            if db_shop2 == None:
                return render.info('未找到所属门店!')

            db_invent = db.inventory.find_one({
                'product_id': user_data.product_id,
                'shop': db_shop2['_id']
            })
            if db_invent:
                db_sku = db.sku_store.find_one({'_id': db_invent['sku']})
                if db_sku:
                    base_sku = db.dereference(db_sku['base_sku'])
                    return render.pos_invent_sku(
                        helper.get_session_uname(),
                        helper.get_privilege_name(), db_sku, db_invent,
                        helper.UNIT_TYPE[db_sku['unit']],
                        (base_sku['name'], base_sku['original'],
                         base_sku['image'][0] if base_sku.has_key('image')
                         and len(base_sku['image']) > 0 else ''),
                        (str(db_shop2['_id']), db_shop2['name'],
                         helper.SHOP_TYPE[db_shop2['type']]),
                        user_data.product_id[0] == 'w', helper.CATEGORY)
                else:
                    return render.info('未查到sku!')
            else:
                return render.info('未查到库存!')

        else:
            raise web.seeother('/')
Example #7
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'DATA_MODIFY'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(page_id='', parent_id='')

        if user_data.page_id == '':
            return render.info('参数错误!')

        db_obj = db.pages.find({'parent_id': user_data.page_id})
        if db_obj.count() > 0:
            return render.info('只能删除空的目录!')

        db.pages.delete_one({
            '_id': ObjectId(user_data.page_id),
            'page_type': 1
        })

        return render.info('成功删除!',
                           '/plat/pages?parent_id=' + user_data['parent_id'])
Example #8
0
    def POST(self):
        if not helper.logged(helper.PRIV_USER, 'CHECK_OBJ'):
            raise web.seeother('/')
        render = helper.create_render()
        user_data = web.input(tpc_id='', status='')

        if user_data.tpc_id == '':
            return render.info('参数错误!')

        if user_data.status == '':
            return render.info('请选择审核结果!')

        tpc_id = user_data['tpc_id']

        message = '审核通过' if user_data['status'] == 'PASSED' else '审核被拒绝'

        # 专辑课程,需要将专辑状态设置为已保存
        object_helper.topic_change_status(tpc_id, user_data['status'], message,
                                          user_data['check_comment'])

        return render.info('成功保存!', '/plat/check_topic')
Example #9
0
 def GET(self):
     if logged(helper.PRIV_ADMIN):
         render = create_render()
         db_shop = db.base_shop.find(
             {
                 'available': 1,
                 'type': {
                     '$in': ['chain', 'store', 'dark']
                 }
             }, {
                 'name': 1,
                 'type': 1
             })
         shops = []
         for s in db_shop:
             shops.append(
                 (s['_id'], s['name'], helper.SHOP_TYPE[s['type']]))
         return render.user_new(session.uname,
                                user_level[session.privilege], shops)
     else:
         raise web.seeother('/')
Example #10
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'CATEGORY'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(cate_id='')

        cate_data = {'cate_id': 'n/a'}

        if user_data.cate_id != '':
            db_obj = db.category_info.find_one({'cate_id': user_data.cate_id})
            if db_obj != None:
                # 已存在的obj
                cate_data = db_obj

        # 此类目上架商品
        r2 = db.online_cate_obj.find({'cate_id': user_data.cate_id},
                                     sort=[('sort_weight', 1)])
        online_obj = [i['obj_id'] for i in r2]

        # 可上架的商品
        all_obj = {}
        r3 = db.obj_store.find({'obj_type': 'course', 'status': 'PASSED'})
        for i in r3:
            all_obj[i['obj_id']] = {
                'obj_name': i['obj_name'],
                'mch_id': i['mch_id'],
                'obj_id': i['obj_id']
            }

        # 所有商家
        all_mch = {}
        r4 = db.merchant.find({'available': 1})
        for i in r4:
            all_mch[i['mch_id']] = i['mch_name']

        return render.category_edit(helper.get_session_uname(),
                                    helper.get_privilege_name(), cate_data,
                                    online_obj, all_obj, all_mch)
Example #11
0
    def GET(self):
        if not logged(helper.PRIV_ADMIN):
            raise web.seeother('/')

        render = create_render()

        users = []
        db_user = db.user.find({
            'privilege': {
                '$nin': [helper.PRIV_ADMIN]
            }
        }).sort([('_id', 1)])
        if db_user.count() > 0:
            for u in db_user:
                if u['uname'] == 'settings':
                    continue
                users.append([
                    u['uname'], u['_id'],
                    int(u['privilege']), u['full_name'], u['login'],
                    u['user_type']
                ])
        return render.user(session.uname, user_level[session.privilege], users)
Example #12
0
    def POST(self):
        web.header("Content-Type", "application/json")
        if helper.logged(helper.PRIV_USER, 'PLAT_BASE_SKU'):
            user_data = web.input(base_sku='')

            if user_data.base_sku == '':
                return json.dumps({'ret': -1, 'msg': '参数错误'})

            db_sku = db.base_sku.find_one(
                {'_id': ObjectId(user_data['base_sku'])},
                {
                    'name': 1,
                    'abstract': 1,
                    #'ref_price'  : 1,
                    #'min_price'  : 1,
                    #'max_price'  : 1,
                    'fresh_time': 1,
                    'original': 1,
                    'available': 1,
                    'image': 1,
                })
            if db_sku:
                return json.dumps({
                    'ret': 0,
                    'name': db_sku['name'],
                    'abstract': db_sku['abstract'],
                    #'ref_price'  : db_sku['ref_price'],
                    #'min_price'  : db_sku['min_price'],
                    #'max_price'  : db_sku['max_price'],
                    'fresh_time': db_sku['fresh_time'],
                    'original': db_sku['original'],
                    'available': db_sku['available'],
                    'image': db_sku['image'],
                })
            else:
                return json.dumps({'ret': -2, 'msg': '无数据返回'})
        else:
            return json.dumps({'ret': -3, 'msg': '无权限访问'})
Example #13
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'CHECK_OBJ'):
            raise web.seeother('/')
        user_data = web.input(page='0')
        render = helper.create_render()

        if not user_data['page'].isdigit():
            return render.info('参数错误!')

        db_sku = db.topic_store.find(
            {'status': {
                '$in': ['WAIT', 'PASSED', 'DENY']
            }},  # 只显示精品课程
            sort=[('tpc_id', -1)],
            limit=PAGE_SIZE,
            skip=int(user_data['page']) * PAGE_SIZE)

        sku_data = []
        for x in db_sku:
            one = {
                'tpc_id': x['tpc_id'],
                'tpc_name': x['tpc_name'],
                'title': x['title'],
                'price': x.get('price', 0),
                'note': x['note'],
                'status': x.get('status', 'SAVED'),
            }
            sku_data.append(one)

        num = db_sku.count()
        if num % PAGE_SIZE > 0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE

        return render.check_topic(helper.get_session_uname(),
                                  helper.get_privilege_name(), sku_data,
                                  range(0, num), helper.OBJ_STATUS)
Example #14
0
    def GET(self):
        if logged(helper.PRIV_ADMIN):
            render = create_render()
            user_data = web.input(uid='')

            if user_data.uid == '':
                return render.info('错误的参数!')

            db_user = db.user.find_one({'_id': ObjectId(user_data.uid)})
            if db_user != None:
                db_shop = db.base_shop.find(
                    {
                        'available': 1,
                        'type': {
                            '$in':
                            ['chain', 'store', 'dark', 'virtual', 'pt_house']
                        }
                    }, {
                        'name': 1,
                        'type': 1
                    })
                shops = []
                for s in db_shop:
                    shops.append(
                        (s['_id'], s['name'], helper.SHOP_TYPE[s['type']]))
                # 若是老用户,则在其menu_level位数的基础上增加至60位权限位
                new_menu_level = db_user['menu_level'] if len(
                    db_user['menu_level']
                ) == 60 else db_user['menu_level'] + 30 * '-'
                return render.user_setting(
                    session.uname, user_level[session.privilege], db_user,
                    time_str(db_user['time']),
                    get_privilege_name(db_user['privilege'], new_menu_level),
                    shops)
            else:
                return render.info('错误的参数!')
        else:
            raise web.seeother('/')
Example #15
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'ONDUTY'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(duty_id='')

        if user_data.duty_id == '':
            return render.info('参数错误!')

        r2 = db.duty.find_one({'_id': ObjectId(user_data.duty_id)})
        if r2 is None:
            return render.info('为未找到值班记录!')

        if r2['status_duty'] != 'SAVED':
            return render.info('只有未提交的记录可以删除!')

        if r2['duty_uid'] != helper.get_session_uname():
            return render.info('只能删除自己的值班记录!')

        db.duty.delete_one({'_id': ObjectId(user_data.duty_id)})

        return render.info('成功删除!', '/duty/list')
Example #16
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'TNM_DATA'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(rule_id='')

        if user_data.rule_id == '':
            return render.info('参数错误!')

        r1 = db.tnm.find_one({'_id': ObjectId(user_data.rule_id)})
        if r1 is None:
            return render.info('rule_id错误!')

        r1.pop('_id')
        r1['tnm_name'] = r1['tnm_name'] + ' - ' + helper.my_rand(4).upper()
        r1['available'] = 0

        r1['history'] = [(helper.time_str(), helper.get_session_uname(), '复制')]
        r2 = db.tnm.insert_one(r1)

        return render.info('复制成功!复制后的病种名为:' + r1['tnm_name'].encode('utf-8'),
                           '/plat/tnm')
Example #17
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'CHECK_OBJ'):
            raise web.seeother('/')

        render = helper.create_render()
        user_data = web.input(obj_id='', action='VIEW')

        if user_data.obj_id == '':
            return render.info('参数错误!')

        db_obj = db.obj_store.find_one({'obj_id': user_data.obj_id})
        if db_obj is None:
            return render.info('未找到课程信息!')

        tpc_name = ''
        if db_obj['obj_type'] == 'topic':  # 专辑课程获取专辑名称
            db_topic = db.topic_store.find_one({'tpc_id': db_obj['tpc_id']})
            if db_topic:
                tpc_name = db_topic['tpc_name']

        return render.check_obj_detail(helper.get_session_uname(),
                                       helper.get_privilege_name(), db_obj,
                                       tpc_name, user_data.action)
Example #18
0
	def POST(self):
		if helper.logged(helper.PRIV_USER,'PLAT_PT_STORE'):
			render = helper.create_render()
			user_data=web.input(region_id=[],title='', tuan_size='',
				price='',tuan_price='',ref_price='', shop_online=[])

			if '' in (user_data.title, user_data.tuan_size, user_data.price, 
				user_data.tuan_price, user_data.ref_price):
				return render.info('必填参数不能为空!')  

			if user_data.region_id==[]:
				return render.info('区域参数不能为空!') 				

			db.pt_store.insert_one({
				'region_id'  : user_data['region_id'],
				'tuan_id'    : 't%s%s' % (helper.time_str(format=2)[2:],helper.my_rand(5)),
				'title'      : user_data['title'],
				'desc'       : user_data['desc'],
				'tuan_size'  : int(user_data['tuan_size']),
				'price'      : '%.2f' % float(user_data['price']),
				'tuan_price' : '%.2f' % float(user_data['tuan_price']),
				'ref_price'  : '%.2f' % float(user_data['ref_price']),
				'expire_time': user_data['expire_time'],
				'expire_tick': int(time.mktime(time.strptime(user_data['expire_time'],"%Y-%m-%d")))+3600*24,
				'volume'     : random.randint(150,200),
				'promote'    : int(user_data['promote']),
				'sale_out'   : int(user_data['sale_out']),
				'sort_weight': int(user_data['sort_weight']),
				'image'      : user_data['image'].split(','),
				'note'       : user_data['note'],
				'online'     : user_data['shop_online'],
				'history'    : [(helper.time_str(), helper.get_session_uname(), '新建活动')], # 纪录操作历史
			})
			db.base_image.update_many({'image':{'$in':user_data['image'].split(',')}},{'$inc':{'refer':1}})
			return render.info('成功保存!','/plat/pt_store')
		else:
			raise web.seeother('/')
Example #19
0
    def GET(self):
        if not helper.logged(helper.PRIV_MCH, 'OBJ_STORE'):
            raise web.seeother('/')
        user_data = web.input(obj_id='', tpc_id='')
        render = helper.create_render()
        mch_id = helper.get_session_mch_id()
        #print mch_id

        if user_data.obj_id == '' and user_data.tpc_id == '':
            return render.info('参数错误!')

        if user_data.obj_id != '':  # 课程
            db_obj = db.obj_store.find_one({
                'obj_id': user_data.obj_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('obj_id参数错误!')

            object_name = db_obj['obj_name']
        else:
            db_obj = db.topic_store.find_one({
                'tpc_id': user_data.tpc_id,
                'mch_id': mch_id
            })
            if db_obj is None:
                return render.info('tpc_id参数错误!')

            object_name = db_obj['tpc_name']

        if db_obj.get('status') == 'PASSED':
            return render.info('此课程已审核通过!')

        return render.check_submit(helper.get_session_uname(),
                                   helper.get_privilege_name(),
                                   user_data.obj_id, user_data.tpc_id,
                                   object_name, db_obj['title'])
Example #20
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'MERCHANT'):
            raise web.seeother('/')
        user_data=web.input(page='0')
        render = helper.create_render()

        if not user_data['page'].isdigit():
            return render.info('参数错误!')  

        # 分页获取数据
        db_sku = db.merchant.find(
            sort=[('available', -1), ('mch_id', -1)],
            limit=PAGE_SIZE,
            skip=int(user_data['page'])*PAGE_SIZE
        )

        num = db_sku.count()
        if num%PAGE_SIZE>0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE
        
        return render.merchant(helper.get_session_uname(), helper.get_privilege_name(), db_sku,
            range(0, num))
Example #21
0
    def GET(self):
        if helper.logged(helper.PRIV_USER, 'STOCK_ORDER'):
            render = helper.create_render(globals={'str': str})

            db_order = db.order_stock.find(
                {},
                {
                    'shop_to': 1,
                    'type': 1,
                    'status': 1,
                    'history': 1
                },
                #limit = 100
            ).sort([('_id', -1)])

            db_shops = db.base_shop.find({}, {'name': 1})
            shops = {}
            for i in db_shops:
                shops[i['_id']] = i['name']
            return render.stock_order(helper.get_session_uname(),
                                      helper.get_privilege_name(), db_order,
                                      helper.ORDER_STATUS, shops)
        else:
            raise web.seeother('/')
Example #22
0
    def GET(self):
        if not helper.logged(helper.PRIV_USER, 'DATA_MODIFY'):
            raise web.seeother('/')
        user_data = web.input(page='0', note_code='')
        render = helper.create_render()

        if not user_data['page'].isdigit():
            return render.info('参数错误!')

        conditions = {}

        note_code = user_data.note_code.strip()
        if note_code != '':

            conditions['note_code'] = {
                '$regex':
                u'%s.*' % (note_code.replace('*', '\\*').replace('?', '\\?')),
                '$options':
                'i'
            }

        # 分页获取数据
        db_sku = db.notes.find(conditions,
                               sort=[('weight', 1)],
                               limit=PAGE_SIZE,
                               skip=int(user_data['page']) * PAGE_SIZE)

        num = db_sku.count()
        if num % PAGE_SIZE > 0:
            num = num / PAGE_SIZE + 1
        else:
            num = num / PAGE_SIZE

        return render.notes(helper.get_session_uname(),
                            helper.get_privilege_name(), db_sku, range(0, num),
                            note_code, int(user_data['page']))
Example #23
0
    def POST(self):  # 修改盘点数量,json 返回
        web.header("Content-Type", "application/json")
        if helper.logged(helper.PRIV_USER, 'POS_AUDIT'):
            user_data = web.input(product_id='', audit_num='')  #

            if user_data.product_id == '':
                return json.dumps({'ret': -1, 'msg': '参数错误'})

            # 查找shop
            db_shop = helper.get_shop_by_uid()

            if user_data.product_id[0] != 'w' and user_data.product_id[
                    2] == '2':  # 称重sku,可能会是浮点数
                audit_num = float(user_data.audit_num)
            else:
                audit_num = int(user_data.audit_num)
            r = db.inventory.update_one(
                {
                    'product_id': user_data.product_id,
                    'shop': db_shop['shop'],
                }, {
                    '$set': {
                        'audit': audit_num
                    },
                    '$push': {
                        'history':
                        (helper.time_str(), helper.get_session_uname(),
                         '记录盘点数量为 %.2f' % float(audit_num))
                    },
                })
            if r.matched_count > 0:
                return json.dumps({'ret': 0, 'num': audit_num})
            else:
                return json.dumps({'ret': -1, 'msg': '未找到库存数据!'})
        else:
            return json.dumps({'ret': -3, 'msg': '无权限访问'})
Example #24
0
	def POST(self):
		if helper.logged(helper.PRIV_USER,'STOCK_INVENTORY'):
			render = helper.create_render()
			user_data=web.input(cat='',content='')

			if user_data.cat=='':
				return render.info('参数错误!')  

			skus=[]

			# 按sku id查, 或者条件为空的查询 查询所以sku
			if user_data['content'].strip()=='' or user_data['cat']=='product_id': 
				if user_data['content'].strip()=='':
					condition = {}
				else:
					condition = {'product_id':user_data['content'].strip()}
				db_sku=db.sku_store.find(condition,{
					'product_id' : 1,
					'base_sku'   : 1,
					'note'       : 1,
					'available'  : 1,
					'is_pack'    : 1,
					'unit'       : 1,
					#'unit_num'   : 1,
					'ref_price'  : 1,
					'app_title'  : 1,
				}).sort([('_id',1)])

				for u in db_sku:
					base_sku = db.dereference(u['base_sku'])

					# 准备数据
					sku_name = base_sku['name'] if len(u['app_title'].strip())==0 else u['app_title']
					skus.append((u['_id'], sku_name, u['note'], u['available'],
						base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image'])>0 else '',
						'', helper.UNIT_TYPE[u['unit']], 
						u['is_pack'], u['ref_price'], u['product_id'], base_sku['original'],
						helper.get_inventory(u['_id'])
					))

			# 按 品名、产地 查
			elif user_data['cat'] in ('name', 'original'): 
				# 先查到base_sku				
				# 模糊查询 {'$regex':'.*小.*','$options': 'i'}
				condition = {'$regex' : u'.*%s.*' % user_data['content'].strip(),'$options': 'i'}
				db_base = db.base_sku.find({user_data['cat']:condition},{
					'name'     : 1,
					'image'    : 1,
					'original' : 1,
				})
				# 再查含有base_sku的sku
				base={}
				for k in db_base:
					base[DBRef('base_sku', k['_id'])] = (k['name'],k['image'],k['original'])

				db_sku=db.sku_store.find({'base_sku':base.key()},{
					'product_id' : 1,
					'base_sku'   : 1,
					'note'       : 1,
					'available'  : 1,
					'is_pack'    : 1,
					'unit'       : 1,
					#'unit_num'   : 1,
					'ref_price'  : 1,
				}).sort([('_id',1)])

				# 准备数据
				for u in db_sku:
					k = base[DBRef('base_sku', u['_id'])]
					skus.append((u['_id'], k['name'], u['note'], u['available'],
						k['image'][0] if k.has_key('image') and len(k['image'])>0 else '',
						'', helper.UNIT_TYPE[u['unit']], 
						u['is_pack'], u['ref_price'], u['product_id'], k['original'],
						helper.get_inventory(u['_id'])
					))

			# 按站点查询
			elif user_data['cat']=='shop':
				condition = {'$regex' : u'.*%s.*' % user_data['content'].strip(),'$options': 'i'}
				db_shop = db.base_shop.find({'name':condition},{'name':1})
				shops = {}
				for h in db_shop:
					shops[h['_id']]=h['name']

				db_invent = db.inventory.find({'shop':{'$in':shops.keys()}},{'sku':1, 'num':1})
				invent = {}
				for i in db_invent:
					print i
					if invent.has_key(i['sku']):
						invent[i['sku']] += i['num']
					else:
						invent[i['sku']]=i['num']

				db_sku=db.sku_store.find({'_id':{'$in':invent.keys()}},{
					'product_id' : 1,
					'base_sku'   : 1,
					'note'       : 1,
					'available'  : 1,
					'is_pack'    : 1,
					'unit'       : 1,
					#'unit_num'   : 1,
					'ref_price'  : 1,
				}).sort([('_id',1)])

				for u in db_sku:
					base_sku = db.dereference(u['base_sku'])

					# 准备数据
					skus.append((u['_id'], base_sku['name'], u['note'], u['available'],
						base_sku['image'][0] if base_sku.has_key('image') and len(base_sku['image'])>0 else '',
						'', helper.UNIT_TYPE[u['unit']], 
						u['is_pack'], u['ref_price'], u['product_id'], base_sku['original'],
						invent[u['_id']]
					))

			return render.stock_invent_sku(helper.get_session_uname(), helper.get_privilege_name(), skus)
		else:
			raise web.seeother('/')
Example #25
0
	def GET(self):
		if helper.logged(helper.PRIV_USER,'STOCK_INVENTORY'):
			render = helper.create_render()
			return render.stock_invent(helper.get_session_uname(), helper.get_privilege_name())
		else:
		    raise web.seeother('/')
Example #26
0
    def POST(self):
        web.header("Content-Type", "application/json")
        if not helper.logged(helper.PRIV_USER, 'DATA_MODIFY'):
            return json.dumps({'ret': -1, 'msg': '无访问权限'})

        param = web.input(page_id='', element_data='', link_data='')

        if '' in (param.page_id, param.element_data, param.link_data):
            return json.dumps({'ret': -1, 'msg': '参数错误'})

        element_data = json.loads(param.element_data)
        link_data = json.loads(param.link_data)

        #print element_data
        #print link_data

        r1 = db.pages.find_one({'_id': ObjectId(param['page_id'])})
        if r1 is None:
            return json.dumps({'ret': -2, 'msg': 'page_id参数错误'})

        # 处理节点
        #{
        #    u'original_text': u'See Suggested Regimens (MANT-A)',
        #    u'angle': 0,
        #    u'inPorts': [u'i'],
        #    u'id': u'cc2b347f-3f6d-470b-b93c-16602765f657',
        #    u'node_id': u'x5',
        #    u'outPorts': [u'o'],
        #    u'attrs': {
        #        u'.label': {u'text': u'See\nSuggested\nRegimens\n(MANT-A)', u'ref-y': 5}
        #    },
        #    u'position': {u'y': 202, u'x': 245},
        #    u'z': 9,
        #    u'type': u'devs.Atomic',
        #    u'ports': {
        #            u'items': [{u'group': u'in', u'id': u'i', u'attrs': {u'.port-label': {u'text': u'i'}}},
        #                        {u'group': u'out', u'id': u'o', u'attrs': {u'.port-label': {u'text': u'o'}}}],
        #            u'groups': {u'out': {u'position': {u'name': u'right'}, u'attrs': {u'.port-label': {u'fill': u'#000'},
        #            u'.port-body': {u'magnet': True, u'stroke': u'#000', u'r': 10, u'fill': u'#fff'}},
        #            u'label': {u'position': {u'args': {u'y': 10}, u'name': u'right'}}}, u'in': {u'position': {u'name': u'left'},
        #            u'attrs': {u'.port-label': {u'fill': u'#000'}, u'.port-body': {u'magnet': True, u'stroke': u'#000',
        #            u'r': 10, u'fill': u'#fff'}}, u'label': {u'position': {u'args': {u'y': 10}, u'name': u'left'}}}}
        #    },
        #    u'size': {u'width': 80, u'height': 66}
        #}

        alert_msg = ''

        start_node = None
        nodes_dict = {}  # 用于添加链接时查询
        node_list = []  # 记录所有节点的ObjectId,用于检查删除的节点

        # >>>>>>>>>>>>>>> 此循环处理中不可以跳出返回,否则会数据保存不完整 <<<<<<<<<<<<<<
        for i in element_data:  #
            #print i

            original_text = i['original_text'].strip()

            if original_text == '0':  # 起始节点
                start_node = i['node_id']

            node_type = 0 if original_text in ['0', '*', '+'] else 1

            if '@' in original_text:  # 检查是否存在调转
                jump_to_page = get_page_id(original_text)
                if jump_to_page:
                    r5 = db.pages.find_one({'page_code': jump_to_page})
                    if r5 is None:
                        alert_msg += (u'跳转的页面(%s)不存在!<br>' % jump_to_page)
                    else:
                        if str(r5['_id']) == param['page_id']:  # 检查是否跳到自己
                            original_text = '@未知页面'
                            alert_msg += (u'不能跳转到当前页面(%s)!<br>' % jump_to_page)

                    original_text = original_text.upper()  # 跳转页面全部大写

                    if original_text[0] == '@':  # 是否是调转节点
                        node_type = 0  # 调整节点也是虚节点

            # 处理纠错结果 # 2019-02-12
            node_question = i.get('node_question', {
                'check': False,
                'correct': []
            })

            # 节点更新内容
            node = {
                'page_id': param['page_id'],
                'node_type': node_type,
                'parent': [],
                'child': [],
                'text': original_text,
                #'node_id'   : i['node_id']
                'position': i['position'],  # 记录节点在页面的位置,方便复原
                'node_prop': i.get('node_prop', ''),  # 节点属性 2018-08-14
                'node_weight': i.get('node_weight', '1'),  # 节点权重 2018-08-14
                'node_question': node_question['check'],  # 2019-02-12
            }

            if i['node_id'] == '':  #说明是新节点
                r3 = db.nodes.insert_one(node)
                node['_id'] = r3.inserted_id
                print 'NEW: ', str(r3.inserted_id)
            else:
                r2 = db.nodes.update_one({'_id': ObjectId(i['node_id'])},
                                         {'$set': node},
                                         upsert=True)
                if r2.upserted_id is not None:  # 更新时插入
                    node['_id'] = r2.upserted_id
                    print 'UPSERT: ', str(r2.inserted_id)
                else:
                    node['_id'] = ObjectId(i['node_id'])

                # 更新纠错记录状态
                if node_question['check'] == False and len(
                        node_question['correct']) > 0:
                    db.correct.update_many(
                        {
                            'node_id': i['node_id'],
                            'status': 'WAIT'
                        }, {'$set': {
                            'status': 'PASS'
                        }})

            nodes_dict[i['id']] = node

            node_list.append(node['_id'])

            #print node

        # 处理连接
        #{
        #    u'target': {
        #        u'id': u'c802b6c6-a694-4b18-aa3a-6dfa436f8637',
        #        u'port': u'i'
        #    },
        #    u'vertices': [
        #        {u'y': 112, u'x': 136},
        #        {u'y': 114, u'x': 232}
        #    ],
        #    u'source': {
        #        u'id': u'bac2de56-266c-4428-9096-29f46d172ead',
        #        u'port': u'o'
        #    },
        #    u'attrs': {
        #        u'.marker-target': {u'd': u'M 10 0 L 0 5 L 10 10 z', u'fill': u'#4B4F6A'}
        #    },
        #    u'z': 3,
        #    u'type': u'devs.Link',
        #    u'id': u'fdf956b4-159a-4776-bd2b-cc9824ab8f28'
        #}

        db.connect.remove({'page_id': param['page_id']})  # 先删除所有连线
        for i in link_data:
            nodes_dict[i['target']['id']]['parent'].append(
                str(nodes_dict[i['source']['id']]['_id']))
            nodes_dict[i['source']['id']]['child'].append(
                str(nodes_dict[i['target']['id']]['_id']))
            db.connect.insert_one({  # 保存连线数据
                'page_id':
                param['page_id'],
                'source':
                str(nodes_dict[i['source']['id']]['_id']),
                'target':
                str(nodes_dict[i['target']['id']]['_id']),
                'vertices':
                i.get('vertices', [])
            })

        # 更新到db
        for i in nodes_dict.values():
            db.nodes.update_one({'_id': i['_id']}, {'$set': i})

        # 删除页面中未更新的,说明这次删除的
        r4 = db.nodes.find({'page_id': param['page_id']})
        for i in r4:
            if i['_id'] not in node_list:
                print 'REMOVE: ', str(i['_id'])
                db.nodes.delete_one({'_id': i['_id']})

        # 更新页面起始节点
        db.pages.update_one({'_id': ObjectId(param['page_id'])}, {
            '$set': {
                'start_node': start_node
            },
            '$push': {
                'history':
                (helper.time_str(), helper.get_session_uname(), '保持规则树')
            }
        })

        if alert_msg == '':
            return json.dumps({'ret': 0, 'msg': '成功保存'})
        else:
            return json.dumps({'ret': 1, 'msg': alert_msg})
Example #27
0
    def POST(self):
        if not helper.logged(helper.PRIV_USER, 'TALKBOT'):
            raise web.seeother('/')
        render = helper.create_render()
        user_data = web.input(rule_id='', rule_name='')

        rule_name = user_data.rule_name.strip()
        if rule_name == '':
            return render.info('规则名不能为空!')

        # 排除规则同名
        find_condition = {
            'rule_name': rule_name,
        }

        if user_data['rule_id'] == 'n/a':  # 新建
            rule_id = None
            message = '新建'
        else:
            rule_id = ObjectId(user_data['rule_id'])
            message = '修改'
            find_condition['_id'] = {'$ne': rule_id}  # 排除自己

        r1 = db.talkbot.find_one(find_condition)
        if r1 is not None:
            return render.info('规则名已存在,不能重复!')

        try:
            update_set = {
                'rule_name': rule_name,
                'question': user_data['question'],
                'reply': user_data['reply'],
                'reply_type': int(user_data['reply_type']),
                'available': int(user_data['available']),
                'last_tick': int(time.time()),  # 更新时间戳
            }
        except ValueError:
            return render.info('请在相应字段输入数字!')

        if rule_id is None:
            update_set['history'] = [(helper.time_str(),
                                      helper.get_session_uname(), message)]
            r2 = db.talkbot.insert_one(update_set)
        else:
            db.talkbot.update_one(
                {'_id': rule_id},
                {
                    '$set': update_set,
                    '$push': {
                        'history': (helper.time_str(),
                                    helper.get_session_uname(), message),
                    }  # 纪录操作历史
                })

        # 刷新规则
        db.sys_refs.update_one({'name': 'talkbot_update'},
                               {'$set': {
                                   'last_tick': int(time.time())
                               }},
                               upsert=True)

        # 重新计算规则
        from talkbot_lib import gensim_index
        if not gensim_index.index_from_db(db):
            return render.info(
                '规则计算出错!',
                '/plat/talkbot_edit?rule_id=' + user_data['rule_id'])
        else:
            return render.info('成功保存!', '/plat/talkbot')
Example #28
0
    def GET(self):
        if helper.logged(helper.PRIV_USER, 'POS_INVENTORY'):
            #render = helper.create_render()

            # 查找shop
            db_shop = helper.get_shop_by_uid()

            # 取得 w-prod 的对应 u-prod 及其他信息
            db_invent = db.inventory.find(
                {
                    'shop': db_shop['shop'],
                    'product_id': {
                        '$regex': 'w.*',
                        '$options': 'i'
                    },
                    'num': {
                        '$gt': 0
                    },
                }, {
                    'ref_prod_id': 1,
                    'product_id': 1,
                    'weight': 1
                })

            u_prod_id = []
            w_prod_id = []
            for i in db_invent:
                u_prod_id.append(i['ref_prod_id'])
                w_prod_id.append(
                    (i['product_id'], i['weight'], i['ref_prod_id']))
            #print u_prod_id

            # 取得 对应 u-prod 的单价
            db_invent2 = db.inventory.find(
                {
                    'shop': db_shop['shop'],
                    'product_id': {
                        '$in': u_prod_id
                    },
                }, {
                    'price': 1,
                    'product_id': 1
                })

            new_price = {}
            for i in db_invent2:
                new_price[i['product_id']] = i['price']
            #print new_price

            # 更新 w-prod 的单价和称重售价
            for i in w_prod_id:
                db.inventory.update_one(
                    {
                        'product_id': i[0],
                        'shop': db_shop['shop'],
                    }, {
                        '$set': {
                            'price':
                            new_price[i[2]],
                            'total':
                            '%.2f' % (float(i[1]) * float(new_price[i[2]]))
                        },
                        '$push': {
                            'history':
                            (helper.time_str(), helper.get_session_uname(),
                             '价格修改为 %s' % str(new_price[i[2]]))
                        },
                    })

            raise web.seeother('/pos/inventory?is_pack=w&show=1')
        else:
            raise web.seeother('/')
Example #29
0
    def POST(self):
        if helper.logged(helper.PRIV_USER, 'PLAT_PT_STORE'):
            render = helper.create_render()
            user_data = web.input(region_id=[],
                                  title='',
                                  tuan_size='',
                                  price='',
                                  tuan_price='',
                                  ref_price='',
                                  shop_online=[])

            if '' in (user_data.title, user_data.tuan_size, user_data.price,
                      user_data.tuan_price, user_data.ref_price):
                return render.info('必填参数不能为空!')

            if user_data.region_id == []:
                return render.info('区域参数不能为空!')

            update_set = {
                'region_id':
                user_data['region_id'],
                'title':
                user_data['title'],
                'desc':
                user_data['desc'],
                'tuan_size':
                int(user_data['tuan_size']),
                'price':
                '%.2f' % float(user_data['price']),
                'tuan_price':
                '%.2f' % float(user_data['tuan_price']),
                'ref_price':
                '%.2f' % float(user_data['ref_price']),
                'expire_time':
                user_data['expire_time'],
                'expire_tick':
                int(
                    time.mktime(
                        time.strptime(user_data['expire_time'], "%Y-%m-%d"))) +
                3600 * 24,
                'promote':
                int(user_data['promote']),
                'sale_out':
                int(user_data['sale_out']),
                'sort_weight':
                int(user_data['sort_weight']),
                'note':
                user_data['note'],
                'online':
                user_data['shop_online'],
            }
            # 如果没有更新图片,就不更新图片 2015-09-04
            if len(user_data['image'].strip()) > 0:
                update_set['image'] = user_data['image'].split(',')
            #print update_set
            db.pt_store.update_one({'tuan_id': user_data['tuan_id']}, {
                '$set': update_set,
                '$push': {
                    'history':
                    (helper.time_str(), helper.get_session_uname(), '修改')
                },
            })

            return render.info('成功保存!', '/plat/pt_store')
        else:
            raise web.seeother('/')
Example #30
0
    def POST(self):
        if not helper.logged(helper.PRIV_USER, 'CATEGORY'):
            raise web.seeother('/')
        render = helper.create_render()
        user_data = web.input(cate_id='', title='', online_list='')

        if user_data.title.strip() == '':
            return render.info('类目名不能为空!')

        if user_data.start_time.strip() == '' or user_data.expire_time.strip(
        ) == '':
            return render.info('起始时间不能为空!')

        if user_data['cate_id'] == 'n/a':  # 新建
            db_pk = db.user.find_one_and_update({'uname': 'settings'},
                                                {'$inc': {
                                                    'pk_count': 1
                                                }}, {'pk_count': 1})
            cate_id = 'c%07d' % db_pk['pk_count']
            message = '新建'
        else:
            cate_id = user_data['cate_id']
            message = '修改'

        try:
            update_set = {
                'cate_id':
                cate_id,
                'title':
                user_data['title'],
                'sort_weight':
                int(user_data['sort_weight']),
                'available':
                int(user_data['available']),
                'last_tick':
                int(time.time()),  # 更新时间戳
                'start_time':
                user_data['start_time'],
                'expire_time':
                user_data['expire_time'],
                'start_tick':
                int(
                    time.mktime(
                        time.strptime(user_data['start_time'],
                                      '%Y-%m-%d %H:%M'))),
                'expire_tick':
                int(
                    time.mktime(
                        time.strptime(user_data['expire_time'],
                                      '%Y-%m-%d %H:%M'))),
            }
        except ValueError:
            return render.info('请在相应字段输入数字!')

        db.category_info.update_one(
            {'cate_id': cate_id},
            {
                '$set': update_set,
                '$push': {
                    'history':
                    (helper.time_str(), helper.get_session_uname(), message),
                }  # 纪录操作历史
            },
            upsert=True)

        if len(user_data.online_list.strip()) > 0:
            online_list = user_data.online_list.split(',')
        else:
            online_list = []

        print online_list

        # 记录类目商品上架信息
        db.online_cate_obj.remove({'cate_id': cate_id})
        for i, obj_id in enumerate(online_list):
            r3 = db.obj_store.find_one({'obj_id': obj_id}, {'status': 1})
            available = (1 if r3['status'] == 'PASSED' else 0) if r3 else 0
            db.online_cate_obj.update_one(
                {
                    'cate_id': cate_id,
                    'obj_id': obj_id
                }, {'$set': {
                    'available': available,
                    'sort_weight': i
                }},
                upsert=True)

        return render.info('成功保存!', '/plat/category')