"已创建采购单", self::ORDER_STATUS_SEND => "供货商已发货", self::ORDER_STATUS_CONFIRM => "已生成入库单", ]; /** * @inheritdoc */ public static function tableName() { return '{{%agent_front_erp_purchase_order}}'; } public function behaviors() { return [ [ 'class' => TimestampBehavior::class, ] ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub if (intval($this->order_status) === self::ORDER_STATUS_CONFIRM) { $agentFrontErpPurchase = AgentFrontErpPurchase::find()->where(['purchase_order_id' => $this->id])->asArray()->all(); $purchase = []; if ($agentFrontErpPurchase) { foreach ($agentFrontErpPurchase as $erpPurchaseItem) { $purchase[] = [ 'id' => $erpPurchaseItem['inventory_id'], 'num' => $erpPurchaseItem['num'] ]; } } $form = new \app\modules\admin\models\agent\front_erp\PurchaseinForm(); $form->front_agent_admin_id = $this->front_agent_admin_id; $form->supplier_id = $this->supplier_id; $form->purchase = $purchase; $res = $form->save(); if ($res['code'] !== 0) { } } return true; } }