HigoWalletFrozenLog.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace addons\HiGo\common\models;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use common\models\user\User;
  5. use common\enums\StatusEnum;
  6. use Yii;
  7. use Exception;
  8. /**
  9. * 嗨呗/嗨值钱包等待处理记录表【订单在走模式发放奖励时:先写入该表,后面结算再写入wallet_log 表】
  10. * This is the model class for table "{{%qimall_addons_higo_wallet_frozen_log}}".
  11. *
  12. * @property int $id
  13. * @property int $mall_id
  14. * @property int $user_id
  15. * @property string $wallet_type 类型[hi_bei:嗨呗,hi_value:嗨值]
  16. * @property string $change_type 操作类型:add-增加,sub-减少
  17. * @property float $change_num 操作数量
  18. * @property float $after_num 变动后数量
  19. * @property string $desc 变动说明
  20. * @property string $source_table 来源表
  21. * @property int $source_table_id 操作来源业务id
  22. * @property string $from_type 来源类型
  23. * @property int $status 状态:0:未结算,1:已结算,-1:无效
  24. * @property int $created_at 添加时间戳
  25. * @property int $updated_at 更新时间戳
  26. * @property string $addon_name 来源插件:默认HiGo
  27. * @property int $is_send
  28. * @property string $setting
  29. */
  30. class HigoWalletFrozenLog extends \common\models\base\BaseActiveRecord
  31. {
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public static function tableName()
  36. {
  37. return '{{%addons_higo_wallet_frozen_log}}';
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function rules()
  43. {
  44. return [
  45. [['mall_id', 'user_id', 'source_table_id', 'status', 'created_at', 'updated_at','is_send'], 'integer'],
  46. [['change_num', 'after_num'], 'number'],
  47. [['wallet_type'], 'string', 'max' => 20],
  48. [['change_type'], 'string', 'max' => 12],
  49. [['addon_name'], 'string', 'max' => 64],
  50. [['desc', 'source_table', 'from_type'], 'string', 'max' => 255],
  51. [['setting'],'string']
  52. ];
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'mall_id' => 'Mall ID',
  62. 'user_id' => 'User ID',
  63. 'wallet_type' => 'Wallet Type',
  64. 'change_type' => 'Change Type',
  65. 'change_num' => 'Change Num',
  66. 'after_num' => 'After Num',
  67. 'desc' => 'Desc',
  68. 'source_table' => 'Source Table',
  69. 'source_table_id' => 'Source Table ID',
  70. 'from_type' => 'From Type',
  71. 'status' => 'Status',
  72. 'created_at' => 'Created At',
  73. 'updated_at' => 'Updated At',
  74. ];
  75. }
  76. public function getUser()
  77. {
  78. return $this->hasOne(User::class, ['id' => 'user_id']);
  79. }
  80. /**
  81. * 保存数据
  82. * @param array $params
  83. * @return bool
  84. */
  85. public static function setData(array $params)
  86. {
  87. try {
  88. $model = new self();
  89. $model->loadDefaultValues();
  90. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  91. return $model;
  92. } catch (Exception $e) {
  93. self::$static_error = $e->getMessage();
  94. return false;
  95. }
  96. }
  97. /**
  98. * 检测奖励是否发放过
  99. * @param $mall_id
  100. * @param $user_id
  101. * @param $source_table
  102. * @param $source_id
  103. * @param $from_type
  104. * @param $wallet_type
  105. * @param $addons_name
  106. * @return HigoWalletLog|null
  107. */
  108. public static function checkSend($mall_id,$user_id,$source_table,$source_id,$from_type,$wallet_type,$addons_name = HiGoEnum::ADDONS_NAME)
  109. {
  110. $log = self::findOne(['mall_id' => $mall_id,'user_id' => $user_id,'wallet_type' => $wallet_type,
  111. 'change_type' => 'add','source_table' => $source_table,'source_table_id' => $source_id,'from_type' => $from_type,
  112. 'status' => StatusEnum::ENABLED,
  113. 'addon_name' => $addons_name
  114. ]);
  115. return $log;
  116. }
  117. }