CommentController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Order;
  5. use app\model\OrderGoods;
  6. use app\model\OrderStaff;
  7. use app\model\Category;
  8. use app\model\Member;
  9. use app\model\Comment;
  10. use app\model\Technical;
  11. class CommentController extends Base
  12. {
  13. public function add()
  14. {
  15. $Membermob = new Member;
  16. $memberinfo = $Membermob->getUserByWechat();
  17. $postJsonString = input('post.postJsonString', '', 'serach_in');
  18. $postdata = json_decode($postJsonString, true);
  19. $technical_uuid = OrderStaff::getuuid($postdata['orderInfo']['id']);
  20. if (empty($postdata['orderInfo']['cat_id'])) {
  21. foreach ($postdata['goods'] as $vo) {
  22. Comment::create([
  23. 'weid' => weid(),
  24. 'uid' => $memberinfo['id'],
  25. 'nick_name' => $memberinfo['nickname'],
  26. 'head_img_url' => $memberinfo['userpic'],
  27. 'status' => 0,
  28. 'technical_uuid' => $technical_uuid,
  29. 'order_id' => $vo['order_id'],
  30. 'goods_id' => $vo['goods_id'],
  31. 'level' => $vo['level'],
  32. 'content' => $vo['content']
  33. ]);
  34. }
  35. } else {
  36. Comment::create([
  37. 'weid' => weid(),
  38. 'uid' => $memberinfo['id'],
  39. 'nick_name' => $memberinfo['nickname'],
  40. 'head_img_url' => $memberinfo['userpic'],
  41. 'status' => 0,
  42. 'order_id' => $postdata['orderInfo']['id'],
  43. 'technical_uuid' => $technical_uuid,
  44. 'cat_id' => $postdata['orderInfo']['cat_id'],
  45. 'level' => $postdata['cateComment']['level'],
  46. 'content' => $postdata['cateComment']['content']
  47. ]);
  48. }
  49. Order::update(['is_comment' => 1, 'id' => $postdata['orderInfo']['id']]);
  50. //增加评价量
  51. if (!empty($technical_uuid)) {
  52. Technical::where('uuid', $technical_uuid)->inc('comment')->update();
  53. }
  54. return $this->json(['msg' => '感谢您的评价', 'data' => $data]);
  55. }
  56. public function getorder()
  57. {
  58. $id = input('get.id', '', 'intval');
  59. $data = Order::order_info($id);
  60. if (!empty($data['orderInfo']['cat_id'])) {
  61. $data['cateComment']['level'] = 5;
  62. $data['cateComment']['content'] = '';
  63. $data['orderInfo']['cateMap']['image'] = Category::getImage($data['orderInfo']['cat_id']);
  64. }
  65. if ($data['orderInfo']['ptype'] == 2) {
  66. $data['technical'] = OrderStaff::getTechnical($data['orderInfo']['id']);
  67. $data['technical']['touxiang'] = toimg($data['technical']['touxiang']);
  68. }
  69. foreach ($data['goods'] as &$vo) {
  70. $vo['goods']['image'] = toimg($vo['goods']['image']);
  71. $vo['level'] = 5;
  72. $vo['content'] = '';
  73. }
  74. return $this->json(['data' => $data]);
  75. }
  76. public function gettechnicalcomment()
  77. {
  78. $uuid = input('get.uuid', '', 'serach_in');
  79. $where['technical_uuid'] = $uuid;
  80. $where['status'] = 1;
  81. $data = Comment::where($where)->order('id asc')->select()->toArray();
  82. foreach ($data as &$vo) {
  83. $vo['nick_name'] = Author()::substr_cut($vo['nick_name']);
  84. }
  85. return $this->json(['data' => $data]);
  86. }
  87. public function getgoodscomment()
  88. {
  89. $goods_id = input('get.goodsId', '', 'serach_in');
  90. $where['goods_id'] = $goods_id;
  91. $where['status'] = 1;
  92. $data = Comment::where($where)->order('id asc')->select()->toArray();
  93. foreach ($data as &$vo) {
  94. $vo['nick_name'] = Author()::substr_cut($vo['nick_name']);
  95. }
  96. return $this->json(['data' => $data]);
  97. }
  98. public function getgoods()
  99. {
  100. $goods_id = input('get.goodsId', '', 'serach_in');
  101. $OrderGoods = new OrderGoods;
  102. $data = $OrderGoods->getOrderGoods($goods_id);
  103. foreach ($data as &$vo) {
  104. $vo['level'] = 5;
  105. $vo['content'] = '';
  106. }
  107. return $this->json(['data' => $data]);
  108. }
  109. }