You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Log;
  4. use DB;
  5. use Illuminate\Http\Request;
  6. use App\Common\ReturnData;
  7. use App\Common\Helper;
  8. use App\Common\Token;
  9. use App\Http\Model\CollectGoods;
  10. use App\Http\Logic\CollectGoodsLogic;
  11. class CollectGoodsController extends BaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function getLogic()
  18. {
  19. return logic('CollectGoods');
  20. }
  21. public function collectGoodsList(Request $request)
  22. {
  23. //参数
  24. $limit = $request->input('limit', 10);
  25. $offset = $request->input('offset', 0);
  26. $where['user_id'] = Token::$uid;
  27. if($request->input('is_attention', null) !== null){$where['is_attention'] = $request->input('is_attention');}
  28. $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
  29. /* if($res['count']>0)
  30. {
  31. foreach($res['list'] as $k=>$v)
  32. {
  33. }
  34. } */
  35. return ReturnData::create(ReturnData::SUCCESS,$res);
  36. }
  37. public function collectGoodsDetail(Request $request)
  38. {
  39. //参数
  40. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  41. $id = $request->input('id');
  42. $where['id'] = $id;
  43. $res = $this->getLogic()->getOne($where);
  44. if(!$res)
  45. {
  46. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  47. }
  48. return ReturnData::create(ReturnData::SUCCESS,$res);
  49. }
  50. //收藏商品
  51. public function collectGoodsAdd(Request $request)
  52. {
  53. if(Helper::isPostRequest())
  54. {
  55. $_POST['user_id'] = Token::$uid;
  56. return $this->getLogic()->add($_POST);
  57. }
  58. }
  59. //修改
  60. public function collectGoodsUpdate(Request $request)
  61. {
  62. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  63. $id = $request->input('id');
  64. if(Helper::isPostRequest())
  65. {
  66. unset($_POST['id']);
  67. $where['id'] = $id;
  68. $where['user_id'] = Token::$uid;
  69. return $this->getLogic()->edit($_POST,$where);
  70. }
  71. }
  72. //取消收藏商品
  73. public function collectGoodsDelete(Request $request)
  74. {
  75. if(!checkIsNumber($request->input('goods_id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  76. $goods_id = $request->input('goods_id');
  77. if(Helper::isPostRequest())
  78. {
  79. $where['goods_id'] = $goods_id;
  80. $where['user_id'] = Token::$uid;
  81. return $this->getLogic()->del($where);
  82. }
  83. }
  84. }