HigoMerchantRewardLog.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace addons\HiGo\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_higo_merchant_reward_log}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id
  11. * @property string $source
  12. * @property int $source_table_id
  13. * @property float $profit_price
  14. * @property float $profit 商家让利嗨呗数量
  15. * @property float $destroy 销毁嗨呗数量
  16. * @property int $platform_account_uid
  17. * @property float $platform_account_reward 平台指定会员嗨呗数量
  18. * @property float $remaining_rewards 剩余模式嗨呗数量
  19. * @property int $status 状态,-1:失效,1:正常,2:冻结
  20. * @property int $created_at 添加时间戳
  21. * @property int $updated_at 更新时间戳
  22. * @property int $handle_status 记录状态:0-等待处理,1-已处理
  23. * @property string $mch_name 商家名称
  24. * @property int $mode_status 是否分佣:0-否,1-冻结,2-完成
  25. * @property float $consumer_hi_value 消费者奖励嗨值基数
  26. * @property float $merchant_hi_value 商家奖励嗨值基数
  27. * @property float $send_profit 已发放的嗨呗奖励
  28. */
  29. class HigoMerchantRewardLog extends \common\models\base\BaseActiveRecord
  30. {
  31. const MODE_STATUS_FAIL = -1;
  32. const MODE_STATUS_WAIT = 0;
  33. const MODE_STATUS_FROZEN = 1;
  34. const MODE_STATUS_FINISH = 2;
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public static function tableName()
  39. {
  40. return '{{%addons_higo_merchant_reward_log}}';
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function rules()
  46. {
  47. return [
  48. [['mall_id', 'source_table_id', 'user_id', 'status', 'created_at', 'updated_at','platform_account_uid','handle_status','mode_status'], 'integer'],
  49. [['profit', 'destroy', 'platform_account_reward', 'remaining_rewards','profit_price','consumer_hi_value','merchant_hi_value','send_profit'], 'number'],
  50. [['source_table','mch_name'],'string']
  51. ];
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function attributeLabels()
  57. {
  58. return [
  59. 'id' => 'ID',
  60. 'mall_id' => 'Mall ID',
  61. 'user_id' => 'User ID',
  62. 'order_id' => 'Order ID',
  63. 'profit' => 'Profit',
  64. 'destroy' => 'Destroy',
  65. 'platform_account' => 'Platform Account',
  66. 'remaining_rewards' => 'Remaining Rewards',
  67. 'status' => 'Status',
  68. 'created_at' => 'Created At',
  69. 'updated_at' => 'Updated At',
  70. ];
  71. }
  72. /**
  73. * 保存数据
  74. * @Author: zmz
  75. * @DateTime: 2022/11/19 09:13
  76. * @Copyright: copyright (c) 2022 广东七件事集团
  77. * @param array $params
  78. * @return bool|self
  79. */
  80. public static function setData(array $params){
  81. try{
  82. if(isset($params['id']) && $params['id']) {
  83. $model = self::findOne(['id' => $params['id']]);
  84. if (empty($model)) throw new \Exception('服务不存在或已删除');
  85. }else{
  86. $model = new self();
  87. $model->loadDefaultValues();
  88. }
  89. if(!$model->load($params,'') || !$model->save()){
  90. throw new \Exception($model->getErrorMessage());
  91. }
  92. return $model;
  93. }catch(\Exception $e){
  94. self::setStaticError($e->getMessage());
  95. return false;
  96. }
  97. }
  98. /**
  99. * 检测奖励是否发放过
  100. * @param $mall_id
  101. * @param $source_table
  102. * @param $source_id
  103. * @return HigoMerchantRewardLog|null
  104. */
  105. public static function checkReward($mall_id,$source_table,$source_id)
  106. {
  107. $log = self::findOne(['mall_id' => $mall_id,'source_table' => $source_table,'source_table_id' => $source_id,'status' => StatusEnum::ENABLED]);
  108. return $log;
  109. }
  110. }