RenewController.php 3.3 KB

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