| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace pt\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\wxUtil;
- 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::fail('已经完成转账,请不要重复请求!');
- }
- $sjId = isset($draw['sjId']) ? $draw['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::getBySjId($sjId);//取支付宝帐号
-
- $asset = xhMerchantAssetService::getBySjId($sjId);
-
- if ($merchantExtInfo['alipayAccount'] == '') {
- util::fail('转账接收方的支付宝帐号为空');
- }
- if ($drawAmount == 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\":\"" . $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::updateBySjId($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" => "支付宝收入:{$drawAmount}元,已汇入您的帐户。\n点击查看结算记录", "color" => "#173177"]
- ]
- ];
- wxUtil::sendTaskInform($data, $openMerchant);
- }
- */
- xhCommonService::sendMobileMsg($admin['mobile'], "您申请的提现金额:{$drawAmount}元已经到帐,请注意查收。");
- 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('转账失败');
-
- }
-
- }
|