| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace addons\Distribution\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_distribution_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 DistributionUpgradeCount extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_distribution_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' => '修改时间',
- ];
- }
- 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;
- }
- }
- }
|