PurchaseController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // ./yii purchase/expire-order
  14. // /usr/local/nginx/html/huahuibao/yii purchase/expire-order
  15. public function actionExpireOrder()
  16. {
  17. $query = new \yii\db\Query();
  18. $query->from(Purchase::tableName());
  19. $date = date("Y-m-d H:i:s");
  20. $query->where(['status' => PurchaseClass::STATUS_UN_PAY])->andWhere(['<=', 'deadline', $date]);
  21. $query->orderBy('deadline ASC');
  22. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  23. //如果有报错,抛出异常
  24. Yii::$app->params['errorReport'] = 1;
  25. $arr = [];
  26. foreach ($query->batch() as $purchases) {
  27. foreach ($purchases as $purchase) {
  28. $connection = Yii::$app->db;
  29. $transaction = $connection->beginTransaction();
  30. $id = $purchase['id'] ?? 0;
  31. $orderSn = $purchase['orderSn'] ?? '';
  32. try {
  33. $current = PurchaseClass::getById($id, true);
  34. $cgStyle = $current->cgStyle ?? dict::getDict('cgStyle', 'hd');
  35. $orderSn = $current->orderSn ?? '';
  36. if ($cgStyle == dict::getDict('cgStyle', 'hd')) {
  37. //花店采购的取消
  38. PurchaseService::expire($current);
  39. $transaction->commit();
  40. noticeUtil::push("【测试】采购单已经取消!订单号:{$orderSn}", '15280215347');
  41. } elseif ($cgStyle == dict::getDict('cgStyle', 'ghs')) {
  42. //供应商发起的记欠款
  43. PurchaseService::debt($current);
  44. $transaction->commit();
  45. noticeUtil::push("【测试】采购单已经记欠款!订单号:{$orderSn}", '15280215347');
  46. } else {
  47. noticeUtil::push("采购单类型没有找到 orderSn:" + $orderSn, '15280215347');
  48. }
  49. } catch (\Exception $e) {
  50. $transaction->rollBack();
  51. $msg = $e->getMessage();
  52. noticeUtil::push("【测试】采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  53. }
  54. $log = "过期的采购单:{$id} json:" . json_encode($purchase);
  55. $arr[] = $log;
  56. }
  57. }
  58. if (!empty($arr)) {
  59. foreach ($arr as $item) {
  60. Yii::info($item);
  61. }
  62. }
  63. }
  64. }