選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

193 行
6.1 KiB

  1. <?php
  2. /**
  3. * 订单控制层类 用于下单、取消订单、获取订单信息等处理
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm OrderController.php
  13. * Create By 2017/6/14 17:32 $
  14. */
  15. namespace zzcx\controllers\order;
  16. use common\service\login\LoginService;
  17. use common\service\pay\PayService;
  18. use common\service\pay\WeChatPay;
  19. use common\util\OrderUtil;
  20. use common\util\Util;
  21. use yii\web\Controller;
  22. use zzcx\service\order\Order;
  23. class OrderController extends Controller
  24. {
  25. private $service = null;
  26. public function service()
  27. {
  28. if ($this->service == null) {
  29. $this->service = new Order();
  30. }
  31. return $this->service;
  32. }
  33. /**
  34. * Des:获取支付参数
  35. * Name: actionGetPayDate
  36. * @return string
  37. * @author 倪宗锋
  38. */
  39. public function actionGetPayDate()
  40. {
  41. $params = [
  42. 'order_id' => $this->_post('order_id', '')
  43. ];
  44. /**如果当前环境是微信 怎进行跳转获取openid放到cookies中*/
  45. $getAppType = Util::checkWeChatOrAliPay();// 1、微信 2、支付宝 3、其他
  46. $key = Util::getSiteConfig()['entryAuthWeChat'];
  47. if ($getAppType == 1 && empty($_COOKIE[$key.'_openid'])) {//微信支付需要使用openid,如果没有则去获取openid后再跳回来
  48. $siteConfig = Util::getSiteConfig();
  49. $redirect = $siteConfig['payUrl'] . $params['order_id'];
  50. $getUrl = LoginService::getLoginUrlUnAuth($redirect, 1);
  51. return Util::returnJsEr('', '', $getUrl);
  52. }
  53. /****获取支付参数***/
  54. $getPayParams = $this->service()->getPayParams($params);
  55. if ($getPayParams['flag'] == false) {
  56. return Util::returnJsEr($getPayParams['msg']);
  57. }
  58. $return = $getPayParams['data'];
  59. return Util::returnJsSu('', ['payType' => $getAppType, 'payParam' => $return]);
  60. }
  61. /**
  62. * Des:校验酒店是否可订
  63. * Name: actionCheckHotel
  64. * @return array
  65. * @author 倪宗锋
  66. */
  67. public function actionCheckHotel()
  68. {
  69. $params = [
  70. 'order_id' => $this->_post('order_id', '')
  71. ];
  72. if (Util::checkPattern('intVal', $params['order_id']) == false) {
  73. return Util::returnArrEr('params error');
  74. }
  75. $result = $this->service()->checkHotel($params['order_id']);
  76. return json_encode($result);
  77. }
  78. /**
  79. * Des:支付回调接口
  80. * 用于接收微信支付结果、支付宝支付结果、余额支付结果
  81. * Name: actionNotify
  82. * @return string
  83. * @author 倪宗锋
  84. */
  85. public function actionNotify()
  86. {
  87. $payType = empty($_POST['app_id']) ? 1 : 2;//1微信2支付宝3余额
  88. if (empty($_POST['system']) == false && $_POST['system'] == 1) {
  89. $payType = 3;
  90. }
  91. if ($payType == 1) {//微信支付
  92. $payFlag = OrderUtil::weChatOrderPay();
  93. } elseif ($payType == 2) {//支付宝支付
  94. $payFlag = OrderUtil::aliOrderPay();
  95. if ($payFlag['flag']) {//返回成功
  96. return 'success';
  97. }else{
  98. return $payFlag['msg'];
  99. }
  100. } else {//余额支付
  101. $payFlag = OrderUtil::amountOrderPay();
  102. }
  103. if ($payFlag['flag']) {//返回成功
  104. $return['return_code'] = 'SUCCESS';
  105. $return['return_msg'] = 'OK';
  106. } else {
  107. $return['return_code'] = 'FAIL';
  108. $return['return_msg'] = $payFlag['msg'];
  109. }
  110. return '<?xml version="1.0" encoding="UTF-8"?>' . Util::arraysToXml(['response' => $return]);//转换为xml返回
  111. }
  112. /**
  113. * Des:下单
  114. * Name: actionMakeOrder
  115. * @return string
  116. * @author 倪宗锋
  117. */
  118. public function actionMakeOrder()
  119. {
  120. /***获取下单参数***/
  121. $params = $this->service()->getMakeOrderParams();
  122. /**调用下单方法**/
  123. $result = OrderUtil::makeOrder($params);
  124. return json_encode($result);
  125. }
  126. /**
  127. * Des:获取推荐产品列表
  128. * Name: actionGetRecommend
  129. * @return string
  130. * @author 倪宗锋
  131. */
  132. public function actionGetRecommend()
  133. {
  134. $order_id = $this->_post('order_id', '');//获取订单ID
  135. $list = $this->service()->getRecommend($order_id);
  136. return json_encode($list);
  137. }
  138. /**
  139. * Des:校验订单的状态
  140. * Name: actionCheckOrderStatus
  141. * @return string
  142. * @author 倪宗锋
  143. */
  144. public function actionCheckOrderStatus()
  145. {
  146. $params = [
  147. 'order_id' => $this->_post('order_id', ''),//订单ID
  148. 'money' => $this->_post('money', ''),//金额
  149. ];
  150. $getStatus = $this->service()->checkOrderStatus($params);
  151. return json_encode($getStatus);
  152. }
  153. /**
  154. * Des:支付成功返回 页面
  155. * Name: actionReturn
  156. * @return \yii\web\Response
  157. * @author 倪宗锋
  158. */
  159. public function actionReturn()
  160. {
  161. $order_id = $this->_get('order_id', '');
  162. return $this->redirect('/web/zzcx/?#/main/pay/pay_success?order_id=' . $order_id);
  163. }
  164. public function actionH5Pay(){
  165. echo "<a href='/zzcx/order/order/test'>支付 </a>";
  166. }
  167. public function actionTest(){
  168. $wechat = new WeChatPay();
  169. $data = [
  170. 'name'=>'ces'.rand(100,9999),
  171. 'total_fee'=> 0.01,
  172. 'order_id'=> 3456
  173. ];
  174. $result = $wechat->H5Pay($data);
  175. if ($result['flag'] == false) {
  176. return $result['msg'];
  177. }else{
  178. return $this->redirect($result['data']['pay_url']);
  179. }
  180. }
  181. }