ClearController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace ghs\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 common\components\lakala\Lakala;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\noticeUtil;
  11. use common\components\util;
  12. use Yii;
  13. class ClearController extends BaseController
  14. {
  15. //获取客户待结订单明细 ssh 20220926
  16. public function actionGetUnClear()
  17. {
  18. $get = Yii::$app->request->get();
  19. $customId = $get['customId'] ?? 0;
  20. $custom = CustomClass::getById($customId, true);
  21. CustomClass::valid($custom, $this->shopId);
  22. $info = ClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  23. if (isset($info->deadline) && $info->deadline < date("Y-m-d H:i:s")) {
  24. $info->status = 3;
  25. $info->save();
  26. util::success(['info' => []]);
  27. }
  28. util::success(['info' => $info]);
  29. }
  30. public function actionCancel()
  31. {
  32. $id = Yii::$app->request->get('id');
  33. $clear = ClearClass::getLockById($id);
  34. if (empty($clear)) {
  35. util::fail('没有结账信息');
  36. }
  37. $ghsId = $clear->ghsId ?? 0;
  38. $orderSn = $clear->orderSn ?? '';
  39. $ghs = GhsClass::getById($ghsId, true);
  40. if (empty($ghs)) {
  41. util::fail('没有找到供货商关系');
  42. }
  43. if ($ghs->shopId != $this->shopId) {
  44. util::fail('不是你的账单哦');
  45. }
  46. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  47. util::fail('账单已完成');
  48. }
  49. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  50. util::fail('账单已取消');
  51. }
  52. $clear->status = ClearClass::STATUS_EXPIRE;
  53. $clear->save();
  54. $ghsShop = $this->shop;
  55. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  56. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  57. $params = [
  58. 'appid' => 'OP00002119',
  59. 'serial_no' => '018b08cfddbd',
  60. 'merchant_no' => $ghsShop->lklSjNo,
  61. 'term_no' => $ghsShop->lklScanTermNo,
  62. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  63. 'lklCertificatePath' => $lklCertificatePath,
  64. ];
  65. $laResource = new Lakala($params);
  66. $closeParams = [
  67. 'orderSn' => $orderSn,
  68. ];
  69. $response = $laResource->close($closeParams);
  70. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  71. //$msg = $response['msg'] ?? '';
  72. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
  73. } else {
  74. //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单成功", '15280215347');
  75. }
  76. util::complete();
  77. }
  78. //城市供货商向基地批发商的结账单 ssh 20220523
  79. public function actionList()
  80. {
  81. $get = Yii::$app->request->get();
  82. $where = [];
  83. if (isset($get['status']) && is_numeric($get['status'])) {
  84. $where['status'] = $get['status'];
  85. }
  86. $ghsId = $get['ghsId'] ?? 0;
  87. if (!empty($ghsId)) {
  88. $ghs = GhsClass::getById($ghsId, true);
  89. GhsClass::valid($ghs, $this->shopId);
  90. $where['ghsId'] = $ghsId;
  91. }
  92. $where['customShopId'] = $this->shopId ?? 0;
  93. $list = ClearService::getClearList($where);
  94. util::success($list);
  95. }
  96. //获取基本信息 ssh 20210625
  97. public function actionGetFullInfo()
  98. {
  99. $id = Yii::$app->request->get('id', '');
  100. $info = clearClass::getById($id);
  101. if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
  102. util::fail('没有权限');
  103. }
  104. $respond = ClearClass::getGhsCgInfo($info);
  105. util::success($respond);
  106. }
  107. //客户的结帐单 ssh 20210625
  108. public function actionCustomList()
  109. {
  110. $get = Yii::$app->request->get();
  111. $where = [];
  112. if (isset($get['status']) && is_numeric($get['status'])) {
  113. $where['status'] = $get['status'];
  114. }
  115. $customId = $get['customId'] ?? 0;
  116. if (!empty($customId)) {
  117. $custom = CustomClass::getById($customId, true);
  118. CustomClass::valid($custom, $this->shopId);
  119. $where['customId'] = $customId;
  120. }
  121. $where['ghsShopId'] = $this->shopId ?? 0;
  122. $list = ClearService::getClearList($where);
  123. $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
  124. $list['totalAmount'] = floatval($totalAmount);
  125. util::success($list);
  126. }
  127. //获取基本信息 ssh 20210625
  128. public function actionGetCustomFullInfo()
  129. {
  130. $id = Yii::$app->request->get('id', '');
  131. $info = ClearClass::getById($id);
  132. if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
  133. util::fail('没有权限');
  134. }
  135. $respond = ClearClass::getSaleInfo($info);
  136. util::success($respond);
  137. }
  138. }