ShareLevel.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%share_level}}".
  13. *
  14. * @property integer $id
  15. * @property string $name
  16. * @property integer $level
  17. * @property integer $is_auto_upgrade
  18. * @property integer $type
  19. * @property string $value
  20. * @property string $condition
  21. * @property integer $profit_type
  22. * @property string $first_profit
  23. * @property string $second_profit
  24. * @property string $third_profit
  25. * @property string $order_layer
  26. * @property string $point_reward
  27. * @property integer $status
  28. * @property string $desc
  29. * @property integer $store_id
  30. * @property integer $is_delete
  31. * @property integer $created_at
  32. * @property integer $updated_at
  33. */
  34. class ShareLevel extends \yii\db\ActiveRecord
  35. {
  36. /**
  37. * @inheritdoc
  38. */
  39. public static function tableName()
  40. {
  41. return '{{%share_level}}';
  42. }
  43. /**
  44. * 是否自动升级
  45. */
  46. CONST AUTO_UPGRADE = 1; //自动升级
  47. CONST NO_AUTO_UPGRADE = 0; //不自动升级
  48. public static $valid_auto_upgrade_arr = [
  49. self::AUTO_UPGRADE,
  50. self::NO_AUTO_UPGRADE
  51. ];
  52. /**
  53. * 删除状态
  54. */
  55. CONST SHARE_IS_DELETE = 1; //已删除
  56. CONST SHARE_NOT_DELETE = 0; //未删除
  57. /**
  58. * 升级条件
  59. */
  60. CONST TYPE_MEMBER = 0; //下级人数
  61. CONST TYPE_COMMISSION = 1; //累计佣金
  62. CONST TYPE_SEND_COMMISSION = 2; //已提现佣金
  63. CONST TYPE_AMOUNT = 3; //累计消费金额
  64. CONST TYPE_COIN = 4; //累计贡献积分
  65. CONST TYPE_SHARE_BASE = 5; //累计固定基数
  66. CONST TYPE_MEMBER_PERFORMANCE = 6; //累计直推用户贡献积分业绩
  67. public static $valid_type_arr = [
  68. self::TYPE_MEMBER,
  69. self::TYPE_COMMISSION,
  70. self::TYPE_SEND_COMMISSION,
  71. self::TYPE_AMOUNT,
  72. self::TYPE_COIN,
  73. self::TYPE_SHARE_BASE,
  74. self::TYPE_MEMBER_PERFORMANCE
  75. ];
  76. /**
  77. * 启用状态
  78. */
  79. CONST STATUS_ON = 1; //启用
  80. CONST STATUS_OFF = 0; //禁用
  81. public static $valid_status_arr = [
  82. self::STATUS_ON,
  83. self::STATUS_OFF
  84. ];
  85. /**
  86. * 分销佣金类型
  87. */
  88. CONST PROFIT_TYPE_PROGRESS = 0; //百分比
  89. CONST PROFIT_TYPE_MONEY = 1; //固定金额
  90. public static $valid_profit_arr = [
  91. self::PROFIT_TYPE_PROGRESS,
  92. self::PROFIT_TYPE_MONEY
  93. ];
  94. /**
  95. * @inheritdoc
  96. */
  97. public function rules()
  98. {
  99. return [
  100. [['id', 'level', 'is_auto_upgrade', 'type', 'profit_type', 'status', 'store_id', 'is_delete', 'order_layer'], 'integer'],
  101. [['value', 'first_profit', 'second_profit', 'third_profit', 'point_reward'], 'number'],
  102. [['name', 'desc', 'condition'], 'string'],
  103. [['created_at', 'updated_at'], 'safe']
  104. ];
  105. }
  106. public function behaviors()
  107. {
  108. return [
  109. [
  110. 'class' => TimestampBehavior::class,
  111. 'value' => time()
  112. ]
  113. ];
  114. }
  115. public function beforeSave($insert)
  116. {
  117. if (parent::beforeSave($insert)) {
  118. $is = self::findOne(['level' => $this->level, 'store_id' => $this->store_id, 'is_delete' => self::SHARE_NOT_DELETE]);
  119. if ($is) {
  120. $open = false;
  121. if ($this->id && $this->id !== $is->id) {
  122. $open = true;
  123. }
  124. if (!$this->id) {
  125. $open = true;
  126. }
  127. if ($open) {
  128. $this->addError('level', '操作失败,当前等级不可用');
  129. return false;
  130. }
  131. }
  132. // if ($this->type && !in_array($this->type, self::$valid_type_arr)) {
  133. // $this->addError('type', '操作失败,升级条件类型信息错误');
  134. // return false;
  135. // }
  136. if ($this->status && !in_array($this->status, self::$valid_status_arr)) {
  137. $this->addError('status', '操作失败,启用状态错误');
  138. return false;
  139. }
  140. if ($this->profit_type && !in_array($this->profit_type, self::$valid_profit_arr)) {
  141. $this->addError('profit_type', '操作失败,分销佣金类型错误');
  142. return false;
  143. }
  144. if ($this->is_auto_upgrade && !in_array($this->is_auto_upgrade, self::$valid_auto_upgrade_arr)) {
  145. $this->addError('is_auto_upgrade', '操作失败,是否自动升级类型错误');
  146. return false;
  147. }
  148. }
  149. return true;
  150. }
  151. /**
  152. * @inheritdoc
  153. */
  154. public function attributeLabels()
  155. {
  156. return [
  157. "id" => "ID",
  158. "name" => "名称",
  159. "level" => "等级",
  160. "is_auto_upgrade" => "是否自动升级",
  161. "type" => "升级条件类型",
  162. "value" => "升级条件值",
  163. "condition" => "升级条件值",
  164. "profit_type" => "分销佣金类型",
  165. "first_profit" => "一级佣金",
  166. "second_profit" => "二级佣金",
  167. "third_profit" => "三级佣金",
  168. "status" => "启用状态",
  169. "desc" => "等级说明",
  170. "store_id" => "Store Id",
  171. "is_delete" => "is Delete",
  172. "created_at" => "创建时间",
  173. "updated_at" => "修改时间",
  174. ];
  175. }
  176. }