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.

122 lines
3.1 KiB

7 years ago
4 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\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\Cart;
  10. use App\Http\Logic\CartLogic;
  11. class CartController extends BaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function getLogic()
  18. {
  19. return logic('Cart');
  20. }
  21. public function cartList(Request $request)
  22. {
  23. //参数
  24. $where['user_id'] = Token::$uid;
  25. $res = $this->getLogic()->getList($where);
  26. return ReturnData::create(ReturnData::SUCCESS,$res);
  27. }
  28. public function cartDetail(Request $request)
  29. {
  30. //参数
  31. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  32. $id = $request->input('id');
  33. $where['id'] = $id;
  34. $res = $this->getLogic()->getOne($where);
  35. if(!$res)
  36. {
  37. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  38. }
  39. return ReturnData::create(ReturnData::SUCCESS,$res);
  40. }
  41. /**
  42. * 添加商品到购物车
  43. *
  44. * @access public
  45. * @param integer $goods_id 商品编号
  46. * @param integer $goods_number 商品数量
  47. * @param json $property 规格值对应的id json数组,预留
  48. * @return boolean
  49. */
  50. public function cartAdd(Request $request)
  51. {
  52. if(Helper::isPostRequest())
  53. {
  54. $_POST['user_id'] = Token::$uid;
  55. return $this->getLogic()->add($_POST);
  56. }
  57. }
  58. //修改
  59. public function cartUpdate(Request $request)
  60. {
  61. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  62. $id = $request->input('id');
  63. if(Helper::isPostRequest())
  64. {
  65. unset($_POST['id']);
  66. $where['id'] = $id;
  67. //$where['user_id'] = Token::$uid;
  68. return $this->getLogic()->edit($_POST,$where);
  69. }
  70. }
  71. //删除
  72. public function cartDelete(Request $request)
  73. {
  74. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  75. $id = $request->input('id');
  76. if(Helper::isPostRequest())
  77. {
  78. $where['id'] = $id;
  79. $where['user_id'] = Token::$uid;
  80. return $this->getLogic()->del($where);
  81. }
  82. }
  83. //清空购物车
  84. public function cartClear(Request $request)
  85. {
  86. if(Helper::isPostRequest())
  87. {
  88. $where['user_id'] = Token::$uid;
  89. return $this->getLogic()->del($where);
  90. }
  91. }
  92. //购物车结算商品列表
  93. public function cartCheckoutGoodsList(Request $request)
  94. {
  95. //参数
  96. $where['ids'] = $request->input('ids','');
  97. $where['user_id'] = Token::$uid;
  98. if($where['ids']=='')
  99. {
  100. return ReturnData::create(ReturnData::PARAMS_ERROR);
  101. }
  102. return $this->getLogic()->cartCheckoutGoodsList($where);
  103. }
  104. }