Invoice.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace common\models\member;
  3. use common\enums\StatusEnum;
  4. /**
  5. * This is the model class for table "rf_member_invoice".
  6. *
  7. * @property int $id
  8. * @property int|null $merchant_id 商户id
  9. * @property int|null $store_id 店铺ID
  10. * @property int|null $member_id 用户id
  11. * @property string|null $title 公司抬头
  12. * @property string|null $duty_paragraph 公司税号
  13. * @property string|null $opening_bank 公司开户行
  14. * @property string|null $opening_bank_account 公司开户行账号
  15. * @property string|null $address 公司地址
  16. * @property string|null $phone 公司电话
  17. * @property string|null $remark 备注
  18. * @property int|null $is_default 默认
  19. * @property int|null $type 类型 1企业 2个人
  20. * @property int|null $status 状态(-1:已删除,0:禁用,1:正常)
  21. * @property int|null $created_at 创建时间
  22. * @property int|null $updated_at 修改时间
  23. */
  24. class Invoice extends \common\models\base\BaseModel
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return 'rf_member_invoice';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['title', 'type'], 'required'],
  40. [['merchant_id', 'store_id', 'member_id', 'is_default', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
  41. [['title', 'duty_paragraph', 'opening_bank'], 'string', 'max' => 200],
  42. [['opening_bank_account'], 'string', 'max' => 100],
  43. [['address', 'remark'], 'string', 'max' => 255],
  44. [['phone'], 'string', 'max' => 50],
  45. ];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => 'ID',
  54. 'merchant_id' => '商户id',
  55. 'store_id' => '店铺ID',
  56. 'member_id' => '用户id',
  57. 'title' => '抬头', // 公司抬头
  58. 'duty_paragraph' => '公司税号', // 公司税号
  59. 'opening_bank' => '公司开户行',
  60. 'opening_bank_account' => '公司开户行账号',
  61. 'address' => '公司地址',
  62. 'phone' => '公司电话',
  63. 'remark' => '备注',
  64. 'is_default' => '默认',
  65. 'type' => '类型', // 1:企业; 2:个人
  66. 'status' => '状态',
  67. 'created_at' => '创建时间',
  68. 'updated_at' => '修改时间',
  69. ];
  70. }
  71. /**
  72. * @param bool $insert
  73. * @return bool
  74. */
  75. public function beforeSave($insert)
  76. {
  77. if (($this->isNewRecord || $this->oldAttributes['is_default'] == StatusEnum::DISABLED) && $this->is_default == StatusEnum::ENABLED) {
  78. self::updateAll(['is_default' => StatusEnum::DISABLED], ['member_id' => $this->member_id, 'is_default' => StatusEnum::ENABLED]);
  79. }
  80. return parent::beforeSave($insert);
  81. }
  82. }
粤ICP备19079148号