RenewController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\set\classes\SetClass;
  4. use biz\sj\classes\SjClass;
  5. use biz\sj\services\MerchantExtendService;
  6. use biz\sj\services\MerchantService;
  7. use bizGhs\shop\classes\RenewClass;
  8. use bizHd\saas\services\RenewService;
  9. use bizHd\saas\services\SetMealService;
  10. use bizHd\user\services\UserService;
  11. use bizHd\wx\classes\WxOpenClass;
  12. use common\components\dict;
  13. use common\components\httpUtil;
  14. use common\components\orderSn;
  15. use common\components\util;
  16. use Yii;
  17. class RenewController extends BaseController
  18. {
  19. //需要续费 ssh 20240426
  20. public function actionNeedRemind()
  21. {
  22. $need = 1;
  23. $shop = $this->shop;
  24. if ($shop->needRenew == 0) {
  25. $need = 0;
  26. }
  27. if ($shop->hasRenew == 1) {
  28. $need = 0;
  29. }
  30. $date = date("Y_m_d");
  31. $staff = $this->shopAdmin;
  32. $staffId = $staff->id ?? 0;
  33. $cacheKey = 'no_remind_' . $date . '_' . $staffId;
  34. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  35. if (!empty($has)) {
  36. $need = 0;
  37. }
  38. $deadline = $shop->deadline ?? '';
  39. $newTime = bcadd(strtotime($deadline), 31536000);
  40. $newDeadline = date("Y-m-d H:i:s", $newTime);
  41. $old = substr($deadline, 0, 11);
  42. $new = substr($newDeadline, 0, 11);
  43. util::success(['need' => $need, 'currentDeadline' => $old, 'newDeadline' => $new]);
  44. }
  45. //当天不需要再提醒 ssh 20240426
  46. public function actionNoRemind()
  47. {
  48. $date = date("Y_m_d");
  49. $staff = $this->shopAdmin;
  50. $staffId = $staff->id ?? 0;
  51. $cacheKey = 'no_remind_' . $date . '_' . $staffId;
  52. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 86400, 'has']);
  53. util::complete();
  54. }
  55. public function actionList()
  56. {
  57. $where = [];
  58. $list = RenewService::getRenewList($where);
  59. util::success($list);
  60. }
  61. //创建续费的订单 ssh 20240425
  62. public function actionCreate()
  63. {
  64. ini_set('date.timezone', 'Asia/Shanghai');
  65. $get = Yii::$app->request->get();
  66. $year = $get['year'] ?? 1;
  67. $orderSn = orderSn::getRenewSn();
  68. $staff = $this->shopAdmin;
  69. $staffId = $staff->id ?? 0;
  70. $shopAdminName = $staff->name ?? '';
  71. $shop = $this->shop;
  72. $shopName = $shop->shopName ?? '';
  73. $shopId = $shop->id ?? 0;
  74. $sjId = $shop->sjId ?? 0;
  75. $sj = SjClass::getById($sjId, true);
  76. $sjName = $sj->name ?? '';
  77. $mainId = $shop->mainId ?? 0;
  78. $pfLevel = $shop->pfLevel ?? 0;
  79. $deadline = $shop->deadline ?? '';
  80. $beforeDeadline = $shop->beforeDeadline ?? '';
  81. if (getenv('YII_ENV') == 'production') {
  82. $unitPrice = $pfLevel == 0 ? 980 : 1980;
  83. } else {
  84. $unitPrice = $pfLevel == 0 ? 0.1 : 0.2;
  85. }
  86. $price = bcmul($unitPrice, $year, 2);
  87. $data = [
  88. 'orderSn' => $orderSn,
  89. 'prePrice' => $price,
  90. 'actPrice' => $price,
  91. 'shopAdminId' => $staffId,
  92. 'shopAdminName' => $shopAdminName,
  93. 'sjId' => $sjId,
  94. 'sjName' => $sjName,
  95. 'mainId' => $mainId,
  96. 'shopId' => $shopId,
  97. 'shopName' => $shopName,
  98. 'pfLevel' => $pfLevel,
  99. 'year' => $year,
  100. 'deadline' => $deadline,
  101. 'beforeDeadline' => $beforeDeadline,
  102. 'status' => 0,
  103. ];
  104. $ret = RenewClass::add($data, true);
  105. $id = $ret->id ?? 0;
  106. $now = time();
  107. $expireTime = $now + 300;//订单5分钟后过期
  108. $totalFee = $price;
  109. $name = "续费{$year}年";
  110. $admin = $this->admin;
  111. $openId = $admin->ghsMiniOpenId;
  112. $capitalType = dict::getDict('capitalType', 'xhRenew', 'id');
  113. $attach = 'capitalType=' . $capitalType;
  114. $wx = Yii::getAlias("@vendor/weixin");
  115. require_once($wx . '/lib/WxPay.Api.php');
  116. require_once($wx . '/example/WxPay.JsApiPay.php');
  117. $input = new \WxPayUnifiedOrder();
  118. $input->SetBody($name);
  119. $input->SetOut_trade_no($orderSn);
  120. $input->SetTotal_fee($totalFee * 100);
  121. $input->SetTime_start(date("YmdHis", $now));
  122. $input->SetAttach($attach);
  123. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  124. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  125. $input->SetTrade_type("JSAPI");
  126. //花卉宝代为申请的微信支付
  127. $sjExtend = WxOpenClass::getGhsWxInfo();
  128. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  129. $input->SetSub_openid($openId);
  130. } else {
  131. $input->SetOpenid($openId);
  132. }
  133. //小程序使用miniAppId
  134. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  135. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  136. $tools = new \JsApiPay();
  137. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  138. $newParams = json_decode($jsApiParameters, true);
  139. $newParams['id'] = $id;
  140. util::success($newParams);
  141. }
  142. //微信支付购买 ssh 2020.1.11
  143. public function actionWxPay()
  144. {
  145. ini_set('date.timezone', 'Asia/Shanghai');
  146. $shopAdminId = $this->shopAdminId;
  147. $addData['shopAdminId'] = $shopAdminId;
  148. $shopAdmin = $this->shopAdmin->attributes;
  149. $adminName = $shopAdmin['name'] ?? '';
  150. $sjId = $shopAdmin['sjId'];
  151. $addData['shopAdminName'] = $adminName;
  152. $set = SetClass::getByCondition(['style' => SetClass::SET_STYLE_GHS], true, 'id asc');
  153. if (empty($set)) {
  154. util::fail('没有找到套餐');
  155. }
  156. $price = $set->price;
  157. $prePrice = $price;
  158. $actPrice = $price;
  159. $setId = $set->id;
  160. $addData['actPrice'] = $actPrice;
  161. $addData['prePrice'] = $prePrice;
  162. $addData['sjId'] = $this->sjId;
  163. $now = time();
  164. $expireTime = $now + 300;//订单5分钟后过期
  165. $addData['deadline'] = date("Y-m-d H:i:s", $expireTime);
  166. $order = RenewService::addOrder($addData);
  167. $orderId = $order['id'];
  168. $orderSn = $order['orderSn'];
  169. $couponId = 0;
  170. $name = $set->name . '开通及续费';
  171. $totalFee = $actPrice;
  172. $admin = $this->admin->attributes;
  173. //小程序使用miniOpenId
  174. $openId = $admin['ghsMiniOpenId'];
  175. $capitalType = dict::getDict('capitalType', 'xhRenew', 'id');
  176. //将流水类型、优惠卷传过去
  177. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&setId=' . $setId . '&sjId=' . $sjId;
  178. $wx = Yii::getAlias("@vendor/weixin");
  179. require_once($wx . '/lib/WxPay.Api.php');
  180. require_once($wx . '/example/WxPay.JsApiPay.php');
  181. $input = new \WxPayUnifiedOrder();
  182. $input->SetBody($name);
  183. $input->SetOut_trade_no($orderSn);
  184. $input->SetTotal_fee($totalFee * 100);
  185. $input->SetTime_start(date("YmdHis", $now));
  186. $input->SetAttach($attach);
  187. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  188. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  189. $input->SetTrade_type("JSAPI");
  190. //花卉宝代为申请的微信支付
  191. $sjExtend = WxOpenClass::getGhsWxInfo();
  192. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  193. $input->SetSub_openid($openId);
  194. } else {
  195. $input->SetOpenid($openId);
  196. }
  197. //小程序使用miniAppId
  198. if (httpUtil::isMiniProgram()) {
  199. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  200. }
  201. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  202. $tools = new \JsApiPay();
  203. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  204. $newParams = json_decode($jsApiParameters, true);
  205. $newParams['orderId'] = $orderId;
  206. $newParams['sjId'] = $this->sjId;
  207. util::success($newParams);
  208. }
  209. }