OrderClearController.php 4.4 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. $info = OrderClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  34. if (!empty($info)) {
  35. util::fail('已有待结账单,请先取消或提醒客户付款');
  36. }
  37. $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
  38. $searchTime = $post['searchTime'] ?? '';
  39. //结账记录太多数据库会报错,所以必须选月份才能结账!!!!!
  40. //订单详情里可以单个结账
  41. if (count((array)$id) > 135) {
  42. util::fail('提交订单数超过135单');
  43. }
  44. $startTime = $post['startTime'] ?? '';
  45. $endTime = $post['endTime'] ?? '';
  46. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  47. $startDate = $period['startTime'];
  48. $endDate = $period['endTime'];
  49. if (bcdiv(bcsub(strtotime($endDate), strtotime($startDate)), 86400) > 50) {
  50. util::fail('超过30天,请按月结账');
  51. }
  52. $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
  53. if (!empty($list)) {
  54. foreach ($list as $item) {
  55. //只要新建账单,老账单就取消掉
  56. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  57. $item->save();
  58. }
  59. }
  60. $payWay = Yii::$app->request->post('payWay', 0);
  61. $connection = Yii::$app->db;
  62. $transaction = $connection->beginTransaction();
  63. $name = $this->shopAdmin['name'] ?? '';
  64. $complete = $post['complete'] ?? 0;
  65. $data = [
  66. 'customId' => $customId,
  67. 'ghsShopAdminId' => $this->shopAdminId ?? 0,
  68. 'ghsShopId' => $this->shopId ?? 0,
  69. 'ghsShopAdminName' => $name,
  70. 'modifyPrice' => $modifyPrice,
  71. 'payWay' => $payWay,
  72. 'complete' => $complete,
  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. }