PurchaseClearController.php 1.7 KB

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