| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\clear\classes\ClearClass;
- use bizGhs\clear\services\ClearService;
- use bizGhs\custom\classes\CustomClass;
- use common\components\lakala\Lakala;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class ClearController extends BaseController
- {
- //结账单取消了,钱给原路退回 ssh 20250501
- public function actionRefundMoney()
- {
- $id = Yii::$app->request->get('id', '');
- $info = ClearClass::getById($id, true);
- if ($info->ghsShopId != $this->shopId) {
- util::fail('不是你的结账单');
- }
- if ($info->status != 3) {
- util::fail('结账单没有取消,不能退钱');
- }
- $addTime = $info->addTime;
- $addTime = strtotime($addTime);
- $earTime = strtotime('2025-05-01 00:00:00');
- if ($addTime < $earTime) {
- util::fail('2025.5.1号前的订单,不能退款');
- }
- $shop = $this->shop;
- $respond = ClearClass::refundMoney($shop, $info);
- $status = $respond['status'];
- $msg = $respond['msg'];
- util::success(['status' => $status], $msg);
- }
- //获取客户待结订单明细 ssh 20220926
- public function actionGetUnClear()
- {
- $get = Yii::$app->request->get();
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $info = ClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
- if (isset($info->deadline) && $info->deadline < date("Y-m-d H:i:s")) {
- $n = date("Y-m-d H:i:s");
- $info->status = 3;
- $info->remark = "账单过期,已自动取消,参数:{$info->deadline} {$n}";
- $info->save();
- util::success(['info' => []]);
- }
- util::success(['info' => $info]);
- }
- public function actionCancel()
- {
- $id = Yii::$app->request->get('id');
- $clear = ClearClass::getLockById($id);
- if (empty($clear)) {
- util::fail('没有结账信息呢');
- }
- $ghsId = $clear->ghsId ?? 0;
- $orderSn = $clear->orderSn ?? '';
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商关系');
- }
- if ($ghs->shopId != $this->shopId) {
- util::fail('不是你的账单哦');
- }
- if ($clear->status == ClearClass::STATUS_HAS_PAY) {
- util::fail('账单已完成');
- }
- if ($clear->status == ClearClass::STATUS_EXPIRE) {
- util::fail('账单已取消');
- }
- $clear->status = ClearClass::STATUS_EXPIRE;
- $clear->remark = "商家手动取消 ".date("Y-m-d H:i:s");
- $clear->save();
- $ghsShop = $this->shop;
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $ghsShop->lklSjNo,
- 'term_no' => $ghsShop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $orderSn,
- ];
- $response = $laResource->close($closeParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- //$msg = $response['msg'] ?? '';
- //noticeUtil::push("\n花店结账单:" . $orderSn . "\n关单失败了\n{$msg} ", '15280215347');
- }
- //收银台关单
- $closeParams = ['orderSn' => $orderSn];
- $response = $laResource->cashClose($closeParams);
- if (isset($response['code']) == false || $response['code'] != '000000') {
- //$msg = $response['msg'] ?? '';
- //noticeUtil::push('单号:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
- }
- util::complete();
- }
- //城市供货商向基地批发商的结账单 ssh 20220523
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- if (isset($get['status']) && is_numeric($get['status'])) {
- $where['status'] = $get['status'];
- }
- $ghsId = $get['ghsId'] ?? 0;
- if (!empty($ghsId)) {
- $ghs = GhsClass::getById($ghsId, true);
- GhsClass::valid($ghs, $this->shopId);
- $where['ghsId'] = $ghsId;
- }
- $where['customShopId'] = $this->shopId ?? 0;
- $list = ClearService::getClearList($where);
- util::success($list);
- }
- //获取基本信息 ssh 20210625
- public function actionGetFullInfo()
- {
- $id = Yii::$app->request->get('id', '');
- $info = clearClass::getById($id);
- if (isset($info['customShopId']) == false || $info['customShopId'] != $this->shopId) {
- util::fail('没有权限');
- }
- $respond = ClearClass::getGhsCgInfo($info);
- util::success($respond);
- }
- //客户的结帐单 ssh 20210625
- public function actionCustomList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- if (isset($get['status']) && is_numeric($get['status'])) {
- $where['status'] = $get['status'];
- }
- $customId = $get['customId'] ?? 0;
- if (!empty($customId)) {
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $where['customId'] = $customId;
- }
- $where['ghsShopId'] = $this->shopId ?? 0;
- $list = ClearService::getClearList($where);
- $totalAmount = ClearClass::sum(['ghsShopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'realPrice');
- $list['totalAmount'] = floatval($totalAmount);
- util::success($list);
- }
- //获取基本信息 ssh 20210625
- public function actionGetCustomFullInfo()
- {
- $id = Yii::$app->request->get('id', '');
- $info = ClearClass::getById($id);
- if (isset($info['ghsShopId']) == false || $info['ghsShopId'] != $this->shopId) {
- util::fail('没有权限');
- }
- $respond = ClearClass::getSaleInfo($info);
- //分享结账单时,显示的标题里面,如果是首店或总店,不显示店名
- $respond['ghsShopName'] = isset($respond['ghsShopName']) && $respond['ghsShopName'] == '总店' ? '' : $respond['ghsShopName'];
- util::success($respond);
- }
- }
|