Collect.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\index\controller\shop;
  3. use app\common\controller\Frontend;
  4. use think\Db;
  5. class Collect extends Frontend
  6. {
  7. protected $layout = 'default';
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = ['*'];
  10. /**
  11. * 我的收藏
  12. */
  13. public function index()
  14. {
  15. $collectList = \addons\shop\model\Collect::with('goods')->where('user_id', $this->auth->id)->order('id', 'desc')->paginate(10);
  16. $this->view->assign('collectList', $collectList);
  17. $this->view->assign('title', "我的收藏");
  18. return $this->view->fetch();
  19. }
  20. /**
  21. * 移除收藏
  22. */
  23. public function del()
  24. {
  25. $id = $this->request->post("id/d");
  26. $collectInfo = \addons\shop\model\Collect::get($id);
  27. if (!$collectInfo) {
  28. $this->error('未找到相关信息');
  29. }
  30. if ($collectInfo['user_id'] != $this->auth->id) {
  31. $this->error('无法进行越权操作');
  32. }
  33. Db::startTrans();
  34. try {
  35. $collectInfo->delete();
  36. Db::commit();
  37. } catch (\Exception $e) {
  38. Db::rollback();
  39. $this->error('删除失败');
  40. }
  41. $this->success();
  42. }
  43. }