| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace addons\ServeBonus\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_servebonus_period}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $period_num 第N期
- * @property float $amounts 出单奖励奖金池,单位:元
- * @property int $amounts_num 出单奖励奖金人数
- * @property float $extra_amounts 加权分红奖金池,单位:元
- * @property int $total_amounts_num 总分红人数
- * @property int $compute_period 结算周期:1天,2周,3月
- * @property int $start_time 结算开始日期
- * @property int $end_time 结算结束日期
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class ServeBonusPeriod extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_servebonus_period}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'period_num', 'amounts_num', 'total_amounts_num', 'compute_period', 'start_time', 'end_time', 'status', 'created_at', 'updated_at'], 'integer'],
- [['amounts', 'extra_amounts','achievement_commission'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'period_num' => '第N期',
- 'amounts' => '出单奖励奖金池,单位:元',
- 'amounts_num' => '出单奖励奖金人数',
- 'extra_amounts' => '加权分红奖金池,单位:元',
- 'total_amounts_num' => '总分红人数',
- 'compute_period' => '结算周期:1天,2周,3月',
- 'start_time' => '结算开始日期',
- 'end_time' => '结算结束日期',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/1/26 0026 10:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param null $params
- * @return bool|int
- */
- public static function setData($mall_id, $params = null)
- {
- try {
- if (empty($params)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->period_num = self::getPrevPeriodNum($mall_id);
- } else {
- $model = self::findOne(['id' => $params['id']]);
- }
- if ($params && !$model->load($params, '')) throw new Exception($model->getErrorMessage());
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return $model->id;
- } catch (\Exception $e) {
- return false;
- }
- }
- /**
- * 获取上一期期数
- * @Author: lun
- * @DateTime: 2022/1/26 0026 10:28
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @return false|int|string
- */
- public static function getPrevPeriodNum($mall_id)
- {
- $period_num = self::find()->select("period_num")->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])->orderBy('period_num desc')->asArray()->scalar();
- $num = empty($period_num) ? 1 : $period_num + 1;
- return $num;
- }
- }
|