SettleController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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('花店信息缺失,编号88611');
  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. $myClearData = [];
  80. foreach ($orderList as $order) {
  81. if ($order->mainId != $this->mainId) {
  82. util::fail('不是你的订单呢');
  83. }
  84. $orderId = $order->id;
  85. $orderSn = $order->orderSn ?? '';
  86. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  87. $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
  88. $myClearData[] = ['orderId' => $orderId, 'clearAmount' => $remainDebtPrice, 'orderSn' => $orderSn];
  89. }
  90. if ($mayClearAmount <= 0) {
  91. util::fail('不需要销账');
  92. }
  93. $orderSn = orderSn::getRechargeSn();
  94. $payWay = 0;
  95. $shopId = $this->shopId;
  96. $mainId = $this->mainId;
  97. $hdId = $hd->id;
  98. $hdName = $hd->name;
  99. $staffId = 0;
  100. $staffName = '';
  101. $customId = $custom->id;
  102. $customName = $custom->name;
  103. $userId = $this->userId;
  104. $staff = [];
  105. //避免重复提交
  106. util::checkRepeatCommit($userId, 6);
  107. $createData = [
  108. 'customId' => $customId,
  109. 'customName' => $customName,
  110. 'userId' => $userId,
  111. 'orderSn' => $orderSn,
  112. 'modPrice' => 1,
  113. 'payWay' => $payWay,
  114. 'style' => 1,
  115. 'shopId' => $shopId,
  116. 'mainId' => $mainId,
  117. 'hdId' => $hdId,
  118. 'hdName' => $hdName,
  119. 'onlinePay' => 1,
  120. 'amount' => $mayClearAmount,
  121. 'staffId' => $staffId,
  122. 'staffName' => $staffName,
  123. 'payStatus' => 0,
  124. 'payTime' => '0000-00-00 00:00:00',
  125. 'status' => 0,
  126. 'remark' => '',
  127. ];
  128. $respond = RechargeClass::addRecharge($createData);
  129. //创建待账单
  130. $settle = SettleClass::addSettle($myClearData, $shop, $custom, $hd, $staff);
  131. $settleId = $settle->id;
  132. $settleAmount = $settle->actPrice;
  133. $settleNo = $settle->orderSn ?? '';
  134. $respond->settleId = $settleId;
  135. $respond->settleAmount = $settleAmount;
  136. $respond->settleNo = $settleNo;
  137. $respond->save();
  138. util::success($respond);
  139. }
  140. }