RenewController.php 8.4 KB

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