ClearController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. }
  74. //收银台关单
  75. $closeParams = ['orderSn' => $orderSn];
  76. $response = $laResource->cashClose($closeParams);
  77. if (isset($response['code']) == false || $response['code'] != '000000') {
  78. //$msg = $response['msg'] ?? '';
  79. //noticeUtil::push('单号:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  80. }
  81. util::complete();
  82. }
  83. //城市供货商向基地批发商的结账单 ssh 20220523
  84. public function actionList()
  85. {
  86. $get = Yii::$app->request->get();
  87. $where = [];
  88. if (isset($get['status']) && is_numeric($get['status'])) {
  89. $where['status'] = $get['status'];
  90. }
  91. $ghsId = $get['ghsId'] ?? 0;
  92. if (!empty($ghsId)) {
  93. $ghs = GhsClass::getById($ghsId, true);
  94. GhsClass::valid($ghs, $this->shopId);
  95. $where['ghsId'] = $ghsId;
  96. }
  97. $where['customShopId'] = $this->shopId ?? 0;
  98. $list = ClearService::getClearList($where);
  99. util::success($list);
  100. }
  101. //获取基本信息 ssh 20210625
  102. public function actionGetFullInfo()
  103. {
  104. $id = Yii::$app->request->get('id', '');
  105. $info = clearClass::getById($id);
  106. if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
  107. util::fail('没有权限');
  108. }
  109. $respond = ClearClass::getGhsCgInfo($info);
  110. util::success($respond);
  111. }
  112. //客户的结帐单 ssh 20210625
  113. public function actionCustomList()
  114. {
  115. $get = Yii::$app->request->get();
  116. $where = [];
  117. if (isset($get['status']) && is_numeric($get['status'])) {
  118. $where['status'] = $get['status'];
  119. }
  120. $customId = $get['customId'] ?? 0;
  121. if (!empty($customId)) {
  122. $custom = CustomClass::getById($customId, true);
  123. CustomClass::valid($custom, $this->shopId);
  124. $where['customId'] = $customId;
  125. }
  126. $where['ghsShopId'] = $this->shopId ?? 0;
  127. $list = ClearService::getClearList($where);
  128. $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
  129. $list['totalAmount'] = floatval($totalAmount);
  130. util::success($list);
  131. }
  132. //获取基本信息 ssh 20210625
  133. public function actionGetCustomFullInfo()
  134. {
  135. $id = Yii::$app->request->get('id', '');
  136. $info = ClearClass::getById($id);
  137. if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
  138. util::fail('没有权限');
  139. }
  140. $respond = ClearClass::getSaleInfo($info);
  141. //分享结账单时,显示的标题里面,如果是首店或总店,不显示店名
  142. $respond['ghsShopName'] = isset($respond['ghsShopName']) && $respond['ghsShopName'] == '总店' ? '' : $respond['ghsShopName'];
  143. util::success($respond);
  144. }
  145. }