UserFavoriteModel.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\user\model;
  12. use think\Db;
  13. use think\Model;
  14. class UserFavoriteModel extends Model
  15. {
  16. public function favorites()
  17. {
  18. $userId = cmf_get_current_user_id();
  19. $userQuery = Db::name("UserFavorite");
  20. $favorites = $userQuery->where('user_id', $userId)->order('id desc')->paginate(10);
  21. $data['page'] = $favorites->render();
  22. $data['lists'] = $favorites->items();
  23. return $data;
  24. }
  25. public function deleteFavorite($id)
  26. {
  27. $userId = cmf_get_current_user_id();
  28. $userQuery = Db::name("UserFavorite");
  29. $where['id'] = $id;
  30. $where['user_id'] = $userId;
  31. $data = $userQuery->where($where)->delete();
  32. return $data;
  33. }
  34. }