UserShareMoney.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use app\models\Option;
  10. use app\constants\OptionSetting;
  11. /**
  12. * This is the model class for table "{{%user_share_money}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $order_id
  17. * @property integer $user_id
  18. * @property integer $type
  19. * @property integer $source
  20. * @property string $money
  21. * @property integer $is_delete
  22. * @property integer $created_at
  23. * @property integer $order_type
  24. * @property string $version
  25. * @property string $desc
  26. */
  27. class UserShareMoney extends \yii\db\ActiveRecord
  28. {
  29. const LEVEL_ORDER_TYPE = 4;
  30. const BONUS_FIRST_SHARE = 1;
  31. const BONUS_SECOND_SHARE = 2;
  32. const BONUS_THIRD_SHARE = 3;
  33. const BONUS_LAYER = 11;
  34. const BONUS_AREA = 12;
  35. const BONUS_SHARE_HOLDER_INVITE = 13;
  36. const BONUS_SHARE_HOLDER_TEAM = 14;
  37. const BONUS_SHARE_HOLDER_TEAM_EQUAL = 15;
  38. const CASE = 20;
  39. const SOURCE_NAME = [
  40. 0 => '--',
  41. self::BONUS_FIRST_SHARE => '一级分销',
  42. self::BONUS_SECOND_SHARE => '二级分销',
  43. self::BONUS_THIRD_SHARE => '三级分销',
  44. 4 => '自购返利',
  45. 5 => '订单佣金',
  46. 6 => '临时关系',
  47. 7 => '推广佣金',
  48. 8 => '一级返现奖励',
  49. 9 => '二级返现奖励',
  50. 10 => '后台修改',
  51. self::BONUS_LAYER => '见点层级奖励',
  52. self::BONUS_AREA => '区域分红',
  53. self::BONUS_SHARE_HOLDER_INVITE => '股东直推',
  54. self::BONUS_SHARE_HOLDER_TEAM => '团队奖励',
  55. self::BONUS_SHARE_HOLDER_TEAM_EQUAL => '团队平级奖励',
  56. self::CASE => '佣金提现',
  57. ];
  58. /**
  59. * @inheritdoc
  60. */
  61. public static function tableName()
  62. {
  63. return '{{%user_share_money}}';
  64. }
  65. /**
  66. * @inheritdoc
  67. */
  68. public function rules()
  69. {
  70. return [
  71. [['store_id', 'order_id', 'user_id', 'type', 'source', 'is_delete', 'created_at', 'order_type'], 'integer'],
  72. [['money'], 'number'],
  73. [['version', 'desc'], 'string', 'max' => 255],
  74. ];
  75. }
  76. /**
  77. * @inheritdoc
  78. */
  79. public function attributeLabels()
  80. {
  81. return [
  82. 'id' => 'ID',
  83. 'store_id' => 'Store ID',
  84. 'order_id' => '订单ID',
  85. 'user_id' => '用户ID',
  86. 'type' => '类型 0--佣金 1--提现 2--股东 3--见点',
  87. 'source' => '佣金来源 1--一级分销 2--二级分销 3--三级分销 4--自购返利 5--订单佣金 6--临时佣金',
  88. 'money' => '金额',
  89. 'is_delete' => 'Is Delete',
  90. 'created_at' => 'Addtime',
  91. 'order_type' => '订单类型 0--商城订单 1--秒杀订单 2--拼团订单 3--预约订单 4--会员订单',
  92. 'version' => '版本',
  93. ];
  94. }
  95. public function afterSave($insert, $changedAttributes)
  96. {
  97. parent::afterSave($insert, $changedAttributes);
  98. if (!cache_lock(['ShareLevelJob', $this->store_id, $this->user_id], 30)) {
  99. \queue_push(new \app\jobs\ShareLevelJob(['store_id' => $this->store_id, 'user_id' => $this->user_id]), 30, 1);
  100. }
  101. }
  102. public static function set($money, $user_id, $order_id, $type, $source = 1, $store_id = 0, $order_type = 0, $desc = '')
  103. {
  104. $model = new UserShareMoney();
  105. $model->store_id = $store_id;
  106. $model->order_id = $order_id;
  107. $model->user_id = $user_id;
  108. $model->type = $type;
  109. $model->source = $source;
  110. $model->money = $money;
  111. $model->is_delete = 0;
  112. $model->created_at = time();
  113. $model->order_type = $order_type;
  114. $model->version = cyy_version();
  115. $model->desc = $desc;
  116. return $model->save();
  117. }
  118. public function getStore(){
  119. return $this->hasOne(Store::className(), ['id'=>'store_id']);
  120. }
  121. public function getOrder(){
  122. return $this->hasOne(Order::className(), ['id'=>'order_id']);
  123. }
  124. public static function getSourceName($source, $store_id)
  125. {
  126. $name = self::SOURCE_NAME[$source] ?? '--';
  127. if (in_array($source, [1, 2, 3])) {
  128. $option = Option::get('share_money_setting', $store_id, OptionSetting::SHARE_GROUP_NAME);
  129. if ($option) {
  130. $data = json_decode($option['value'], true);
  131. if ($source == 1) {
  132. $name = $data['level_one']['text'] ?? $name;
  133. }
  134. if ($source == 2) {
  135. $name = $data['level_two']['text'] ?? $name;
  136. }
  137. if ($source == 3) {
  138. $name = $data['level_three']['text'] ?? $name;
  139. }
  140. }
  141. }
  142. return $name;
  143. }
  144. }