|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- /**
- * 订单控制层类 用于下单、取消订单、获取订单信息等处理
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm OrderController.php
- * Create By 2017/6/14 17:32 $
- */
-
- namespace zzcx\controllers\order;
-
- use common\service\login\LoginService;
- use common\service\pay\PayService;
- use common\service\pay\WeChatPay;
- use common\util\OrderUtil;
- use common\util\Util;
- use yii\web\Controller;
- use zzcx\service\order\Order;
-
- class OrderController extends Controller
- {
- private $service = null;
-
- public function service()
- {
- if ($this->service == null) {
- $this->service = new Order();
- }
- return $this->service;
- }
-
- /**
- * Des:获取支付参数
- * Name: actionGetPayDate
- * @return string
- * @author 倪宗锋
- */
- public function actionGetPayDate()
- {
- $params = [
- 'order_id' => $this->_post('order_id', '')
- ];
- /**如果当前环境是微信 怎进行跳转获取openid放到cookies中*/
- $getAppType = Util::checkWeChatOrAliPay();// 1、微信 2、支付宝 3、其他
- $key = Util::getSiteConfig()['entryAuthWeChat'];
- if ($getAppType == 1 && empty($_COOKIE[$key.'_openid'])) {//微信支付需要使用openid,如果没有则去获取openid后再跳回来
- $siteConfig = Util::getSiteConfig();
- $redirect = $siteConfig['payUrl'] . $params['order_id'];
- $getUrl = LoginService::getLoginUrlUnAuth($redirect, 1);
- return Util::returnJsEr('', '', $getUrl);
- }
- /****获取支付参数***/
- $getPayParams = $this->service()->getPayParams($params);
- if ($getPayParams['flag'] == false) {
- return Util::returnJsEr($getPayParams['msg']);
- }
- $return = $getPayParams['data'];
- return Util::returnJsSu('', ['payType' => $getAppType, 'payParam' => $return]);
- }
-
- /**
- * Des:校验酒店是否可订
- * Name: actionCheckHotel
- * @return array
- * @author 倪宗锋
- */
- public function actionCheckHotel()
- {
- $params = [
- 'order_id' => $this->_post('order_id', '')
- ];
- if (Util::checkPattern('intVal', $params['order_id']) == false) {
- return Util::returnArrEr('params error');
- }
- $result = $this->service()->checkHotel($params['order_id']);
- return json_encode($result);
- }
-
- /**
- * Des:支付回调接口
- * 用于接收微信支付结果、支付宝支付结果、余额支付结果
- * Name: actionNotify
- * @return string
- * @author 倪宗锋
- */
- public function actionNotify()
- {
- $payType = empty($_POST['app_id']) ? 1 : 2;//1微信2支付宝3余额
- if (empty($_POST['system']) == false && $_POST['system'] == 1) {
- $payType = 3;
- }
- if ($payType == 1) {//微信支付
- $payFlag = OrderUtil::weChatOrderPay();
- } elseif ($payType == 2) {//支付宝支付
- $payFlag = OrderUtil::aliOrderPay();
- if ($payFlag['flag']) {//返回成功
- return 'success';
- }else{
- return $payFlag['msg'];
- }
- } else {//余额支付
- $payFlag = OrderUtil::amountOrderPay();
- }
- if ($payFlag['flag']) {//返回成功
- $return['return_code'] = 'SUCCESS';
- $return['return_msg'] = 'OK';
- } else {
- $return['return_code'] = 'FAIL';
- $return['return_msg'] = $payFlag['msg'];
- }
- return '<?xml version="1.0" encoding="UTF-8"?>' . Util::arraysToXml(['response' => $return]);//转换为xml返回
- }
-
- /**
- * Des:下单
- * Name: actionMakeOrder
- * @return string
- * @author 倪宗锋
- */
- public function actionMakeOrder()
- {
- /***获取下单参数***/
- $params = $this->service()->getMakeOrderParams();
- /**调用下单方法**/
- $result = OrderUtil::makeOrder($params);
- return json_encode($result);
- }
-
- /**
- * Des:获取推荐产品列表
- * Name: actionGetRecommend
- * @return string
- * @author 倪宗锋
- */
- public function actionGetRecommend()
- {
- $order_id = $this->_post('order_id', '');//获取订单ID
- $list = $this->service()->getRecommend($order_id);
- return json_encode($list);
- }
-
- /**
- * Des:校验订单的状态
- * Name: actionCheckOrderStatus
- * @return string
- * @author 倪宗锋
- */
- public function actionCheckOrderStatus()
- {
- $params = [
- 'order_id' => $this->_post('order_id', ''),//订单ID
- 'money' => $this->_post('money', ''),//金额
- ];
- $getStatus = $this->service()->checkOrderStatus($params);
- return json_encode($getStatus);
- }
-
- /**
- * Des:支付成功返回 页面
- * Name: actionReturn
- * @return \yii\web\Response
- * @author 倪宗锋
- */
- public function actionReturn()
- {
- $order_id = $this->_get('order_id', '');
- return $this->redirect('/web/zzcx/?#/main/pay/pay_success?order_id=' . $order_id);
- }
-
- public function actionH5Pay(){
- echo "<a href='/zzcx/order/order/test'>支付 </a>";
- }
- public function actionTest(){
- $wechat = new WeChatPay();
- $data = [
- 'name'=>'ces'.rand(100,9999),
- 'total_fee'=> 0.01,
- 'order_id'=> 3456
- ];
- $result = $wechat->H5Pay($data);
- if ($result['flag'] == false) {
- return $result['msg'];
- }else{
- return $this->redirect($result['data']['pay_url']);
- }
- }
- }
|