DrawCashController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace pt\controllers;
  3. use common\components\stringUtil;
  4. use common\services\xhAdminToMerchantService;
  5. use common\services\xhCommonService;
  6. use common\services\xhMerchantAssetService;
  7. use common\services\xhUserService;
  8. use common\services\xhWxOpenService;
  9. use common\services\xhMerchantExtendService;
  10. use Yii;
  11. use common\models\xhDrawCash;
  12. use common\components\page;
  13. use common\services\xhMerchantService;
  14. use common\services\xhDrawCashService;
  15. use common\services\xhTMessageService;
  16. use common\components\util;
  17. use common\components\wxUtil;
  18. use common\services\xhStatIncomeService;
  19. class DrawCashController extends PlatformController
  20. {
  21. public function actionList()
  22. {
  23. $get = Yii::$app->request->get();
  24. $query = xhDrawCash::find();
  25. $countQuery = clone $query;
  26. $count = $countQuery->count();
  27. $page = isset($get['page']) ? $get['page'] : 1;
  28. $pageSize = 20;
  29. $offset = ($page - 1) * $pageSize;
  30. $models = $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
  31. $page = new page($count, $page, $pageSize);
  32. $paging = $page->fpage();
  33. return $this->render('list', ['models' => $models, 'paging' => $paging]);
  34. }
  35. /**
  36. * 提现审核通过
  37. */
  38. public function actionCompleteOrder()
  39. {
  40. $get = Yii::$app->request->get();
  41. $id = isset($get['id']) ? $get['id'] : 0;
  42. $draw = xhDrawCashService::getById($id);
  43. $drawAmount = isset($draw['amount']) ? floatval($draw['amount']) : 0;
  44. if ($draw['status'] == 1) {
  45. util::fail('已经完成转账,请不要重复请求!');
  46. }
  47. $sjId = isset($draw['sjId']) ? $draw['sjId'] : 0;
  48. $admin = xhAdminToMerchantService::getAdminByMerchantId($sjId);
  49. $time = strtotime(date("Y-m-d"));
  50. $income = xhStatIncomeService::getByIds($sjId, $time);
  51. $amount = isset($income['amount']) ? $income['amount'] : 0;
  52. $merchantExtInfo = xhMerchantExtendService::getBySjId($sjId);//取支付宝帐号
  53. $asset = xhMerchantAssetService::getBySjId($sjId);
  54. if ($merchantExtInfo['alipayAccount'] == '') {
  55. util::fail('转账接收方的支付宝帐号为空');
  56. }
  57. if ($drawAmount == 0) {
  58. util::fail('转账金额为0');
  59. }
  60. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  61. require_once($alipayWap . '/aop/AopClient.php');
  62. require_once($alipayWap . '/aop/request/AlipayFundTransToaccountTransferRequest.php');
  63. require_once($alipayWap . '/config.php');
  64. $aop = new \AopClient();
  65. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  66. $aop->appId = $config['app_id'];
  67. $aop->rsaPrivateKey = $config['merchant_private_key'];
  68. $aop->alipayrsaPublicKey = $config['alipay_public_key'];
  69. $aop->apiVersion = '1.0';
  70. $aop->signType = 'RSA2';
  71. $aop->postCharset = 'UTF-8';
  72. $aop->format = 'json';
  73. $request = new \AlipayFundTransToaccountTransferRequest ();
  74. $request->setBizContent("{" .
  75. "\"out_biz_no\":\"" . $id . "\"," .
  76. "\"payee_type\":\"ALIPAY_LOGONID\"," .
  77. "\"payee_account\":\"" . $merchantExtInfo['alipayAccount'] . "\"," .
  78. "\"amount\":\"" . $drawAmount . "\"," .
  79. "\"payee_real_name\":\"" . $merchantExtInfo['alipayAccountName'] . "\"," .
  80. "\"payer_show_name\":\"厦门中花汇信息科技有限公司\"," .
  81. "\"remark\":\"提现申请\"" .
  82. " }");
  83. $result = $aop->execute($request);
  84. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  85. $resultCode = $result->$responseNode->code;
  86. $returnOrderId = $result->$responseNode->order_id;
  87. if (!empty($resultCode) && $resultCode == 10000) {
  88. xhDrawCashService::updateById($id, ['thirdSerialNumber' => $returnOrderId, 'status' => 1]);
  89. $remainAmount = stringUtil::calcSub($asset['freezeBalance'], $drawAmount);
  90. xhMerchantAssetService::updateBySjId($sjId, ['freezeBalance' => $remainAmount]);
  91. /*
  92. $openId = $admin['openId'];
  93. $openMerchant = xhWxOpenService::getMerchant();//取平台绑定的商家
  94. $openMerchantId = $openMerchant['id'];
  95. $allTM = xhTMessageService::getList($openMerchantId);
  96. $shortTempId = 'OPENTM201319876';
  97. if(isset($allTM[$shortTempId])){
  98. $tempId = $allTM[$shortTempId];
  99. $data = [
  100. "touser" => $openId,
  101. "template_id" => $tempId,
  102. "url" => Yii::$app->params['adminUrl'] . '/draw-cash/list',
  103. "data" => [
  104. "first" => ["value" => '已经完成结算。', "color" => "#173177"],
  105. "keyword1" => ["value" => '当天', "color" => "#173177"],
  106. "keyword2" => ["value" => $amount . '元', "color" => "#173177"],
  107. "remark" => ["value" => "支付宝收入:{$drawAmount}元,已汇入您的帐户。\n点击查看结算记录", "color" => "#173177"]
  108. ]
  109. ];
  110. wxUtil::sendTaskInform($data, $openMerchant);
  111. }
  112. */
  113. xhCommonService::sendMobileMsg($admin['mobile'], "您申请的提现金额:{$drawAmount}元已经到帐,请注意查收。");
  114. util::complete();
  115. } else {
  116. $msg = $result->$responseNode->msg;
  117. $sub_code = $result->$responseNode->sub_code;
  118. $sub_msg = $result->$responseNode->sub_msg;
  119. Yii::info("转帐失败,原因:code:" . $resultCode . " msg:" . $msg . " sub_code:" . $sub_code . " sub_msg:" . $sub_msg);
  120. }
  121. util::fail('转账失败');
  122. }
  123. }