On this page
商品评价列表
控制器 app/controller/admin/OrderItem.php
php
public function index(){
$param = request()->param();
$limit = intval(getValByKey('limit',$param,10));
$title = getValByKey('title',$param,'');
$list = \app\model\OrderItem::hasWhere('goodsItem',function ($query) use($title){
$query->where('title', 'like', '%'.$title.'%');
})
->whereNotNull('review_time')
->with(['goodsItem','user'])
->page($param['page'],$limit)
->order([ 'id'=>'desc' ])
->select();
$totalCount = \app\model\OrderItem::hasWhere('goodsItem',function ($query) use($title){
$query->where('title', 'like', '%'.$title.'%');
})
->whereNotNull('review_time')
->count();
return showSuccess([
'list'=>$list,
'totalCount'=>$totalCount
]);
}
模型 app/model/OrderItem.php
php
protected $json = ['review','extra'];
protected $jsonAssoc = true;
public function getReviewTimeAttr($value){
return date('Y-m-d H:i:s', $value);
}
// 关联订单
public function order(){
return $this->belongsTo('Order');
}
// 关联用户
public function user(){
return $this->belongsTo(\app\model\User::class)->hidden(['password']);
}
// 关联goods
public function goods(){
return $this->belongsTo('goods','shop_id');
}
// 关联goods_skus
public function goodsSkus(){
return $this->belongsTo('goodsSkus','shop_id');
}
// 关联商品
public function goodsItem(){
return $this->belongsTo('goods','goods_id');
}
验证器 app/validate/admin/OrderItem.php
php
protected $rule = [
'page' => 'require|integer|>:0',
];
protected $scene = [
...
'index'=>['page'],
...
];
路由 router/admin.php
php
Route::get('goods_comment/:page','admin.OrderItem/index');