ReportPool.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. use yii\behaviors\TimestampBehavior;
  10. use Yii;
  11. /**
  12. * This is the model class for table "{{%bonus_pool}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $start_time
  17. * @property integer $end_time
  18. * @property integer $created_at
  19. */
  20. class ReportPool extends \yii\db\ActiveRecord
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%report_pool}}';
  28. }
  29. public function behaviors()
  30. {
  31. return [
  32. [
  33. 'class' => TimestampBehavior::class,
  34. 'attributes' => [
  35. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  36. ]
  37. ]
  38. ];
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['store_id', 'start_time', 'end_time', 'created_at','is_send','send_time','commit_time' ,'number'], 'integer'],
  47. [[ 'reward_amount'], 'number'],
  48. [['created_at'], 'safe']
  49. ];
  50. }
  51. public static function getBonusPool($store_id, $params = [], $field = '*') {
  52. $query = self::find()->where(['store_id' => $store_id]);
  53. if ($params) {
  54. $query->andWhere($params);
  55. }
  56. $data = $query->select($field)->orderBy('id desc')->asArray()->all();
  57. foreach ($data as &$item) {
  58. if (isset($item['start_time']) && isset($item['end_time'])) {
  59. $item['instalments'] = date("Y-m-d", $item['start_time']) . '~' . date("Y-m-d", $item['end_time']);
  60. }
  61. }
  62. return $data;
  63. }
  64. }