ErpPurchasein.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%erp_purchasein}}".
  13. *
  14. * @property integer $id
  15. */
  16. class ErpPurchasein extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%erp_purchasein}}';
  24. }
  25. public static function saveList($order, $purchase) {
  26. $order_id = $order['id'];
  27. $order_no = $order['order_no'];
  28. foreach($purchase as $item){
  29. $model = new ErpPurchasein();
  30. $model->inventory_id = $item['id'];
  31. $model->num = $item['num'];
  32. $model->purchase_order_id = $order_id;
  33. if (!$model->save()) {
  34. \Yii::error([__METHOD__, $model->attributes]);
  35. throw new \Exception(array_shift($model->getFirstErrors()));
  36. }
  37. $ei = ErpInventory::findOne($model->inventory_id);
  38. $logSave = ErpInventory::logSave($ei, $model->num, ErpInventoryLog::LOG_TYPE_PURCHASEIN, $order_id, $order_no);
  39. if ($logSave['code'] != 0) {
  40. \Yii::error([__METHOD__, $logSave]);
  41. throw new \Exception('库存日志保存失败!' . $logSave['msg']);
  42. }
  43. }
  44. }
  45. }