ErpPurchase.php 989 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_purchase}}".
  13. *
  14. * @property integer $id
  15. */
  16. class ErpPurchase extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%erp_purchase}}';
  24. }
  25. public static function saveList($order_id, $purchase) {
  26. foreach($purchase as $item){
  27. $model = new ErpPurchase();
  28. $model->inventory_id = $item['id'];
  29. $model->num = $item['num'];
  30. $model->purchase_order_id = $order_id;
  31. if (!$model->save()) {
  32. \Yii::error([__METHOD__, $model->attributes]);
  33. throw new \Exception(array_shift($model->getFirstErrors()));
  34. }
  35. }
  36. }
  37. }