| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace common\models;
- use Yii;
- use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
- /**
- * This is the model class for table "{{%USER_WALLET}}".
- *
- * @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'],
- [['CASH'], 'number'],
- [['UPDATED_AT', 'CLEAR_BY_CLOSED_AT'], 'integer'],
- [['ID','USER_ID'], 'string', 'max' => 32],
- [['USER_ID'], 'unique'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'USER_ID' => '用户id',
- 'CASH' => '现金',
- 'UPDATED_AT' => '修改时间',
- 'CLEAR_BY_CLOSED_AT' => '清空关停会员钱包时间',
- ];
- }
- /**
- * 操作日志记录条件
- * @return array
- */
- public function attrLabelsWithLogType(){
- return [
- 'USER_ID' => '用户id',
- 'CLEAR_BY_CLOSED_AT' => [
- 'label' => '清空关停会员钱包时间',
- 'type' => ValueTypeConfig::DATE_TIME_TYPE,
- ],
- ];
- }
- /**
- * 获取一名会员的余额
- * @param $userId
- * @return array|null
- */
- public static function getCashByUserId($userId){
- $data = UserPerformance::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'USER_ID,CASH');
- if(!$data){
- $data = [
- 'USER_ID' => $userId,
- 'CASH' => 0,
- ];
- }
- return $data;
- }
- }
|