PurchaseController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace console\controllers;
  3. use bizHd\purchase\classes\PurchaseClass;
  4. use bizHd\purchase\models\Purchase;
  5. use bizHd\purchase\services\PurchaseService;
  6. use common\components\dict;
  7. use common\components\noticeUtil;
  8. use yii\console\Controller;
  9. use Yii;
  10. class PurchaseController extends Controller
  11. {
  12. //采购订单过期变更 shish 2021.5.14
  13. public function actionExpireOrder()
  14. {
  15. $hdInvite = dict::getDict('cgStyle', 'ghs');
  16. $query = new \yii\db\Query();
  17. $query->from(Purchase::tableName());
  18. $date = date("Y-m-d H:i:s");
  19. $query->where(['status' => PurchaseClass::STATUS_UN_PAY])->where(['cgStyle' => $hdInvite])->andWhere(['<=', 'deadline', $date]);
  20. $query->orderBy('deadline ASC');
  21. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  22. //如果有报错,抛出异常
  23. Yii::$app->params['errorReport'] = 1;
  24. $arr = [];
  25. foreach ($query->batch() as $purchases) {
  26. foreach ($purchases as $purchase) {
  27. $connection = Yii::$app->db;//事务处理
  28. $transaction = $connection->beginTransaction();
  29. $id = $purchase['id'] ?? 0;
  30. $orderSn = $purchase['orderSn'] ?? '';
  31. try {
  32. $current = PurchaseClass::getById($id, true);
  33. PurchaseService::expire($current);
  34. $transaction->commit();
  35. //noticeUtil::push("采购单已过期,库存已回滚 订单号:{$orderSn}", '15280215347');
  36. } catch (\Exception $e) {
  37. $transaction->rollBack();
  38. $msg = $e->getMessage();
  39. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  40. }
  41. $log = "过期的采购单:{$id} json:" . json_encode($purchase);
  42. $arr[] = $log;
  43. }
  44. }
  45. if (!empty($arr)) {
  46. foreach ($arr as $item) {
  47. Yii::info($item);
  48. }
  49. }
  50. }
  51. //待付款订单自动变成欠款订单
  52. public function actionSetDebtOrder()
  53. {
  54. $ghsInvite = dict::getDict('cgStyle', 'ghs');
  55. $query = new \yii\db\Query();
  56. $query->from(Purchase::tableName());
  57. $date = date("Y-m-d H:i:s");
  58. $query->where(['status' => PurchaseClass::STATUS_UN_PAY])->where(['cgStyle' => $ghsInvite])->andWhere(['<=', 'autoSetTime', $date]);
  59. $query->orderBy('autoSetTime ASC');
  60. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  61. //如果有报错,抛出异常
  62. Yii::$app->params['errorReport'] = 1;
  63. $arr = [];
  64. foreach ($query->batch() as $purchases) {
  65. foreach ($purchases as $purchase) {
  66. $connection = Yii::$app->db;//事务处理
  67. $transaction = $connection->beginTransaction();
  68. $id = $purchase['id'] ?? 0;
  69. $orderSn = $purchase['orderSn'] ?? '';
  70. try {
  71. $current = PurchaseClass::getById($id, true);
  72. //供应商发起的记欠款
  73. PurchaseService::debt($current);
  74. $transaction->commit();
  75. noticeUtil::push("采购单已经记欠款!订单号:{$orderSn}", '15280215347');
  76. } catch (\Exception $e) {
  77. $transaction->rollBack();
  78. $msg = $e->getMessage();
  79. noticeUtil::push("待付款采购单设置为欠款单报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  80. }
  81. $log = "待付款采购单设置为欠款单:{$id} json:" . json_encode($purchase);
  82. $arr[] = $log;
  83. }
  84. }
  85. if (!empty($arr)) {
  86. foreach ($arr as $item) {
  87. Yii::info($item);
  88. }
  89. }
  90. }
  91. }