| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace addons\BossAchievement\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_boss_achievement_month}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property float|null $achievement 当月总业绩,单位:元
- * @property float $bonus 可得分红,单位:元
- * @property float $settlement_money 结算金额,单位:元
- * @property int $settlement_num 结算人数
- * @property float $standard_money 考核要求,单位:元
- * @property int $month 月份,如:202207
- * @property int $is_settlement 是否已结算[0=否,1=是]
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class BossAchievementMonth extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_achievement_month}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'settlement_num', 'month', 'is_settlement', 'status', 'created_at', 'updated_at'], 'integer'],
- [['achievement', 'bonus', 'settlement_money','standard_money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'achievement' => '当月总业绩,单位:元',
- 'bonus' => '可得分红,单位:元',
- 'settlement_money' => '结算金额,单位:元',
- 'settlement_num' => '结算人数',
- 'standard_money' => '考核要求,单位:元',
- 'month' => '月份,如:202207',
- 'is_settlement' => '是否已结算[0=否,1=是]',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 关联用户信息
- * @Author: lun
- * @DateTime: 2022/7/10 0010 17:46
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,avatar_url');
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/7/10 0010 16:24
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool
- */
- public static function setData($params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'month' => $params['month'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->user_id = $params['user_id'];
- $model->month = $params['month'];
- $model->loadDefaultValues();
- }
- if (!empty($params['goods_price'])) $model->achievement += $params['goods_price'];
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 批量插入数据
- * @Author: lun
- * @DateTime: 2022/7/10 0010 16:28
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $parent_ids
- * @param $params
- */
- public static function batchSetData($parent_ids, $params)
- {
- try {
- foreach ($parent_ids as $user_id) {
- $params['user_id'] = $user_id;
- $res = self::setData($params);
- if ($res === false) throw new Exception(self::getStaticError());
- }
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|