RenewController.php 8.1 KB

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