UserWallet.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 UserWallet extends \common\components\ActiveRecord
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%USER_WALLET}}';
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['USER_ID'], 'required'],
  31. [['CASH'], 'number'],
  32. [['UPDATED_AT', 'CLEAR_BY_CLOSED_AT'], 'integer'],
  33. [['ID','USER_ID'], 'string', 'max' => 32],
  34. [['USER_ID'], 'unique'],
  35. ];
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'ID' => 'ID',
  44. 'USER_ID' => '用户id',
  45. 'CASH' => '现金',
  46. 'UPDATED_AT' => '修改时间',
  47. 'CLEAR_BY_CLOSED_AT' => '清空关停会员钱包时间',
  48. ];
  49. }
  50. /**
  51. * 操作日志记录条件
  52. * @return array
  53. */
  54. public function attrLabelsWithLogType(){
  55. return [
  56. 'USER_ID' => '用户id',
  57. 'CLEAR_BY_CLOSED_AT' => [
  58. 'label' => '清空关停会员钱包时间',
  59. 'type' => ValueTypeConfig::DATE_TIME_TYPE,
  60. ],
  61. ];
  62. }
  63. /**
  64. * 获取一名会员的余额
  65. * @param $userId
  66. * @return array|null
  67. */
  68. public static function getCashByUserId($userId){
  69. $data = UserWallet::findOneAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId], 'USER_ID,CASH');
  70. if(!$data){
  71. $data = [
  72. 'USER_ID' => $userId,
  73. 'CASH' => 0,
  74. ];
  75. }
  76. return $data;
  77. }
  78. }