NoticeController.php 20.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
<?php

class pay_NoticeController extends QLib_Controller_Pay_Action
{
    /**
     * 处理支付的结果
     * Enter description here ...
     * @param array $payResult
     */
    public function payResultDeal($payResult, $payment)
    {

        $dealResult = array(
            'code' => 500,
            'message' => '支付失败'
        );
        $this->view->resultData = $payResult;

        if ($payResult->payResult == 200) {
            //支付成功
            $orderCode = $payResult->orderCode;
            //加载订单数据
            $this->view->order = $orderInfo = QModels_Orders_Client::getOther(QModels_Orders_Client::getOneByCodeNoUid($orderCode));
            if ($orderInfo['is_cancel'] == 'Y' && $orderInfo['payment_status'] == 'N') {
                //订单已取消
                QINLib_Sms_SmsInterface::sendErrMsg("支付成功,但订单已取消,订单号为" . $orderCode);
                QINLogs_Sys::logger('order_log', 'pay_amount_error', array('orderid' => $orderCode, 'message' => "支付成功,但订单已取消,需联系客服"), QINLogs_Sys::ERROR_ERROR, array('order_code' => $orderCode));
                $dealResult['code'] = 417;
                $dealResult['message'] = '支付成功,但订单已取消,需联系客服';
                return $dealResult;
            }
            if (round($orderInfo['amount'], 2) != round($payResult->totalFee, 2)) {
                //支付金额与订单金额不一致
                QINLogs_Sys::logger('order_log', 'pay_amount_error', array('orderid' => $orderCode, 'message' => "支付金额与订单金额不一致"), QINLogs_Sys::ERROR_ERROR, array('order_code' => $orderCode));
                $dealResult['code'] = 415;
                $dealResult['message'] = '支付金额与订单金额不一致';
                return $dealResult;
            }

            $get_yoho_coin = 0;
            if (!empty($orderInfo['goods'])) {
                foreach ($orderInfo['goods'] as $g) {
                    $get_yoho_coin += $g['price']['yoho_coin_num'];
                }
            }
            $this->view->get_yoho_coin = $get_yoho_coin;

            if (empty($orderInfo)) {
                $dealResult['code'] = 300;
                $dealResult['message'] = '支付成功,但不存在该订单';
                return $dealResult;
            }
            
            //记录交易号和支付订单号(如果有银行流水号会记录银行流水号)
            $payOrderCode = $payResult->payOrderCode ?  $payResult->payOrderCode : "";
            $tradeNo = $payResult->tradeNo ? $payResult->tradeNo : "";
            $bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : "";
            $statusData = $this->buildPayresultData($payment, $payResult->bankName, $payResult->bankCode, $orderInfo["amount"],$payOrderCode,$tradeNo,$bankBillNo);
            //测试记录返回给erp的数据
            //@error_log("\r\n".date('Y-m-d H:i:s') . "erp接收数据:\r\n" . var_export($statusData,true), 3, '/tmp/pay/erpreceive.log');
            
            $erpOrder = QErp_Order_Factory::factory();
            $erpRet = $erpOrder->submitOrderStatus($orderCode, QConfigs_Order_Config::$orderStatusCode['pay_success'], $statusData);
            //修改订单状态
            $res = QModels_Orders_Client::updatePaymentStatus($orderInfo['id'], $orderInfo['uid'], $payment, 'Y', $payResult->bankName);
            $dealResult['code'] = 200;
            $dealResult['message'] = '支付成功,请等待发货';
            //如果是虚拟订单,还需要别的处理
            if ($orderInfo['attribute'] == 3) {
                ##################### 虚拟订单 ############################
                $orderInfo = QINOrders_Models_Client::getOrderByCode($orderCode);
                YOHOCart_Hook_Orders_IssueTicket::pay($orderCode, $orderInfo['uid']);
                $orderData = array(
                    'order_id' => $orderInfo['id'],
                    'uid' => $orderInfo['uid'],
                    'attribute' => $orderInfo['attribute']
                );
                YOHOCart_Hook_Orders_EndBase::updateOrdersStatus($orderData);
                ##################### 虚拟订单 ############################
                $dealResult['code'] = 200;
                $dealResult['message'] = '购票成功';
                return $dealResult;
            }
        }
        return $dealResult;
    }


    /**
     * 构建支付结果数组
     * Enter description here ...
     * @param integer $payment
     * @param string $bankName
     * @param string $bankCode
     * @param float $amount
     * @param float $payOrderCode 支付订单号
     * @param float $tradeNo 交易号
     * @param float $bankBillNo 银行流水号
     */
    private function buildPayresultData($payment, $bankName, $bankCode, $amount,$payOrderCode = "",$tradeNo = "",$bankBillNo = "")
    {
        $payData = array(
            'payment'=>$payment,
            'paymentCode' => "",
            'bankCode' => $bankCode,
            'bankName' => $bankName,
            'amount' => $amount,
            'payOrderCode' => $payOrderCode,
            'tradeNo' => $tradeNo,
            'bankBillNo' => $bankBillNo
        );
        $paymentArr = array(
            '1' => 90, //财付通
            '2' => 80, //支付宝
            '3' => 111, //建设银行
            '4' => 60, //网银在线
            '5' => 123, //招商银行
            '6' => 122, //环迅IPS
            '7' => 121, //首信易
            '8' => 120, //快钱神州行
            '9' => 119, //快钱
            '10' => 118, //网银信用卡
            '11' => 70, //盛付通
            '12' => 80, //支付宝直连
            '13' => 117, //支付宝快捷网关
            '14' => 116, //银联手机支付
            '15' => 115, //支付宝手机
            '16' => 100, //通联支付
            '17' => 114, //支付宝扫码支付
            '18' => 113, //阿里wap支付
            '19' => 112, //支付宝手机极简收银
            '20' => 111, //极简手机支付
            '21' => 110 //微信支付
        );
        $payData['paymentCode'] = isset($paymentArr[$payment]) ? $paymentArr[$payment] : 0;
        return $payData;
    }

    /**
     * 通用显示结果的方法
     * Enter description here ...
     * @param unknown_type $dealResult
     */
    public function commonShowResult($dealResult)
    {
        if ($dealResult['code'] == 200) {
            $this->_helper->viewRenderer('pay-success');
        } else if ($dealResult['code'] == 500) {
            $this->_helper->viewRenderer('pay-fail');
        } else {
            $this->view->dealResult = $dealResult;
            $this->_helper->viewRenderer('other-error');
        }
    }

    /**
     * 支付宝后台服务器返回,主要是用于补单
     * Enter description here ...
     */
    public function alipaynoticeAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/alipaynotice.log');
        $this->_helper->layout->disableLayout();
        $payment = QCPay_Models_Payment_Client::getOneById(2);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 2);
            echo "success";
        }
        exit();
    }
    
    /**
     * 支付宝浏览器端返回
     * Enter description here ...
     */
    public function alipayreturnAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_GET,true), 3, '/tmp/pay/alipayreturn.log');
        $payment = QCPay_Models_Payment_Client::getOneById(2);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultDeal($res, 2);
        $this->commonShowResult($dealResult);
    }
    
    /**
     * 支付宝二维码支付
     */
    public function alibarcodenoticeAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/alibarcodenotice.log');
        $this->_helper->layout->disableLayout();
        $payment = QCPay_Models_Payment_Client::getOneById(17);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 17);
            echo "success";
        }
        exit();
    }


    /**
     * 支付宝浏览器端返回
     * Enter description here ...
     */
    public function alibarcodereturnAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_GET,true), 3, '/tmp/pay/alibarcodereturn.log');
        $payment = QCPay_Models_Payment_Client::getOneById(17);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultDeal($res, 17);
        $this->commonShowResult($dealResult);
    }

    /**
     * 通联支付返回
     */
    public function allinpayreturnAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_GET,true), 3, '/tmp/pay/allinpayreturn.log');
        $payment = QCPay_Models_Payment_Client::getOneById(16);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultDeal($res, 16);
        $this->commonShowResult($dealResult);
    }

    /**
     * 通联支付
     */
    public function allinpaynoticeAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/allinpaynotice.log');
        $this->_helper->layout->disableLayout();
        $payment = QCPay_Models_Payment_Client::getOneById(16);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 16);
            echo "success";
        }
        exit();
    }

    /**
     * 支付宝快捷网关浏览器回复
     */
    public function aliexpressgatewayreturnAction()
    {
        //@error_log(date('Y-m-d H:i:s') . "页面返回:" . var_export($_POST,true), 3, '/tmp/pay/aliexpressgateway.log');
        $payment = QCPay_Models_Payment_Client::getOneById(13);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultDeal($res, 13);
        $this->commonShowResult($dealResult);
    }

    /**
     * 支付宝快捷网关自动对账回复
     */
    public function aliexpressgatewaynoticeAction()
    {
        //@error_log(date('Y-m-d H:i:s') . "页面返回:" . var_export($_POST,true), 3, '/tmp/pay/aliexpressgateway.log');
        $this->_helper->layout->disableLayout();
        $payment = QCPay_Models_Payment_Client::getOneById(13);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 13);
            echo "success";
        }
        exit();
    }

    /**
     *
     * Enter description here ...
     */
    public function alibanknoticeAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/alibank.log');
        $this->_helper->layout->disableLayout();
        $payment = QCPay_Models_Payment_Client::getOneById(12);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 12);
            echo "success";
        }
        exit();
    }

    public function alibankreturnAction()
    {
        $payment = QCPay_Models_Payment_Client::getOneById(12);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_GET);
        $dealResult = $this->payResultDeal($res, 12);
        $this->commonShowResult($dealResult);
    }

    /**
     * 网银信用卡
     * Enter description here ...
     */
    public function chinabankAction()
    {
		//@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/chinabank.log');
        $payment = QCPay_Models_Payment_Client::getOneById(4);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultDeal($res, 4);
        $this->commonShowResult($dealResult);
    }

    /**
     * 网银在线自动接收
     * Enter description here ...
     */
    public function chinabankautorevAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/chinabankautorev.log');
        $payment = QCPay_Models_Payment_Client::getOneById(4);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST);
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 4);
            echo "ok";
        } else {
            echo 'error';
        }
        exit();
    }

    /**
     * 腾讯财付通的回应
     * Enter description here ...
     */
    public function tenpayAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/tenpay.log');
        $payment = QCPay_Models_Payment_Client::getOneById(1);
        $payService = QCPay_Utils_Factory::factory($payment);
        $rspParams = $payService->parseResponse($_GET); //财付通是以get方式回复的。
        $dealResult = $this->payResultDeal($rspParams, 1);
        //财付通有自己的结果查看方式
        $this->view->orderCode = $rspParams->orderCode;
    }

    /**
     * 显示结果
     * Enter description here ...
     */
    public function showresultAction()
    {
        echo '通用显示结果';
        exit;

    }

    /**
     * 快钱的回复
     * Enter description here ...
     */
    public function kuaiqianAction()
    {
        $payment = QCPay_Models_Payment_Client::getOneById(2);
        $payService = QCPay_Utils_Factory::factory($payment);
        $rspParams = $payService->parseResponse($_GET);
    }

    /**
     * 盛付通浏览器返回
     * Enter description here ...
     */
    public function shengpayreturnAction()
    {
        //	$strData = '{"Amount":"0.01","PayAmount":"0.01","OrderNo":"1070021504","serialno":"B000110726001873577","Status":"01","MerchantNo":"408258","PayChannel":"04","Discount":"1","SignType":"2","PayTime":"20110726162126","CurrencyType":"RMB","ProductNo":"","ProductDesc":"","Remark1":"","Remark2":"","ExInfo":"bankid:SDTBNK","Branch":"SHB","MAC":"8ABC0FBAA3EE3202F16A915B42571B58"}';
        //	$pars = json_decode($strData, true);
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/shengpayreturn.log');
        $payment = QCPay_Models_Payment_Client::getOneById(11);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST);
        $dealResult = $this->payResultDeal($res, 11);
        $this->commonShowResult($dealResult);

    }

    /**
     * 盛付通服务器端返回
     * Enter description here ...
     */
    public function shengpaynoticeAction()
    {
        //@error_log("\r\n".date('Y-m-d H:i:s') . "页面返回:\r\n" . var_export($_POST,true), 3, '/tmp/pay/shengpaynotice.log');
        $payment = QCPay_Models_Payment_Client::getOneById(11);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST);
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 11);
            echo "OK";
        }
        exit();
    }

    /**
     * 银联手机支付结果返回
     */
    public function unionpaymobilenoticeAction()
    {
        //@error_log(date('Y-m-d H:i:s') . "页面返回:" . var_export($_POST,true), 3, '/tmp/pay/unionpaymobile.log');
        $xml = file_get_contents("php://input", 'r');
        $payment = QCPay_Models_Payment_Client::getOneById(14);
        $payService = QCPay_Utils_Factory::factory($payment);
        $ret = $payService->parseResponse(array('xml' => $xml));
        if ($ret->payResult == 200) {
            $dealResult = $this->payResultDeal($ret, 14);
            echo $ret->returnData;
        }
        exit();

    }

    /**
     * 支付宝手机支付的返回
     */
    public function alimobilenoticeAction()
    {
        //@error_log(date('Y-m-d H:i:s') . "页面返回:" . var_export($_POST,true), 3, '/tmp/pay/alimobile.log');
        $params = array();
        $params['notify_data'] = $this->helpGpost('notify_data');
        $params['sign'] = $this->helpGpost('sign');
        $payment = QCPay_Models_Payment_Client::getOneById(15);
        $payService = QCPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($params); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 15);
            echo "success";
        } else {
            echo "fail";
        }
        exit();
    }
    
    /**
     * 支付宝手机支付(极简)的返回
     */
    public function alimobilenoticeminiAction()
    {
        //@error_log(date('Y-m-d H:i:s') . "页面返回" . var_export($_POST,true), 3, '/tmp/pay/alimobilenoticemini.log');
    	$params = array();
    	$params = $_POST;
    	$payment = QCPay_Models_Payment_Client::getOneById(20);
    	$payService = QCPay_Utils_Factory::factory($payment);
    	$res = $payService->parseResponse($params); //支付宝通知使用的
    	if ($res->payResult != -1) {
    		$dealResult = $this->payResultDeal($res, 20);
    		echo "success";
    	} else {
    		echo "fail";
    	}
    	exit();
    }

    /**
     * 极简收银台的返回
     */
    public function alimobilesimpleAction()
    {
        /*
 array (
  'discount' => '0.00',
  'payment_type' => '1',
  'subject' => '903533384',
  'trade_no' => '2014031870580136',
  'buyer_email' => 'newalipaytest@sina.com',
  'gmt_create' => '2014-03-18 11:42:23',
  'notify_type' => 'trade_status_sync',
  'quantity' => '1',
  'out_trade_no' => '903533384',
  'seller_id' => '2088701661478015',
  'notify_time' => '2014-03-18 13:06:46',
  'body' => 'yoho',
  'trade_status' => 'WAIT_BUYER_PAY',
  'is_total_fee_adjust' => 'Y',
  'total_fee' => '8.00',
  'seller_email' => 'zfb@yoho.cn',
  'price' => '8.00',
  'buyer_id' => '2088802749169369',
  'notify_id' => '2f2f5620d9816ab2b9b799278c65d90a40',
  'use_coupon' => 'N',
  'sign_type' => 'RSA',
  'sign' => 'jXPXkDu6OVdSJ6SuNdSikXJllgrcNZewWqOjBAhF3Vsy6d++7mY7esruABH+2VuKJvrTARzNjKKMDNJeAoGdEyMQ/BBIPzuqxxnhZ6vtwXNzPtGSn/rvNtGoe4dxgqXcnU6mXqXmL5G4nSQPkem1B7ZsR9ak7mWpu98nbTeMQHE=',
)
         */
        //@error_log(date('Y-m-d H:i:s') . "页面返回:" . var_export($_POST,true), 3, '/tmp/pay/alimobilesimple.log');
        $payment = QINPay_Models_Payment_Client::getOneById(19);
        $payService = QINPay_Utils_Factory::factory($payment);
        $res = $payService->parseResponse($_POST); //支付宝通知使用的
        if ($res->payResult != -1) {
            $dealResult = $this->payResultDeal($res, 19);
            echo "success";
        } else {
            echo "fail";
        }
        exit();
    }

    /**
     * 微信扫码支付返回返回
     * Enter description here ...
     */
    public function wechatqrcodereturnAction()
    {
        //http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
        $payment = QCPay_Models_Payment_Client::getOneById(21);
        $payService = QCPay_Utils_Factory::factory($payment);
        $arrResponse = array('payResult'=>-1);
        $uid = $this->helpAuth();
        if($orderInfo = QINOrders_Models_Client::getByOrdercode($uid,$_GET['ordercode'])){
            $arrResponse = $orderInfo;
            $arrResponse['payResult'] = 200;
        }
        $res = $payService->parseResponse($arrResponse);
        $dealResult = $this->payResultDeal($res, 21);
        $this->commonShowResult($dealResult);
    }
}