| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * InventiryList.php
- * todo 文件描述
- * Created on 2024/3/26 10:13
- * @author: hankaige
- */
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%inventory_list}}".
- * @property integer $id
- * @property integer $store_id
- * @property string $inventory_no
- * @property integer $goods_count
- * @property integer $order_count
- * @property integer $is_delete
- * @property integer $created_at
- */
- class InventiryList extends \yii\db\ActiveRecord
- {
- public static function tableName()
- {
- return "{{%inventory_list}}";
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- public function rules()
- {
- return [
- [
- [
- 'store_id',
- 'inventory_no',
- 'goods_count',
- 'order_count'
- ],
- 'required'
- ],
- [
- [
- 'store_id',
- 'goods_count',
- 'order_count'
- ],
- 'integer'
- ],
- [
- ['inventory_no'],
- 'string'
- ],
- [
- 'inventory_no',
- 'unique'
- ]
- ];
- }
- public function attributeLabels()
- {
- return [
- 'store_id' => '商城ID',
- 'inventory_no' => '备货单单号',
- 'goods_count' => '包含商品数量',
- 'order_count' => '包含订单数量'
- ];
- }
- /**
- * 生成备货单单号
- * @return string
- * @author: hankaige
- * @Time: 2024/3/26 10:32
- */
- public static function createOrderNo()
- {
- while (TRUE) {
- $order_no = 'IN' . date('YmdHis') . mt_rand(100000, 999999);
- $exist_order_no = self::find()->where(['inventory_no' => $order_no])->exists();
- if (!$exist_order_no) {
- break;
- }
- }
- return $order_no;
- }
- public function getOrder()
- {
- return $this->hasMany(InventoryOrder::tableName(), ['inventory_id' => 'id']);
- }
- public function getGoods()
- {
- return $this->hasMany(InventoryOrderGoods::tableName(), ['inventory_id' => 'id']);
- }
- }
|