StoreProductReply.php 5.3 KB

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