| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace common\models;
- use Yii;
- use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
- /**
- * This is the model class for table "{{%USER_PERFORMANCE}}".
- *
- * @property string $ID
- * @property string $USER_ID
- * @property string $CASH
- * @property integer $UPDATED_AT
- * @property integer $CLEAR_BY_CLOSED_AT
- * @property User $user
- */
- class UserPerformance extends \common\components\ActiveRecord
- {
- const NEWS = 10;
- const USING = 20;
- const FINISHED = 30;
- const NULLIFY = 40;
- const EXPIRED = 50;
- public static function getEffective(): array
- {
- return [self::NEWS, self::USING];
- }
- public static function getInvalid(): array
- {
- return [self::FINISHED, self::NULLIFY, self::EXPIRED];
- }
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%USER_PERFORMANCE}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['USER_ID'], 'required'],
- [['AMOUNTS', 'ORIGINAL'], 'number'],
- [['UPDATED_AT', 'STATUS_ID'], 'integer'],
- [['ID','USER_ID'], 'string', 'max' => 32],
- [['USER_ID'], 'unique'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'USER_ID' => '用户id',
- 'AMOUNTS' => '当前余额',
- 'ORIGINAL' => '原始金额',
- 'UPDATED_AT' => '修改时间',
- ];
- }
- /**
- * 获取一名会员的余额
- * @param $userId
- * @return array|null
- */
- public static function getAmountByUserId($userId)
- {
- $data = UserPerformance::find()->select('SUM(AMOUNTS) AS AMOUNTS')->where('USER_ID=:USER_ID AND STATUS_ID<(:STATUS_ID)', [':USER_ID' => $userId, ':STATUS_ID' => self::FINISHED])->asArray()->one();
- if(!$data){
- $data = [
- 'USER_ID' => $userId,
- 'AMOUNTS' => 0,
- ];
- }
- return $data;
- }
- }
|