StoreProductReply.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\store;
  12. use basic\ModelBasic;
  13. use service\UtilService;
  14. use traits\ModelTrait;
  15. class StoreProductReply extends ModelBasic
  16. {
  17. use ModelTrait;
  18. protected $insert = ['add_time'];
  19. protected function setAddTimeAttr()
  20. {
  21. return time();
  22. }
  23. protected function setPicsAttr($value)
  24. {
  25. return is_array($value) ? json_encode($value) : $value;
  26. }
  27. protected function getPicsAttr($value)
  28. {
  29. return json_decode($value,true);
  30. }
  31. public static function reply($group,$type = 'product')
  32. {
  33. $group['reply_type'] = $type;
  34. return self::set($group);
  35. }
  36. public static function productValidWhere($alias = '')
  37. {
  38. $model = new self;
  39. if($alias){
  40. $model->alias($alias);
  41. $alias .= '.';
  42. }
  43. return $model->where("{$alias}is_del",0)->where("{$alias}reply_type",'product');
  44. }
  45. public static function getProductReplyList($productId,$order = 'All',$first = 0,$limit = 8)
  46. {
  47. $model = self::productValidWhere('A')->where('A.product_id',$productId)
  48. ->field('A.product_score,A.service_score,A.comment,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info,A.merchant_reply_content')
  49. ->join('__USER__ B','A.uid = B.uid')
  50. ->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique');
  51. $baseOrder = 'A.add_time DESC,A.product_score DESC, A.service_score DESC';
  52. if($order == 'new') $model->order($baseOrder);
  53. else if($order == 'pic') $model->where('A.pics',['<>',''],['<>','[]'])->order('LENGTH(A.comment) DESC,'.$baseOrder);
  54. else $model->order('LENGTH(A.comment) DESC,'.$baseOrder);
  55. $list = $model->limit($first,$limit)->select()->toArray()?:[];
  56. foreach ($list as $k=>$reply){
  57. $list[$k] = self::tidyProductReply($reply);
  58. }
  59. return $list;
  60. }
  61. public static function tidyProductReply($res)
  62. {
  63. $res['cart_info'] = json_decode($res['cart_info'],true)?:[];
  64. $res['suk'] = isset($res['cart_info']['productInfo']['attrInfo']) ? $res['cart_info']['productInfo']['attrInfo']['suk'] : '';
  65. $res['nickname'] = UtilService::anonymity($res['nickname']);
  66. $res['add_time'] = date('Y-m-d H:i',$res['add_time']);
  67. $res['star'] = ceil(($res['product_score'] + $res['service_score'])/2);
  68. $res['comment'] = $res['comment']?:'此用户没有填写评价';
  69. unset($res['cart_info']);
  70. return $res;
  71. }
  72. public static function isReply($unique,$reply_type = 'product')
  73. {
  74. return self::be(['unique'=>$unique,'reply_type'=>$reply_type]);
  75. }
  76. public static function getRecProductReply($productId)
  77. {
  78. $res = self::productValidWhere('A')->where('A.product_id',$productId)
  79. ->field('A.product_score,A.service_score,A.comment,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info')
  80. ->join('__USER__ B','A.uid = B.uid')
  81. ->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique')
  82. ->order('A.product_score DESC, A.service_score DESC, A.add_time DESC')->find();
  83. if(!$res) return null;
  84. return self::tidyProductReply($res->toArray());
  85. }
  86. }