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.

128 lines
3.9 KiB

7 years ago
4 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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\Comment;
  10. use App\Http\Logic\CommentLogic;
  11. class CommentController extends BaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function getLogic()
  18. {
  19. return logic('Comment');
  20. }
  21. public function commentList(Request $request)
  22. {
  23. //参数
  24. $limit = $request->input('limit', 10);
  25. $offset = $request->input('offset', 0);
  26. $where['user_id'] = Token::$uid;
  27. $where['comment_type'] = 0;if($request->input('comment_type')!=null){$where['comment_type'] = $request->input('comment_type');}; //0商品评价,1文章评价
  28. if($request->input('comment_rank', '') != ''){$where['comment_rank'] = $request->input('comment_rank');}
  29. if($request->input('id_value', '') != ''){$where['id_value'] = $request->input('id_value');}
  30. if($request->input('parent_id', '') != ''){$where['parent_id'] = $request->input('parent_id');}
  31. $where['status'] = Comment::SHOW_COMMENT;
  32. $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
  33. /* if($res['count']>0)
  34. {
  35. foreach($res['list'] as $k=>$v)
  36. {
  37. }
  38. } */
  39. return ReturnData::create(ReturnData::SUCCESS,$res);
  40. }
  41. public function commentDetail(Request $request)
  42. {
  43. //参数
  44. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  45. $id = $request->input('id');
  46. $where['id'] = $id;
  47. $res = $this->getLogic()->getOne($where);
  48. if(!$res)
  49. {
  50. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  51. }
  52. return ReturnData::create(ReturnData::SUCCESS,$res);
  53. }
  54. //添加
  55. public function commentAdd(Request $request)
  56. {
  57. if(Helper::isPostRequest())
  58. {
  59. $_POST['user_id'] = Token::$uid;
  60. $_POST['add_time'] = time();
  61. $_POST['ip_address'] = Helper::getRemoteIp();
  62. return $this->getLogic()->add($_POST);
  63. }
  64. }
  65. //评价批量添加
  66. public function commentBatchAdd(Request $request)
  67. {
  68. if($request->input('comment',null)==null || $request->input('order_id',null)==null){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  69. $comment = json_decode($request->input('comment'),true);
  70. if($comment)
  71. {
  72. foreach($comment as $k=>$v)
  73. {
  74. $comment[$k]['user_id'] = Token::$uid;
  75. $comment[$k]['ip_address'] = Helper::getRemoteIp();
  76. $comment[$k]['add_time'] = time();
  77. $comment[$k]['order_id'] = $request->input('order_id');
  78. }
  79. }
  80. return $this->getLogic()->batchAdd($comment);
  81. }
  82. //修改
  83. public function commentUpdate(Request $request)
  84. {
  85. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  86. $id = $request->input('id');
  87. if(Helper::isPostRequest())
  88. {
  89. unset($_POST['id']);
  90. $where['id'] = $id;
  91. $where['user_id'] = Token::$uid;
  92. return $this->getLogic()->edit($_POST,$where);
  93. }
  94. }
  95. //删除
  96. public function commentDelete(Request $request)
  97. {
  98. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  99. $id = $request->input('id');
  100. if(Helper::isPostRequest())
  101. {
  102. $where['id'] = $id;
  103. $where['user_id'] = Token::$uid;
  104. return $this->getLogic()->del($where);
  105. }
  106. }
  107. }