ClearController.php 5.6 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->remark = "客户手动取消 ".date('Y-m-d H:i:s');
  40. $clear->save();
  41. $orderSn = $clear->orderSn ?? '';
  42. $ghsShopId = $clear->ghsShopId ?? 0;
  43. $ghsShop = ShopClass::getById($ghsShopId, true);
  44. if (!empty($ghsShop)) {
  45. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  46. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  47. $params = [
  48. 'appid' => 'OP00002119',
  49. 'serial_no' => '018b08cfddbd',
  50. 'merchant_no' => $ghsShop->lklSjNo,
  51. 'term_no' => $ghsShop->lklScanTermNo,
  52. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  53. 'lklCertificatePath' => $lklCertificatePath,
  54. ];
  55. $laResource = new Lakala($params);
  56. $closeParams = [
  57. 'orderSn' => $orderSn,
  58. ];
  59. $response = $laResource->close($closeParams);
  60. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  61. $msg = $response['msg'] ?? '';
  62. $code = $response['code'] ?? 0;
  63. if (!in_array($code, ['BBS11114'])) {
  64. noticeUtil::push("花店结账:" . $orderSn . " 关单没有成功 {$msg} {$code}", '15280215347');
  65. }
  66. }
  67. //收银台关单
  68. $closeParams = ['orderSn' => $orderSn];
  69. $response = $laResource->cashClose($closeParams);
  70. if (isset($response['code']) == false || $response['code'] != '000000') {
  71. $msg = $response['msg'] ?? '';
  72. $code = $response['code'] ?? 0;
  73. if (!in_array($code, ['000091'])) {
  74. noticeUtil::push('花店结账:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg . $code, '15280215347');
  75. }
  76. }
  77. }
  78. util::complete();
  79. }
  80. //结款单 ssh 20210625
  81. public function actionList()
  82. {
  83. $get = Yii::$app->request->get();
  84. $where = [];
  85. if (isset($get['status']) && is_numeric($get['status'])) {
  86. $where['status'] = $get['status'];
  87. }
  88. $ghsId = $get['ghsId'] ?? 0;
  89. if (!empty($ghsId)) {
  90. $ghs = GhsClass::getById($ghsId, true);
  91. GhsClass::valid($ghs, $this->shopId);
  92. $where['ghsId'] = $ghsId;
  93. }
  94. $where['customShopId'] = $this->shopId ?? 0;
  95. $list = ClearService::getClearList($where);
  96. util::success($list);
  97. }
  98. //获取基本信息 ssh 20210625
  99. public function actionGetFullInfo()
  100. {
  101. $id = Yii::$app->request->get('id');
  102. $info = ClearClass::getById($id);
  103. $respond = ClearClass::getCgInfo($info);
  104. util::success($respond);
  105. }
  106. //获取支付宝付款码 ssh 20240713
  107. public function actionGetAliPayClearCode()
  108. {
  109. $get = Yii::$app->request->get();
  110. $orderSn = $get['orderSn'] ?? 0;
  111. $info = ClearClass::getByCondition(['orderSn' => $orderSn], true);
  112. if (empty($info)) {
  113. util::fail('没有找到结账单');
  114. }
  115. if (getenv('YII_ENV') == 'production') {
  116. $url = "https://mall.huahb.cn/#/admin/clear/alipay?orderSn={$orderSn}";
  117. } else {
  118. $url = "https://mall.huaml.com/#/admin/clear/alipay?orderSn={$orderSn}";
  119. }
  120. $unique = "order_clear_ali_pay_" . $orderSn;
  121. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  122. $imageUrl = imgUtil::groupImg($imgUrl);
  123. util::success(['imgUrl' => $imageUrl]);
  124. }
  125. //获取结账单详情 ssh 20220509
  126. public function actionDetail()
  127. {
  128. $id = Yii::$app->request->get('id');
  129. $clear = ClearClass::getById($id);
  130. if (empty($clear)) {
  131. util::fail('没有结账信息哦');
  132. }
  133. $deadline = isset($clear['deadline']) && !empty($clear['deadline']) ? strtotime($clear['deadline']) : 0;
  134. $now = time();
  135. $remainSecond = bcsub($deadline, $now);
  136. $remainSecond = bcsub($remainSecond, 100);
  137. $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
  138. $clear['remainSecond'] = $remainSecond;
  139. $clear['hasRenew'] = 1;
  140. util::success($clear);
  141. }
  142. }