PurchaseClearController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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([
  16. 'clearStyle' => dict::getDict('clearStyle', 'gys2KmGys'),
  17. 'shopId' => $this->shopId,
  18. 'status' => PurchaseClearClass::STATUS_AWAIT_PAY
  19. ], null, '*', null, true);
  20. if (!empty($list)) {
  21. foreach ($list as $item) {
  22. $deadline = $item->deadline;
  23. $deadTime = strtotime($deadline);
  24. if ($current > $deadTime) {
  25. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  26. $item->save();
  27. } else {
  28. util::fail('还有待付款的结账单');
  29. }
  30. }
  31. }
  32. $post['sjId'] = $this->sjId;
  33. $post['shopId'] = $this->shopId;
  34. $post['clearStyle'] = dict::getDict('clearStyle', 'gys2KmGys');
  35. $post['customShopAdminId'] = $this->shopAdminId;
  36. $post['customShopId'] = $this->shopId ?? 0;
  37. $shopAdmin = $this->shopAdmin;
  38. $shopAdminName = $shopAdmin['name'] ?? '';
  39. $post['customShopAdminName'] = $shopAdminName;
  40. $connection = Yii::$app->db;
  41. $transaction = $connection->beginTransaction();
  42. try {
  43. $respond = ClearClass::addOrder($post);
  44. $transaction->commit();
  45. util::success($respond);
  46. } catch (\Exception $e) {
  47. $transaction->rollBack();
  48. Yii::info("下单失败原因:" . $e->getMessage());
  49. util::fail('下单失败');
  50. }
  51. }
  52. }