| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use Yii;
- use yii\data\Pagination;
- /**
- * This is the model class for table "{{%user_report}}".
- *
- * @property int $id
- * @property int $mall_id Mall Id
- * @property int $user_id 会员ID
- * @property string $title 举报标题
- * @property string|null $content 举报内容
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class UserReport extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_report}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'title'], 'required'],
- [['mall_id', 'user_id', 'created_at', 'updated_at'], 'integer'],
- [['content'], 'string'],
- [['title'], 'string', 'max' => 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;
- }
- }
|