RenewController.php 8.6 KB

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