| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\clear\classes\ClearClass;
- use bizGhs\clear\services\ClearService;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClearClass;
- use bizHd\shop\classes\ShopClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\lakala\Lakala;
- use common\components\noticeUtil;
- use common\components\util;
- use common\components\qrCodeUtil;
- use Yii;
- class ClearController extends BaseController
- {
- public $guestAccess = ['get-full-info', 'detail', 'get-ali-pay-clear-code'];
- //取消结账单 ssh 20220509
- public function actionCancel()
- {
- $id = Yii::$app->request->get('id');
- $clear = ClearClass::getLockById($id);
- if (empty($clear)) {
- util::fail('没有结账信息哈');
- }
- $customId = $clear->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- $customShopId = $custom->shopId ?? 0;
- if ($customShopId != $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();
- $orderSn = $clear->orderSn ?? '';
- $ghsShopId = $clear->ghsShopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (!empty($ghsShop)) {
- $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'] ?? '';
- $code = $response['code'] ?? 0;
- if (!in_array($code, ['BBS11114'])) {
- noticeUtil::push("花店结账:" . $orderSn . " 关单没有成功 {$msg} {$code}", '15280215347');
- }
- }
- //收银台关单
- $closeParams = ['orderSn' => $orderSn];
- $response = $laResource->cashClose($closeParams);
- if (isset($response['code']) == false || $response['code'] != '000000') {
- $msg = $response['msg'] ?? '';
- $code = $response['code'] ?? 0;
- if (!in_array($code, ['000091'])) {
- noticeUtil::push('花店结账:' . $orderSn . ',关单没有成功(收银台-支付宝),' . $msg . $code, '15280215347');
- }
- }
- }
- util::complete();
- }
- //结款单 ssh 20210625
- 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');
- $salt = Yii::$app->request->get('salt');
- $info = ClearClass::getById($id);
- if (empty($info)) {
- util::fail('没有结账单');
- }
- if (empty($salt)) {
- if (!isset($info['customShopId']) || $info['customShopId'] != $this->shopId) {
- //util::fail('不是你的结账信息');
- }
- } else {
- if (!isset($info['salt']) || $info['salt'] != $salt) {
- util::fail('不是你的结账信息哦');
- }
- }
- $respond = ClearClass::getCgInfo($info);
- util::success($respond);
- }
- //获取支付宝付款码 ssh 20240713
- public function actionGetAliPayClearCode()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? 0;
- $info = ClearClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info)) {
- util::fail('没有找到结账单');
- }
- if (getenv('YII_ENV') == 'production') {
- $url = "https://mall.huahb.cn/#/admin/clear/alipay?orderSn={$orderSn}";
- } else {
- $url = "https://mall.huaml.com/#/admin/clear/alipay?orderSn={$orderSn}";
- }
- $unique = "order_clear_ali_pay_" . $orderSn;
- $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
- $imageUrl = imgUtil::groupImg($imgUrl);
- util::success(['imgUrl' => $imageUrl]);
- }
- //获取结账单详情 ssh 20220509
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id');
- $clear = ClearClass::getById($id);
- if (empty($clear)) {
- util::fail('没有结账信息哦');
- }
- $deadline = isset($clear['deadline']) && !empty($clear['deadline']) ? strtotime($clear['deadline']) : 0;
- $now = time();
- $remainSecond = bcsub($deadline, $now);
- $remainSecond = bcsub($remainSecond, 100);
- $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
- $clear['remainSecond'] = $remainSecond;
- $clear['hasRenew'] = 1;
- //如果是虚拟关系,暂时允许花店一键结账
- $ghsId = $clear['ghsId'] ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- $live = $ghs->live ?? 1;
- $clear['live'] = $live;
- util::success($clear);
- }
- public function actionHasWxPay()
- {
- $id = Yii::$app->request->get('id');
- $clear = ClearClass::getById($id, true);
- if (empty($clear)) {
- util::fail('没有结账信息哦');
- }
- if ($clear->customShopId != $this->shopId) {
- util::fail('不是你的结账单');
- }
- util::checkRepeatCommit($this->adminId, 4);
- //暂时用批发端的写法来顶替一下
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $payWay = 0;
- $amount = $clear->actPrice ?? 0;
- $customId = $clear->customId ?? 0;
- $custom = CustomClass::getLockById($customId);
- $shop = $this->shop;
- $staff = $this->shopAdmin;
- //充值
- $return = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay);
- $custom = $return['custom'];
- $ghs = $return['ghs'];
- //结账(充值销账链路,现金/余额已在 rechargeBalance 处理)
- OrderClearClass::confirmClear($clear, $payWay, ['skipCashMoney' => true]);
- $clearInfo = OrderClearClass::getLockById($id);
- //结账消余额
- CustomClass::clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clearInfo);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- }
|