UserPerformance.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
  5. /**
  6. * This is the model class for table "{{%USER_WALLET}}".
  7. *
  8. * @property string $ID
  9. * @property string $USER_ID
  10. * @property string $CASH
  11. * @property integer $UPDATED_AT
  12. * @property integer $CLEAR_BY_CLOSED_AT
  13. * @property User $user
  14. */
  15. class UserPerformance extends \common\components\ActiveRecord
  16. {
  17. const NEWS = 10;
  18. const USING = 20;
  19. const FINISHED = 30;
  20. const NULLIFY = 40;
  21. const EXPIRED = 50;
  22. public static function getEffective(): array
  23. {
  24. return [self::NEWS, self::USING];
  25. }
  26. public static function getInvalid(): array
  27. {
  28. return [self::FINISHED, self::NULLIFY, self::EXPIRED];
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%USER_PERFORMANCE}}';
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['USER_ID'], 'required'],
  44. [['CASH'], 'number'],
  45. [['UPDATED_AT', 'CLEAR_BY_CLOSED_AT'], 'integer'],
  46. [['ID','USER_ID'], 'string', 'max' => 32],
  47. [['USER_ID'], 'unique'],
  48. ];
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. public function attributeLabels()
  54. {
  55. return [
  56. 'ID' => 'ID',
  57. 'USER_ID' => '用户id',
  58. 'CASH' => '现金',
  59. 'UPDATED_AT' => '修改时间',
  60. 'CLEAR_BY_CLOSED_AT' => '清空关停会员钱包时间',
  61. ];
  62. }
  63. /**
  64. * 操作日志记录条件
  65. * @return array
  66. */
  67. public function attrLabelsWithLogType(){
  68. return [
  69. 'USER_ID' => '用户id',
  70. 'CLEAR_BY_CLOSED_AT' => [
  71. 'label' => '清空关停会员钱包时间',
  72. 'type' => ValueTypeConfig::DATE_TIME_TYPE,
  73. ],
  74. ];
  75. }
  76. /**
  77. * 获取一名会员的余额
  78. * @param $userId
  79. * @return array|null
  80. */
  81. public static function getCashByUserId($userId){
  82. $data = UserPerformance::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'USER_ID,CASH');
  83. if(!$data){
  84. $data = [
  85. 'USER_ID' => $userId,
  86. 'CASH' => 0,
  87. ];
  88. }
  89. return $data;
  90. }
  91. }