98 lines
3.9 KiB
PHP
98 lines
3.9 KiB
PHP
<?php
|
|
namespace app\controllers\merchant;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Store;
|
|
//商品属性
|
|
class CommentController extends CommonController{
|
|
//评价列表
|
|
public function actionCommentList(){
|
|
$result=axios_request();
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$this->wqData['storeId'];
|
|
$page=$result['page']?:1;
|
|
$star=$result['star'];
|
|
$timeType=$result['timeType'];
|
|
$keyword=$result['keyword'];
|
|
$timeArr=$this->timeArr[$timeType];
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$data= (new \yii\db\Query())
|
|
->select('a.orderId,a.star,a.id,a.body,b.portrait,b.userName,from_unixtime(a.createdAt)createdAt,a.reply,a.state,a.media')
|
|
->from('{{%ybwm_comment}} a')
|
|
->leftJoin('{{%ybwm_member}} b','a.userId=b.id')
|
|
->where(['a.deleteAt'=>0,'a.storeId'=>$storeId]);
|
|
if($star==1){
|
|
$data->andWhere('a.star>3');
|
|
}
|
|
if($star==2){
|
|
$data->andWhere('a.star=3');
|
|
}
|
|
if($star==3){
|
|
$data->andWhere('a.star<3');
|
|
}
|
|
if($timeArr){
|
|
$data->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>$timeArr['startTime'],':endTime'=>$timeArr['endTime']]);
|
|
}
|
|
if($keyword){
|
|
$data->andWhere(['or',['like','b.userName',$keyword],['like','a.outTradeNo',$keyword],['like','b.userTel',$keyword]]);
|
|
}
|
|
// echo ddSql($data->offset($num)
|
|
// ->limit($limit));die;
|
|
$count=$data->count();
|
|
$res=$data->offset($num)
|
|
->limit($limit)
|
|
->all();
|
|
for($i=0;$i<count($res);$i++){
|
|
$res[$i]['media']=json_decode($res[$i]['media'],true);
|
|
$res[$i]['goods']=(new \yii\db\Query())
|
|
->from('{{%ybwm_order_goods}}')->select('id,name,num')
|
|
->where(['orderId'=>$res[$i]['orderId'],'item'=>1])->all();
|
|
}
|
|
$list['list']=$res;
|
|
$starStatistics=(new \yii\db\Query())
|
|
->select(['sum(if(star>3,1,0)) as good','sum(if(star=3,1,0)) as middle',
|
|
'sum(if(star<3,1,0)) as difference','TRUNCATE(avg(star),1) as average'])
|
|
->from('{{%ybwm_comment}}')
|
|
->where(['deleteAt'=>0,'state'=>2,'storeId'=>$storeId])->one();
|
|
$commentStatistics=(new \yii\db\Query())
|
|
->from('{{%ybwm_comment}}')
|
|
->where(['deleteAt'=>0,'storeId'=>$storeId]);
|
|
$list['average']=$starStatistics['average'];
|
|
$list['good']=$starStatistics['good'];
|
|
$list['goodStar']=sprintf("%.1f",(clone $commentStatistics)->andWhere('star>3')->average('star')?:0);
|
|
$list['middle']=$starStatistics['middle'];
|
|
$list['middleStar']=sprintf("%.1f",(clone $commentStatistics)->andWhere('star=3')->average('star')?:0);
|
|
$list['difference']=$starStatistics['difference'];
|
|
$list['differenceStar']=sprintf("%.1f",(clone $commentStatistics)->andWhere('star<3')->average('star')?:0);
|
|
return $this->result(1,'成功',$list,$count);
|
|
}
|
|
//修改评价
|
|
public function actionModifyComment(){
|
|
$result=axios_request();
|
|
if($result['type']==1){
|
|
//通过
|
|
$data['state']=2;
|
|
}
|
|
if($result['type']==2){
|
|
//拒绝
|
|
$data['state']=3;
|
|
}
|
|
if($result['type']==3){
|
|
//回复
|
|
$data['reply']=$result['reply'];
|
|
}
|
|
if($result['type']==4){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_comment}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
} |