'empty', 'key_name' => 'user_id', 'error_msg' => '用户id有误', ], [ 'checked_type' => 'in', 'key_name' => 'user_type', 'checked_data' => [0,1], 'error_msg' => '用户类型有误', ], [ 'checked_type' => 'empty', 'key_name' => 'md5_key', 'error_msg' => '数据key有误', ], [ 'checked_type' => 'empty', 'key_name' => 'fields', 'error_msg' => '请选择字段', ], ]; $ret = ParamsChecked($params, $p); if($ret !== true) { return DataReturn($ret, -1); } // 数据 $data = [ 'user_id' => intval($params['user_id']), 'user_type' => intval($params['user_type']), 'md5_key' => $params['md5_key'], 'fields' => empty($params['fields']) ? '' : (is_array($params['fields']) ? json_encode($params['fields'], JSON_UNESCAPED_UNICODE) : $params['fields']), 'add_time' => time(), 'upd_time' => time(), ]; if(Db::name('FormTableUserFields')->insertGetId($data) <= 0) { return DataReturn(MyLang('common.operate_fail'), -100); } return DataReturn(MyLang('common.operate_success'), 0); } /** * 用户字段选择重置 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2020-10-08 * @desc description * @param [array] $params [输入参数] */ public static function FieldsSelectReset($params = []) { // 参数校验 $p = [ [ 'checked_type' => 'empty', 'key_name' => 'user_id', 'error_msg' => '用户id有误', ], [ 'checked_type' => 'in', 'key_name' => 'user_type', 'checked_data' => [0,1], 'error_msg' => '用户类型有误', ], [ 'checked_type' => 'empty', 'key_name' => 'md5_key', 'error_msg' => '数据key有误', ], ]; $ret = ParamsChecked($params, $p); if($ret !== true) { return DataReturn($ret, -1); } // 数据删除 $where = [ 'user_id' => intval($params['user_id']), 'user_type' => intval($params['user_type']), 'md5_key' => $params['md5_key'], ]; if(Db::name('FormTableUserFields')->where($where)->delete() === false) { return DataReturn(MyLang('common.operate_fail'), -100); } return DataReturn(MyLang('common.operate_success'), 0); } /** * 获取用户选择的字段数据 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2020-10-08 * @desc description * @param [array] $params [输入参数] */ public static function FieldsSelectData($params = []) { // 模块 $module_name = RequestModule(); // 当前用户 if($module_name == 'admin') { $admin = AdminService::LoginInfo(); $user_id = empty($admin['id']) ? 0 : $admin['id']; $user_type = 0; } else { $user = UserService::LoginUserInfo(); $user_id = empty($user['id']) ? 0 : $user['id']; $user_type = 1; } if(empty($user_id)) { return DataReturn('用户信息有误', -1); } if(empty($params['md5_key'])) { return DataReturn('数据key有误', -1); } // 获取数据 $where = [ 'user_id' => $user_id, 'user_type' => $user_type, 'md5_key' => $params['md5_key'], ]; // 获取数据 $data = Db::name('FormTableUserFields')->where($where)->order('id desc')->find(); $data = empty($data['fields']) ? [] : json_decode($data['fields'], true); return DataReturn(MyLang('common.handle_success'), 0, $data); } } ?>