From 37ffc0b622e77426ab0e9559b1535f1cd74b08ac Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 5 Jun 2024 19:33:00 +0800 Subject: [PATCH] add share record --- plugins/Common.php | 82 +++++++++++++++- .../tajian/controller/FrontapiController.php | 75 ++++++++++++++ themes/tajian/controller/MyController.php | 6 +- themes/tajian/views/my/sharedir.php | 97 ++++++++++++------- www/css/tajian.css | 1 + www/js/tajian.js | 39 +++++++- 6 files changed, 262 insertions(+), 38 deletions(-) diff --git a/plugins/Common.php b/plugins/Common.php index 9402c39..fe4ec33 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -23,7 +23,7 @@ Class Common { return str_replace($findChars, '', $str); } - public static function isCellphoneNumber($number) { + public static function isCellphoneNumber($number) { return preg_match("/^1[3456789][0-9]{9}$/", $number); } @@ -48,7 +48,7 @@ Class Common { $logOk = @error_log("{$logTime} invite {$cellphone}\n", 3, "{$logDir}{$friendsLogfile}"); } - //保存用户多收藏夹目录映射配置 + //保存用户多收藏夹目录映射关系 public static function saveUserDirMap($cellphone, $username, $new_dir) { $my_user_map = self::getMyDirs($cellphone, $username); array_push($my_user_map, $new_dir); @@ -70,6 +70,80 @@ Class Common { 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) { $new_dir = 2000; //默认从编号2000开始 @@ -403,4 +477,8 @@ Class Common { return $url; } + public static function maskCellphone($cellphone) { + return preg_replace("/^(.{3,})\d{4}(.{4})$/i", '$1****$2', $cellphone); + } + } \ No newline at end of file diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index ee77d69..24d8fec 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -1319,6 +1319,9 @@ eof; $saved = Common::saveUserDirMap($friends_cellphone, $loginedUser['username'], $share_dir); if ($saved !== false) { + //保存共享记录 + Common::saveMyShareDirs($loginedUser['cellphone'], $loginedUser['username'], $friends_cellphone, $share_dir); + $msg = "账号共享完成"; $code = 1; }else { @@ -1330,5 +1333,77 @@ eof; 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')); + } + } diff --git a/themes/tajian/controller/MyController.php b/themes/tajian/controller/MyController.php index 29d3f25..edc6aa2 100644 --- a/themes/tajian/controller/MyController.php +++ b/themes/tajian/controller/MyController.php @@ -67,7 +67,7 @@ Class MyController extends SiteController { $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']; $params = compact( @@ -173,6 +173,8 @@ Class MyController extends SiteController { } } + $myShareDirs = Common::getMyShareDirs($loginedUser['cellphone'], $loginedUser['username']); + //VIP身份判断 $isVipUser = true; if (empty($loginedUser['cellphone']) || !in_array($loginedUser['cellphone'], FSC::$app['config']['tajian_vip_user'])) { @@ -181,7 +183,7 @@ Class MyController extends SiteController { $defaultTitle = "共享账号"; $viewName = 'sharedir'; - return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'isVipUser')); + return $this->actionIndex($viewName, $defaultTitle, compact('myDirs', 'myNicks', 'isMine', 'myShareDirs', 'isVipUser')); } } \ No newline at end of file diff --git a/themes/tajian/views/my/sharedir.php b/themes/tajian/views/my/sharedir.php index 87aa630..09709d5 100644 --- a/themes/tajian/views/my/sharedir.php +++ b/themes/tajian/views/my/sharedir.php @@ -10,43 +10,74 @@ $max_num = !empty(FSC::$app['config']['tajian']['max_dir_num']) ? FSC::$app['con -
- -
此功能限VIP使用,限时免费开通请联系客服哦
- - -
- - -
+
+ + +
此功能限VIP使用,限时免费开通请联系客服哦
+ + +
+ + +
-
- + + $nickname) { + //忽略不属于自己的账号 + if (!empty($viewData['isMine']) && empty($viewData['isMine'][$dir])) {continue;} - echo <<{$nickname} + echo <<{$nickname} eof; - } - } ?> - -
-

说明:
把聚宝盆共享给朋友之后,你们可以共同维护里面的内容。

+ } + } ?> + +
+

说明:
把聚宝盆共享给朋友之后,你们可以共同维护里面的内容。

+ +
+ +
+
+ +
+

共享记录(点击删除)

+
+ $dirs) { + $maskPhone = Common::maskCellphone($friends_cellphone); -
- + +eof; + } + + echo << + 朋友手机号:{$maskPhone} +

{$btn_html}

+
+eof; + } + ?>
- + \ No newline at end of file diff --git a/www/css/tajian.css b/www/css/tajian.css index b8ba2d1..6ff1043 100644 --- a/www/css/tajian.css +++ b/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 label{display:inline-block;cursor:pointer} .favmg-item .act_tags label input{cursor:pointer} +.fav-group{background:#EEE;padding:5px;margin-bottom:10px} /* layout index */ body.layout_index{background-color:#e5f1f3} diff --git a/www/js/tajian.js b/www/js/tajian.js index 59cbb4d..d684831 100644 --- a/www/js/tajian.js +++ b/www/js/tajian.js @@ -15,6 +15,7 @@ var taJian = { deleteFav: '/frontapi/deletefav', //删除收藏的视频 createNewFav: '/frontapi/createdir', //创建新的收藏夹 shareFav2Friend: '/frontapi/sharedir', //共享收藏夹给朋友 + deleteSharedFav: '/frontapi/delsharedir', //取消共享收藏夹给朋友 sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码 register: '/frontapi/createuser', //注册 @@ -690,7 +691,7 @@ if ($('#share_dir_form').get(0)) { bt.prop('disabled', false); btText.text('保存'); if (data.code == 1) { - location.href = '/' + current_user_id + '/my/'; + location.reload(); } else { alert(data.err); } @@ -704,6 +705,42 @@ if ($('#share_dir_form').get(0)) { $('#share_dir_form .jsbtn').click(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); } })();