ClearController.php 4.0 KB

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