RenewController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantExtendService;
  4. use biz\sj\services\MerchantService;
  5. use bizHd\saas\services\RenewService;
  6. use bizHd\saas\services\SetMealService;
  7. use bizHd\user\services\UserService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\httpUtil;
  11. use common\components\util;
  12. use Yii;
  13. class RenewController extends BaseController
  14. {
  15. public function actionList()
  16. {
  17. $where = [];
  18. $list = RenewService::getRenewList($where);
  19. util::success($list);
  20. }
  21. //微信支付购买 ssh 2020.1.11
  22. public function actionWxPay()
  23. {
  24. ini_set('date.timezone', 'Asia/Shanghai');
  25. $sj = $this->sj;
  26. $setId = isset($sj['setId']) ? $sj['setId'] : 0;
  27. $set = SetMealService::getById($setId);
  28. if (empty($set)) {
  29. util::fail('没有找到套餐');
  30. }
  31. $shopAdminId = $this->shopAdminId;
  32. $addData['shopAdminId'] = $shopAdminId;
  33. $shopAdmin = $this->shopAdmin;
  34. $adminName = $shopAdmin['name'] ?? '';
  35. $addData['shopAdminName'] = $adminName;
  36. $price = $set['price'];
  37. $prePrice = $price;
  38. $actPrice = $price;
  39. $addData['actPrice'] = $actPrice;
  40. $addData['prePrice'] = $prePrice;
  41. $addData['merchantId'] = $this->sjId;
  42. $now = time();
  43. $expireTime = $now + 300;//订单5分钟后过期
  44. $addData['deadline'] = $expireTime;
  45. $order = RenewService::addOrder($addData);
  46. $orderId = $order['id'];
  47. $orderSn = $order['orderSn'];
  48. $couponId = 0;
  49. $name = $set['name'] . '开通续费';
  50. $totalFee = $actPrice;
  51. $admin = $this->admin;
  52. //小程序使用miniOpenId
  53. $openId = $admin['miniOpenId'];
  54. $capitalType = dict::getDict('capitalType', 'xhRenew', 'id');
  55. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
  56. $wx = Yii::getAlias("@vendor/weixin");
  57. require_once($wx . '/lib/WxPay.Api.php');
  58. require_once($wx . '/example/WxPay.JsApiPay.php');
  59. $input = new \WxPayUnifiedOrder();
  60. $input->SetBody($name);
  61. $input->SetOut_trade_no($orderSn);
  62. $input->SetTotal_fee($totalFee * 100);
  63. $input->SetTime_start(date("YmdHis", $now));
  64. $input->SetAttach($attach);
  65. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  66. $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
  67. $input->SetTrade_type("JSAPI");
  68. //花卉宝代为申请的微信支付
  69. $sjExtend = WxOpenClass::getGhsWxInfo();
  70. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  71. $input->SetSub_openid($openId);
  72. } else {
  73. $input->SetOpenid($openId);
  74. }
  75. //小程序使用miniAppId
  76. if (httpUtil::isMiniProgram()) {
  77. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  78. }
  79. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  80. $tools = new \JsApiPay();
  81. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  82. $newParams = json_decode($jsApiParameters, true);
  83. $newParams['orderId'] = $orderId;
  84. $newParams['merchantId'] = $this->sjId;
  85. util::success($newParams);
  86. }
  87. }