UnionpayUserBankCard.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace addons\UnionPay\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\common\UserBankCard;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_addons_unionpay_user_bankcard".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城id
  12. * @property int $user_id 用户id
  13. * @property int $card_id 银行卡id,qimall_user_bank_card 表的id
  14. * @property int $id_type 持卡人证件类型:0-身份证,2-护照,5-港澳通行证,6-台湾通行证等
  15. * @property string $id_no 持卡人证件号码
  16. * @property string $mobile 银行卡绑定的手机号
  17. * @property string $validdate 有效期/信用卡不能为空
  18. * @property string $cvv2 Cvv2/信用卡不能为空
  19. * @property string $sign_no 快捷支付-签约id
  20. * @property int $is_sign 是否开通快捷支付
  21. * @property int $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int $created_at 添加时间戳
  23. * @property int $updated_at 更新时间戳
  24. */
  25. class UnionpayUserBankCard extends BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_unionpay_user_bank_card}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['mall_id', 'user_id'], 'required'],
  41. [['mall_id', 'user_id', 'card_id', 'id_type', 'is_sign', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['id_no'], 'string', 'max' => 50],
  43. [['mobile', 'validdate', 'cvv2', 'sign_no'], 'string', 'max' => 32],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => 'ID',
  53. 'mall_id' => '商城id',
  54. 'user_id' => '用户id',
  55. 'card_id' => '银行卡id,qimall_user_bank_card 表的id',
  56. 'id_type' => '持卡人证件类型:0-身份证,2-护照,5-港澳通行证,6-台湾通行证等',
  57. 'id_no' => '持卡人证件号码',
  58. 'mobile' => '银行卡绑定的手机号',
  59. 'validdate' => '有效期/信用卡不能为空',
  60. 'cvv2' => 'Cvv2/信用卡不能为空',
  61. 'sign_no' => '快捷支付-签约id',
  62. 'is_sign' => '是否开通快捷支付',
  63. 'status' => '状态[-1:删除;0:禁用;1启用]',
  64. 'created_at' => '添加时间戳',
  65. 'updated_at' => '更新时间戳',
  66. ];
  67. }
  68. public function getUser(){
  69. return $this->hasOne(UserBankCard::class, ['id' => 'card_id']);
  70. }
  71. public static function setData(int $mall_id, array $data)
  72. {
  73. if (empty($data['id'])) {
  74. $model = self::findOne([
  75. 'mall_id' => $mall_id,
  76. 'card_id' => $data['card_id'],
  77. 'user_id' => $data['user_id'],
  78. 'status' => StatusEnum::ENABLED
  79. ]);
  80. if (empty($model)) {
  81. $model = new self();
  82. $model->loadDefaultValues();
  83. $model->mall_id = $mall_id;
  84. $model->user_id = $data['user_id'];
  85. }
  86. unset($data['id']);
  87. } else {
  88. $model = self::findOne(['mall_id' => $mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]);
  89. if (empty($model)) throw new \Exception('数据记录异常');
  90. }
  91. if (!$model->load($data, '')) throw new \Exception($model->getErrorMessage());
  92. if (!$model->save()) {
  93. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  94. return false;
  95. }
  96. return $model;
  97. }
  98. }