ServeBonusPeriod.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace addons\ServeBonus\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_servebonus_period}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $period_num 第N期
  12. * @property float $amounts 出单奖励奖金池,单位:元
  13. * @property int $amounts_num 出单奖励奖金人数
  14. * @property float $extra_amounts 加权分红奖金池,单位:元
  15. * @property int $total_amounts_num 总分红人数
  16. * @property int $compute_period 结算周期:1天,2周,3月
  17. * @property int $start_time 结算开始日期
  18. * @property int $end_time 结算结束日期
  19. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $created_at
  21. * @property int $updated_at
  22. */
  23. class ServeBonusPeriod extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_servebonus_period}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'period_num', 'amounts_num', 'total_amounts_num', 'compute_period', 'start_time', 'end_time', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['amounts', 'extra_amounts','achievement_commission'], 'number'],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => '商城ID',
  50. 'period_num' => '第N期',
  51. 'amounts' => '出单奖励奖金池,单位:元',
  52. 'amounts_num' => '出单奖励奖金人数',
  53. 'extra_amounts' => '加权分红奖金池,单位:元',
  54. 'total_amounts_num' => '总分红人数',
  55. 'compute_period' => '结算周期:1天,2周,3月',
  56. 'start_time' => '结算开始日期',
  57. 'end_time' => '结算结束日期',
  58. 'status' => '状态[-1:删除;0:禁用;1启用]',
  59. 'created_at' => 'Created At',
  60. 'updated_at' => 'Updated At',
  61. ];
  62. }
  63. /**
  64. * 保存数据
  65. * @Author: lun
  66. * @DateTime: 2022/1/26 0026 10:30
  67. * @Copyright: copyright (c) 2021 广东七件事集团
  68. * @param $mall_id
  69. * @param null $params
  70. * @return bool|int
  71. */
  72. public static function setData($mall_id, $params = null)
  73. {
  74. try {
  75. if (empty($params)) {
  76. $model = new self();
  77. $model->loadDefaultValues();
  78. $model->mall_id = $mall_id;
  79. $model->period_num = self::getPrevPeriodNum($mall_id);
  80. } else {
  81. $model = self::findOne(['id' => $params['id']]);
  82. }
  83. if ($params && !$model->load($params, '')) throw new Exception($model->getErrorMessage());
  84. if (!$model->save()) throw new Exception($model->getErrorMessage());
  85. return $model->id;
  86. } catch (\Exception $e) {
  87. return false;
  88. }
  89. }
  90. /**
  91. * 获取上一期期数
  92. * @Author: lun
  93. * @DateTime: 2022/1/26 0026 10:28
  94. * @Copyright: copyright (c) 2021 广东七件事集团
  95. * @param $mall_id
  96. * @return false|int|string
  97. */
  98. public static function getPrevPeriodNum($mall_id)
  99. {
  100. $period_num = self::find()->select("period_num")->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])->orderBy('period_num desc')->asArray()->scalar();
  101. $num = empty($period_num) ? 1 : $period_num + 1;
  102. return $num;
  103. }
  104. }