PurchaseClearController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. //1客户清算 2供货商清算
  30. $post['type'] = 1;
  31. $post['customShopAdminId'] = $this->shopAdminId;
  32. $shopAdmin = $this->shopAdmin;
  33. $shopAdminName = $shopAdmin['name'] ?? '';
  34. $post['customShopAdminName'] = $shopAdminName;
  35. $connection = Yii::$app->db;
  36. $transaction = $connection->beginTransaction();
  37. try {
  38. $respond = ClearClass::addOrder($post);
  39. $transaction->commit();
  40. util::success($respond);
  41. } catch (\Exception $e) {
  42. $transaction->rollBack();
  43. Yii::info("下单失败原因:" . $e->getMessage());
  44. util::fail('下单失败');
  45. }
  46. }
  47. }