TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'] ] ] ]; } /** * {@inheritdoc} */ public function rules() { return [ [['store_id', 'code', 'name', 'unit', 'exchange_rate', 'enable', 'enable_bussiness_mode', 'enable_goods_deduct'], 'required'], [['id', 'store_id', 'ts_cardinal_number', 'ex_cardinal_number', 'enable', 'enable_bussiness_mode', 'enable_exchange', 'enable_goods_deduct', 'is_transfer', 'created_at', 'updated_at', 'enable_balance', 'enable_draw', 'enable_transmit', 'transmit_user_type', 'scale'], 'integer'], [['exchange_rate', 'transfer_fee_rate', 'balance_rate', 'transmit_rate', 'balance_fee_ratio', 'draw_fee_ratio', 'remainder', 'guid_price','cny_price', 'exchange_price'], 'number'], [['name', 'unit'], 'string', 'max' => 64], ['code', 'checkCode'], [['code'], 'match', 'pattern' => '/^[a-z][a-z_0-9]{1,}$/', 'message' => '币种码只能以小写字母、数字和下划线构成,并且只能以字母开头'], [['code', 'symbol', 'plugin_code', 'type'], 'string', 'max' => 32], [['logo'], 'string', 'max' => 128], [['remark'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => '店铺ID', 'name' => '币种名称', 'scale' => '精度', 'unit' => '币种单位', 'code' => '币种代码', 'plugin_code' => '插件代码', 'logo' => '币种图标', 'exchange_rate' => '兑换比例', 'exchange_price' => '兑换价', 'enable' => '是否启用 【1是 0否】', 'enable_bussiness_mode' => '是否支持商业模式【1是 0否】', 'enable_goods_deduct' => '是否支持商品抵扣【1是 0否】', 'remark' => '备注', 'is_transfer' => '是否支持转账', 'transfer_fee_rate' => '转账手续费', 'type' => '货币类型', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'ts_cardinal_number' => '转送基数', 'ex_cardinal_number' => '兑换基数', 'remainder' => '无质押需要剩余', ]; } /** * 验证code合法性 */ public function checkCode($attribute, $params) { if (in_array($this->code, ['balance', 'score', 'commission'])) $this->addError('code', '此币种代码已被使用'); $currency = self::find()->where(array('code' => $this->code, 'store_id' => $this->store_id))->one(); /* @var Currency[] $currency */ if (!empty($currency)) { if ($this->exchange_rate != $currency->exchange_rate) { $this->addError('code', '此币种代码已被使用,兑换比例不能修改'); } } } public static function getCurrencyByCode($store_id, $code) { return self::find()->where(array('store_id' => $store_id, 'code' => $code, 'enable' => 1))->one(); } }