ClearController.php 6.3 KB

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