TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'] ] ] ]; } public function rules() { return [ [ [ 'store_id', 'inventory_id', 'sorting_no', 'goods_count', 'order_count', 'md_id' ], 'required' ], [ [ 'inventory_id', 'goods_count', 'order_count', 'md_id', 'driver_id' ], 'integer' ], [ ['sorting_no'], 'string' ], [ 'sorting_no', 'unique' ] ]; } public function attributeLabels() { return [ 'inventory_id' => '商城ID', 'sorting_no' => '备货单单号', 'goods_count' => '包含商品数量', 'order_count' => '包含订单数量', 'md_id' => '门店ID', 'driver_id' => '司机ID' ]; } /** * 生成备货单单号 * @return string * @author: hankaige * @Time: 2024/3/26 10:32 */ public static function createOrderNo() { while (TRUE) { $order_no = 'SL' . date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = self::find()->where(['sorting_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } return $order_no; } public function getMd() { return $this->hasOne(Md::class, ['id' => 'md_id'])->select('id,name,province,city,district'); } public function getDriver() { return $this->hasOne(MdGroupDriver::className(), ['id' => 'driver_id'])->select('id,name,mobile,code'); } public function getOrder(){ return $this->hasMany(SortingOrder::className(),['sorting_id'=>'id'])->with('order'); } }