AgentFrontErpPurchaseOrder.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "{{%agent_front_erp_purchase_order}}".
  13. *
  14. * @property integer $id
  15. * @property string $order_no
  16. * @property integer $front_agent_admin_id
  17. * @property integer $supplier_id
  18. * @property integer $num
  19. * @property integer $order_status
  20. */
  21. class AgentFrontErpPurchaseOrder extends \yii\db\ActiveRecord
  22. {
  23. const ORDER_STATUS_CREATE = 0;//采购单已生成
  24. const ORDER_STATUS_SEND = 1;//供货商发货
  25. const ORDER_STATUS_CONFIRM = 2;//仓库收货
  26. const ORDER_STATUS_ARR = [
  27. self::ORDER_STATUS_CREATE => "已创建采购单",
  28. self::ORDER_STATUS_SEND => "供货商已发货",
  29. self::ORDER_STATUS_CONFIRM => "已生成入库单",
  30. ];
  31. /**
  32. * @inheritdoc
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%agent_front_erp_purchase_order}}';
  37. }
  38. public function behaviors()
  39. {
  40. return [
  41. [
  42. 'class' => TimestampBehavior::class,
  43. ]
  44. ];
  45. }
  46. public function afterSave($insert, $changedAttributes)
  47. {
  48. parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
  49. if (intval($this->order_status) === self::ORDER_STATUS_CONFIRM) {
  50. $agentFrontErpPurchase = AgentFrontErpPurchase::find()->where(['purchase_order_id' => $this->id])->asArray()->all();
  51. $purchase = [];
  52. if ($agentFrontErpPurchase) {
  53. foreach ($agentFrontErpPurchase as $erpPurchaseItem) {
  54. $purchase[] = [
  55. 'id' => $erpPurchaseItem['inventory_id'],
  56. 'num' => $erpPurchaseItem['num']
  57. ];
  58. }
  59. }
  60. $form = new \app\modules\admin\models\agent\front_erp\PurchaseinForm();
  61. $form->front_agent_admin_id = $this->front_agent_admin_id;
  62. $form->supplier_id = $this->supplier_id;
  63. $form->purchase = $purchase;
  64. $res = $form->save();
  65. if ($res['code'] !== 0) {
  66. }
  67. }
  68. return true;
  69. }
  70. }