HuifuPayUserBankcard.php 4.9 KB

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