ClearController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. $info->status = 3;
  48. $info->save();
  49. util::success(['info' => []]);
  50. }
  51. util::success(['info' => $info]);
  52. }
  53. public function actionCancel()
  54. {
  55. $id = Yii::$app->request->get('id');
  56. $clear = ClearClass::getLockById($id);
  57. if (empty($clear)) {
  58. util::fail('没有结账信息呢');
  59. }
  60. $ghsId = $clear->ghsId ?? 0;
  61. $orderSn = $clear->orderSn ?? '';
  62. $ghs = GhsClass::getById($ghsId, true);
  63. if (empty($ghs)) {
  64. util::fail('没有找到供货商关系');
  65. }
  66. if ($ghs->shopId != $this->shopId) {
  67. util::fail('不是你的账单哦');
  68. }
  69. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  70. util::fail('账单已完成');
  71. }
  72. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  73. util::fail('账单已取消');
  74. }
  75. $clear->status = ClearClass::STATUS_EXPIRE;
  76. $clear->save();
  77. $ghsShop = $this->shop;
  78. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  79. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  80. $params = [
  81. 'appid' => 'OP00002119',
  82. 'serial_no' => '018b08cfddbd',
  83. 'merchant_no' => $ghsShop->lklSjNo,
  84. 'term_no' => $ghsShop->lklScanTermNo,
  85. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  86. 'lklCertificatePath' => $lklCertificatePath,
  87. ];
  88. $laResource = new Lakala($params);
  89. $closeParams = [
  90. 'orderSn' => $orderSn,
  91. ];
  92. $response = $laResource->close($closeParams);
  93. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  94. //$msg = $response['msg'] ?? '';
  95. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
  96. }
  97. //收银台关单
  98. $closeParams = ['orderSn' => $orderSn];
  99. $response = $laResource->cashClose($closeParams);
  100. if (isset($response['code']) == false || $response['code'] != '000000') {
  101. //$msg = $response['msg'] ?? '';
  102. //noticeUtil::push('单号:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  103. }
  104. util::complete();
  105. }
  106. //城市供货商向基地批发商的结账单 ssh 20220523
  107. public function actionList()
  108. {
  109. $get = Yii::$app->request->get();
  110. $where = [];
  111. if (isset($get['status']) && is_numeric($get['status'])) {
  112. $where['status'] = $get['status'];
  113. }
  114. $ghsId = $get['ghsId'] ?? 0;
  115. if (!empty($ghsId)) {
  116. $ghs = GhsClass::getById($ghsId, true);
  117. GhsClass::valid($ghs, $this->shopId);
  118. $where['ghsId'] = $ghsId;
  119. }
  120. $where['customShopId'] = $this->shopId ?? 0;
  121. $list = ClearService::getClearList($where);
  122. util::success($list);
  123. }
  124. //获取基本信息 ssh 20210625
  125. public function actionGetFullInfo()
  126. {
  127. $id = Yii::$app->request->get('id', '');
  128. $info = clearClass::getById($id);
  129. if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
  130. util::fail('没有权限');
  131. }
  132. $respond = ClearClass::getGhsCgInfo($info);
  133. util::success($respond);
  134. }
  135. //客户的结帐单 ssh 20210625
  136. public function actionCustomList()
  137. {
  138. $get = Yii::$app->request->get();
  139. $where = [];
  140. if (isset($get['status']) && is_numeric($get['status'])) {
  141. $where['status'] = $get['status'];
  142. }
  143. $customId = $get['customId'] ?? 0;
  144. if (!empty($customId)) {
  145. $custom = CustomClass::getById($customId, true);
  146. CustomClass::valid($custom, $this->shopId);
  147. $where['customId'] = $customId;
  148. }
  149. $where['ghsShopId'] = $this->shopId ?? 0;
  150. $list = ClearService::getClearList($where);
  151. $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
  152. $list['totalAmount'] = floatval($totalAmount);
  153. util::success($list);
  154. }
  155. //获取基本信息 ssh 20210625
  156. public function actionGetCustomFullInfo()
  157. {
  158. $id = Yii::$app->request->get('id', '');
  159. $info = ClearClass::getById($id);
  160. if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
  161. util::fail('没有权限');
  162. }
  163. $respond = ClearClass::getSaleInfo($info);
  164. //分享结账单时,显示的标题里面,如果是首店或总店,不显示店名
  165. $respond['ghsShopName'] = isset($respond['ghsShopName']) && $respond['ghsShopName'] == '总店' ? '' : $respond['ghsShopName'];
  166. util::success($respond);
  167. }
  168. }