BankAccount.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace common\models\member;
  3. use common\behaviors\MerchantBehavior;
  4. use common\enums\AccountTypeEnum;
  5. use common\enums\StatusEnum;
  6. /**
  7. * This is the model class for table "{{%member_bank_account}}".
  8. *
  9. * @property int $id
  10. * @property int|null $merchant_id 商户id
  11. * @property int|null $member_id 会员id
  12. * @property int|null $member_type 会员类型
  13. * @property string $realname 真实姓名
  14. * @property string $mobile 手机号
  15. * @property string|null $account_number 银行账号
  16. * @property int|null $account_type 账户类型
  17. * @property string|null $account_type_name 账户类型名称
  18. * @property string|null $bank_name 银行信息
  19. * @property string|null $bank_branch 银行支行信息
  20. * @property string|null $bank_number 银行编码
  21. * @property string|null $identity_card 身份证
  22. * @property string|null $identity_card_front 身份证正面
  23. * @property string|null $identity_card_back 身份证背面
  24. * @property int|null $is_default 是否默认账号
  25. * @property int|null $audit_status 审核状态
  26. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  27. * @property int|null $created_at 创建时间
  28. * @property int|null $updated_at 修改时间
  29. */
  30. class BankAccount extends \common\models\base\BaseModel
  31. {
  32. use MerchantBehavior;
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public static function tableName()
  37. {
  38. return '{{%member_bank_account}}';
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['account_type', 'realname', 'mobile'], 'required'],
  47. ['account_type', 'in', 'range' => AccountTypeEnum::getKeys()],
  48. [['merchant_id', 'member_id', 'member_type', 'account_type', 'is_default', 'audit_status', 'status', 'created_at', 'updated_at'], 'integer'],
  49. [['realname', 'account_number'], 'string', 'max' => 50],
  50. [['mobile', 'identity_card'], 'string', 'max' => 20],
  51. [['account_type_name'], 'string', 'max' => 30],
  52. [['bank_name'], 'string', 'max' => 100],
  53. [['bank_branch', 'identity_card_front', 'identity_card_back'], 'string', 'max' => 200],
  54. ];
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function attributeLabels()
  60. {
  61. return [
  62. 'id' => 'ID',
  63. 'merchant_id' => '商户id',
  64. 'member_id' => '会员id',
  65. 'member_type' => '会员类型',
  66. 'realname' => '真实姓名',
  67. 'mobile' => '手机号',
  68. 'account_number' => '银行账号',
  69. 'account_type' => '账户类型',
  70. 'account_type_name' => '账户类型名称',
  71. 'bank_name' => '银行信息',
  72. 'bank_branch' => '银行支行信息',
  73. 'identity_card' => '身份证',
  74. 'identity_card_front' => '身份证正面',
  75. 'identity_card_back' => '身份证背面',
  76. 'is_default' => '默认账号',
  77. 'audit_status' => '审核状态',
  78. 'status' => '状态',
  79. 'created_at' => '创建时间',
  80. 'updated_at' => '修改时间',
  81. ];
  82. }
  83. /**
  84. * @param bool $insert
  85. * @return bool
  86. */
  87. public function beforeSave($insert)
  88. {
  89. $this->account_type_name = AccountTypeEnum::getValue($this->account_type);
  90. if (($this->isNewRecord || $this->oldAttributes['is_default'] == StatusEnum::DISABLED) && $this->is_default == StatusEnum::ENABLED) {
  91. self::updateAll(['is_default' => StatusEnum::DISABLED], ['member_id' => $this->member_id, 'merchant_id' => $this->merchant_id, 'is_default' => StatusEnum::ENABLED]);
  92. }
  93. if ($this->account_type != AccountTypeEnum::UNION) {
  94. $this->bank_name = '';
  95. $this->bank_branch = '';
  96. }
  97. return parent::beforeSave($insert);
  98. }
  99. }
粤ICP备19079148号