Browse Source

add share record

master
filesite 6 months ago
parent
commit
37ffc0b622
  1. 80
      plugins/Common.php
  2. 75
      themes/tajian/controller/FrontapiController.php
  3. 6
      themes/tajian/controller/MyController.php
  4. 33
      themes/tajian/views/my/sharedir.php
  5. 1
      www/css/tajian.css
  6. 39
      www/js/tajian.js

80
plugins/Common.php

@ -48,7 +48,7 @@ Class Common {
$logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}"); $logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}");
} }
//保存用户多收藏夹目录映射配置 //保存用户多收藏夹目录映射关系
public static function saveUserDirMap($cellphone, $username, $new_dir) { public static function saveUserDirMap($cellphone, $username, $new_dir) {
$my_user_map = self::getMyDirs($cellphone, $username); $my_user_map = self::getMyDirs($cellphone, $username);
array_push($my_user_map, $new_dir); array_push($my_user_map, $new_dir);
@ -70,6 +70,80 @@ Class Common {
return $saved === false ? false : true; return $saved === false ? false : true;
} }
//获取用户共享目录记录
public static function getMyShareDirs($cellphone, $username) {
$my_id = self::getUserId($cellphone);
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$rootDir = str_replace("/{$username}", "/{$my_id}", $rootDir); //获取自己的目录
if (!is_dir($rootDir)) {
$my_first_id = self::getMappedUsername($cellphone);
$rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录
}
$map = array();
if (is_dir($rootDir)) {
$cache_filename = "{$rootDir}/share_dirs.json";
if (file_exists($cache_filename)) {
$json = file_get_contents($cache_filename);
$map = json_decode($json, true);
}
}
return $map;
}
//保存用户共享目录记录
public static function saveMyShareDirs($cellphone, $username, $friends_cellphone, $share_dir) {
$shareDirs = self::getMyShareDirs($cellphone, $username);
if (empty($shareDirs) || empty($shareDirs[$friends_cellphone])) {
$shareDirs[$friends_cellphone] = array($share_dir);
}else if(!in_array($share_dir, $shareDirs[$friends_cellphone])) {
array_push($shareDirs[$friends_cellphone], $share_dir);
}
$my_id = self::getUserId($cellphone);
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$rootDir = str_replace("/{$username}", "/{$my_id}", $rootDir); //获取自己的目录
if (!is_dir($rootDir)) {
$my_first_id = self::getMappedUsername($cellphone);
$rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录
}
$saved = false;
if (is_dir($rootDir)) {
$cache_filename = "{$rootDir}/share_dirs.json";
$saved = file_put_contents($cache_filename, json_encode($shareDirs, JSON_PRETTY_PRINT));
}
return $saved === false ? false : true;
}
//从用户共享目录记录里删除一个共享
public static function deleteFromMyShareDirs($cellphone, $username, $friends_cellphone, $share_dir) {
$shareDirs = self::getMyShareDirs($cellphone, $username);
if(!empty($shareDirs[$friends_cellphone]) && in_array($share_dir, $shareDirs[$friends_cellphone])) {
$shareDirs[$friends_cellphone] = array_diff($shareDirs[$friends_cellphone], array($share_dir));
}else {
return false;
}
$my_id = self::getUserId($cellphone);
$rootDir = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
$rootDir = str_replace("/{$username}", "/{$my_id}", $rootDir); //获取自己的目录
if (!is_dir($rootDir)) {
$my_first_id = self::getMappedUsername($cellphone);
$rootDir = str_replace("/{$my_id}", "/{$my_first_id}", $rootDir); //获取自己的目录
}
$saved = false;
if (is_dir($rootDir)) {
$cache_filename = "{$rootDir}/share_dirs.json";
$saved = file_put_contents($cache_filename, json_encode($shareDirs, JSON_PRETTY_PRINT));
}
return $saved === false ? false : true;
}
//获取新收藏夹目录名 //获取新收藏夹目录名
public static function getNewFavDir($cellphone) { public static function getNewFavDir($cellphone) {
$new_dir = 2000; //默认从编号2000开始 $new_dir = 2000; //默认从编号2000开始
@ -403,4 +477,8 @@ Class Common {
return $url; return $url;
} }
public static function maskCellphone($cellphone) {
return preg_replace("/^(.{3,})\d{4}(.{4})$/i", '$1****$2', $cellphone);
}
} }

75
themes/tajian/controller/FrontapiController.php

@ -1319,6 +1319,9 @@ eof;
$saved = Common::saveUserDirMap($friends_cellphone, $loginedUser['username'], $share_dir); $saved = Common::saveUserDirMap($friends_cellphone, $loginedUser['username'], $share_dir);
if ($saved !== false) { if ($saved !== false) {
//保存共享记录
Common::saveMyShareDirs($loginedUser['cellphone'], $loginedUser['username'], $friends_cellphone, $share_dir);
$msg = "账号共享完成"; $msg = "账号共享完成";
$code = 1; $code = 1;
}else { }else {
@ -1330,5 +1333,77 @@ eof;
return $this->renderJson(compact('code', 'msg', 'err')); return $this->renderJson(compact('code', 'msg', 'err'));
} }
//删除一个账号共享
public function actionDelsharedir() {
$ip = $this->getUserIp();
$check_time = 120; //2 分钟内
$max_time_in_minutes = 10; //最多 10 次
$isUserGotRequestLimit = $this->requestLimit($ip, $max_time_in_minutes, $check_time);
if ($isUserGotRequestLimit) {
$this->logError("Request limit got, ip: {$ip}");
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...');
}
//只允许修改自己的数据
$loginedUser = Common::getUserFromSession();
if (empty($loginedUser['username'])) {
throw new Exception('Oops,你还没登录哦');
}else if (
!empty(FSC::$app['config']['multipleUserUriParse'])
&& (empty(FSC::$app['user_id']) || FSC::$app['user_id'] != $loginedUser['username'])
) {
throw new Exception('Oops,请求地址有误');
}
//返回给视图的变量
$code = 0;
$msg = '';
$err = '';
//用户提交的数据检查
$postParams = $this->post();
if (!empty($postParams)) {
$friends_cellphone = $this->post('cellphone', '');
$share_dir = $this->post('dir', '');
if (empty($friends_cellphone) || Common::isCellphoneNumber($friends_cellphone) == false) {
$err = "请填写正确的手机号码";
}else if (empty($share_dir)) {
$err = "请选择要取消共享的账号";
}else if ($friends_cellphone == $loginedUser['cellphone']) {
$err = "不能取消自己的账号哦";
}
//只能取消属于自己的账号
if (empty($err)) {
$isMine = Common::isMyFavDir($loginedUser['cellphone'], $loginedUser['username'], $share_dir);
if (empty($isMine)) {
$err = '只能取消共享自己的账号';
}else {
//检查朋友的账号是否存在
$friend_exist = Common::getUserDataDir($friends_cellphone, $loginedUser['username']);
if (empty($friend_exist)) {
$err = "{$friends_cellphone} 还没注册哦,请朋友先注册吧";
}
}
}
if (empty($err)) { //如果数据检查通过,尝试保存
$saved = Common::deleteFromMyShareDirs($loginedUser['cellphone'], $loginedUser['username'], $friends_cellphone, $share_dir);
if ($saved !== false) {
$msg = "取消账号共享完成";
$code = 1;
}else {
$err = "取消账号共享失败,请稍后重试";
}
}
}
return $this->renderJson(compact('code', 'msg', 'err'));
}
} }

6
themes/tajian/controller/MyController.php

@ -67,7 +67,7 @@ Class MyController extends SiteController {
$nickname = $this->getNickname($readmeFile); $nickname = $this->getNickname($readmeFile);
//显示手机号码 //显示手机号码
$cellphone_hide = preg_replace("/^(.{3,})\d{4}(.{4})$/i", '$1****$2', $loginedUser['cellphone']); $cellphone_hide = Common::maskCellphone($loginedUser['cellphone']);
$pageTitle = "{$defaultTitle} | " . FSC::$app['config']['site_name']; $pageTitle = "{$defaultTitle} | " . FSC::$app['config']['site_name'];
$params = compact( $params = compact(
@ -173,6 +173,8 @@ Class MyController extends SiteController {
} }
} }
$myShareDirs = Common::getMyShareDirs($loginedUser['cellphone'], $loginedUser['username']);
//VIP身份判断 //VIP身份判断
$isVipUser = true; $isVipUser = true;
if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) { if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) {
@ -181,7 +183,7 @@ Class MyController extends SiteController {
$defaultTitle = "共享账号"; $defaultTitle = "共享账号";
$viewName = 'sharedir'; $viewName = 'sharedir';
return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'isVipUser')); return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'myShareDirs', 'isVipUser'));
} }
} }

33
themes/tajian/views/my/sharedir.php

@ -10,7 +10,8 @@ $max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['con
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="<?=$linkPrefix?>/my/">&lt;&lt;返回</a> <a href="<?=$linkPrefix?>/my/">&lt;&lt;返回</a>
</div> </div>
<form class="g_form_style mt65" id="share_dir_form" action="" method="POST"> <div class="g_form_style mt65">
<form id="share_dir_form" action="" method="POST">
<?php if (empty($viewData['isVipUser'])) { ?> <?php if (empty($viewData['isVipUser'])) { ?>
<div class="alert warning">此功能限VIP使用,限时免费开通请联系客服哦</div> <div class="alert warning">此功能限VIP使用,限时免费开通请联系客服哦</div>
<?php } ?> <?php } ?>
@ -49,4 +50,34 @@ eof;
</button> </button>
</div> </div>
</form> </form>
<hr class="mt20">
<h3 class="mt20">共享记录<small>(点击删除)</small></h3>
<div class="mt10 my_share_dirs">
<?php
foreach($viewData['myShareDirs'] as $friends_cellphone => $dirs) {
$maskPhone = Common::maskCellphone($friends_cellphone);
$btn_html = '';
foreach($dirs as $dir) {
$btn_html .= <<<eof
<button type="button" data-cellphone="{$friends_cellphone}" data-dir="{$dir}" class="btn-danger btn-del mt10">
{$viewData['myNicks'][$dir]}
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash3" viewBox="0 0 16 16">
<path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5"></path>
</svg>
</button>
eof;
}
echo <<<eof
<div class="fav-group">
朋友手机号:<strong>{$maskPhone}</strong>
<p>{$btn_html}</p>
</div>
eof;
}
?>
</div>
</div>
</main> </main>

1
www/css/tajian.css

@ -292,6 +292,7 @@ select.tagselect{max-width:100%}
.favmg-item .act_tags{min-height:40px;background-color:#EEE;padding:4px;margin-right:4px;margin-top:5px} .favmg-item .act_tags{min-height:40px;background-color:#EEE;padding:4px;margin-right:4px;margin-top:5px}
.favmg-item .act_tags label{display:inline-block;cursor:pointer} .favmg-item .act_tags label{display:inline-block;cursor:pointer}
.favmg-item .act_tags label input{cursor:pointer} .favmg-item .act_tags label input{cursor:pointer}
.fav-group{background:#EEE;padding:5px;margin-bottom:10px}
/* layout index */ /* layout index */
body.layout_index{background-color:#e5f1f3} body.layout_index{background-color:#e5f1f3}

39
www/js/tajian.js

@ -15,6 +15,7 @@ var taJian = {
deleteFav: '/frontapi/deletefav', //删除收藏的视频 deleteFav: '/frontapi/deletefav', //删除收藏的视频
createNewFav: '/frontapi/createdir', //创建新的收藏夹 createNewFav: '/frontapi/createdir', //创建新的收藏夹
shareFav2Friend: '/frontapi/sharedir', //共享收藏夹给朋友 shareFav2Friend: '/frontapi/sharedir', //共享收藏夹给朋友
deleteSharedFav: '/frontapi/delsharedir', //取消共享收藏夹给朋友
sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码 sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码
register: '/frontapi/createuser', //注册 register: '/frontapi/createuser', //注册
@ -690,7 +691,7 @@ if ($('#share_dir_form').get(0)) {
bt.prop('disabled', false); bt.prop('disabled', false);
btText.text('保存'); btText.text('保存');
if (data.code == 1) { if (data.code == 1) {
location.href = '/' + current_user_id + '/my/'; location.reload();
} else { } else {
alert(data.err); alert(data.err);
} }
@ -704,6 +705,42 @@ if ($('#share_dir_form').get(0)) {
$('#share_dir_form .jsbtn').click(handle_share_dir); $('#share_dir_form .jsbtn').click(handle_share_dir);
$('#share_dir_form').submit(handle_share_dir); $('#share_dir_form').submit(handle_share_dir);
//取消共享
var handle_delete_share = function(e) {
var btn = $(e.target);
if (e.target.tagName.toLowerCase() != 'button') {
btn = btn.parents('button');
}
var cellphone = btn.attr('data-cellphone'),
dir = btn.attr('data-dir'),
favName = btn.text().replace(/\s/g, '');
if (!cellphone || !dir) {
alert('系统异常,请刷新网页!');
return false;
}
if (confirm('确定取消账号共享【' + favName + '】吗?')) {
btn.prop('disabled', true);
var datas = {
'cellphone': cellphone,
'dir': dir
};
publicAjax(taJian.apis.deleteSharedFav, 'POST', datas, function (data) {
btn.prop('disabled', false);
if (data.code == 1) {
location.reload();
} else {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
btn.prop('disabled', false);
alert('网络请求失败,请重试。');
});
}
};
$('.my_share_dirs .btn-del').click(handle_delete_share);
} }
})(); })();

Loading…
Cancel
Save