RenewController.php 8.4 KB

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