JoinPayUserBankcard.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version:
  5. * @Author: ewgof
  6. * @Date: 2022-04-08 15:34:51
  7. * @LastEditors: ewgof
  8. * @LastEditTime: 2022-04-08 16:17:29
  9. */
  10. namespace addons\JoinPay\common\models;
  11. use common\enums\StatusEnum;
  12. use Yii;
  13. /**
  14. * This is the model class for table "{{%addons_joinpay_user_bankcard}}".
  15. *
  16. * @property int $id
  17. * @property int $mall_id 商城id
  18. * @property int $user_id 用户id
  19. * @property int $card_id 银行卡id,qimall_user_bank_card 表的id
  20. * @property string $payer_name 持卡人姓名
  21. * @property int $id_type 持卡人证件类型:1-身份证,2-军官证,3-士兵证,4-护照等
  22. * @property string $id_no 持卡人证件号码
  23. * @property string $bank_name 银行名称
  24. * @property string $bank_code 银行简码
  25. * @property string $bank_card_no 银行卡号
  26. * @property string $mobile_no 银行卡绑定的手机号
  27. * @property string $expire_date 信用卡有效期,格式:yy/mm格式
  28. * @property string $cvv 信用卡cvv安全码
  29. * @property string $sign_no 快捷支付-签约id
  30. * @property int $is_sign 是否开通快捷支付
  31. * @property string $card_type 银行卡类型,dc->储蓄卡,cc->信用卡
  32. * @property string $card_type_name 银行卡类型名称
  33. * @property int $status 状态[-1:删除;0:禁用;1启用]
  34. * @property int $created_at 添加时间戳
  35. * @property int $updated_at 更新时间戳
  36. */
  37. class JoinPayUserBankcard extends \common\models\base\BaseActiveRecord
  38. {
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public static function tableName()
  43. {
  44. return '{{%addons_joinpay_user_bankcard}}';
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function rules()
  50. {
  51. return [
  52. [['mall_id', 'user_id'], 'required'],
  53. [['mall_id', 'user_id', 'card_id', 'id_type', 'is_sign', 'status', 'created_at', 'updated_at'], 'integer'],
  54. [['payer_name', 'id_no', 'bank_name'], 'string', 'max' => 50],
  55. [['bank_code', 'mobile_no', 'expire_date', 'cvv', 'sign_no', 'card_type', 'card_type_name'], 'string', 'max' => 32],
  56. [['bank_card_no'], 'string', 'max' => 64],
  57. ];
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'id' => 'ID',
  66. 'mall_id' => '商城id',
  67. 'user_id' => '用户id',
  68. 'card_id' => '银行卡id,qimall_user_bank_card 表的id',
  69. 'payer_name' => '持卡人姓名',
  70. 'id_type' => '持卡人证件类型:1-身份证,2-军官证,3-士兵证,4-护照等',
  71. 'id_no' => '持卡人证件号码',
  72. 'bank_name' => '银行名称',
  73. 'bank_code' => '银行简码',
  74. 'bank_card_no' => '银行卡号',
  75. 'mobile_no' => '银行卡绑定的手机号',
  76. 'expire_date' => '信用卡有效期,格式:yy/mm格式',
  77. 'cvv' => '信用卡cvv安全码',
  78. 'sign_no' => '快捷支付-签约id',
  79. 'is_sign' => '是否开通快捷支付',
  80. 'card_type' => '银行卡类型,dc->储蓄卡,cc->信用卡',
  81. 'card_type_name' => '银行卡类型名称',
  82. 'status' => '状态[-1:删除;0:禁用;1启用]',
  83. 'created_at' => '添加时间戳',
  84. 'updated_at' => '更新时间戳',
  85. ];
  86. }
  87. public static function setData(int $mall_id, array $data)
  88. {
  89. if (empty($data['id'])) {
  90. $model = self::findOne([
  91. 'mall_id' => $mall_id,
  92. 'card_id' => $data['card_id'],
  93. 'payer_name' => $data['payer_name'],
  94. 'bank_card_no' => $data['bank_card_no'],
  95. 'status' => StatusEnum::ENABLED
  96. ]);
  97. if (empty($model)) {
  98. $model = new self();
  99. $model->loadDefaultValues();
  100. $model->mall_id = $mall_id;
  101. }
  102. unset($data['id']);
  103. } else {
  104. $model = self::findOne(['mall_id' => $mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]);
  105. if (empty($model)) throw new \Exception('数据记录异常');
  106. }
  107. foreach ($data as $key => $val) {
  108. $model->$key = $val;
  109. }
  110. if (!$model->save()) {
  111. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  112. return false;
  113. }
  114. return $model;
  115. }
  116. }