| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- /**
- * Class SaasUser
- * @package app\models
- * @property integer $id
- * @property integer $mobile
- * @property integer $is_delete
- * @property string $price
- * @property integer $parent_id
- * @property integer $platform_open_id
- * @property integer $platform_open_id_merchant
- * @property integer $share_profit
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $store_id
- * @property string $name
- * @property string $avatar
- * @property integer $gender
- * @property string $access_token
- * @property integer $integral
- * @property integer $total_integral
- * @property string $bytedance_open_id
- * @property string $withdraw_method
- * @property integer $is_salesman
- * @property string $ali_user_id
- * @property string $league_price
- * @property string $ali_openId
- * @property integer $purchase_money
- * @property integer $is_cloud_inventory
- * @property integer $cloud_inventory_level
- * @property integer $level_name
- * @property integer $cloud_inventory_balance
- * @property integer $cloud_inventory_freeze_balance
- * @property integer $cloud_inventory_total_balance
- * @property integer $uid
- *
- */
- class SaasUserNew extends \yii\db\ActiveRecord
- {
- /**
- * 是否删除
- */
- const DELETE_STATUS_TRUE = 1;
- /**
- * 是否删除
- */
- const DELETE_STATUS_FALSE = 0;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%saas_user_new}}';
- }
- public function behaviors()
- {
- return [
- [
- // 自动更新创建和更新时间
- 'class' => TimestampBehavior::class,
- 'value' => time()
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- ['share_profit', 'number'],
- [['platform_open_id', 'platform_open_id_merchant', 'access_token', 'name', 'avatar', 'bytedance_open_id', 'withdraw_method', 'ali_user_id', 'mobile', 'ali_openId'], 'string'],
- [['platform_open_id', 'platform_open_id_merchant', 'access_token', 'name', 'avatar'], 'trim'],
- [['id', 'parent_id', 'is_delete', 'created_at', 'updated_at', 'store_id', 'gender', 'is_salesman'], 'integer'],
- [['integral', 'total_integral'], 'number'],
- [['created_at', 'update_at'], 'safe']
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mobile' => '手机号',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'parent_id' => '父ID',
- 'is_delete' => '是否已删除',
- 'store_id' => '商城ID',
- 'platform_open_id' => '平台小程序openid',
- 'platform_open_id_merchant' => '批发端小程序openid',
- 'share_profit' => '联盟佣金',
- 'name' => '昵称',
- 'avatar' => '头像',
- 'gender' => '性别',
- 'access_token' => 'token',
- 'withdraw_method' => '提现方式',
- 'league_price' => '联盟券',
- 'ali_user_id' => '支付宝user_id',
- 'integral' => '积分',
- 'total_integral' => '累计积分',
- 'ali_openId' => '支付宝新openid'
- ];
- }
- /**
- * {@inheritdoc}
- */
- public static function findIdentityByAccessToken($token)
- {
- return static::findOne(['access_token' => $token]);
- }
- /**
- * @param $user_id
- * @return int
- */
- public static function findSaasIdByUserId($user_id)
- {
- $user = User::find()->alias('u')
- ->leftJoin(['su' => SaasUserNew::tableName()], 'su.mobile=u.binding')
- ->where([
- 'u.id' => $user_id,
- ])
- ->select('su.id as saas_user_id, u.id as user_id')
- ->asArray()
- ->one();
- return $user ? $user['saas_user_id'] : 0;
- }
- /**
- * @param $store_id
- * @param $user_id
- * @return int
- */
- public static function findUserIdByStoreIdAndSaasId($store_id, $saas_user_id)
- {
- $user = self::find()->alias('su')
- ->leftJoin(['u' => User::tableName()], 'su.mobile=u.binding')
- ->where([
- 'su.id' => $saas_user_id,
- 'u.store_id' => $store_id,
- ])
- ->select('su.id as saas_user_id, u.id as user_id')
- ->asArray()
- ->one();
- return $user ? $user['user_id'] : 0;
- }
- /**
- * @param $user_id
- * @return int
- */
- public static function findFirstStoreIdByUserId($user_id)
- {
- $user = User::find()->alias('u')
- ->leftJoin(['su' => SaasUserNew::tableName()], 'su.mobile=u.binding')
- ->where([
- 'u.id' => $user_id,
- ])
- ->select('su.id as saas_user_id, u.id as user_id, su.store_id')
- ->asArray()
- ->one();
- return $user ? $user['store_id'] : 0;
- }
- /**
- * @param $user_id
- * @return int
- */
- public static function findSaasParentIdByUserId($user_id)
- {
- $user = User::find()->alias('u')
- ->leftJoin(['su' => SaasUserNew::tableName()], 'su.mobile=u.binding')
- ->where([
- 'u.id' => $user_id,
- ])
- ->select('su.parent_id as saas_parent_user_id, u.id as user_id')
- ->asArray()
- ->one();
- return $user ? $user['saas_parent_user_id'] : 0;
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- if (empty($this->uid)){
- $saasUser = SaasUserNew::find()->orderBy(['id' => SORT_DESC])->one();
- if (!empty($saasUser['uid'])){
- $this->uid = intval($saasUser['uid'] + rand(10,30));
- }else{
- $this->uid = intval($saasUser['id'] + rand(10,30));
- }
- }
- return true;
- }
- return false;
- }
- public static function setUid()
- {
- $saasUser = SaasUserNew::find()->where(['is', 'uid', null])->all();
- if (!empty($saasUser)){
- foreach ($saasUser as $item){
- $maxSaasUser = SaasUserNew::find()->orderBy(['uid' => SORT_DESC])->one();
- $uid = intval($maxSaasUser['uid'] + rand(10,30));
- SaasUserNew::updateAll(['uid'=> $uid],['id'=> $item['id']]);
- }
- }
- return true;
- }
- }
|