shop; if ($shop->needRenew == 0) { $need = 0; } if ($shop->hasRenew == 1) { $need = 0; } $renewType = $shop->renewType ?? 0; $date = date("Y_m_d"); $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $cacheKey = 'no_remind_' . $date . '_' . $staffId; $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (!empty($has)) { $need = 0; } $deadline = $shop->deadline ?? ''; $newTime = bcadd(strtotime($deadline), 31536000); $newDeadline = date("Y-m-d H:i:s", $newTime); $old = substr($deadline, 0, 11); $new = substr($newDeadline, 0, 11); $hasRenew = $shop->hasRenew ?? 0; util::success(['need' => $need, 'currentDeadline' => $old, 'newDeadline' => $new, 'hasRenew' => $hasRenew, 'renewType' => $renewType]); } //当天不需要再提醒 ssh 20240426 public function actionNoRemind() { $date = date("Y_m_d"); $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $cacheKey = 'no_remind_' . $date . '_' . $staffId; $mainId = $this->mainId; $time = 86400; if (getenv('YII_ENV') == 'production') { //莱漫和国恋需要更多提醒次数 if ($mainId == 7704 || $mainId == 65) { $time = 15000; } } else { if ($mainId == 644) { $time = 86400; } } Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $time, 'has']); util::complete(); } public function actionList() { $where = []; $list = RenewService::getRenewList($where); util::success($list); } //创建续费的订单 ssh 20240425 public function actionCreate() { ini_set('date.timezone', 'Asia/Shanghai'); $get = Yii::$app->request->get(); $year = $get['year'] ?? 1; $orderSn = orderSn::getRenewSn(); $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $shopAdminName = $staff->name ?? ''; $shop = $this->shop; $shopName = $shop->shopName ?? ''; $shopId = $shop->id ?? 0; $sjId = $shop->sjId ?? 0; $sj = SjClass::getById($sjId, true); $sjName = $sj->name ?? ''; $mainId = $shop->mainId ?? 0; $pfLevel = $shop->pfLevel ?? 0; $deadline = $shop->deadline ?? ''; $beforeDeadline = $shop->beforeDeadline ?? ''; if (getenv('YII_ENV') == 'production') { $unitPrice = $pfLevel == 0 ? 1580 : 2580; if ($mainId == 50) { $unitPrice = $pfLevel == 0 ? 0.5 : 1; } } else { $unitPrice = $pfLevel == 0 ? 0.1 : 0.2; } $price = bcmul($unitPrice, $year, 2); $data = [ 'orderSn' => $orderSn, 'prePrice' => $price, 'actPrice' => $price, 'shopAdminId' => $staffId, 'shopAdminName' => $shopAdminName, 'sjId' => $sjId, 'sjName' => $sjName, 'mainId' => $mainId, 'shopId' => $shopId, 'shopName' => $shopName, 'pfLevel' => $pfLevel, 'year' => $year, 'deadline' => $deadline, 'beforeDeadline' => $beforeDeadline, 'status' => 0, ]; $ret = RenewClass::add($data, true); $id = $ret->id ?? 0; $now = time(); $expireTime = $now + 300;//订单5分钟后过期 $totalFee = $price; $name = "续费{$year}年"; $admin = $this->admin; $openId = $admin->ghsMiniOpenId; $capitalType = dict::getDict('capitalType', 'xhRenew', 'id'); $attach = 'capitalType=' . $capitalType; $wx = Yii::getAlias("@vendor/weixin"); require_once($wx . '/lib/WxPay.Api.php'); require_once($wx . '/example/WxPay.JsApiPay.php'); $input = new \WxPayUnifiedOrder(); $input->SetBody($name); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($totalFee * 100); $input->SetTime_start(date("YmdHis", $now)); $input->SetAttach($attach); $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟 $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $sjExtend = WxOpenClass::getGhsWxInfo(); if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //小程序使用miniAppId $sjExtend['wxAppId'] = $sjExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend); $newParams = json_decode($jsApiParameters, true); $newParams['id'] = $id; util::success($newParams); } //微信支付购买 ssh 2020.1.11 public function actionWxPay() { ini_set('date.timezone', 'Asia/Shanghai'); $shopAdminId = $this->shopAdminId; $addData['shopAdminId'] = $shopAdminId; $shopAdmin = $this->shopAdmin->attributes; $adminName = $shopAdmin['name'] ?? ''; $sjId = $shopAdmin['sjId']; $addData['shopAdminName'] = $adminName; $set = SetClass::getByCondition(['style' => SetClass::SET_STYLE_GHS], true, 'id asc'); if (empty($set)) { util::fail('没有找到套餐'); } $price = $set->price; $prePrice = $price; $actPrice = $price; $setId = $set->id; $addData['actPrice'] = $actPrice; $addData['prePrice'] = $prePrice; $addData['sjId'] = $this->sjId; $now = time(); $expireTime = $now + 300;//订单5分钟后过期 $addData['deadline'] = date("Y-m-d H:i:s", $expireTime); $order = RenewService::addOrder($addData); $orderId = $order['id']; $orderSn = $order['orderSn']; $couponId = 0; $name = $set->name . '开通及续费'; $totalFee = $actPrice; $admin = $this->admin->attributes; //小程序使用miniOpenId $openId = $admin['ghsMiniOpenId']; $capitalType = dict::getDict('capitalType', 'xhRenew', 'id'); //将流水类型、优惠卷传过去 $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&setId=' . $setId . '&sjId=' . $sjId; $wx = Yii::getAlias("@vendor/weixin"); require_once($wx . '/lib/WxPay.Api.php'); require_once($wx . '/example/WxPay.JsApiPay.php'); $input = new \WxPayUnifiedOrder(); $input->SetBody($name); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($totalFee * 100); $input->SetTime_start(date("YmdHis", $now)); $input->SetAttach($attach); $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟 $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $sjExtend = WxOpenClass::getGhsWxInfo(); if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //小程序使用miniAppId if (httpUtil::isMiniProgram()) { $sjExtend['wxAppId'] = $sjExtend['miniAppId']; } $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend); $newParams = json_decode($jsApiParameters, true); $newParams['orderId'] = $orderId; $newParams['sjId'] = $this->sjId; util::success($newParams); } }