| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%agent_front_erp_purchase_order}}".
- *
- * @property integer $id
- * @property string $order_no
- * @property integer $front_agent_admin_id
- * @property integer $supplier_id
- * @property integer $num
- * @property integer $order_status
- */
- class AgentFrontErpPurchaseOrder extends \yii\db\ActiveRecord
- {
- const ORDER_STATUS_CREATE = 0;//采购单已生成
- const ORDER_STATUS_SEND = 1;//供货商发货
- const ORDER_STATUS_CONFIRM = 2;//仓库收货
- const ORDER_STATUS_ARR = [
- self::ORDER_STATUS_CREATE => "已创建采购单",
- 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;
- }
- }
|