ClearController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\noticeUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ClearController extends BaseController
  13. {
  14. public $guestAccess = ['get-full-info', 'detail'];
  15. //取消结账单 ssh 20220509
  16. public function actionCancel()
  17. {
  18. $id = Yii::$app->request->get('id');
  19. $clear = ClearClass::getLockById($id);
  20. if (empty($clear)) {
  21. util::fail('没有结账信息');
  22. }
  23. $customId = $clear->customId ?? 0;
  24. $custom = CustomClass::getById($customId, true);
  25. $customShopId = $custom->shopId ?? 0;
  26. if ($customShopId != $this->shopId) {
  27. util::fail('没有权限');
  28. }
  29. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  30. util::fail('账单已完成');
  31. }
  32. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  33. util::fail('账单已取消');
  34. }
  35. $clear->status = ClearClass::STATUS_EXPIRE;
  36. $clear->save();
  37. $orderSn = $clear->orderSn ?? '';
  38. $ghsShopId = $clear->ghsShopId ?? 0;
  39. $ghsShop = ShopClass::getById($ghsShopId, true);
  40. if (!empty($ghsShop)) {
  41. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  42. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  43. $params = [
  44. 'appid' => 'OP00002119',
  45. 'serial_no' => '018b08cfddbd',
  46. 'merchant_no' => $ghsShop->lklSjNo,
  47. 'term_no' => $ghsShop->lklScanTermNo,
  48. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  49. 'lklCertificatePath' => $lklCertificatePath,
  50. ];
  51. $laResource = new Lakala($params);
  52. $closeParams = [
  53. 'orderSn' => $orderSn,
  54. ];
  55. $response = $laResource->close($closeParams);
  56. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  57. $msg = $response['msg'] ?? '';
  58. noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
  59. } else {
  60. noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单成功", '15280215347');
  61. }
  62. }
  63. util::complete();
  64. }
  65. //结款单 ssh 20210625
  66. public function actionList()
  67. {
  68. $get = Yii::$app->request->get();
  69. $where = [];
  70. if (isset($get['status']) && is_numeric($get['status'])) {
  71. $where['status'] = $get['status'];
  72. }
  73. $ghsId = $get['ghsId'] ?? 0;
  74. if (!empty($ghsId)) {
  75. $ghs = GhsClass::getById($ghsId, true);
  76. GhsClass::valid($ghs, $this->shopId);
  77. $where['ghsId'] = $ghsId;
  78. }
  79. $where['customShopId'] = $this->shopId ?? 0;
  80. $list = ClearService::getClearList($where);
  81. util::success($list);
  82. }
  83. //获取基本信息 ssh 20210625
  84. public function actionGetFullInfo()
  85. {
  86. $id = Yii::$app->request->get('id');
  87. $info = ClearClass::getById($id);
  88. $respond = ClearClass::getCgInfo($info);
  89. util::success($respond);
  90. }
  91. //获取结账单详情 ssh 20220509
  92. public function actionDetail()
  93. {
  94. $id = Yii::$app->request->get('id');
  95. $clear = ClearClass::getById($id);
  96. if (empty($clear)) {
  97. util::fail('没有结账信息');
  98. }
  99. $deadline = isset($clear['deadline']) && !empty($clear['deadline']) ? strtotime($clear['deadline']) : 0;
  100. $now = time();
  101. $remainSecond = bcsub($deadline, $now);
  102. $remainSecond = bcsub($remainSecond, 100);
  103. $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
  104. $clear['remainSecond'] = $remainSecond;
  105. util::success($clear);
  106. }
  107. }