HigoWalletFreezeLog.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace addons\HiGo\common\models;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\common\CapitalLog;
  6. use Yii;
  7. use Exception;
  8. /**
  9. * This is the model class for table "{{%addons_higo_wallet_freeze_log}}".
  10. * 嗨呗/嗨值钱包冻结记录表,对应wallet表中freeze字段
  11. * @property int $id
  12. * @property int $mall_id
  13. * @property int $user_id
  14. * @property string $wallet_type 类型[hi_bei:嗨呗,hi_value:嗨值]
  15. * @property string $change_type 操作类型:add-增加,sub-减少
  16. * @property float $change_num 操作数量
  17. * @property float $after_num 变动后数量
  18. * @property string $desc 变动说明
  19. * @property string $source_table 来源表
  20. * @property int $source_table_id 操作来源业务id
  21. * @property string $from_type 来源类型
  22. * @property int $status 状态:0:未结算,1:已结算,-1:无效
  23. * @property int $created_at 添加时间戳
  24. * @property int $updated_at 更新时间戳
  25. * @property string $addon_name 来源插件名称
  26. */
  27. class HigoWalletFreezeLog extends \common\models\base\BaseActiveRecord
  28. {
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%addons_higo_wallet_freeze_log}}';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['mall_id', 'user_id', 'source_table_id', 'status', 'created_at', 'updated_at'], 'integer'],
  43. [['change_num', 'after_num'], 'number'],
  44. [['wallet_type'], 'string', 'max' => 20],
  45. [['change_type'], 'string', 'max' => 12],
  46. [['desc', 'source_table', 'from_type'], 'string', 'max' => 255],
  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. 'created_at' => 'Created At',
  69. 'updated_at' => 'Updated At',
  70. 'addon_name' => 'Addon Name',
  71. ];
  72. }
  73. /**
  74. * 检测奖励是否发放过
  75. * @param $mall_id
  76. * @param $user_id
  77. * @param $source_table
  78. * @param $source_id
  79. * @param $from_type
  80. * @param $wallet_type
  81. * @param $addons_name
  82. * @return HigoWalletLog|null
  83. */
  84. public static function checkSend($mall_id, $user_id, $source_table, $source_id, $from_type, $wallet_type,$addons_name = HiGoEnum::ADDONS_NAME)
  85. {
  86. return self::findOne(['mall_id' => $mall_id,'user_id' => $user_id,'wallet_type' => $wallet_type,
  87. 'change_type' => CapitalLog::CHANGE_TYPE_ADD,'source_table' => $source_table,'source_table_id' => $source_id,
  88. 'from_type' => $from_type,'status' => StatusEnum::ENABLED,
  89. 'addon_name' => $addons_name
  90. ]);
  91. }
  92. /**
  93. * 保存数据
  94. * @param array $params
  95. * @return boolean|self
  96. */
  97. public static function setData(array $params)
  98. {
  99. try {
  100. $model = new self();
  101. $model->loadDefaultValues();
  102. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  103. return $model;
  104. } catch (Exception $e) {
  105. self::$static_error = $e->getMessage();
  106. return false;
  107. }
  108. }
  109. }