RenewController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace hd\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. $shopAdminId = $this->shopAdminId;
  26. $addData['shopAdminId'] = $shopAdminId;
  27. $shopAdmin = $this->shopAdmin;
  28. $adminName = $shopAdmin['name'] ?? '';
  29. $addData['shopAdminName'] = $adminName;
  30. $price = 0.01;
  31. $prePrice = $price;
  32. $actPrice = $price;
  33. $addData['actPrice'] = $actPrice;
  34. $addData['prePrice'] = $prePrice;
  35. $addData['merchantId'] = $this->sjId;
  36. $now = time();
  37. $expireTime = $now + 300;//订单5分钟后过期
  38. $addData['deadline'] = date("Y-m-d H:i:s", $expireTime);
  39. $order = RenewService::addOrder($addData);
  40. $orderId = $order['id'];
  41. $orderSn = $order['orderSn'];
  42. $couponId = 0;
  43. $name = '基础版开通续费';
  44. $totalFee = $actPrice;
  45. $admin = $this->admin;
  46. //小程序使用miniOpenId
  47. $openId = $admin['miniOpenId'];
  48. $capitalType = dict::getDict('capitalType', 'xhRenew', 'id');
  49. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
  50. $wx = Yii::getAlias("@vendor/weixin");
  51. require_once($wx . '/lib/WxPay.Api.php');
  52. require_once($wx . '/example/WxPay.JsApiPay.php');
  53. $input = new \WxPayUnifiedOrder();
  54. $input->SetBody($name);
  55. $input->SetOut_trade_no($orderSn);
  56. $input->SetTotal_fee($totalFee * 100);
  57. $input->SetTime_start(date("YmdHis", $now));
  58. $input->SetAttach($attach);
  59. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  60. $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
  61. $input->SetTrade_type("JSAPI");
  62. //花卉宝代为申请的微信支付
  63. $merchantExtend = WxOpenClass::getWxInfo();
  64. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  65. $input->SetSub_openid($openId);
  66. } else {
  67. $input->SetOpenid($openId);
  68. }
  69. //小程序使用miniAppId
  70. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  71. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  72. $tools = new \JsApiPay();
  73. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  74. $newParams = json_decode($jsApiParameters, true);
  75. $newParams['orderId'] = $orderId;
  76. $newParams['merchantId'] = $this->sjId;
  77. util::success($newParams);
  78. }
  79. }