OrderCommentForm.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1\admin;
  8. use app\models\Goods;
  9. use app\models\OrderComment;
  10. use app\models\User;
  11. use yii\base\Model;
  12. class OrderCommentForm extends Model
  13. {
  14. public $store_id;
  15. public $id;
  16. public $status;
  17. public $reply_content;
  18. public $pic_list;
  19. public $mch_id;
  20. /**
  21. * 获取评论列表
  22. * @return array
  23. */
  24. public function getComment() {
  25. $query = OrderComment::find()->alias('oc')->where(['oc.store_id' => $this->store_id,
  26. 'oc.is_delete' => OrderComment::IS_DELETE_FALSE, 'oc.mch_id' => 0]);
  27. $query
  28. ->leftJoin(['u' => User::tableName()], 'oc.user_id=u.id')
  29. ->leftJoin(['g' => Goods::tableName()], 'oc.goods_id=g.id')
  30. ->select('oc.created_at, oc.user_id as uid,oc.is_virtual,oc.virtual_user,oc.id,u.nickname,u.platform,u.avatar_url,
  31. oc.score,oc.content,oc.pic_list,g.name goods_name,g.cover_pic,oc.is_hide,oc.reply_content')
  32. ->orderBy('oc.created_at DESC');
  33. $pagination = pagination_make($query);
  34. $list = $pagination['list'];
  35. foreach ($list as $key => &$value) {
  36. if ($value['is_virtual'] == 1) {
  37. $list[$key]['nickname'] = '(' . $value['virtual_user'] . ')';
  38. }
  39. $value['score'] = intval($value['score']);
  40. $value['pic_list'] = json_decode($value['pic_list'], true);
  41. $value['created_at'] = date('m-d H:i', $value['created_at']);
  42. // TODO: 其他数据
  43. }
  44. return [
  45. 'code' => 0,
  46. 'msg' => 'success',
  47. 'data' => [
  48. 'data' => $list,
  49. 'pageNo' => $pagination['pageNo'],
  50. 'totalCount' => $pagination['totalCount']
  51. ],
  52. ];
  53. }
  54. /**
  55. * 回复消息
  56. * @return array
  57. */
  58. public function reply() {
  59. $query = OrderComment::find()->where(['id' => $this->id])->one();
  60. if (!$query || empty($this->reply_content)) {
  61. return [
  62. 'code' => 1,
  63. 'msg' => '参数错误',
  64. ];
  65. }
  66. $query->reply_content = $this->reply_content;
  67. if ($query->save()) {
  68. return [
  69. 'code' => 0,
  70. 'msg' => '回复成功',
  71. ];
  72. } else {
  73. return [
  74. 'code' => 1,
  75. 'msg' => '回复失败',
  76. ];
  77. }
  78. }
  79. /**
  80. * 隐藏评论
  81. * @return array
  82. */
  83. public function hideStatus()
  84. {
  85. $order_comment = OrderComment::findOne([
  86. 'store_id' => $this->store_id,
  87. 'id' => $this->id,
  88. ]);
  89. if ($order_comment) {
  90. $order_comment->is_hide = $this->status;
  91. $order_comment->save();
  92. }
  93. return [
  94. 'code' => 0,
  95. 'msg' => '操作成功',
  96. ];
  97. }
  98. /**
  99. * 删除评论
  100. * @return array
  101. */
  102. public function deleteStatus()
  103. {
  104. $order_comment = OrderComment::findOne([
  105. 'store_id' => $this->store_id,
  106. 'id' => $this->id,
  107. ]);
  108. if ($order_comment) {
  109. $order_comment->is_delete = $this->status;
  110. $order_comment->save();
  111. }
  112. return [
  113. 'code' => 0,
  114. 'msg' => '操作成功',
  115. ];
  116. }
  117. }