SettleController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. //创建结账和充值单 ssh 20250709
  17. public function actionCreateOrder()
  18. {
  19. $post = Yii::$app->request->post();
  20. $shop = $this->shop;
  21. if (empty($shop)) {
  22. util::fail('没有门店信息');
  23. }
  24. $hd = $this->hd;
  25. if (empty($hd)) {
  26. util::fail('没有花店信息呢');
  27. }
  28. $custom = $this->custom;
  29. if (empty($custom)) {
  30. util::fail('花店信息缺失');
  31. }
  32. $idList = $post['ids'] ?? '';
  33. $idList = trim($idList);
  34. if (empty($idList)) {
  35. util::fail('请选择订单');
  36. }
  37. $ids = explode(',', $idList);
  38. if (empty($ids)) {
  39. util::fail('请选择订单哦');
  40. }
  41. $mayClearAmount = 0;
  42. $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  43. if (empty($orderList)) {
  44. util::fail('没有选订单');
  45. }
  46. foreach ($orderList as $order) {
  47. if ($order->mainId != $this->mainId) {
  48. util::fail('不是你的订单呢');
  49. }
  50. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  51. $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
  52. }
  53. if (empty($mayClearAmount)) {
  54. util::fail('不需要销账');
  55. }
  56. $orderSn = orderSn::getRechargeSn();
  57. $payWay = 0;
  58. $shopId = $this->shopId;
  59. $mainId = $this->mainId;
  60. $hdId = $hd->id;
  61. $hdName = $hd->name;
  62. $staffId = 0;
  63. $staffName = '';
  64. $customId = $custom->id;
  65. $customName = $custom->name;
  66. $userId = $this->userId;
  67. $settleParams = [];
  68. $staff = [];
  69. //避免重复提交
  70. util::checkRepeatCommit($userId, 8);
  71. $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  72. if (!empty($hasSettle)) {
  73. util::fail('这个客户名下有待结账单,请先取消');
  74. }
  75. //创建待账单
  76. $settle = SettleClass::addSettle($orderList, $shop, $custom, $hd, $staff, $settleParams);
  77. $settleId = $settle->id;
  78. $settleAmount = $settle->actPrice;
  79. $createData = [
  80. 'customId' => $customId,
  81. 'customName' => $customName,
  82. 'userId' => $userId,
  83. 'orderSn' => $orderSn,
  84. 'modPrice' => 1,
  85. 'payWay' => $payWay,
  86. 'style' => 1,
  87. 'shopId' => $shopId,
  88. 'mainId' => $mainId,
  89. 'hdId' => $hdId,
  90. 'hdName' => $hdName,
  91. 'onlinePay' => 1,
  92. 'amount' => $mayClearAmount,
  93. 'staffId' => $staffId,
  94. 'staffName' => $staffName,
  95. 'payStatus' => 0,
  96. 'payTime' => '0000-00-00 00:00:00',
  97. 'status' => 0,
  98. 'settleId' => $settleId,
  99. 'settleAmount' => $settleAmount,
  100. 'remark' => '',
  101. ];
  102. $respond = RechargeClass::addRecharge($createData);
  103. util::success($respond);
  104. }
  105. }