def active(token): res_dir = request.get_json() e_id = res_dir['id'] e_bool = res_dir['bool'] # noinspection PyBroadException try: _express = Express.query.filter_by(id=e_id).first() _express.active = e_bool db.session.flush() db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def edit(token): res_dir = request.get_json() e_id = res_dir['id'] e_name = res_dir['name'] price = res_dir['price'] # noinspection PyBroadException try: _product = Products.query.filter_by(id=e_id).first() _product.name = e_name _product.price = price db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def apply_discount_state_change(token): power = token['power'] res_dir = request.get_json() # noinspection PyBroadException try: _order = Orders.query.filter_by(id=res_dir.get('id')).update({ 'apply_discount_state': res_dir['apply_discount_state'], 'price': res_dir['price'] }) db.session.flush() db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def del_product(token): """ 删除产品 :param token: :return: """ res_dir = request.get_json() p_id = res_dir['id'] # noinspection PyBroadException try: _product = Products.query.filter_by(id=p_id).first() db.session.delete(_product) db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def creat(token): """ 添加产品 :param token: :return: """ res_dir = request.get_json() # noinspection PyBroadException try: _product = Products(**res_dir) db.session.add(_product) db.session.flush() db.session.commit() except Exception: return Error409.to_dict() Succ200.data = {'id': _product.id, 'active': _product.active} return Succ200.to_dict()
def del_list(token): res_dir = request.get_json() o_id = res_dir.get('id') power = token['power'] u_id = token['u_id'] if power not in INSIDE: # 如果不在可以看到所有订单的群组里 就添加搜索条件 _order = Orders.query.filter_by(id=o_id, input_staff=u_id).first() else: _order = Orders.query.filter_by(id=o_id).first() if not _order: return Error406.to_dict() # noinspection PyBroadException try: db.session.delete(_order) db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def update_school_log(token): res_dir = request.get_json() o_id = res_dir.get('id') u_id = token['u_id'] if 'school_code' in res_dir: del res_dir['school_code'] if 'id' in res_dir: del res_dir['id'] # noinspection PyBroadException try: _log = School_log.query.filter_by(id=o_id, u_id=u_id, status=1).update(res_dir) db.session.flush() db.session.commit() _log = School_log.query.filter_by(id=o_id, u_id=u_id, status=1).first() except Exception: return Error409.to_dict() Succ200.data = _log.to_dict() return Succ200.to_dict()
def active(token): """ 是否激活产品 :param token: :return: """ res_dir = request.get_json() p_id = res_dir['id'] e_bool = res_dir['bool'] # noinspection PyBroadException try: _product = Products.query.filter_by(id=p_id).first() _product.active = e_bool db.session.flush() db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def update_list(token): u_id = token['u_id'] power = token['power'] res_dir = list_data_handle(request.get_json(), u_id, False) # noinspection PyBroadException try: if power not in INSIDE: _order = Orders.query.filter_by(id=res_dir.get('id'), input_staff=u_id, delivery_state=0).update(res_dir) else: _order = Orders.query.filter( Orders.id == res_dir.get('id'), Orders.delivery_state != 3).update(res_dir) db.session.flush() db.session.commit() except Exception: return Error409.to_dict() Succ200.data = None return Succ200.to_dict()
def add_school_log(token): res_dir = request.get_json() title = res_dir['title'] content = res_dir['content'] school_code = res_dir['school_code'] u_id = token['u_id'] # noinspection PyBroadException try: Log = School_log() Log.school_code = school_code Log.u_id = u_id Log.title = title Log.content = content db.session.add(Log) db.session.flush() db.session.commit() except Exception: return Error409.to_dict() data = {'input_time': Log.input_time, 'id': Log.id} Succ200.data = data return Succ200.to_dict()
def order_list(token): u_id = token['u_id'] res_dir = request.get_json() page_index = res_dir.get('page') # 页数 limit = res_dir.get('limit') # 一页多少条 power = token['power'] day = str(datetime.now().day) if 'manage' in res_dir and res_dir.get('manage'): # 管理页面请求拦截 search_var(res_dir) if limit < 100: if power in PUBLICIST: # sql = Orders.query.filter(get_safety_list(**res_dir, token=token)).filter(publicist_safety(u_id)) sql = Orders.query.filter( get_safety_list(**res_dir, token=token)).filter( Orders.publicist == u_id) else: sql = Orders.query.filter( get_safety_list(**res_dir, token=token)) else: sql = Orders.query.with_entities( Orders.buy_product, Orders.parent, Orders.phone, Orders.address, Orders.price, Orders.buy_num, Orders.pay_method, Orders.remarks, Orders.id).filter(Orders.delivery_state == 0, Orders.apply_discount_state != 1, extract('day', Orders.delivery_time) <= day) else: sql = Orders.query.filter(Orders.input_staff == u_id, Orders.delivery_state == 0) # noinspection PyBroadException try: items = sql.limit(limit).offset((page_index - 1) * limit) total = sql.count() except Exception: return Error409.to_dict() data = {'items': [], 'total': total} if limit < 100: for item in items: dict_item = item.to_dict() dict_item['input_staff'] = get_user_name(dict_item['input_staff'] or u_id) dict_item['id'] = str(dict_item['id']).zfill(6) dict_item['ppg_id'] = str(dict_item['ppg_id']).zfill(6) dict_item['school'] = item.orders_school.school_name dict_item['publicist'] = get_user_name(dict_item['publicist']) data['items'].append(dict_item) else: for item in items: data['items'].append({ 'buy_product': item[0], 'parent': item[1], 'phone': item[2], 'address': item[3], 'price': item[4], 'buy_num': item[5], 'pay_method': item[6], 'remarks': item[7], 'id': str(item[8]).zfill(6) }) Succ200.data = data return Succ200.to_dict()