255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'title' => 'Title', 'content' => 'Content', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @return ActiveQueryInterface the relational query object. */ public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } /** * 获取分页数据 * * @param integer $mall_id * @param integer $page * @param integer $limit * @param callable $callback * @param string $order_by * @return array */ public static function getPageList( int $mall_id, int $page, int $limit, callable $callback, string $order_by = 'id desc' ) :array { $model = static::find()->where(['mall_id' => $mall_id]); if (!empty($callback)) call_user_func($callback, $model); $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]); $model->limit($pagination->limit)->offset($pagination->offset); $list = $model->asArray()->orderBy($order_by)->all(); $data['list'] = $list; $data['page_count'] = $pagination->pageCount; $data['current_page'] = $page + 1; return $data; } /** * 添加举报 * * @param integer $user_id * @param integer $mall_id * @param string $title * @param string $content * @return true|static */ public static function addReport( int $user_id, int $mall_id, string $title, string $content ) { $model = new static(); $model->load(compact('user_id', 'mall_id', 'title', 'content'), ''); return $model->save() ? true : $model; } }