ClearController.php 5.1 KB

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