product.php rec add,application/wap/model/store/StoreProductReply.php · 众邦科技/CRMEB打通版 - Gitee.com...

/**

*

* @author: xaboy<365615158@qq.com>

* @day: 2017/12/29

*/

namespace app\wap\model\store;

use basic\ModelBasic;

use service\UtilService;

use traits\ModelTrait;

class StoreProductReply extends ModelBasic

{

use ModelTrait;

protected $insert = ['add_time'];

protected function setAddTimeAttr()

{

return time();

}

protected function setPicsAttr($value)

{

return is_array($value) ? json_encode($value) : $value;

}

protected function getPicsAttr($value)

{

return json_decode($value,true);

}

public static function reply($group,$type = 'product')

{

$group['reply_type'] = $type;

return self::set($group);

}

public static function productValidWhere($alias = '')

{

$model = new self;

if($alias){

$model->alias($alias);

$alias .= '.';

}

return $model->where("{$alias}is_del",0)->where("{$alias}reply_type",'product');

}

public static function getProductReplyList($productId,$order = 'All',$first = 0,$limit = 8)

{

$model = self::productValidWhere('A')->where('A.product_id',$productId)

->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')

->join('__USER__ B','A.uid = B.uid')

->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique');

$baseOrder = 'A.add_time DESC,A.product_score DESC, A.service_score DESC';

if($order == 'new') $model->order($baseOrder);

else if($order == 'pic') $model->where('A.pics',['<>',''],['<>','[]'])->order('A.add_time DESC,'.$baseOrder);

else $model->order('A.add_time DESC,'.$baseOrder);

$list = $model->limit($first,$limit)->select()->toArray()?:[];

foreach ($list as $k=>$reply){

$list[$k] = self::tidyProductReply($reply);

}

return $list;

}

public static function tidyProductReply($res)

{

$res['cart_info'] = json_decode($res['cart_info'],true)?:[];

$res['suk'] = isset($res['cart_info']['productInfo']['attrInfo']) ? $res['cart_info']['productInfo']['attrInfo']['suk'] : '';

$res['nickname'] = UtilService::anonymity($res['nickname']);

$res['add_time'] = date('Y-m-d H:i',$res['add_time']);

$res['star'] = ceil(($res['product_score'] + $res['service_score'])/2);

$res['comment'] = $res['comment']?:'此用户没有填写评价';

unset($res['cart_info']);

return $res;

}

public static function isReply($unique,$reply_type = 'product')

{

return self::be(['unique'=>$unique,'reply_type'=>$reply_type]);

}

public static function getRecProductReply($productId)

{

$res = self::productValidWhere('A')->where('A.product_id',$productId)

->field('A.product_score,A.service_score,A.comment,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info')

->join('__USER__ B','A.uid = B.uid')

->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique')

->order('A.add_time DESC,A.product_score DESC, A.service_score DESC, A.add_time DESC')->find();

if(!$res) return null;

return self::tidyProductReply($res->toArray());

}

}

一键复制

编辑

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值