CashController.php 5.0 KB

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