RenewController.php 9.0 KB

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