|
|
@@ -0,0 +1,135 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace www\controllers;
|
|
|
+
|
|
|
+use common\components\stringUtil;
|
|
|
+use common\services\xhAdminToMerchantService;
|
|
|
+
|
|
|
+use common\services\xhCommonService;
|
|
|
+use common\services\xhMerchantAssetService;
|
|
|
+use common\services\xhUserService;
|
|
|
+
|
|
|
+use common\services\xhWxOpenService;
|
|
|
+
|
|
|
+use common\services\xhMerchantExtendService;
|
|
|
+use Yii;
|
|
|
+use common\models\xhDrawCash;
|
|
|
+use common\components\page;
|
|
|
+use common\services\xhMerchantService;
|
|
|
+use common\services\xhDrawCashService;
|
|
|
+use common\services\xhTMessageService;
|
|
|
+use common\components\util;
|
|
|
+use common\components\weixinUtil;
|
|
|
+use common\services\xhStatIncomeService;
|
|
|
+
|
|
|
+class DrawCashController extends PlatformController
|
|
|
+{
|
|
|
+ public function actionList()
|
|
|
+ {
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $query = xhDrawCash::find();
|
|
|
+ $countQuery = clone $query;
|
|
|
+ $count = $countQuery->count();
|
|
|
+ $page = isset($get['page']) ? $get['page'] : 1;
|
|
|
+ $pageSize = 20;
|
|
|
+ $offset = ($page - 1) * $pageSize;
|
|
|
+ $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
|
|
|
+ $page = new page($count, $page, $pageSize);
|
|
|
+ $paging = $page->fpage();
|
|
|
+ return $this->render('list', ['models' => $models, 'paging' => $paging]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现审核通过
|
|
|
+ */
|
|
|
+ public function actionCompleteOrder()
|
|
|
+ {
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = isset($get['id']) ? $get['id'] : 0;
|
|
|
+ $draw = xhDrawCashService::getById($id);
|
|
|
+ $drawAmount = isset($draw['amount']) ? floatval($draw['amount']) : 0;
|
|
|
+ if ($draw['status'] == 1) {
|
|
|
+ util::failInfo('已经完成转账,请不要重复请求!');
|
|
|
+ }
|
|
|
+ $merchantId = isset($draw['merchantId']) ? $draw['merchantId'] : 0;
|
|
|
+ $admin = xhAdminToMerchantService::getAdminByMerchantId($merchantId);
|
|
|
+ $time = strtotime(date("Y-m-d"));
|
|
|
+ $income = xhStatIncomeService::getByIds($merchantId, $time);
|
|
|
+ $amount = isset($income['amount']) ? $income['amount'] : 0;
|
|
|
+ $merchantExtInfo = xhMerchantExtendService::getByMerchantId($merchantId);//取支付宝帐号
|
|
|
+
|
|
|
+ $asset = xhMerchantAssetService::getByMerchantId($merchantId);
|
|
|
+
|
|
|
+ if ($merchantExtInfo['alipayAccount'] == '') {
|
|
|
+ util::failInfo('转账接收方的支付宝帐号为空');
|
|
|
+ }
|
|
|
+ if ($drawAmount == 0) {
|
|
|
+ util::failInfo('转账金额为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\":\"" . $drawAmount . "\"," .
|
|
|
+ "\"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'], $drawAmount);
|
|
|
+ xhMerchantAssetService::updateByMerchantId($merchantId, ['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" => "支付宝收入:{$drawAmount}元,已汇入您的帐户。\n点击查看结算记录", "color" => "#173177"]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ weixinUtil::sendTaskInform($data, $openMerchant);
|
|
|
+ }
|
|
|
+ */
|
|
|
+ xhCommonService::sendMobileMsg($admin['mobile'], "您申请的提现金额:{$drawAmount}元已经到帐,请注意查收。");
|
|
|
+ util::successInfo();
|
|
|
+ } 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::failInfo('转账失败');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|