get('p_sources'); } public static function tableName() { return '{{%coin_issue_coin}}'; } public function rules() { return [ [['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge'], 'required'], [['total', 'category', 'type', 'platform_id', 'chain_id'], 'integer'], [['introduction', 'charge_unit'], 'string', 'length' => [1, 20]], ['symbol', 'string', 'length' => [6, 128]], ['name', 'string', 'length' => [1, 20]], ['nickname', 'string', 'length' => [0, 10]], [['token_type', 'nickname'], 'safe'], #['status', 'in', 'range' => [1, 2, 0]], ['name', 'verfiyName'], ['symbol', 'verfiySymbol'], ['total', 'verfiyAmount'] ]; } public function scenarios() { $scenarios = [ self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit', 'charge', 'token_type', 'nickname'], self:: SCENARIOS_CREATE_MALL => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'token_type', 'nickname'], self:: SCENARIOS_UPDATE => ['status'], self:: SCENARIOS_CANCEL => ['status'], ]; return array_merge(parent:: scenarios(), $scenarios); } public function verfiyName($attribute, $params) { //增发 if (CoinIssueCoin::TYPE_YES == $this->type) { $model = CoinIssueCoin::find()->where(['name' => $this->name, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one(); if (false == $model) { $this->addError($attribute, '该Token币种尚未发行'); return false; } if (0 == $model->category) { $this->addError($attribute, '该Token币种不可增发'); return false; } } //非增发 if (CoinIssueCoin::TYPE_NO == $this->type) { $model = CoinIssueCoin::find() ->where(['name' => $this->name, 'platform_id' => $this->platform_id]) ->andWhere(['<>', 'status', CoinIssueCoin::STATUS_FAILED]) ->orderBy('id desc')->one(); if ($model) { $this->addError($attribute, 'Token名称已存在'); return false; } } } public function verfiySymbol($attribute, $params) { if (!preg_match('/^[a-zA-Z0-9]+$/u', $this->symbol)) { $this->addError($attribute, 'Token简称必须包含字母和数字'); return false; } if (CoinIssueCoin::TYPE_YES == $this->type) { $model = CoinIssueCoin::find()->where(['symbol' => $this->symbol, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one(); if (false == $model) { $this->addError($attribute, '该Token币种尚未发行'); return false; } if (0 == $model->category) { $this->addError($attribute, '该Token币种不可增发'); return false; } } if (CoinIssueCoin::TYPE_NO == $this->type) { $model = CoinIssueCoin::find() ->where(['symbol' => $this->symbol, 'platform_id' => $this->platform_id]) ->andWhere(['<>', 'status', CoinIssueCoin::STATUS_FAILED]) ->orderBy('id desc')->one(); if ($model) { $this->addError($attribute, 'Token名称已存在'); return false; } } } public function verfiyAmount($attribute, $params) { if (CoinIssueCoin::TYPE_YES == $this->type) { if ($this->$attribute > (10 * 1e4)) { $this->addError($attribute, '增发发行量不能超过10亿'); return false; } } $issue_record = CoinIssueCoin::find()->where(['platform_id' => $this->platform_id, 'symbol' => $this->symbol, 'status' => CoinIssueCoin::STATUS_SUCCESS])->sum('total'); $issue_record = empty($issue_record) ? 0 : $issue_record; if ($issue_record + $this->$attribute > (900 * 1e4)) { $this->addError($attribute, '最大发行量900亿,目前已发行' . $issue_record . '亿'); return false; } } public function attributeLabels() { return [ 'name' => 'Token全称', 'symbol' => 'Token简称', 'total' => '发行数量', 'owner' => '接收地址', 'introduction' => 'Token简介', 'category' => '是否增发', 'chain_id' => '平行链名称', 'msg' => '失败原因', 'status' => '状态', 'charge_unit' => '手续费', ]; } public function attributes() { return array_merge(parent::attributes(), ['issue_charge', 'url', 'chain_name']); } public function getChain() { return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']); } public function getPlatform() { return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']); } public function getTransfer() { return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']); } public function getRevoke() { return $this->hasOne(CoinIssueRevokeRecord::className(), ['issue_coin_id' => 'id']); } }