HouseEmail.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace common\models;
  3. class HouseEmail extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. [['hid', 'email'], 'required', 'message' => '{attribute}不能为空'],
  9. ['hid', 'unique', 'targetClass' => 'common\models\HouseEmail', 'on' => ['add', 'edit'], 'message' => '该楼盘已经设置过邮箱'],
  10. ['hid', 'number'],
  11. ['email', 'email'],
  12. ];
  13. }
  14. public function attributeLabels()
  15. {
  16. return [
  17. 'hid' => '楼盘',
  18. 'email' => '邮箱',
  19. ];
  20. }
  21. public function Authenticator($input)
  22. {
  23. $this->load($input, '');
  24. if (!$this->validate()) return $this->errors;
  25. return $this;
  26. }
  27. /**
  28. * 返回后台查询的数据
  29. * @param $input
  30. * @return array|\yii\db\ActiveRecord[]
  31. */
  32. public function getList($input)
  33. {
  34. $query = self::find();
  35. $query->select(['pfg_house_email.id', 'pfg_house_email.email', 'pfg_house_email.create_at', 'pfg_house.name']);
  36. $query->leftJoin('pfg_house', 'pfg_house_email.hid = pfg_house.id');
  37. if (!empty($input['text'])) {
  38. $query->andWhere(['like', 'pfg_house_email.email', $input['text']]);
  39. $query->orWhere(['like', 'pfg_house.name', $input['text']]);
  40. }
  41. $query->orderBy(['pfg_house_email.email' => SORT_DESC, 'pfg_house_email.id' => SORT_DESC]);
  42. return $query->asArray()->all();
  43. }
  44. /**
  45. * 返回后台数据条数
  46. * @param $input
  47. * @return int|string
  48. */
  49. public function Total($input)
  50. {
  51. $query = self::find();
  52. $query->leftJoin('pfg_house', 'pfg_house_email.hid = pfg_house.id');
  53. if (!empty($input['text'])) {
  54. $query->andWhere(['like', 'pfg_house_email.email', $input['text']]);
  55. $query->orWhere(['like', 'pfg_house.name', $input['text']]);
  56. }
  57. return $query->count();
  58. }
  59. /**
  60. * 查询该楼盘是否单独设置了邮箱
  61. * @param $hid
  62. * @return array|null|\yii\db\ActiveRecord
  63. */
  64. public function findEmail($hid)
  65. {
  66. $query = self::find();
  67. $query->select(['email']);
  68. $query->andWhere(['hid' => $hid]);
  69. return $query->asArray()->one();
  70. }
  71. }