ClearController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 bizHd\wx\classes\WxOpenClass;
  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. //获取客户待结订单明细 ssh 20220926
  15. public function actionGetUnClear()
  16. {
  17. $get = Yii::$app->request->get();
  18. $customId = $get['customId'] ?? 0;
  19. $custom = CustomClass::getById($customId, true);
  20. CustomClass::valid($custom, $this->shopId);
  21. $info = ClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
  22. if (isset($info->deadline) && $info->deadline < date("Y-m-d H:i:s")) {
  23. $info->status = 3;
  24. $info->save();
  25. util::success(['info' => []]);
  26. }
  27. util::success(['info' => $info]);
  28. }
  29. public function actionCancel()
  30. {
  31. $id = Yii::$app->request->get('id');
  32. $clear = ClearClass::getLockById($id);
  33. if (empty($clear)) {
  34. util::fail('没有结账信息');
  35. }
  36. $ghsId = $clear->ghsId ?? 0;
  37. $orderSn = $clear->orderSn ?? '';
  38. $ghs = GhsClass::getById($ghsId, true);
  39. if (empty($ghs)) {
  40. util::fail('没有找到供货商关系');
  41. }
  42. if ($ghs->shopId != $this->shopId) {
  43. util::fail('没有权限');
  44. }
  45. if ($clear->status == ClearClass::STATUS_HAS_PAY) {
  46. util::fail('账单已完成');
  47. }
  48. if ($clear->status == ClearClass::STATUS_EXPIRE) {
  49. util::fail('账单已取消');
  50. }
  51. $clear->status = ClearClass::STATUS_EXPIRE;
  52. $clear->save();
  53. //关闭微信的订单
  54. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  55. require_once($wx . '/lib/WxPay.Api.php');
  56. require_once($wx . '/example/WxPay.MicroPay.php');
  57. //获取微信商户号等信息
  58. $sjExtend = WxOpenClass::getWxInfo();
  59. $mid = $sjExtend['wxPayMerchantId'] ?? '';
  60. $appId = $sjExtend['miniAppId'] ?? '';
  61. $key = $sjExtend['wxPayKey'] ?? '';
  62. $input = new \WxPayCloseOrder();
  63. $input->SetOut_trade_no($orderSn);
  64. $config = new \WxPayConfig();
  65. $config->SetAppId($appId);
  66. $config->SetMerchantId($mid);
  67. $config->SetKey($key);
  68. $return = \WxPayApi::closeOrder($config, $input);
  69. if (isset($return['return_code']) && $return['return_code'] == 'SUCCESS') {
  70. //noticeUtil::push('花店结账单:' . $orderSn . ',微信关闭订单成功。', '15280215347');
  71. } else {
  72. noticeUtil::push('花店结账单:' . $orderSn . ',微信关闭订单失败了。', '15280215347');
  73. }
  74. util::complete();
  75. }
  76. //城市供货商向基地批发商的结账单 ssh 20220523
  77. public function actionList()
  78. {
  79. $get = Yii::$app->request->get();
  80. $where = [];
  81. if (isset($get['status']) && is_numeric($get['status'])) {
  82. $where['status'] = $get['status'];
  83. }
  84. $ghsId = $get['ghsId'] ?? 0;
  85. if (!empty($ghsId)) {
  86. $ghs = GhsClass::getById($ghsId, true);
  87. GhsClass::valid($ghs, $this->shopId);
  88. $where['ghsId'] = $ghsId;
  89. }
  90. $where['customShopId'] = $this->shopId ?? 0;
  91. $list = ClearService::getClearList($where);
  92. util::success($list);
  93. }
  94. //获取基本信息 ssh 20210625
  95. public function actionGetFullInfo()
  96. {
  97. $id = Yii::$app->request->get('id', '');
  98. $info = clearClass::getById($id);
  99. if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
  100. util::fail('没有权限');
  101. }
  102. $respond = ClearClass::getGhsCgInfo($info);
  103. util::success($respond);
  104. }
  105. //客户的结帐单 ssh 20210625
  106. public function actionCustomList()
  107. {
  108. $get = Yii::$app->request->get();
  109. $where = [];
  110. if (isset($get['status']) && is_numeric($get['status'])) {
  111. $where['status'] = $get['status'];
  112. }
  113. $customId = $get['customId'] ?? 0;
  114. if (!empty($customId)) {
  115. $custom = CustomClass::getById($customId, true);
  116. CustomClass::valid($custom, $this->shopId);
  117. $where['customId'] = $customId;
  118. }
  119. $where['ghsShopId'] = $this->shopId ?? 0;
  120. $list = ClearService::getClearList($where);
  121. $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
  122. $list['totalAmount'] = floatval($totalAmount);
  123. util::success($list);
  124. }
  125. //获取基本信息 ssh 20210625
  126. public function actionGetCustomFullInfo()
  127. {
  128. $id = Yii::$app->request->get('id', '');
  129. $info = ClearClass::getById($id);
  130. if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
  131. util::fail('没有权限');
  132. }
  133. $respond = ClearClass::getSaleInfo($info);
  134. util::success($respond);
  135. }
  136. }