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']); } }