ClearController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\clear\classes\ClearClass;
  5. use bizGhs\clear\services\ClearService;
  6. use bizGhs\custom\classes\CustomClass;
  7. use common\components\lakala\Lakala;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\noticeUtil;
  11. use common\components\util;
  12. use Yii;
  13. class ClearController extends BaseController
  14. {
  15. //结账单取消了,钱给原路退回 ssh 20250501
  16. public function actionRefundMoney()
  17. {
  18. $id = Yii::$app->request->get('id', '');
  19. $info = ClearClass::getById($id, true);
  20. if ($info->ghsShopId != $this->shopId) {
  21. util::fail('不是你的结账单');
  22. }
  23. if ($info->status != 3) {
  24. util::fail('结账单没有取消,不能退钱');
  25. }
  26. $addTime = $info->addTime;
  27. $addTime = strtotime($addTime);
  28. $earTime = strtotime('2025-05-01 00:00:00');
  29. if ($addTime < $earTime) {
  30. util::fail('2025.5.1号前的订单,不能退款');
  31. }
  32. $shop = $this->shop;
  33. $respond = ClearClass::refundMoney($shop, $info);
  34. $status = $respond['status'];
  35. $msg = $respond['msg'];
  36. util::success(['status' => $status], $msg);
  37. }
  38. //获取客户待结订单明细 ssh 20220926
  39. public function actionGetUnClear()
  40. {
  41. $get = Yii::$app->request->get();
  42. $customId = $get['customId'] ?? 0;
  43. $custom = CustomClass::getById($customId, true);
  44. CustomClass::valid($custom, $this->shopId);
  45. $info = ClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  46. if (isset($info->deadline) && $info->deadline < date("Y-m-d H:i:s")) {
  47. $n = date("Y-m-d H:i:s");
  48. $info->status = 3;
  49. $info->remark = "账单过期,已自动取消,参数:{$info->deadline} {$n}";
  50. $info->save();
  51. util::success(['info' => []]);
  52. }
  53. util::success(['info' => $info]);
  54. }
  55. public function actionCancel()
  56. {
  57. $id = Yii::$app->request->get('id');
  58. $clear = ClearClass::getLockById($id);
  59. if (empty($clear)) {
  60. util::fail('没有结账信息呢');
  61. }
  62. $ghsId = $clear->ghsId ?? 0;
  63. $orderSn = $clear->orderSn ?? '';
  64. $ghs = GhsClass::getById($ghsId, true);
  65. if (empty($ghs)) {
  66. util::fail('没有找到供货商关系');
  67. }
  68. if ($ghs->shopId != $this->shopId) {
  69. util::fail('不是你的账单哦');
  70. }
  71. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  72. util::fail('账单已完成');
  73. }
  74. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  75. util::fail('账单已取消');
  76. }
  77. $clear->status = ClearClass::STATUS_EXPIRE;
  78. $clear->remark = "商家手动取消 ".date("Y-m-d H:i:s");
  79. $clear->save();
  80. $ghsShop = $this->shop;
  81. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  82. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  83. $params = [
  84. 'appid' => 'OP00002119',
  85. 'serial_no' => '018b08cfddbd',
  86. 'merchant_no' => $ghsShop->lklSjNo,
  87. 'term_no' => $ghsShop->lklScanTermNo,
  88. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  89. 'lklCertificatePath' => $lklCertificatePath,
  90. ];
  91. $laResource = new Lakala($params);
  92. $closeParams = [
  93. 'orderSn' => $orderSn,
  94. ];
  95. $response = $laResource->close($closeParams);
  96. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  97. //$msg = $response['msg'] ?? '';
  98. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
  99. }
  100. //收银台关单
  101. $closeParams = ['orderSn' => $orderSn];
  102. $response = $laResource->cashClose($closeParams);
  103. if (isset($response['code']) == false || $response['code'] != '000000') {
  104. //$msg = $response['msg'] ?? '';
  105. //noticeUtil::push('单号:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  106. }
  107. util::complete();
  108. }
  109. //城市供货商向基地批发商的结账单 ssh 20220523
  110. public function actionList()
  111. {
  112. $get = Yii::$app->request->get();
  113. $where = [];
  114. if (isset($get['status']) && is_numeric($get['status'])) {
  115. $where['status'] = $get['status'];
  116. }
  117. $ghsId = $get['ghsId'] ?? 0;
  118. if (!empty($ghsId)) {
  119. $ghs = GhsClass::getById($ghsId, true);
  120. GhsClass::valid($ghs, $this->shopId);
  121. $where['ghsId'] = $ghsId;
  122. }
  123. $where['customShopId'] = $this->shopId ?? 0;
  124. $list = ClearService::getClearList($where);
  125. util::success($list);
  126. }
  127. //获取基本信息 ssh 20210625
  128. public function actionGetFullInfo()
  129. {
  130. $id = Yii::$app->request->get('id', '');
  131. $info = clearClass::getById($id);
  132. if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
  133. util::fail('没有权限');
  134. }
  135. $respond = ClearClass::getGhsCgInfo($info);
  136. util::success($respond);
  137. }
  138. //客户的结帐单 ssh 20210625
  139. public function actionCustomList()
  140. {
  141. $get = Yii::$app->request->get();
  142. $where = [];
  143. if (isset($get['status']) && is_numeric($get['status'])) {
  144. $where['status'] = $get['status'];
  145. }
  146. $customId = $get['customId'] ?? 0;
  147. if (!empty($customId)) {
  148. $custom = CustomClass::getById($customId, true);
  149. CustomClass::valid($custom, $this->shopId);
  150. $where['customId'] = $customId;
  151. }
  152. $where['ghsShopId'] = $this->shopId ?? 0;
  153. $list = ClearService::getClearList($where);
  154. $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
  155. $list['totalAmount'] = floatval($totalAmount);
  156. util::success($list);
  157. }
  158. //获取基本信息 ssh 20210625
  159. public function actionGetCustomFullInfo()
  160. {
  161. $id = Yii::$app->request->get('id', '');
  162. $info = ClearClass::getById($id);
  163. if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
  164. util::fail('没有权限');
  165. }
  166. $respond = ClearClass::getSaleInfo($info);
  167. //分享结账单时,显示的标题里面,如果是首店或总店,不显示店名
  168. $respond['ghsShopName'] = isset($respond['ghsShopName']) && $respond['ghsShopName'] == '总店' ? '' : $respond['ghsShopName'];
  169. util::success($respond);
  170. }
  171. }