shish 5 лет назад
Родитель
Сommit
b181d2bf48
2 измененных файлов с 141 добавлено и 1 удалено
  1. 115 0
      app-pt/controllers/CashController.php
  2. 26 1
      sql.sql

+ 115 - 0
app-pt/controllers/CashController.php

@@ -0,0 +1,115 @@
+<?php
+
+namespace pt\controllers;
+
+use biz\sj\classes\CashClass;
+use common\components\util;
+use Yii;
+
+class CashController extends BaseController
+{
+
+    //提现记录 shish 2021.5.17
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $status = $get['status'] ?? 0;
+        $where = [];
+        if (!empty($status)) {
+            $where['status'] = $status;
+        }
+        $list = CashClass::getCashList($where);
+        util::success($list);
+    }
+
+    //提现审核通过 shish 2021.5.17
+    public function actionCheck()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $cash = CashClass::getById($id, true);
+        if ($cash['status'] == 2) {
+            util::fail('已经完成转账,请不要重复请求!');
+        }
+        $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
+        $sjId = isset($cash->sjId) ? $cash->sjId : 0;
+        $admin = xhAdminToMerchantService::getAdminByMerchantId($sjId);
+        $time = strtotime(date("Y-m-d"));
+        $income = xhStatIncomeService::getByIds($sjId, $time);
+        $amount = isset($income['amount']) ? $income['amount'] : 0;
+        $merchantExtInfo = xhMerchantExtendService::getByMerchantId($sjId);//取支付宝帐号
+
+        $asset = xhMerchantAssetService::getByMerchantId($sjId);
+
+        if ($merchantExtInfo['alipayAccount'] == '') {
+            util::fail('转账接收方的支付宝帐号为空');
+        }
+        if ($cashAmount == 0) {
+            util::fail('转账金额为0');
+        }
+        $alipayWap = Yii::getAlias("@vendor/alipayWap");
+        require_once($alipayWap . '/aop/AopClient.php');
+        require_once($alipayWap . '/aop/request/AlipayFundTransToaccountTransferRequest.php');
+        require_once($alipayWap . '/config.php');
+
+        $aop = new \AopClient();
+        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
+        $aop->appId = $config['app_id'];
+        $aop->rsaPrivateKey = $config['merchant_private_key'];
+        $aop->alipayrsaPublicKey = $config['alipay_public_key'];
+        $aop->apiVersion = '1.0';
+        $aop->signType = 'RSA2';
+        $aop->postCharset = 'UTF-8';
+        $aop->format = 'json';
+        $request = new \AlipayFundTransToaccountTransferRequest ();
+        $request->setBizContent("{" .
+            "\"out_biz_no\":\"" . $id . "\"," .
+            "\"payee_type\":\"ALIPAY_LOGONID\"," .
+            "\"payee_account\":\"" . $merchantExtInfo['alipayAccount'] . "\"," .
+            "\"amount\":\"" . $cashAmount . "\"," .
+            "\"payee_real_name\":\"" . $merchantExtInfo['alipayAccountName'] . "\"," .
+            "\"payer_show_name\":\"厦门中花汇信息科技有限公司\"," .
+            "\"remark\":\"提现申请\"" .
+            "  }");
+        $result = $aop->execute($request);
+        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+        $resultCode = $result->$responseNode->code;
+        $returnOrderId = $result->$responseNode->order_id;
+        if (!empty($resultCode) && $resultCode == 10000) {
+            xhDrawCashService::updateById($id, ['thirdSerialNumber' => $returnOrderId, 'status' => 1]);
+            $remainAmount = stringUtil::calcSub($asset['freezeBalance'], $cashAmount);
+            xhMerchantAssetService::updateByMerchantId($sjId, ['freezeBalance' => $remainAmount]);
+            /*
+            $openId = $admin['openId'];
+            $openMerchant = xhWxOpenService::getMerchant();//取平台绑定的商家
+            $openMerchantId = $openMerchant['id'];
+            $allTM = xhTMessageService::getList($openMerchantId);
+            $shortTempId = 'OPENTM201319876';
+            if(isset($allTM[$shortTempId])){
+            $tempId =  $allTM[$shortTempId];
+            $data = [
+                "touser" => $openId,
+                "template_id" => $tempId,
+                "url" => Yii::$app->params['adminUrl'] . '/draw-cash/list',
+                "data" => [
+                    "first" => ["value" => '已经完成结算。', "color" => "#173177"],
+                    "keyword1" => ["value" => '当天', "color" => "#173177"],
+                    "keyword2" => ["value" => $amount . '元', "color" => "#173177"],
+                    "remark" => ["value" => "支付宝收入:{$cashAmount}元,已汇入您的帐户。\n点击查看结算记录", "color" => "#173177"]
+                ]
+            ];
+            wxUtil::sendTaskInform($data, $openMerchant);
+            }
+            */
+            xhCommonService::sendMobileMsg($admin['mobile'], "您申请的提现金额:{$cashAmount}元已经到帐,请注意查收。");
+            util::complete();
+        } else {
+            $msg = $result->$responseNode->msg;
+            $sub_code = $result->$responseNode->sub_code;
+            $sub_msg = $result->$responseNode->sub_msg;
+            Yii::info("转帐失败,原因:code:" . $resultCode . " msg:" . $msg . " sub_code:" . $sub_code . " sub_msg:" . $sub_msg);
+        }
+        util::fail('转账失败');
+    }
+
+}

+ 26 - 1
sql.sql

@@ -2525,4 +2525,29 @@ ALTER TABLE `xhSetMeal` ADD `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIME
 TRUNCATE `xhSetMeal`;
 INSERT INTO xhSetMeal(id,`style`,`name`,price,num) VALUES(NULL,1,'基础版',1980,0),(NULL,2,'基础版',2980,0);
 ALTER TABLE `xhSetMeal` RENAME TO `xhSet`;
-ALTER TABLE xhRenew MODIFY `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '1 待付款 2已付款';
+ALTER TABLE xhRenew MODIFY `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '1 待付款 2已付款';
+drop table if exists `xhShopYeChange`;
+CREATE TABLE if not exists `xhShopYeChange` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `relateId` int(11) NOT NULL DEFAULT '0' COMMENT '关联订单id',
+  `capitalType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '流水类型',
+  `amount` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '变动金额',
+  `balance` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
+  `txBalance` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '可提现余额',
+  `io` tinyint(4) NOT NULL DEFAULT '0' COMMENT '类型 0减少 1增加',
+  `payWay` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付方式',
+  `fromType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '来源 0门店 1商城 2朋友圈 3..',
+  `event` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '事项',
+  `sjId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `shopId` int(11) NOT NULL DEFAULT '0' COMMENT '门店id',
+  `remark` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
+  `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+  PRIMARY KEY (`id`)
+) COMMENT='门店余额变化记录';
+ALTER TABLE xhShopYeChange MODIFY `balance` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '当前余额';
+ALTER TABLE xhShopYeChange MODIFY `txBalance` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '当前可提现余额';
+ALTER TABLE xhCash MODIFY `event` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '说明';
+ALTER TABLE xhCash ADD sjName VARCHAR(100) NOT NULL DEFAULT '' COMMENT '商家名称' AFTER `shopId`;
+ALTER TABLE xhCash ADD shopName VARCHAR(100) NOT NULL DEFAULT '' COMMENT '门店名称' AFTER `sjName`;
+ALTER TABLE xhCash ADD shopAdminId INT NOT NULL DEFAULT 0 COMMENT '申请提现的员工' AFTER `shopId`;