| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace addons\UnionPay\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\common\UserBankCard;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_unionpay_user_bankcard".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $user_id 用户id
- * @property int $card_id 银行卡id,qimall_user_bank_card 表的id
- * @property int $id_type 持卡人证件类型:0-身份证,2-护照,5-港澳通行证,6-台湾通行证等
- * @property string $id_no 持卡人证件号码
- * @property string $mobile 银行卡绑定的手机号
- * @property string $validdate 有效期/信用卡不能为空
- * @property string $cvv2 Cvv2/信用卡不能为空
- * @property string $sign_no 快捷支付-签约id
- * @property int $is_sign 是否开通快捷支付
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- */
- class UnionpayUserBankCard extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_unionpay_user_bank_card}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id'], 'required'],
- [['mall_id', 'user_id', 'card_id', 'id_type', 'is_sign', 'status', 'created_at', 'updated_at'], 'integer'],
- [['id_no'], 'string', 'max' => 50],
- [['mobile', 'validdate', 'cvv2', 'sign_no'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'user_id' => '用户id',
- 'card_id' => '银行卡id,qimall_user_bank_card 表的id',
- 'id_type' => '持卡人证件类型:0-身份证,2-护照,5-港澳通行证,6-台湾通行证等',
- 'id_no' => '持卡人证件号码',
- 'mobile' => '银行卡绑定的手机号',
- 'validdate' => '有效期/信用卡不能为空',
- 'cvv2' => 'Cvv2/信用卡不能为空',
- 'sign_no' => '快捷支付-签约id',
- 'is_sign' => '是否开通快捷支付',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- ];
- }
- public function getUser(){
- return $this->hasOne(UserBankCard::class, ['id' => 'card_id']);
- }
- public static function setData(int $mall_id, array $data)
- {
- if (empty($data['id'])) {
- $model = self::findOne([
- 'mall_id' => $mall_id,
- 'card_id' => $data['card_id'],
- 'user_id' => $data['user_id'],
- 'status' => StatusEnum::ENABLED
- ]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->user_id = $data['user_id'];
- }
- unset($data['id']);
- } else {
- $model = self::findOne(['mall_id' => $mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) throw new \Exception('数据记录异常');
- }
- if (!$model->load($data, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|