OrderClearController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use bizGhs\order\classes\OrderClearClass;
  6. use bizHd\purchase\classes\PurchaseClearClass;
  7. use common\components\dateUtil;
  8. use common\components\dict;
  9. use Yii;
  10. use common\components\util;
  11. class OrderClearController extends BaseController
  12. {
  13. //收款 ssh 2021.2.4
  14. public function actionClear()
  15. {
  16. $post = Yii::$app->request->post();
  17. $shopAdmin = $this->shopAdmin;
  18. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  19. util::fail('超管才能结帐');
  20. }
  21. $id = Yii::$app->request->post('id');
  22. $customId = Yii::$app->request->post('customId', 0);
  23. if (empty($id)) {
  24. util::fail('请选择交易记录');
  25. }
  26. //抹零之后的价格
  27. $modifyPrice = Yii::$app->request->post('modifyPrice', 0.00);
  28. if (is_numeric($modifyPrice) == false || $modifyPrice <= 0) {
  29. util::fail('金额填错了哦');
  30. }
  31. $custom = CustomClass::getById($customId, true);
  32. CustomClass::valid($custom, $this->shopId);
  33. $current = time();
  34. $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
  35. $searchTime = $post['searchTime'] ?? '';
  36. //结账记录太多数据库会报错,所以必须选月份才能结账!!!!!
  37. //订单详情里可以单个结账
  38. if (count((array)$id) > 100) {
  39. util::fail('订单太多,请选月份再结');
  40. }
  41. $startTime = $post['startTime'] ?? '';
  42. $endTime = $post['endTime'] ?? '';
  43. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  44. $startDate = $period['startTime'];
  45. $endDate = $period['endTime'];
  46. if (bcdiv(bcsub(strtotime($endDate), strtotime($startDate)), 86400) > 50) {
  47. util::fail('超过30天,请按月结账');
  48. }
  49. //查找有没结帐订单还没有过期
  50. $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
  51. if (!empty($list)) {
  52. foreach ($list as $item) {
  53. $deadline = $item->deadline;
  54. $deadTime = strtotime($deadline);
  55. if ($current > $deadTime) {
  56. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  57. $item->save();
  58. } else {
  59. util::success(['hasUnComplete' => 1], '此客户还有待完成结账单');
  60. }
  61. }
  62. }
  63. $payWay = Yii::$app->request->post('payWay', 0);
  64. $connection = Yii::$app->db;
  65. $transaction = $connection->beginTransaction();
  66. $name = $this->shopAdmin['name'] ?? '';
  67. $data = [
  68. 'customId' => $customId,
  69. 'ghsShopAdminId' => $this->shopAdminId,
  70. 'ghsShopAdminName' => $name,
  71. 'modifyPrice' => $modifyPrice,
  72. 'payWay' => $payWay,
  73. ];
  74. try {
  75. $respond = OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);
  76. $transaction->commit();
  77. util::success($respond);
  78. } catch (\Exception $exception) {
  79. $transaction->rollBack();
  80. Yii::info("批量收款失败:" . $exception->getMessage());
  81. util::fail('操作失败');
  82. }
  83. util::complete();
  84. }
  85. //确认结账 ssh 20220510
  86. public function actionConfirmClear()
  87. {
  88. $get = Yii::$app->request->get();
  89. $id = $get['id'] ?? 0;
  90. $payWay = $get['payWay'] ?? dict::getDict('payWay', 'wxPay');
  91. $clear = OrderClearClass::getById($id, true);
  92. if (empty($clear)) {
  93. util::fail('没有找到结账单');
  94. }
  95. $ghsId = $clear->ghsId ?? 0;
  96. $ghs = GhsClass::getById($ghsId, true);
  97. if ($ghs->shopId != $this->shopId) {
  98. util::fail('没有权限');
  99. }
  100. $connection = Yii::$app->db;
  101. $transaction = $connection->beginTransaction();
  102. try {
  103. OrderClearClass::confirmClear($clear, $payWay);
  104. $transaction->commit();
  105. util::complete();
  106. } catch (\Exception $exception) {
  107. $transaction->rollBack();
  108. Yii::info("失败:" . $exception->getMessage());
  109. util::fail('操作失败');
  110. }
  111. }
  112. }