IntegralRechargeListForm.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\modules\admin\models\q_and_a;
  3. use app\models\IntegralRecharge;
  4. use yii\base\Model;
  5. /**
  6. * @property \app\models\IntegralRecharge $model;
  7. */
  8. class IntegralRechargeListForm extends Model
  9. {
  10. public $id;
  11. public $name;
  12. public $sort;
  13. public $state;
  14. public $store_id;
  15. public $dateTime;
  16. public function rules()
  17. {
  18. return [
  19. [['name', 'sort','state'], 'required'],
  20. [['id'], 'integer'],
  21. [['name', 'dateTime'], 'string', 'max' => 255],
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'name' => '充值名称',
  28. 'state' => '是否启用',
  29. ];
  30. }
  31. public function search()
  32. {
  33. $query = IntegralRecharge::find()->alias('ro')->where([
  34. 'ro.is_delete' => 0,
  35. 'ro.store_id' => $this->store_id,
  36. ])->orderBy('ro.id DESC');
  37. if ($this->name) {
  38. $query->andWhere(['like', 'ro.name', $this->name]);
  39. }
  40. if ($this->state >= 0) {
  41. $query->andWhere(['ro.state' => $this->state]);
  42. }
  43. if ($this->dateTime) {
  44. $query->andWhere(['>=', 'ro.created_at', strtotime($this->dateTime[0])]);
  45. $query->andWhere(['<=', 'ro.created_at', strtotime($this->dateTime[1])]);
  46. }
  47. $data = pagination_make($query);
  48. foreach ($data['list'] as &$item) {
  49. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  50. }
  51. return [
  52. 'code' => 0,
  53. 'data' => [
  54. 'data' => $data['list'],
  55. 'pageNo' => $data['pageNo'],
  56. 'totalCount' => $data['totalCount']
  57. ],
  58. 'sql' => $query->createCommand()->getRawSql(),
  59. ];
  60. }
  61. }