InventiryList.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * InventiryList.php
  4. * todo 文件描述
  5. * Created on 2024/3/26 10:13
  6. * @author: hankaige
  7. */
  8. namespace app\models;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%inventory_list}}".
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property string $inventory_no
  16. * @property integer $goods_count
  17. * @property integer $order_count
  18. * @property integer $is_delete
  19. * @property integer $created_at
  20. */
  21. class InventiryList extends \yii\db\ActiveRecord
  22. {
  23. public static function tableName()
  24. {
  25. return "{{%inventory_list}}";
  26. }
  27. public function behaviors()
  28. {
  29. return [
  30. [
  31. 'class' => TimestampBehavior::class,
  32. 'attributes' => [
  33. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  34. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  35. ]
  36. ]
  37. ];
  38. }
  39. public function rules()
  40. {
  41. return [
  42. [
  43. [
  44. 'store_id',
  45. 'inventory_no',
  46. 'goods_count',
  47. 'order_count'
  48. ],
  49. 'required'
  50. ],
  51. [
  52. [
  53. 'store_id',
  54. 'goods_count',
  55. 'order_count'
  56. ],
  57. 'integer'
  58. ],
  59. [
  60. ['inventory_no'],
  61. 'string'
  62. ],
  63. [
  64. 'inventory_no',
  65. 'unique'
  66. ]
  67. ];
  68. }
  69. public function attributeLabels()
  70. {
  71. return [
  72. 'store_id' => '商城ID',
  73. 'inventory_no' => '备货单单号',
  74. 'goods_count' => '包含商品数量',
  75. 'order_count' => '包含订单数量'
  76. ];
  77. }
  78. /**
  79. * 生成备货单单号
  80. * @return string
  81. * @author: hankaige
  82. * @Time: 2024/3/26 10:32
  83. */
  84. public static function createOrderNo()
  85. {
  86. while (TRUE) {
  87. $order_no = 'IN' . date('YmdHis') . mt_rand(100000, 999999);
  88. $exist_order_no = self::find()->where(['inventory_no' => $order_no])->exists();
  89. if (!$exist_order_no) {
  90. break;
  91. }
  92. }
  93. return $order_no;
  94. }
  95. public function getOrder()
  96. {
  97. return $this->hasMany(InventoryOrder::tableName(), ['inventory_id' => 'id']);
  98. }
  99. public function getGoods()
  100. {
  101. return $this->hasMany(InventoryOrderGoods::tableName(), ['inventory_id' => 'id']);
  102. }
  103. }