ClearController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace hd\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 bizHd\shop\classes\ShopClass;
  8. use common\components\dict;
  9. use common\components\imgUtil;
  10. use common\components\lakala\Lakala;
  11. use common\components\noticeUtil;
  12. use common\components\util;
  13. use common\components\qrCodeUtil;
  14. use Yii;
  15. class ClearController extends BaseController
  16. {
  17. public $guestAccess = ['get-full-info', 'detail', 'get-ali-pay-clear-code'];
  18. //取消结账单 ssh 20220509
  19. public function actionCancel()
  20. {
  21. $id = Yii::$app->request->get('id');
  22. $clear = ClearClass::getLockById($id);
  23. if (empty($clear)) {
  24. util::fail('没有结账信息哈');
  25. }
  26. $customId = $clear->customId ?? 0;
  27. $custom = CustomClass::getById($customId, true);
  28. $customShopId = $custom->shopId ?? 0;
  29. if ($customShopId != $this->shopId) {
  30. util::fail('没有权限');
  31. }
  32. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  33. util::fail('账单已完成');
  34. }
  35. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  36. util::fail('账单已取消');
  37. }
  38. $clear->status = ClearClass::STATUS_EXPIRE;
  39. $clear->save();
  40. $orderSn = $clear->orderSn ?? '';
  41. $ghsShopId = $clear->ghsShopId ?? 0;
  42. $ghsShop = ShopClass::getById($ghsShopId, true);
  43. if (!empty($ghsShop)) {
  44. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  45. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  46. $params = [
  47. 'appid' => 'OP00002119',
  48. 'serial_no' => '018b08cfddbd',
  49. 'merchant_no' => $ghsShop->lklSjNo,
  50. 'term_no' => $ghsShop->lklScanTermNo,
  51. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  52. 'lklCertificatePath' => $lklCertificatePath,
  53. ];
  54. $laResource = new Lakala($params);
  55. $closeParams = [
  56. 'orderSn' => $orderSn,
  57. ];
  58. $response = $laResource->close($closeParams);
  59. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  60. //$msg = $response['msg'] ?? '';
  61. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
  62. } else {
  63. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单成功", '15280215347');
  64. }
  65. //收银台关单
  66. $closeParams = ['orderSn' => $orderSn];
  67. $response = $laResource->cashClose($closeParams);
  68. if (isset($response['code']) == false || $response['code'] != '000000') {
  69. $msg = $response['msg'] ?? '';
  70. noticeUtil::push('单号:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  71. } else {
  72. noticeUtil::push('单号:' . $orderSn . ',关单成功(收银台-支付宝)', '15280215347');
  73. }
  74. }
  75. util::complete();
  76. }
  77. //结款单 ssh 20210625
  78. public function actionList()
  79. {
  80. $get = Yii::$app->request->get();
  81. $where = [];
  82. if (isset($get['status']) && is_numeric($get['status'])) {
  83. $where['status'] = $get['status'];
  84. }
  85. $ghsId = $get['ghsId'] ?? 0;
  86. if (!empty($ghsId)) {
  87. $ghs = GhsClass::getById($ghsId, true);
  88. GhsClass::valid($ghs, $this->shopId);
  89. $where['ghsId'] = $ghsId;
  90. }
  91. $where['customShopId'] = $this->shopId ?? 0;
  92. $list = ClearService::getClearList($where);
  93. util::success($list);
  94. }
  95. //获取基本信息 ssh 20210625
  96. public function actionGetFullInfo()
  97. {
  98. $id = Yii::$app->request->get('id');
  99. $info = ClearClass::getById($id);
  100. $respond = ClearClass::getCgInfo($info);
  101. util::success($respond);
  102. }
  103. //获取支付宝付款码 ssh 20240713
  104. public function actionGetAliPayClearCode()
  105. {
  106. $get = Yii::$app->request->get();
  107. $orderSn = $get['orderSn'] ?? 0;
  108. $info = ClearClass::getByCondition(['orderSn' => $orderSn], true);
  109. if (empty($info)) {
  110. util::fail('没有找到结账单');
  111. }
  112. if (getenv('YII_ENV') == 'production') {
  113. $url = "https://mall.huahb.cn/#/admin/clear/alipay?orderSn={$orderSn}";
  114. } else {
  115. $url = "https://mall.huaml.com/#/admin/clear/alipay?orderSn={$orderSn}";
  116. }
  117. $unique = "order_clear_ali_pay_" . $orderSn;
  118. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  119. $imageUrl = imgUtil::groupImg($imgUrl);
  120. util::success(['imgUrl' => $imageUrl]);
  121. }
  122. //获取结账单详情 ssh 20220509
  123. public function actionDetail()
  124. {
  125. $id = Yii::$app->request->get('id');
  126. $clear = ClearClass::getById($id);
  127. if (empty($clear)) {
  128. util::fail('没有结账信息哦');
  129. }
  130. $deadline = isset($clear['deadline']) && !empty($clear['deadline']) ? strtotime($clear['deadline']) : 0;
  131. $now = time();
  132. $remainSecond = bcsub($deadline, $now);
  133. $remainSecond = bcsub($remainSecond, 100);
  134. $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
  135. $clear['remainSecond'] = $remainSecond;
  136. $clear['hasRenew'] = 1;
  137. util::success($clear);
  138. }
  139. }