TestNumber.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace common\models;
  3. class TestNumber extends Common
  4. {
  5. /**
  6. * @return array
  7. */
  8. public function rules()
  9. {
  10. return [
  11. [['number'], 'required', 'message' => '{attribute}不能为空'],
  12. ['number', 'unique', 'targetClass' => 'common\models\TestNumber', 'on' => ['add', 'edit'], 'message' => '该号码已经存在'],
  13. ['explain', 'string', 'max' => 255],
  14. ];
  15. }
  16. /**
  17. * @return array
  18. */
  19. public function attributeLabels()
  20. {
  21. return [
  22. 'number' => '测试号码',
  23. 'explain' => '说明',
  24. ];
  25. }
  26. /**
  27. * 统计条数
  28. * @param $input
  29. * @return int|string
  30. */
  31. public function total($input)
  32. {
  33. $query = self::find();
  34. if (!empty($input['number'])) {
  35. $query->andWhere(['like', 'number', $input['number']]);
  36. }
  37. return $query->count();
  38. }
  39. /**
  40. * 后台 - 测试号码页面数据
  41. * @param $input
  42. * @return array|\yii\db\ActiveRecord[]
  43. */
  44. public function getList($input)
  45. {
  46. $query = self::find();
  47. if (!empty($input['number'])) {
  48. $query->andWhere(['like', 'number', $input['number']]);
  49. }
  50. if (!empty($input['page'])) {
  51. $query->limit = $input['limit'];
  52. $query->offset = ($input['page'] - 1) * $input['limit'];
  53. }
  54. $query->orderBy(['pfg_test_number.is_show' => SORT_ASC, 'pfg_test_number.create_at' => SORT_DESC]);
  55. return $query->asArray()->all();
  56. }
  57. }