GoodsDetection.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\behaviors\TimestampBehavior;
  9. use yii\db\ActiveRecord;
  10. use yii\helpers\Json;
  11. /**
  12. * 商品检测报告模型
  13. *
  14. * @property int $id
  15. * @property int $goods_id 商品ID
  16. * @property int $store_id
  17. * @property string $report_name 报告名称
  18. * @property string $detection_agency 检测方
  19. * @property int $detection_number 检测序号
  20. * @property string $detection_date 检测日期
  21. * @property string $images 图片路径
  22. * @property int $created_at
  23. * @property int $is_delete
  24. * @property int $updated_at
  25. */
  26. class GoodsDetection extends ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%goods_detection}}';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['goods_id', 'report_name', 'detection_agency', 'detection_number', 'detection_date'], 'required'],
  42. [['goods_id','store_id', 'detection_number','is_delete', 'created_at', 'updated_at', 'detection_date'], 'integer'],
  43. [['detection_number'], 'integer', 'min' => 1, 'max' => 999],
  44. [['report_name'], 'string', 'max' => 20],
  45. [['detection_agency'], 'string', 'max' => 4],
  46. [['images'], 'safe'],
  47. ];
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'goods_id' => '商品ID',
  57. 'report_name' => '报告名称',
  58. 'detection_agency' => '检测方',
  59. 'detection_number' => '检测序号',
  60. 'detection_date' => '检测日期',
  61. 'images' => '检测图片',
  62. 'imageFiles' => '上传图片',
  63. 'created_at' => '创建时间',
  64. 'updated_at' => '更新时间',
  65. ];
  66. }
  67. /**
  68. * 保存前处理
  69. */
  70. public function behaviors()
  71. {
  72. return [
  73. [
  74. 'class' => TimestampBehavior::class,
  75. 'attributes' => [
  76. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  77. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  78. ]
  79. ]
  80. ];
  81. }
  82. /**
  83. * 获取图片数组
  84. */
  85. public function getImageArray()
  86. {
  87. return $this->images ? Json::decode($this->images) : [];
  88. }
  89. /**
  90. * 关联商品
  91. */
  92. public function getProduct()
  93. {
  94. return $this->hasOne(Goods::class, ['id' => 'goods_id']);
  95. }
  96. }