PurchaseClearController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\clear\classes\ClearClass;
  4. use bizHd\purchase\classes\PurchaseClearClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use Yii;
  8. class PurchaseClearController extends BaseController
  9. {
  10. //供货商向基地供货商结账生成订单 ssh 20220523
  11. public function actionCreateOrder()
  12. {
  13. $post = Yii::$app->request->post();
  14. $current = time();
  15. $list = ClearClass::getAllByCondition(['shopId' => $this->shopId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY], null, '*', null, true);
  16. if (!empty($list)) {
  17. foreach ($list as $item) {
  18. $deadline = $item->deadline;
  19. $deadTime = strtotime($deadline);
  20. if ($current > $deadTime) {
  21. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  22. $item->save();
  23. } else {
  24. util::fail('还有结算订单待付款');
  25. }
  26. }
  27. }
  28. $post['sjId'] = $this->sjId;
  29. $post['shopId'] = $this->shopId;
  30. $post['clearStyle'] = dict::getDict('clearStyle', 'gys2KmGys');
  31. $post['customShopAdminId'] = $this->shopAdminId;
  32. $post['customShopId'] = $this->shopId ?? 0;
  33. $shopAdmin = $this->shopAdmin;
  34. $shopAdminName = $shopAdmin['name'] ?? '';
  35. $post['customShopAdminName'] = $shopAdminName;
  36. $connection = Yii::$app->db;
  37. $transaction = $connection->beginTransaction();
  38. try {
  39. $respond = ClearClass::addOrder($post);
  40. $transaction->commit();
  41. util::success($respond);
  42. } catch (\Exception $e) {
  43. $transaction->rollBack();
  44. Yii::info("下单失败原因:" . $e->getMessage());
  45. util::fail('下单失败');
  46. }
  47. }
  48. }