CommentController.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Comment;
  5. use app\model\Goods;
  6. use app\model\Order;
  7. class CommentController extends Base
  8. {
  9. function index()
  10. {
  11. $keyword = input('post.keyword', '', 'serach_in');
  12. $query = Comment::where(['weid' => weid()]);
  13. if (!empty($keyword)) {
  14. $query->where('content', 'like', '%' . $keyword . '%');
  15. }
  16. $res = $query->order('id desc')
  17. ->paginate(getpage())
  18. ->toArray();
  19. if (!empty($res['data'])) {
  20. foreach ($res['data'] as &$vo) {
  21. $vo['goodsName'] = Goods::getGoodsName($vo['goods_id']);
  22. }
  23. }
  24. $data['data'] = $res;
  25. return $this->json($data);
  26. }
  27. function listUpdate()
  28. {
  29. $data = only('id,status,sort');
  30. if (!$data['id']) throw new ValidateException('参数错误');
  31. Comment::update($data);
  32. $comment = Comment::find($data['id']);
  33. if ($comment) {
  34. Order::where('uuid', $comment->technical_uuid)->update(['comment' => Comment::total_byuuid($comment->technical_uuid)]);
  35. }
  36. return $this->json(['msg' => '操作成功']);
  37. }
  38. }