1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\api\controller;
- use think\Db;
- use app\common\model\user\Share as ShareModel;
- use app\api\validate\ShareValidate;
- use app\common\Service\Share\ShareService;
- class Share extends Base
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- public function add()
- {
- $params = $this->request->only(['shareId', 'spm', 'page', 'query', 'from', 'platform']);
- // 验证参数
- $validate = new ShareValidate();
- if (!$validate->scene('add')->check($params)) {
- $this->error($validate->getError());
- }
- $user = auth_user();
- if (!$user) {
- $this->error('用户未登录');
- }
- // 使用服务类添加分享记录
- $shareInfo = ShareService::addShareLog($user, $params);
- if ($shareInfo) {
- $this->success('添加分享记录成功', $shareInfo);
- } else {
- $this->error('添加分享记录失败');
- }
- }
- /**
- * 查看分享记录
- */
- public function index()
- {
- $user = auth_user();
- $logs = ShareModel::with(['user' => function ($query) {
- return $query->field(['id', 'nickname', 'avatar']);
- }])->where('share_id', $user->id)->paginate($this->request->param('list_rows', 8));
- $this->success('获取成功', $logs);
- }
- }
|