127 lines
4.6 KiB
PHP
127 lines
4.6 KiB
PHP
<?php
|
|
/** ZJMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2022-2032 四川正今科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.zjphp.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道官方颁发授权证书,无纸质授权凭证书视为侵权行为。
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace app\model\newModel\common;
|
|
|
|
use addon\article\model\Article;
|
|
use addon\article\model\ArticleShareRecord;
|
|
use app\model\NewBaseModel;
|
|
|
|
class ShareRecord extends NewBaseModel{
|
|
|
|
protected $pk = 'id';
|
|
//protected $autoWriteTimestamp = false; // 开启自动时间戳
|
|
protected $createTime = 'create_time'; // 默认添加时间字段
|
|
protected $updateTime = 'update_time'; // 默认编辑时间字段
|
|
protected $deleteTime = false; // 软删除字段
|
|
protected $type = [
|
|
'time' => '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);
|
|
}
|
|
|
|
|
|
} |