ClearController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. $code = $response['code'] ?? 0;
  62. if (!in_array($code, ['BBS11114'])) {
  63. noticeUtil::push("花店结账:" . $orderSn . " 关单没有成功 {$msg} {$code}", '15280215347');
  64. }
  65. }
  66. //收银台关单
  67. $closeParams = ['orderSn' => $orderSn];
  68. $response = $laResource->cashClose($closeParams);
  69. if (isset($response['code']) == false || $response['code'] != '000000') {
  70. $msg = $response['msg'] ?? '';
  71. $code = $response['code'] ?? 0;
  72. if (!in_array($code, ['000091'])) {
  73. noticeUtil::push('花店结账:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg . $code, '15280215347');
  74. }
  75. }
  76. }
  77. util::complete();
  78. }
  79. //结款单 ssh 20210625
  80. public function actionList()
  81. {
  82. $get = Yii::$app->request->get();
  83. $where = [];
  84. if (isset($get['status']) && is_numeric($get['status'])) {
  85. $where['status'] = $get['status'];
  86. }
  87. $ghsId = $get['ghsId'] ?? 0;
  88. if (!empty($ghsId)) {
  89. $ghs = GhsClass::getById($ghsId, true);
  90. GhsClass::valid($ghs, $this->shopId);
  91. $where['ghsId'] = $ghsId;
  92. }
  93. $where['customShopId'] = $this->shopId ?? 0;
  94. $list = ClearService::getClearList($where);
  95. util::success($list);
  96. }
  97. //获取基本信息 ssh 20210625
  98. public function actionGetFullInfo()
  99. {
  100. $id = Yii::$app->request->get('id');
  101. $info = ClearClass::getById($id);
  102. $respond = ClearClass::getCgInfo($info);
  103. util::success($respond);
  104. }
  105. //获取支付宝付款码 ssh 20240713
  106. public function actionGetAliPayClearCode()
  107. {
  108. $get = Yii::$app->request->get();
  109. $orderSn = $get['orderSn'] ?? 0;
  110. $info = ClearClass::getByCondition(['orderSn' => $orderSn], true);
  111. if (empty($info)) {
  112. util::fail('没有找到结账单');
  113. }
  114. if (getenv('YII_ENV') == 'production') {
  115. $url = "https://mall.huahb.cn/#/admin/clear/alipay?orderSn={$orderSn}";
  116. } else {
  117. $url = "https://mall.huaml.com/#/admin/clear/alipay?orderSn={$orderSn}";
  118. }
  119. $unique = "order_clear_ali_pay_" . $orderSn;
  120. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  121. $imageUrl = imgUtil::groupImg($imgUrl);
  122. util::success(['imgUrl' => $imageUrl]);
  123. }
  124. //获取结账单详情 ssh 20220509
  125. public function actionDetail()
  126. {
  127. $id = Yii::$app->request->get('id');
  128. $clear = ClearClass::getById($id);
  129. if (empty($clear)) {
  130. util::fail('没有结账信息哦');
  131. }
  132. $deadline = isset($clear['deadline']) && !empty($clear['deadline']) ? strtotime($clear['deadline']) : 0;
  133. $now = time();
  134. $remainSecond = bcsub($deadline, $now);
  135. $remainSecond = bcsub($remainSecond, 100);
  136. $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
  137. $clear['remainSecond'] = $remainSecond;
  138. $clear['hasRenew'] = 1;
  139. util::success($clear);
  140. }
  141. }