Share.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. use app\common\model\Share as ShareModel;
  5. use app\api\validate\ShareValidate;
  6. class Share extends Base
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = ['*'];
  10. public function add()
  11. {
  12. $params = $this->request->only(['shareId', 'spm', 'page', 'query', 'from', 'platform']);
  13. $validate = new ShareValidate();
  14. if (!$validate->scene('add')->check($params)) {
  15. $this->error($validate->getError());
  16. }
  17. $userId = $this->auth->id;
  18. // $shareInfo = ShareModel::log($userId, $params);
  19. $this->success("");
  20. }
  21. /**
  22. * 查看分享记录
  23. */
  24. public function index()
  25. {
  26. $user = auth_user();
  27. $logs = ShareModel::with(['user' => function ($query) {
  28. return $query->field(['id', 'nickname', 'avatar']);
  29. }])->where('share_id', $user->id)->paginate($this->request->param('list_rows', 8));
  30. $this->success('获取成功', $logs);
  31. }
  32. }