def add(): access_status = judging_permissions('5_0_0') if access_status.get('code') != 200: return jsonify(access_status) data = get_request_params() _insert(data) return jsonify({'code': 200, 'msg': u'success'})
def add(): data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() result = _insert(data) if result.get('status', False): return jsonify({'code': 200, 'msg': u'成功'}) else: return jsonify({'code': 203, 'msg': result.get('msg', '')})
def add(): data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() user_obj = admin_user.find_one({'username': data.get('username')}) if user_obj: return jsonify({'code': 202, 'msg': u'此账号已经存在,请不要重复添加'}) result = _insert(data) if result.get('status', False): return jsonify({'code': 200, 'msg': u'成功'}) else: return jsonify({'code': 203, 'msg': result.get('msg', '')})
def add(): data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() access_status = judging_permissions('2_2_0') if access_status.get('code') != 200: return jsonify(access_status) _file = request.files img_url_file = _file.get('img_url') if img_url_file: result, img_url = upload_img(img_url_file) if not result: return jsonify({'code': 206, 'msg': img_url}) data.update({'img_url': img_url}) result = _insert(data) if result.get('status', False): return jsonify({'code': 200, 'msg': u'成功'}) else: return jsonify({'code': 203, 'msg': result.get('msg', '')})
def add(): data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() access_status = judging_permissions('2_1_0') if access_status.get('code') != 200: return jsonify(access_status) created_time = timestamp_to_strftime(time.time() + 24 * 60 * 60, format='%Y-%m-%d') income_obj = income.find_one({'created_time': created_time}) if income_obj: return jsonify({'code': 202, 'msg': u'当天收益已存在请不要重复添加'}) income_obj = income.find_one({'created_time': timestamp_to_strftime(time.time(), format='%Y-%m-%d')}) if income_obj: data['historical_income'] = int(data.get('yesterday_income', 0)) + income_obj.get('historical_income') else: data['historical_income'] = data.get('yesterday_income', 0) result = _insert(data) if result.get('status', False): return jsonify({'code': 200, 'msg': u'成功'}) else: return jsonify({'code': 203, 'msg': result.get('msg', '')})
def update(): access_status = judging_permissions('operation:edit') if access_status.get('code') != 200: return jsonify(access_status) _update = {} data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() _obj = operation.find_one() if not _obj: result = _insert(data) if result.get('status'): return jsonify({'code': 200, 'msg': u'成功'}) return jsonify({'code': 200, 'msg': u'不存在'}) try: red_hour_per_json = json.loads(data.get('red_hour_per_json')) except: return jsonify({'code': 201, 'msg': u'红包时间点分配比例json数据错误'}) per_total = 0 for hour_int in range(24): hour_dict = red_hour_per_json.get(str(hour_int)) if not hour_dict: return jsonify({'code': 201, 'msg': u'红包时间点分配比例json数据错误'}) per_total += hour_dict.get('per', 0) if per_total != 100: return jsonify({'code': 201, 'msg': u'红包时间点分配比例json数据错误'}) red_hour_per_json_str = json.dumps(red_hour_per_json, ensure_ascii=False) data.update({'red_hour_per_json': red_hour_per_json_str}) try: check_in_calorific_json = json.loads( data.get('check_in_calorific_json')) except: return jsonify({'code': 201, 'msg': u'参数错误'}) check_in_calorific_json_str = json.dumps(check_in_calorific_json, ensure_ascii=False) data.update({'check_in_calorific_json': check_in_calorific_json_str}) try: calorific_cash_json = json.loads(data.get('calorific_cash_json')) except: return jsonify({'code': 201, 'msg': u'参数错误'}) calorific_cash_json_str = json.dumps(calorific_cash_json, ensure_ascii=False) data.update({'calorific_cash_json': calorific_cash_json_str}) try: withdraw_cash_json = json.loads(data.get('withdraw_cash_json')) except: return jsonify({'code': 201, 'msg': u'参数错误'}) withdraw_cash_json_str = json.dumps(withdraw_cash_json, ensure_ascii=False) data.update({'withdraw_cash_json': withdraw_cash_json_str}) try: withdraw_cash_json_new = json.loads(data.get('withdraw_cash_json_new')) except: return jsonify({'code': 201, 'msg': u'参数错误'}) withdraw_cash_json_new_str = json.dumps(withdraw_cash_json_new, ensure_ascii=False) data.update({'withdraw_cash_json_new': withdraw_cash_json_new_str}) for key in default_values: if key in data: _values = data.get(key) # if isinstance(_values, str) or isinstance(_values, unicode): if isinstance(_values, str): _values = _values.strip() if key in int_key: try: _values = int(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if key in float_key: try: _values = float(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if _obj.get(key) != _values: _update.update({key: _values}) if _update: try: operation.update_one({'_id': _obj.get('_id')}, {'$set': _update}) return jsonify({'code': 200, 'msg': u'成功'}) except: pass else: return jsonify({'code': 203, 'msg': u'无更新数据'}) return jsonify({'code': 204, 'msg': u'失败'})
def update(): _update = {} data = {key: dict(request.form)[key][0] for key in dict(request.form)} if not data: data = request.get_json() _obj = system.find_one() if not _obj: result = _insert(data) if result.get('status'): return jsonify({'code': 200, 'msg': u'成功'}) return jsonify({'code': 200, 'msg': u'不存在'}) for key in default_values: if key in data: _values = data.get(key) # if isinstance(_values, str) or isinstance(_values, unicode): if isinstance(_values, str): _values = _values.strip() if key in int_key: try: _values = int(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if key in float_key: try: _values = float(_values) except: return jsonify({'code': 201, 'msg': u'参数错误'}) if _obj.get(key) != _values: _update.update({key: _values}) if 'img_url' in _update: del _update['img_url'] _file = request.files img_url_file = _file.get('img_url') if img_url_file: result, img_url = upload_img(img_url_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'img_url': img_url}) if 'ball_avatar' in _update: del _update['ball_avatar'] _file = request.files ball_avatar_file = _file.get('ball_avatar') if ball_avatar_file: result, img_url = upload_img(ball_avatar_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'ball_avatar': img_url}) if 'gzh_qrcode' in _update: del _update['gzh_qrcode'] _file = request.files gzh_qrcode_file = _file.get('gzh_qrcode') if gzh_qrcode_file: result, img_url = upload_img(gzh_qrcode_file) if not result: return jsonify({'code': 206, 'msg': img_url}) _update.update({'gzh_qrcode': img_url}) if _update: try: system.update_one({'_id': _obj.get('_id')}, {'$set': _update}) return jsonify({'code': 200, 'msg': u'成功'}) except: pass else: return jsonify({'code': 203, 'msg': u'无更新数据'}) return jsonify({'code': 204, 'msg': u'失败'})