'timestamp:Y-m-d H:i', ]; /** * Common: 记录分享信息 * Author: wu-hui * Time: 2022/11/04 15:09 * @param $params * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function addInfo($params){ $pathInfo = $this->handlePath($params['share_path']); $where['member_id'] = $params['member_id']; $objectName = ''; // 信息处理 switch($pathInfo['path']){ // 文章详情分享 case '/pages_aijiu/article/detail': $where['object_id'] = $pathInfo['article_id']; $where['type'] = 1; $objectName = (new Article())->where('article_id',$pathInfo['article_id'])->value('article_title'); // 记录文章分享信息 $articleRecordInfo = [ 'article_id' => $pathInfo['article_id'], 'member_id' => $params['member_id'], 'share_id' => $pathInfo['share_id'] ]; (new ArticleShareRecord())->addInfo($articleRecordInfo); break; } // 记录分享 由于要统计每天的分享 所以这里一直为添加 $recordInfo = $this->where($where)->find(); if(!$recordInfo) $recordInfo = new self(); $recordInfo->object_title = $objectName; $recordInfo->object_id = $where['object_id']; $recordInfo->member_id = $where['member_id']; $recordInfo->type = $where['type']; $recordInfo->frequency += 1; $recordInfo->save(); return $this->success(); } /** * Common: 处理url信息 * Author: wu-hui * Time: 2022/11/04 15:05 * @param $path * @return array */ private function handlePath($path){ $fragment = parse_url($path)['fragment']; $pathArr = explode('?',$fragment); $pathInfo['path'] = $pathArr[0]; foreach(explode('&',$pathArr[1]) as $item){ $field = explode('=',$item); $pathInfo[$field[0]] = $field[1]; } return $pathInfo; } /** * Common: 文章分享记录 * Author: wu-hui * Time: 2022/11/07 14:16 * @return array */ public function articleRecord($memberId){ // 参数获取 $page = input('page',1); $pageSize = input('page_size',PAGE_LIST_ROWS); $searchText = (string)trim(input('search_text')); // 列表获取 $result = $this->alias('sr') ->field('a.article_id,a.article_title,a.cover_img,sr.update_time as time') ->join('article a','a.article_id = sr.object_id','LEFT') ->where('sr.type',1) ->where('a.status',1) ->where('a.site_id',$this->site_id) ->where('sr.member_id',$memberId) ->when(strlen($searchText) > 0,function($query) use ($searchText){ $query->where('a.article_title','like',"%{$searchText}%"); }) ->where('sr.member_id',$memberId) ->order('sr.update_time','DESC') ->paginate(['list_rows' => $pageSize,'page' => $page]); if($result) $result = $result->toArray(); $list = [ 'count' => $result['total'], 'list' => $result['data'], 'page_count' => $result['last_page'], ]; return $this->success($list); } }