HappinessPvWalletLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_happiness_pv_wallet_log}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id
  11. * @property string $wallet_type
  12. * @property string $change_type 操作类型:add-增加,sub-减少
  13. * @property float $change_num 操作数量
  14. * @property float $after_num 变动后数量
  15. * @property string $desc 变动说明
  16. * @property string $source_table 来源表
  17. * @property int $source_table_id 操作来源业务id
  18. * @property string $from_type 来源类型
  19. * @property int $status 状态,-1:失效,1:正常,2:冻结
  20. * @property string $order_no 订单号
  21. * @property int $created_at 添加时间戳
  22. * @property int $updated_at 更新时间戳
  23. * @property string $addon_name 来源插件名称
  24. */
  25. class HappinessPvWalletLog extends \common\models\base\BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_happiness_pv_wallet_log}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['change_num', 'mall_id', 'user_id'], 'required'],
  41. [['mall_id', 'user_id', 'source_table_id', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['change_num', 'after_num'], 'number'],
  43. [['wallet_type'], 'string', 'max' => 20],
  44. [['change_type'], 'string', 'max' => 12],
  45. [['desc', 'source_table', 'from_type'], 'string', 'max' => 255],
  46. [['order_no'], 'string', 'max' => 100],
  47. [['addon_name'], 'string', 'max' => 64],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels()
  54. {
  55. return [
  56. 'id' => 'ID',
  57. 'mall_id' => 'Mall ID',
  58. 'user_id' => 'User ID',
  59. 'wallet_type' => 'Wallet Type',
  60. 'change_type' => 'Change Type',
  61. 'change_num' => 'Change Num',
  62. 'after_num' => 'After Num',
  63. 'desc' => 'Desc',
  64. 'source_table' => 'Source Table',
  65. 'source_table_id' => 'Source Table ID',
  66. 'from_type' => 'From Type',
  67. 'status' => 'Status',
  68. 'order_no' => 'Order No',
  69. 'created_at' => 'Created At',
  70. 'updated_at' => 'Updated At',
  71. 'addon_name' => 'Addon Name',
  72. ];
  73. }
  74. public static function setData($params)
  75. {
  76. try {
  77. if (isset($params['id']) && !empty($params['id'])) {
  78. $model = self::findOne(['id' => $params['id']]);
  79. if (!$model) {
  80. throw new \Exception( self::tableName() . '记录不存在');
  81. }
  82. } else {
  83. $model = new self();
  84. $model->loadDefaultValues();
  85. }
  86. if (!$model->load($params, '') || !$model->save()) {
  87. throw new \Exception($model->getErrorMessage());
  88. }
  89. return $model;
  90. } catch (\Exception $e) {
  91. self::$static_error = $e->getMessage();
  92. return false;
  93. }
  94. }
  95. public function getUser()
  96. {
  97. return $this->hasOne(User::class, ['id' => 'user_id']);
  98. }
  99. }