修复评论报错

This commit is contained in:
liaofei 2019-09-03 11:16:50 +08:00
parent 25a0259cb8
commit c13ff1312e
2 changed files with 11 additions and 16 deletions

View File

@ -29,19 +29,10 @@ class StoreProductReply extends AuthController
*/
public function index()
{
$where = Util::getMore([
['is_reply',''],
['comment',''],
],$this->request);
$product_id = 0;
$product_id = input('product_id');
if($product_id)
$where['product_id'] = $product_id;
else
$where['product_id'] = 0;
$this->assign('where',$where);
if(!$product_id) $product_id = 0;
$this->assign('is_layui',true);
$this->assign(ProductReplyModel::systemPage($where));
$this->assign('product_id',(int)$product_id);
return $this->fetch();
}
@ -52,6 +43,8 @@ class StoreProductReply extends AuthController
['limit',10],
['title',''],
['is_reply',''],
['product_name',''],
['product_id',0],
]);
return JsonService::successful(ProductReplyModel::getProductImaesList($where));
}

View File

@ -29,22 +29,24 @@ class StoreProductReply extends ModelBasic
* @param string $alias
* @param object $model
* */
public static function valiWhere($where,$alias='',$model=null)
public static function valiWhere($where,$alias='',$joinAlias='',$model=null)
{
$model=is_null($model) ? new self() : $model;
if($alias){
$model=$model->alias($alias);
$alias.='.';
}
$joinAlias=$joinAlias ? $joinAlias.'.' : '';
if(isset($where['title']) && $where['title']!='') $model=$model->where("{$alias}comment",'LIKE',"%$where[title]%");
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",'GT',0);
if(isset($where['producr_id']) && $where['producr_id']!=0) $model=$model->where('product_id',$where['producr_id']);
if(isset($where['producr_id']) && $where['producr_id']!=0) $model=$model->where($alias.'product_id',$where['producr_id']);
if(isset($where['product_name']) && $where['product_name']) $model=$model->where("{$joinAlias}store_name",'LIKE',"%$where[product_name]%");
return $model->where("{$alias}is_del",0);
}
public static function getProductImaesList($where)
{
$list=self::valiWhere($where,'a')->group('p.id')->join('__WECHAT_USER__ u','u.uid=a.uid')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')->field(['p.id','p.image','p.store_name','p.price'])->page($where['page'],$where['limit'])->select();
$list=self::valiWhere($where,'a','p')->group('p.id')->join('__WECHAT_USER__ u','u.uid=a.uid')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')->field(['p.id','p.image','p.store_name','p.price'])->page($where['page'],$where['limit'])->select();
$list=count($list) ? $list->toArray() : [];
foreach ($list as &$item){
$item['store_name']=self::getSubstrUTf8($item['store_name'],10,'UTF-8','');
@ -55,7 +57,7 @@ class StoreProductReply extends ModelBasic
public static function getProductReplyList($where)
{
$data=self::valiWhere($where,'a')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')
$data=self::valiWhere($where,'a','p')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')
->join('__WECHAT_USER__ u','u.uid=a.uid')
->order('a.add_time desc,a.is_reply asc')
->field('a.*,u.nickname,u.headimgurl as avatar')
@ -65,7 +67,7 @@ class StoreProductReply extends ModelBasic
foreach ($data as &$item){
$item['time']=\service\UtilService::timeTran($item['add_time']);
}
$count=self::valiWhere($where,'a')->join('__WECHAT_USER__ u','u.uid=a.uid')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')->count();
$count=self::valiWhere($where,'a','p')->join('__WECHAT_USER__ u','u.uid=a.uid')->join("__STORE_PRODUCT__ p",'a.product_id=p.id')->count();
return ['list'=>$data,'count'=>$count];
}
/**