| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace addons\Distribution\common\models;
- use addons\ServeBonus\common\models\ServeBonusUpgradeCount;
- 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_direct".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 用户ID
- * @property int|null $recommend_uid 被推荐的用户
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 修改时间
- */
- class DistributionUpgradeDirect extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_distribution_upgrade_direct}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'recommend_uid', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'recommend_uid' => '被推荐的用户',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public static function setData($params)
- {
- try {
- $model = self::findOne(['user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED]);
- if ($model) return true;
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->user_id = $params['parent_id'];
- $model->recommend_uid = $params['user_id'];
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- // 增加直推用户数量
- $res = DistributionUpgradeCount::setData($model->mall_id, $model->user_id, 1);
- if ($res == false) throw new \Exception(DistributionUpgradeCount::getStaticError());
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|