StoreProductReply.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\admin\model\store;
  3. use app\admin\model\user\User;
  4. use app\models\store\StoreOrder;
  5. use crmeb\traits\ModelTrait;
  6. use crmeb\basic\BaseModel;
  7. /**
  8. * 评论管理 model
  9. * Class StoreProductReply
  10. * @package app\admin\model\store
  11. */
  12. class StoreProductReply extends BaseModel
  13. {
  14. /**
  15. * 数据表主键
  16. * @var string
  17. */
  18. protected $pk = 'id';
  19. /**
  20. * 模型名称
  21. * @var string
  22. */
  23. protected $name = 'store_product_reply';
  24. use ModelTrait;
  25. protected function getPicsAttr($value)
  26. {
  27. return json_decode($value, true);
  28. }
  29. /**
  30. * 设置where条件
  31. * @param array $where
  32. * @param string $alias
  33. * @param object $model
  34. * */
  35. public static function valiWhere($where, $alias = '', $joinAlias = '', $model = null)
  36. {
  37. $model = is_null($model) ? new self() : $model;
  38. if ($alias) {
  39. $model = $model->alias($alias);
  40. $alias .= '.';
  41. }
  42. $joinAlias = $joinAlias ? $joinAlias . '.' : '';
  43. if (isset($where['title']) && $where['title'] != '') $model = $model->where("{$alias}comment", 'LIKE', "%$where[title]%");
  44. if (isset($where['is_reply']) && $where['is_reply'] != '') $model = $where['is_reply'] >= 0 ? $model->where("{$alias}is_reply", $where['is_reply']) : $model->where("{$alias}is_reply", '>', 0);
  45. if (isset($where['producr_id']) && $where['producr_id'] != 0) $model = $model->where($alias . 'product_id', $where['producr_id']);
  46. if (isset($where['product_name']) && $where['product_name']) $model = $model->where("{$joinAlias}store_name", 'LIKE', "%$where[product_name]%");
  47. if (isset($where['order_id']) && $where['order_id'] != '') {
  48. $model = $model->join('store_order o', 'o.id = a.oid')->where('o.order_id', $where['order_id']);
  49. }
  50. if (isset($where['nickname']) && $where['nickname']) {
  51. $model = $model->join('user u', 'u.uid = a.uid')->where('u.nickname', 'like', "%$where[nickname]%");
  52. }
  53. if (isset($where['score_type']) && $where['score_type'] != '') {
  54. switch ((int)$where['score_type']) {
  55. case 1:
  56. $model = $model->where('product_score', 5)->where('service_score', 5);
  57. break;
  58. case 2:
  59. $model = $model->where(function ($query) {
  60. $query->where('product_score', '<', 3)->whereOr('service_score', '<', 3);
  61. });
  62. break;
  63. }
  64. }
  65. return $model->where("{$alias}is_del", 0);
  66. }
  67. public static function getProductImaesList($where)
  68. {
  69. $list = self::valiWhere($where, 'a', 'p')->group('p.id')->join('wechat_user u', 'u.uid=a.uid', 'LEFT')->join("store_product p", 'a.product_id=p.id', 'LEFT')->field(['p.id', 'p.image', 'p.store_name', 'p.price'])->page($where['page'], $where['limit'])->select();
  70. $list = count($list) ? $list->toArray() : [];
  71. foreach ($list as &$item) {
  72. $item['store_name'] = self::getSubstrUTf8($item['store_name'], 10, 'UTF-8', '');
  73. }
  74. return $list;
  75. }
  76. public static function getProductReplyList($where)
  77. {
  78. $data = self::valiWhere($where, 'a', 'p')
  79. ->join("store_product p", 'a.product_id=p.id', 'left')
  80. ->order('a.add_time desc,a.is_reply asc')
  81. ->field(['a.*', 'p.image', 'p.store_name'])
  82. ->page((int)$where['message_page'], (int)$where['limit'])
  83. ->select();
  84. $data = count($data) ? $data->toArray() : [];
  85. foreach ($data as &$item) {
  86. $item['_add_time'] = time_tran($item['add_time']);
  87. $item['order_id'] = StoreOrder::where('id', $item['oid'])->value('order_id');
  88. if ($item['uid']) {
  89. $userInfo = User::where('uid', $item['uid'])->field(['avatar', 'nickname'])->find();
  90. if ($userInfo) {
  91. $item['nickname'] = $userInfo['nickname'];
  92. $item['avatar'] = $userInfo['avatar'];
  93. }
  94. }
  95. }
  96. $count = self::valiWhere($where, 'a', 'p')->join("store_product p", 'a.product_id=p.id', 'left')->count();
  97. return ['list' => $data, 'count' => $count];
  98. }
  99. /**
  100. * @param $where
  101. * @return array
  102. */
  103. public static function systemPage($where)
  104. {
  105. $model = new self;
  106. if ($where['comment'] != '') $model = $model->where('r.comment', 'LIKE', "%$where[comment]%");
  107. if ($where['is_reply'] != '') {
  108. if ($where['is_reply'] >= 0) {
  109. $model = $model->where('r.is_reply', $where['is_reply']);
  110. } else {
  111. $model = $model->where('r.is_reply', '>', 0);
  112. }
  113. }
  114. if ($where['product_id']) $model = $model->where('r.product_id', $where['product_id']);
  115. $model = $model->alias('r')->join('wechat_user u', 'u.uid=r.uid');
  116. $model = $model->join('store_product p', 'p.id=r.product_id');
  117. $model = $model->where('r.is_del', 0);
  118. $model = $model->field('r.*,u.nickname,u.headimgurl,p.store_name');
  119. $model = $model->order('r.add_time desc,r.is_reply asc');
  120. return self::page($model, function ($itme) {
  121. }, $where);
  122. }
  123. }