SettleController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\order\classes\SettleClass;
  4. use bizHd\recharge\classes\RechargeClass;
  5. use bizHd\wx\classes\WxOpenClass;
  6. use bizMall\order\classes\OrderClass;
  7. use common\components\dict;
  8. use common\components\lakala\Lakala;
  9. use common\components\noticeUtil;
  10. use common\components\orderSn;
  11. use common\components\util;
  12. use Yii;
  13. class SettleController extends BaseController
  14. {
  15. public $guestAccess = [];
  16. public function actionGetDetail()
  17. {
  18. $get = Yii::$app->request->get();
  19. $id = $get['id'] ?? 0;
  20. $settle = SettleClass::getById($id);
  21. if ($settle['customUserId'] != $this->userId) {
  22. util::fail('不是你的账单');
  23. }
  24. $respond = SettleClass::getMyDetail($settle);
  25. util::success($respond);
  26. }
  27. public function actionCancelSettle()
  28. {
  29. util::fail('开发中');
  30. }
  31. public function actionGetList()
  32. {
  33. $get = Yii::$app->request->get();
  34. $where = [];
  35. if (isset($get['status']) && is_numeric($get['status'])) {
  36. $where['status'] = $get['status'];
  37. }
  38. $hdId = $get['hdId'] ?? 0;
  39. if (!empty($hdId)) {
  40. //BaseController文件有判断是否本人花店,这里不需要再判断
  41. $where['hdId'] = $hdId;
  42. }
  43. $where['shopId'] = $this->shopId;
  44. $list = \bizMall\settle\classes\SettleClass::getSettleList($where);
  45. $totalAmount = SettleClass::sum(['shopId' => $this->shopId, 'status' => 2, 'hdId' => $hdId], 'actPrice');
  46. $list['totalAmount'] = floatval($totalAmount);
  47. util::success($list);
  48. }
  49. //创建结账和充值单 ssh 20250709
  50. public function actionCreateOrder()
  51. {
  52. $post = Yii::$app->request->post();
  53. $shop = $this->shop;
  54. if (empty($shop)) {
  55. util::fail('没有门店信息');
  56. }
  57. $hd = $this->hd;
  58. if (empty($hd)) {
  59. util::fail('没有花店信息呢');
  60. }
  61. $custom = $this->custom;
  62. if (empty($custom)) {
  63. util::fail('花店信息缺失');
  64. }
  65. $idList = $post['ids'] ?? '';
  66. $idList = trim($idList);
  67. if (empty($idList)) {
  68. util::fail('请选择订单');
  69. }
  70. $ids = explode(',', $idList);
  71. if (empty($ids)) {
  72. util::fail('请选择订单哦');
  73. }
  74. $mayClearAmount = 0;
  75. $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  76. if (empty($orderList)) {
  77. util::fail('没有选订单');
  78. }
  79. foreach ($orderList as $order) {
  80. if ($order->mainId != $this->mainId) {
  81. util::fail('不是你的订单呢');
  82. }
  83. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  84. $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
  85. }
  86. if (empty($mayClearAmount)) {
  87. util::fail('不需要销账');
  88. }
  89. $orderSn = orderSn::getRechargeSn();
  90. $payWay = 0;
  91. $shopId = $this->shopId;
  92. $mainId = $this->mainId;
  93. $hdId = $hd->id;
  94. $hdName = $hd->name;
  95. $staffId = 0;
  96. $staffName = '';
  97. $customId = $custom->id;
  98. $customName = $custom->name;
  99. $userId = $this->userId;
  100. $settleParams = [];
  101. $staff = [];
  102. //避免重复提交
  103. util::checkRepeatCommit($userId, 8);
  104. $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  105. if (!empty($hasSettle)) {
  106. util::fail('这个客户名下有待结账单,请先取消');
  107. }
  108. //创建待账单
  109. $settle = SettleClass::addSettle($orderList, $shop, $custom, $hd, $staff, $settleParams);
  110. $settleId = $settle->id;
  111. $settleAmount = $settle->actPrice;
  112. $settleNo = $settle->orderSn ?? '';
  113. $createData = [
  114. 'customId' => $customId,
  115. 'customName' => $customName,
  116. 'userId' => $userId,
  117. 'orderSn' => $orderSn,
  118. 'modPrice' => 1,
  119. 'payWay' => $payWay,
  120. 'style' => 1,
  121. 'shopId' => $shopId,
  122. 'mainId' => $mainId,
  123. 'hdId' => $hdId,
  124. 'hdName' => $hdName,
  125. 'onlinePay' => 1,
  126. 'amount' => $mayClearAmount,
  127. 'staffId' => $staffId,
  128. 'staffName' => $staffName,
  129. 'payStatus' => 0,
  130. 'payTime' => '0000-00-00 00:00:00',
  131. 'status' => 0,
  132. 'settleId' => $settleId,
  133. 'settleAmount' => $settleAmount,
  134. 'settleNo' => $settleNo,
  135. 'remark' => '',
  136. ];
  137. $respond = RechargeClass::addRecharge($createData);
  138. util::success($respond);
  139. }
  140. }