Invoice.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\TinyShop\common\models\order;
  3. use common\enums\AuditStatusEnum;
  4. use common\traits\HasOneMember;
  5. /**
  6. * This is the model class for table "{{%addon_tiny_shop_order_invoice}}".
  7. *
  8. * @property int $id
  9. * @property int|null $merchant_id 商户id
  10. * @property int|null $store_id 店铺ID
  11. * @property int|null $member_id 用户ID
  12. * @property int|null $order_id 订单ID
  13. * @property string|null $order_sn 订单编号
  14. * @property string|null $title 公司抬头
  15. * @property string|null $duty_paragraph 公司税号
  16. * @property string|null $opening_bank 公司开户行
  17. * @property string|null $opening_bank_account 公司开户行账号
  18. * @property string|null $address 公司地址
  19. * @property string|null $phone 公司电话
  20. * @property string|null $remark 备注
  21. * @property string|null $explain 说明
  22. * @property int|null $type 类型 1企业 2个人
  23. * @property float|null $tax_money 税费
  24. * @property int|null $audit_status 开具状态
  25. * @property int|null $audit_time 开具时间
  26. * @property int|null $status 状态
  27. * @property int|null $created_at 创建时间
  28. * @property int|null $updated_at 修改时间
  29. */
  30. class Invoice extends \common\models\base\BaseModel
  31. {
  32. use HasOneMember;
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public static function tableName()
  37. {
  38. return '{{%addon_tiny_shop_order_invoice}}';
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['merchant_id', 'store_id', 'member_id', 'order_id', 'type', 'audit_status', 'audit_time', 'status', 'created_at', 'updated_at'], 'integer'],
  47. [['tax_money'], 'number'],
  48. [['order_sn'], 'string', 'max' => 30],
  49. [['title', 'duty_paragraph', 'opening_bank'], 'string', 'max' => 200],
  50. [['opening_bank_account'], 'string', 'max' => 100],
  51. [['address', 'remark', 'explain'], 'string', 'max' => 255],
  52. [['phone'], 'string', 'max' => 50],
  53. ];
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function attributeLabels()
  59. {
  60. return [
  61. 'id' => 'ID',
  62. 'merchant_id' => '商户id',
  63. 'store_id' => '店铺ID',
  64. 'member_id' => '用户ID',
  65. 'order_id' => '订单ID',
  66. 'order_sn' => '订单编号',
  67. 'title' => '公司抬头',
  68. 'duty_paragraph' => '公司税号',
  69. 'opening_bank' => '公司开户行',
  70. 'opening_bank_account' => '公司开户行账号',
  71. 'address' => '公司地址',
  72. 'phone' => '公司电话',
  73. 'remark' => '备注',
  74. 'explain' => '说明',
  75. 'type' => '类型', // 1 企业 2 个人
  76. 'tax_money' => '税费',
  77. 'audit_status' => '开具状态',
  78. 'audit_time' => '开具时间',
  79. 'status' => '状态',
  80. 'created_at' => '创建时间',
  81. 'updated_at' => '修改时间',
  82. ];
  83. }
  84. /**
  85. * 关联订单
  86. *
  87. * @return \yii\db\ActiveQuery
  88. */
  89. public function getOrder()
  90. {
  91. return $this->hasOne(Order::class, ['id' => 'order_id']);
  92. }
  93. /**
  94. * @param $insert
  95. * @return bool
  96. */
  97. public function beforeSave($insert)
  98. {
  99. if ($this->audit_status == AuditStatusEnum::ENABLED && $this->oldAttributes['audit_status'] != AuditStatusEnum::ENABLED) {
  100. $this->audit_time = time();
  101. }
  102. return parent::beforeSave($insert);
  103. }
  104. }
粤ICP备19079148号