OrderClearController.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\order\classes\OrderClearClass;
  5. use bizHd\purchase\classes\PurchaseClearClass;
  6. use common\components\dateUtil;
  7. use Yii;
  8. use common\components\util;
  9. class OrderClearController extends BaseController
  10. {
  11. //收款 ssh 2021.2.4
  12. public function actionClear()
  13. {
  14. $shopAdmin = $this->shopAdmin;
  15. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  16. util::fail('超管才能结帐');
  17. }
  18. $id = Yii::$app->request->post('id');
  19. $customId = Yii::$app->request->post('customId', 0);
  20. if (empty($id)) {
  21. util::fail('请选择交易记录');
  22. }
  23. //抹零之后的价格
  24. $modifyPrice = Yii::$app->request->post('modifyPrice', 0.00);
  25. if (is_numeric($modifyPrice) == false || $modifyPrice <= 0) {
  26. util::fail('金额填错了哦');
  27. }
  28. $custom = CustomClass::getById($customId, true);
  29. CustomClass::valid($custom, $this->shopId);
  30. $current = time();
  31. $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
  32. $searchTime = $get['searchTime'] ?? '';
  33. //结账记录太多数据库会报错,所以必须选月份才能结账!!!!!
  34. if (empty($searchTime)) {
  35. util::fail('请选择月份');
  36. }
  37. $startTime = $get['startTime'] ?? '';
  38. $endTime = $get['endTime'] ?? '';
  39. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  40. $startDate = $period['startTime'];
  41. $endDate = $period['endTime'];
  42. $where['addTime'] = ['between', [$startDate, $endDate]];
  43. if (bcdiv(bcsub(strtotime($endDate), strtotime($startDate)), 86400) > 50) {
  44. util::fail('超过30天,请按月结账');
  45. }
  46. //查找有没结帐订单还没有过期
  47. $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
  48. if (!empty($list)) {
  49. foreach ($list as $item) {
  50. $deadline = $item->deadline;
  51. $deadTime = strtotime($deadline);
  52. if ($current > $deadTime) {
  53. $item->status = PurchaseClearClass::STATUS_EXPIRE;
  54. $item->save();
  55. } else {
  56. util::fail('客户是否也在结账?请几分钟后再试');
  57. }
  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. $data = [
  65. 'customId' => $customId,
  66. 'ghsShopAdminId' => $this->shopAdminId,
  67. 'ghsShopAdminName' => $name,
  68. 'modifyPrice' => $modifyPrice,
  69. 'payWay' => $payWay,
  70. ];
  71. try {
  72. OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);
  73. $transaction->commit();
  74. } catch (\Exception $exception) {
  75. $transaction->rollBack();
  76. Yii::info("批量收款失败:" . $exception->getMessage());
  77. util::fail('操作失败');
  78. }
  79. util::complete();
  80. }
  81. }