| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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_upgrade_count}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 服务商ID
- * @property int|null $direct_num 好友人数
- * @property float|null $achievement 服务商团队业绩,单位:元
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 修改时间
- */
- class ServeBonusUpgradeCount extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_servebonus_upgrade_count}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'direct_num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['achievement'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '服务商ID',
- 'direct_num' => '好友人数',
- 'achievement' => '服务商团队业绩,单位:元',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- /**
- * 保存业绩
- * @Author: lun
- * @DateTime: 2023/4/1 0001 15:34
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param $user_id
- * @param int $direct_num
- * @param int $achievement
- * @return bool
- */
- public static function setData($mall_id, $user_id, $direct_num = 0, $achievement = 0)
- {
- try {
- $model = self::findOne(['user_id' => $user_id, 'status' => StatusEnum::ENABLED]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $mall_id;
- $model->user_id = $user_id;
- $model->loadDefaultValues();
- }
- !empty($direct_num) && $model->direct_num += $direct_num;
- !empty($achievement) && $model->achievement += $achievement;
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|