def category_edit(): """ 编辑商品分类 """ g.page_type = '' g.title = u'编辑商品分类' gc_id = toint(request.args.get('gc_id', '0')) if gc_id <= 0: return u'参数出错' edit_gc_id = gc_id goods_cat_info = GoodsCategory.query.get_or_404(gc_id) parent_gc_id = goods_cat_info.parent_id if goods_cat_info.parent_id else None node_chain_arr = goods_cat_info.node_chain cat_name_chain = None chain_gc_id_list = map(lambda gc_id:gc_id, node_chain_arr.split(',')) parent_gc_id_list = chain_gc_id_list[:-1] goods_cat_list = [] for gc_id in parent_gc_id_list: gc = GoodsCategory() if not gc_id: continue gc_id = toint(gc_id) if gc_id <= 0: return u'节点链数据不正确' parent_cat_info = GoodsCategory.query.get_or_404(gc_id) parent_cat_name = parent_cat_info.category_name setattr(gc,'goods_cat_name', parent_cat_name) setattr(gc,'gc_id', gc_id) goods_cat_list.append(gc) attr_group_cat_list = db.session.query(AttrGroupInCategory.agic_id, AttrGroupInCategory.gc_id, AttrGroup.ag_name,AttrGroup.ag_id, AttrGroup.alias_name, AttrGroup.ag_type).\ filter(AttrGroupInCategory.ag_id == AttrGroup.ag_id).\ filter(AttrGroupInCategory.gc_id == edit_gc_id).\ group_by(AttrGroupInCategory.agic_id.desc()).all() agic_ag_id_list = db.session.query(AttrGroupInCategory.ag_id).filter(AttrGroupInCategory.gc_id == edit_gc_id).all() agic_ag_id_list = map(lambda ag_id:ag_id,[agic_ag_id.ag_id for agic_ag_id in agic_ag_id_list]) attr_group_list = db.session.query(AttrGroup.ag_id, AttrGroup.ag_name).\ filter(not_(AttrGroup.ag_id.in_(agic_ag_id_list))).\ group_by(AttrGroup.ag_id.asc()).\ order_by(AttrGroup.ag_id.desc()).all() return render_template('goods/category_add.html.j2', f=goods_cat_info,**locals())
def check(self): """ 检查 """ # 资讯主图 status = toint(self.form.get('status'), 0) is_top = toint(self.form.get('is_top'), 0) _news_img = request.files.get('news_img', None) # 是否创建资讯 self.is_new = True if self.news_id == 0 else False # 检查 - 必填项 # required_arr = ['title', 'detail', 'status', 'jingdu_weidu', 'nc_id'] required_arr = ['title', 'detail', 'status', 'is_top', 'nc_id'] for key in required_arr: value = self.form.get(key, '').strip() if not value: self.errmsg[key] = u'必填项' # 检查 - 新建资讯是否上传资讯主图 if self.is_new and not _news_img: self.errmsg['news_img'] = u'必填项' # 检查 - 资讯是否存在 if not self.is_new: self.news = News.get(self.news_id) if not self.news: self.errmsg['submit'] = u'资讯不存在' if status == -1: self.errmsg['status'] = u'请选择显示状态' if is_top == -1: self.errmsg['is_top'] = u'请选择是否推荐到首页' # 检查 - 资讯主图是否合法 if _news_img: oss = AliyunOSS('news', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_news_img) self.news_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['news_img'] = u'资讯主图只允许是图片文件' except Exception, e: self.errmsg['news_img'] = u'资讯主图上传失败'
def attr_group_attr_list(): """ ajax 根据属性组获取属性列表 """ resjson.action_code = 12 ag_id = toint(request.form.get('ag_id'), 0) attr_list = Attr.query.filter(Attr.ag_id == ag_id).order_by(Attr.ag_id.desc()).all() return resjson.print_json(0, u'ok', {'attr_list':attr_list})
def spec_add(): """新增规格""" args = request.args spec_id = toint(args.get('spec_id', '0')) st_id = toint(args.get('st_id', '0')) sort_order = toint(args.get('sort_order', '0')) spec_key = args.get('spec_key', '') spec_value = args.get('spec_value', '') if spec_id > 0: s = Spec.query.get(spec_id) if not s: return u'获取规格信息失败' else: s = Spec.create(add_time=int(time.time())) s.update(st_id=st_id, spec_key=spec_key, spec_value=spec_value, sort_order=sort_order, commit=True) return u'ok'
def html_section_number_options(): """一元购活动期数选择""" lt_id = toint(request.form.get('lt_id', '0')) if lt_id <= 0: return u'参数出错' section_number_list = Lottery.query.filter(Lottery.lt_id == lt_id).all() return render_template('order/section_number_options.html.j2', section_number_list=section_number_list)
def category_save(): """ 保存分类 """ g.page_type = '' g.title = u'保存分类' form = request.form edit_gc_id = toint(form.get('edit_gc_id', '0')) category_name = form.get('category_name', '').strip() brief = form.get('brief', '') sort_order = toint(form.get('sort_order', '0')) status = toint(form.get('status', '-1')) category_img = request.files['category_img'] errmsg = {} # GoodsCategory表是否为空 goods_category_list = GoodsCategory.query.all() if edit_gc_id <= 0: gs = GoodsCategory() db.session.add(gs) else: gs = GoodsCategory.query.get_or_404(edit_gc_id) #判段新增商品分类是否重复 is_exit_category = GoodsCategory.query.filter(GoodsCategory.gc_id != edit_gc_id).\ filter(GoodsCategory.category_name == category_name).first() if is_exit_category: errmsg['category_name'] = u'新增商品分类已经存在' g.errmsg = errmsg return render_template('goods/category_add.html.j2', f=form,**locals()) if category_img: oss = AliyunOSS('user', current_app.config['SAVE_TARGET_PATH']) try: oss.save(category_img) gs.category_img = oss.put_to_oss() except UploadNotAllowed, e: errmsg['category_img'] = u'只允许是图片文件' return render_template('goods/category_add.html.j2', f=form,**locals()) except Exception, e: errmsg['category_img'] = u'原图上传失败' return render_template('goods/category_add.html.j2', f=form,**locals())
def news_list(page=1, page_size=20): """ 资讯列表 """ g.page_type = 'search' g.title = u'资讯列表' g.add_new = True g.button_name = u'添加资讯' args = request.args title = args.get('title', '').strip() begin_add_time = args.get('begin_add_time', '').strip() end_add_time = args.get('end_add_time', '').strip() nc_id = toint(args.get('nc_id', '-1')) status = toint(args.get('status', '-1')) q = News.query query_dict = { 'title': title, 'nc_id': nc_id, 'status': status, 'begin_add_time': begin_add_time, 'end_add_time': end_add_time, } q = News.query q = easy_query_filter(News, q, query_dict) news_count = get_count(q) news_list = q.order_by(News.news_id.desc()).\ offset((page-1)*page_size).limit(page_size).all() pagination = Pagination(None, page, page_size, news_count, None) res = make_response( render_template( 'news/news_list.html.j2', news_list=news_list, pagination=pagination, Object=News, )) res.set_cookie('goback_url', request.url) return res
def delete_attr_group(): """删除属性组属性""" attr_id = toint(request.args.get('attr_id', '0')) if attr_id <= 0: return u'参数出错' attr = Attr.query.get_or_404(attr_id) if attr: db.session.delete(attr) db.session.commit() return u'ok'
def check(self): """ 检查 """ # 商品主图 _goods_img = request.files.get('goods_img', None) # 商品相册 _gallery_list = request.files.getlist('gallery') # 筛选属性 _attr_id_list = request.form.getlist('attr_id') _attr_id_list = list(set(_attr_id_list)) # SKU _sku_list = request.form.getlist('sku') _sku_name_list = request.form.getlist('sku_name') _sku_price_list = request.form.getlist('sku_price') _sku_quantity_list = request.form.getlist('sku_quantity') # 是否创建商品 self.is_new = True if self.goods_id == 0 else False # 检查 - 必填项 required_arr = ['goods_name', 'is_sale', 'is_hot', 'is_pre', 'is_new', 'goods_price', 'is_free_shipping', 'is_return'] for key in required_arr: value = self.form.get(key, '').strip() if not value: self.errmsg[key] = u'必填项' # 检查 - 新建商品是否上传商品主图 if self.is_new and not _goods_img: self.errmsg['goods_img'] = u'必填项' gc_id = toint(self.form.get('gc_id', '0')) if gc_id <= 0: self.errmsg['gc_id'] = u'必填项' # 检查 - 商品是否存在 if not self.is_new: self.goods = Goods.get(self.goods_id) if not self.goods: self.errmsg['submit'] = u'商品不存在' # 检查 - 商品主图是否合法 if _goods_img: oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH']) try: oss.save(_goods_img) self.goods_img = oss.put_to_oss() except UploadNotAllowed, e: self.errmsg['goods_img'] = u'商品图片只允许是图片文件' except Exception, e: self.errmsg['goods_img'] = u'商品图片上传失败'
def recharge_card_detail(): """充值卡详情""" g.page_type = '' g.title = u'充值卡详情' rc_id = toint(request.args.get('rc_id', '0')) recharge_card_info = RechargeCard.query.get_or_404(rc_id) return render_template('sys/card_detail.html.j2', f=recharge_card_info, **locals())
def st_delete(): """移除规格模板""" st_id = toint(request.args.get('st_id', '0')) st = SpecTemplate.query.get(st_id) if not st: return u'该模板已经被移除' st.delete(commit=True) return u'ok'
def gs_delete(): """移除商品规格""" gs_id = toint(request.args.get('gs_id', '0')) gs = GoodsSpec.query.get(gs_id) if not gs: return u'该规格已经被移除' gs.delete(commit=True) return u'ok'
def s_delete(): """移除规格""" spec_id = toint(request.args.get('spec_id', '0')) s = Spec.query.get(spec_id) if not s: return u'该规格已经被移除' s.delete(commit=True) return u'ok'
def st_add(): """添加商品模板""" args = request.args goods_id = toint(args.get('goods_id', '0')) st_id = toint(args.get('st_id', '0')) if st_id <= 0 or goods_id <= 0: return u'参数出错' st = SpecTemplate.query.get(st_id) s_list = Spec.query.filter(Spec.st_id == st.st_id).all() goods = Goods.query.get(goods_id) if not goods: return u'获取商品信息失败' gs = None for s in s_list: is_gs_exit = GoodsSpec.query.filter(GoodsSpec.goods_id == goods_id).\ filter(GoodsSpec.spec_key == s.spec_key).\ filter(GoodsSpec.spec_value == s.spec_value).first() if is_gs_exit: log_info('### is_gs_exit:%s'% is_gs_exit) continue gs = GoodsSpec.create(goods_id=goods_id, spec_key=s.spec_key, spec_value=s.spec_value, sort_order=s.sort_order, add_time=int(time.time())) if not gs: return u'新增模板已经存在' gs.update(commit=True) return u'ok'
def permission_sort_modify(): """权限列表排序""" permission_id = toint(request.args.get('permission_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if permission_id <= 0: return u'参数出错' p = Permission.get(permission_id) if p: p.update(sort_order=new_sort, commit=True) return u'ok'
def menu_edit(): """菜单编辑""" g.title = u'菜单编辑' g.page_type = '' permission_id = toint(request.args.get('permission_id', '0')) if permission_id <= 0: return u'参数出错' p = Permission.query.get_or_404(permission_id) menu_type = 0 if p.parent_id == 0 else 1 setattr(p, 'menu_type', menu_type) return render_template('sys/menu_add.html.j2', f=p)
def lottery_detail(page=1, page_size=30): """一元云购活动详情""" g.page_type = '' g.title = u'一元云购活动详情' lottery_id = toint(request.args.get('lottery_id', '0')) lottery_info = Lottery.query.filter( Lottery.lottery_id == lottery_id).first() goods_list = Goods.query.filter(Goods.kind == 2).\ filter(Goods.is_sale == 1).all() if lottery_info is None: return u'一元云购活动不存在' param_dict = get_params({ 'lottery_name': str, 'lottery_number': str, 'nickname': str, 'order_id': int, 'is_prize': int, 'add_time': str }) query_dict = { 'lottery_number': param_dict['lottery_number'], 'order_id': param_dict['order_id'], 'is_prize': param_dict['is_prize'], 'add_time': param_dict['add_time'] } q = db.session.query(LotteryNumber.ln_id, LotteryNumber.order_id, LotteryNumber.lottery_number, LotteryNumber.is_prize, LotteryNumber.add_time,Lottery.lottery_name,User.nickname).\ filter(Lottery.lottery_id == LotteryNumber.lottery_id).\ filter(LotteryNumber.uid == User.uid).\ filter(LotteryNumber.lottery_id == lottery_id) q = easy_query_filter(LotteryNumber, q, query_dict) if param_dict['nickname']: q = q.filter(User.nickname.like(u'%' + param_dict['nickname'] + u'%')) if param_dict['lottery_name']: q = q.filter( Lottery.lottery_name.like(u'%' + param_dict['lottery_name'] + u'%')) lottery_count = get_count(q) lottery_number_list = q.order_by(LotteryNumber.ln_id.desc()).offset((page-1)*page_size).\ limit(page_size).all() pagination = Pagination(None, page, page_size, lottery_count, None) return render_template('lottery/add.html.j2', f=lottery_info, **locals())
def user_coupon(page=1, page_size=20): """ 用户优惠券 """ g.title = u'用户优惠券' g.page_type = 'search' args = request.args uid = toint(args.get('uid', 0)) mobile = args.get('mobile', '') cb_id = toint(args.get('cb_id', 0)) coupon_id = toint(args.get('coupon_id', 0)) q = Coupon.query if uid > 0: q = q.filter(Coupon.uid == uid) if cb_id: q = q.filter(Coupon.cb_id == cb_id) if coupon_id: q = q.filter(Coupon.coupon_id == coupon_id) if mobile: q = q.filter(Coupon.uid == User.uid).\ filter(User.mobile == mobile) user_coupon_count = get_count(q) user_coupon_list = q.order_by(Coupon.add_time.desc()).\ offset((page-1)*page_size).limit(page_size).all() pagination = Pagination(None, page, page_size, user_coupon_count, None) res = make_response( render_template('coupon/user_coupon.html.j2', user_coupon_list=user_coupon_list, pagination=pagination)) res.set_cookie('goback_url', request.url) return res
def in_column_sort_modify(): """修改栏目商品排序""" gic_id = toint(request.args.get('gic_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if gic_id <= 0: return u'参数出错' gic = GoodsInColumn.get(gic_id) if gic: gic.sort_order = new_sort db.session.commit() return u'ok'
def recharge_card_delete(): """移除充值卡""" rc_id = toint(request.args.get('rc_id', '0')) if rc_id <= 0: return u'参数出错' rc = RechargeCard.query.get_or_404(rc_id) if rc: db.session.delete(rc) db.session.commit() return 'ok'
def sort_modify(): """修改排序""" img_id = toint(request.args.get('img_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if img_id <= 0: return u'参数出错' img = Img.get(img_id) if img: img.sort_order = new_sort db.session.commit() return u'ok'
def ad_delete(): """移除广告""" adv_id = toint(request.args.get('adv_id', '0')) if adv_id <= 0: return u'参数出错' ad = Adv.query.get_or_404(adv_id) if ad: db.session.delete(ad) db.session.commit() return 'ok'
def sort_modify(): """修改排序""" adv_id = toint(request.args.get('adv_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if adv_id <= 0: return u'参数出错' ad = Adv.get(adv_id) if ad: ad.sort_order = new_sort db.session.commit() return u'ok'
def card_sort_modify(): """修改排序""" rc_id = toint(request.args.get('rc_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if rc_id <= 0: return u'参数出错' rc = RechargeCard.get(rc_id) if rc: rc.sort_order = new_sort db.session.commit() return u'ok'
def sort_modify(): """修改排序""" news_id = toint(request.args.get('news_id', '0')) new_sort = toint(request.args.get('new_sort', '0')) new_sort = new_sort if new_sort > 0 else -1 if new_sort < 0: return u'只能输入大于0的数字' if new_sort > 10000000: return u'数字不能过大' if news_id <= 0: return u'参数出错' news_info = News.get(news_id) if news_info: news_info.sort_order = new_sort db.session.commit() return u'ok'
def delete_news_goods(): """删除资讯商品""" ng_id = toint(request.args.get('ng_id', '0')) if ng_id <= 0: return u'参数出错' ng = NewsGoods.query.get_or_404(ng_id) if ng: db.session.delete(ng) db.session.commit() return u'ok'
def save(self): """ 保存 """ salon_name = self.form.get('salon_name', '').strip() desc = self.form.get('desc', '').strip() sort_order = toint(self.form.get('sort_order', 0)) us_id = toint(self.form.get('us_id', 0)) uid = session['uid'] if self.is_new: self.salon = UserSalon.create(add_time=self.current_time) # 群组原图 if self.salon_img: self.salon.update(salon_img=self.salon_img) invitation_code = randomstr(6).upper() self.salon.update(salon_name=salon_name, desc=desc, user_count=1, sort_order=sort_order, invitation_code=invitation_code, commit=True) # 创建rongcloud群组 if self.is_new: admin_uid = get_uid() rgs = RcGroupService() rgs.create(admin_uid, self.salon.us_id, self.salon.salon_name) uis = UserInSalon() uis.uid = admin_uid uis.us_id = self.salon.us_id uis.add_time = int(time.time()) db.session.add(uis) db.session.commit() return True
def edit(): """权限编辑""" args = request.args permission_id = toint(args.get('permission_id', '0')) rp_id = toint(args.get('rp_id', '0')) endpoint_list = args.get('endpoint_list', '').strip() sort_order = toint(args.get('sort_order', '0')) if permission_id <= 0 or rp_id <= 0: return u'参数出错' p = Permission.query.get(permission_id) if not p: return u'获取权限信息失败' rp =RolePermission.query.get(rp_id) if not rp: return u'获取角色权限失败' p.update(sort_order=sort_order) rp.update(endpoint_list=endpoint_list, commit=True) return u'ok'
def delete(): """ 删除资讯 """ news_id = toint(request.args.get('news_id', '0')) if news_id <= 0: return u'参数出错' n = News.query.get_or_404(news_id) if n: db.session.delete(n) db.session.commit() return u'ok'
def st_detail(): """规格模板详情""" st_id = toint(request.args.get('st_id', '0')) if st_id <= 0: return u'参数出错' st = SpecTemplate.query.get(st_id) if not st: return u'获取规格模板失败' spec_list = Spec.query.filter(Spec.st_id == st.st_id).\ order_by(Spec.add_time.desc()).all() return render_template('goods/st_detail.html.j2', f=st, **locals())