| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?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 "{{%erp_purchasein}}".
- *
- * @property integer $id
- */
- class ErpPurchasein extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%erp_purchasein}}';
- }
-
- public static function saveList($order, $purchase) {
- $order_id = $order['id'];
- $order_no = $order['order_no'];
- foreach($purchase as $item){
- $model = new ErpPurchasein();
- $model->inventory_id = $item['id'];
- $model->num = $item['num'];
- $model->purchase_order_id = $order_id;
- if (!$model->save()) {
- \Yii::error([__METHOD__, $model->attributes]);
- throw new \Exception(array_shift($model->getFirstErrors()));
- }
-
- $ei = ErpInventory::findOne($model->inventory_id);
-
- $logSave = ErpInventory::logSave($ei, $model->num, ErpInventoryLog::LOG_TYPE_PURCHASEIN, $order_id, $order_no);
- if ($logSave['code'] != 0) {
- \Yii::error([__METHOD__, $logSave]);
- throw new \Exception('库存日志保存失败!' . $logSave['msg']);
- }
- }
- }
- }
|