def get_product_info(): args_dic = {} oid = request.args.get('sellerid') pname = request.args.get('productname') firsttype = request.args.get('type1') secondtype = request.args.get('type2') type_ids = None if firsttype is not None: tp_args_dic = {'type1': firsttype} if secondtype is not None: tp_args_dic['type2'] = secondtype type_ids = [typ['typeid'] for typ in Type.get_type(tp_args_dic)] if oid is not None: args_dic['oid'] = oid if pname is not None: args_dic['pname'] = pname if type_ids is not None: args_dic['types'] = type_ids products = Product.get_product(args_dic) typeid_list = [product['typeid'] for product in products] types = Type.get_type({'typeid_list': typeid_list}) types_dic = {} for typ in types: types_dic[typ['typeid']] = typ for product in products: product['type1'] = types_dic[product['typeid']]['type1'] product['type2'] = types_dic[product['typeid']]['type2'] return jsonify({'data': products})
def put_product_info(): prid = request.args.get('uid', type=int) product = Product().query.filter_by(pid=prid).first() type1 = request.form.get('type1') type2 = request.form.get('type2') types = [ typ['typeid'] for typ in Type.get_type({ 'type1': type1, 'type2': type2 }) ] if len(types) == 0: return jsonify({'status': 'fail'}) type_id = types[0] if product == None: return jsonify({'status': 'fail'}) else: product.iName = request.form.get('productname') product.typeID = type_id product.iPrice = request.form.get('price') product.remain = request.form.get('remain') product.description = request.form.get('description') db_app.session.commit() return jsonify({'status': 'success'})
def get_type(): args_dic = {} f_type = request.args.get('first_type') if f_type != None: args_dic['type1'] = f_type types = Type.get_type(args_dic) return jsonify({'data': types})
def del_type(): tid = request.args.get('typeid', type=int) typ = Type().query.filter_by(typeID=tid).first() if typ == None: return jsonify({'status': 'fail'}) else: db_app.session.delete(typ) db_app.session.commit() return jsonify({'status': 'success'})
def add_product_info(): type1 = request.form.get('type1') type2 = request.form.get('type2') types = [ typ['typeid'] for typ in Type.get_type({ 'type1': type1, 'type2': type2 }) ] if len(types) == 0: return jsonify({'status': 'fail'}) type_id = types[0] product = Product( iName=request.form.get('productname'), Type_typeID=type_id, iPrice=request.form.get('price'), remain=request.form.get('remain'), description=request.form.get('description'), Official_user_official_userID=request.form.get('sellerid')) db_app.session.add(product) db_app.session.commit() return jsonify({'status': 'success'})
def get_type(): args_dic = {} type1 = request.args.get('type1') type2 = request.args.get('type2') sellerid = request.args.get('sellerid', type=int) if type1: args_dic['type1'] = type1 if type2: args_dic['type2'] = type2 if sellerid: args_dic['oid'] = sellerid print(args_dic) type_list = Type.get_type(args_dic) print(len(type_list)) args_dic['types'] = [types['typeid'] for types in type_list] products = Product.get_product(args_dic) print(len(products)) args_dic['pid_list'] = [prod['uid'] for prod in products] products = DetailOrder.get_type_product(args_dic) print(len(products)) totals = 0 totaln = 0 for product in products: totals += product['totalprice'] totaln += product['totalnumber'] return jsonify({'data': {'totalsum': totals, 'totalnumber': totaln}})
def add_type(): typ = Type(type1=request.form.get('firsttype'), type2=request.form.get('secondtype')) db_app.session.add(typ) db_app.session.commit() return jsonify({'status': 'success'})