12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace common\models;
- class TestNumber extends Common
- {
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [['number'], 'required', 'message' => '{attribute}不能为空'],
- ['number', 'unique', 'targetClass' => 'common\models\TestNumber', 'on' => ['add', 'edit'], 'message' => '该号码已经存在'],
- ['explain', 'string', 'max' => 255],
- ];
- }
- /**
- * @return array
- */
- public function attributeLabels()
- {
- return [
- 'number' => '测试号码',
- 'explain' => '说明',
- ];
- }
- /**
- * 统计条数
- * @param $input
- * @return int|string
- */
- public function total($input)
- {
- $query = self::find();
- if (!empty($input['number'])) {
- $query->andWhere(['like', 'number', $input['number']]);
- }
- return $query->count();
- }
- /**
- * 后台 - 测试号码页面数据
- * @param $input
- * @return array|\yii\db\ActiveRecord[]
- */
- public function getList($input)
- {
- $query = self::find();
- if (!empty($input['number'])) {
- $query->andWhere(['like', 'number', $input['number']]);
- }
- if (!empty($input['page'])) {
- $query->limit = $input['limit'];
- $query->offset = ($input['page'] - 1) * $input['limit'];
- }
- $query->orderBy(['pfg_test_number.is_show' => SORT_ASC, 'pfg_test_number.create_at' => SORT_DESC]);
- return $query->asArray()->all();
- }
- }
|