request->get(); if (getenv('YII_ENV') == 'dev') { $ip = Yii::$app->request->getUserIP(); if ($ip == '127.0.0.1') { util::success(['rechargeAccountLink' => 'www.google.com', 'orderLink' => 'www.google.com']); } } $orderId = $get['orderId'] ?? 0; $account = $this->shopId; $page = 'pages/member/recharge?account=' . $account; $ret = WxMiniClass::getShortLink($page); $link = $ret['link'] ?? ''; $orderLink = ''; if (!empty($orderId)) { $order = OrderClass::getById($orderId, true); if ($order->mainId != $this->mainId) { util::fail('访问错误'); } $orderPage = 'pages/order/detail?account=' . $account . '&id=' . $orderId; $res = WxMiniClass::getShortLink($orderPage); $orderLink = $res['link'] ?? ''; } util::success(['rechargeAccountLink' => $link, 'orderLink' => $orderLink]); } //获取扫码充值的小程序码 public function actionGetRechargeCode() { $shopId = $this->shopId; $recharge = MemberWealClass::getAllByCondition(['shopId' => $shopId], 'recharge asc', '*', null); //这里取前面三个放在海报里,对应表名是 xhMemberRecharge 不是 MemberWeal $merchant = WxOpenClass::getMallWxInfo(); $page = 'pages/member/recharge'; $ptStyle = dict::getDict('ptStyle', 'mall'); $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId; $imgUrl = miniUtil::generateUnlimitedRechargeMiniCode($merchant, $page, $scene, $ptStyle); $prefix = imgUtil::getPrefix(); $titleBase64 = stringUtil::ossBase64('扫码充值'); $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl); $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image'; $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40'; $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50'; $posterUrl = $prefix . 'poster/recharge_poster.jpg'; // 组合充值海报:将前3条充值活动写入海报对应位置 // 海报尺寸:955x1439;以下坐标为在设计稿上测得的三行“进店充值/获得”数值区大致位置 // 位置从上到下三行,左列为“进店充值”,中列为“获得” $posterProcess = '?x-oss-process=image'; // 将小程序码放到右下角白色区域,大小与白色区域一致(可按需微调) $qrWidth = 230; // 白色区域宽度,像素 $qrRightPadding = 144; // 距离右边的留白 $qrBottomPadding = 72; // 距离底部的留白 // 先用 $imgUrl 生成按宽度缩放后的小程序码图片,再拼接到海报 $miniCodeResizeUrl = $imgUrl . (strpos($imgUrl, '?') === false ? '?x-oss-process=image' : '&x-oss-process=image'); $miniCodeResizeUrl .= '/resize,w_' . $qrWidth; $miniCodeResizeBase64 = stringUtil::ossBase64($miniCodeResizeUrl); $posterProcess .= '/watermark,image_' . $miniCodeResizeBase64 . ',g_se,x_' . $qrRightPadding . ',y_' . $qrBottomPadding; $positions = [ ['recharge' => ['x' => 220, 'y' => 655], 'give' => ['x' => 500, 'y' => 655]], ['recharge' => ['x' => 220, 'y' => 840], 'give' => ['x' => 500, 'y' => 840]], ['recharge' => ['x' => 220, 'y' => 1020], 'give' => ['x' => 500, 'y' => 1020]], ]; $fontSize = 50; // 数值字号 if (!empty($recharge)) { // 先生成同一张图片上的文字水印串,最后再与$posterProcess合并 $textProcess = ''; $topThree = array_slice($recharge, 0, 3); foreach ($topThree as $index => $val) { $pos = $positions[$index] ?? null; if ($pos === null) { continue; } $rechargeText = (string)(intval($val['recharge']) ?? ''); $giveText = (string)(intval($val['give']) ?? ''); if ($rechargeText !== '') { $rechargeBase64 = stringUtil::ossBase64($rechargeText); $textProcess .= '/watermark,text_' . $rechargeBase64 . ',g_nw,x_' . $pos['recharge']['x'] . ',y_' . $pos['recharge']['y'] . ',size_' . $fontSize . ',color_333333,type_' . stringUtil::ossBase64('fangzhengheiti'); } if ($giveText !== '') { $giveBase64 = stringUtil::ossBase64($giveText); $textProcess .= '/watermark,text_' . $giveBase64 . ',g_nw,x_' . $pos['give']['x'] . ',y_' . $pos['give']['y'] . ',size_' . $fontSize . ',color_8B0000,type_' . stringUtil::ossBase64('fangzhengheiti'); } } $posterProcess .= $textProcess; } $posterUrl .= $posterProcess; $respond = ['imgUrl' => $memberUrl, 'posterUrl' => $posterUrl]; util::success($respond); } //手动给客户充值 ssh 20250301 public function actionManRecharge() { $post = Yii::$app->request->post(); $shopAdmin = $this->shopAdmin; if ($shopAdmin->super != 1) { util::fail('超管才能充值'); } $staffId = $shopAdmin->id; $staffName = $shopAdmin->name; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $payWay = $post['payWay'] ?? 0; $amount = $post['amount'] ?? 0; $remark = $post['remark'] ?? ''; $customId = $post['customId'] ?? 0; $shOrderId = $post['shOrderId'] ?? 0; $custom = \bizHd\custom\classes\CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } //避免重复提交 util::checkRepeatCommit($customId, 4); $shOrderSn = ''; if (!empty($shOrderId)) { $shOrder = OrderClass::getById($shOrderId, true); if ($shOrder->forward != 1) { util::fail('不是售后付款单'); } if ($shOrder->mainId != $this->mainId) { util::fail('不是你的单'); } //判断是否充值过了 \bizHd\recharge\classes\RechargeClass::checkShOrderRecharge($shOrder); $shOrderSn = $shOrder->orderSn ?? ''; } $refundOrderId = $post['refundOrderId'] ?? 0; $refundOrderSn = ''; if (!empty($refundOrderId)) { //线下订单售后,充值 $myOrder = OrderClass::getById($refundOrderId, true); if ($myOrder->mainId != $this->mainId) { util::fail('不是你的订单'); } $refundOrderSn = $myOrder->orderSn ?? ''; } $customName = $custom->name; $userId = $custom->userId ?? 0; $hdId = $custom->hdId; $hd = HdClass::getById($hdId, true); if (empty($hd)) { util::fail('花店信息缺失,编号9886'); } $hdName = $hd->name; $shopId = $this->shopId; $mainId = $this->mainId; $orderSn = orderSn::getRechargeSn(); $rechargeData = [ 'orderSn' => $orderSn, 'modPrice' => 1, 'payWay' => $payWay, 'shopId' => $shopId, 'mainId' => $mainId, 'hdId' => $hdId, 'hdName' => $hdName, 'onlinePay' => 1, 'amount' => $amount, 'staffId' => $staffId, 'staffName' => $staffName, 'payStatus' => 0, 'payTime' => '0000-00-00 00:00:00', 'status' => 0, 'remark' => $remark, 'customId' => $customId, 'customName' => $customName, 'userId' => $userId, 'shOrderId' => $shOrderId, 'shOrderSn' => $shOrderSn, 'refundOrderId' => $refundOrderId, 'refundOrderSn' => $refundOrderSn, ]; $respond = \bizHd\recharge\classes\RechargeClass::addRecharge($rechargeData); $id = $respond->id; $recharge = RechargeClass::getLockById($id); $params = ['onlinePay' => 1, 'side' => 0]; //充值成功并且销账 \bizHd\recharge\classes\RechargeClass::complete($recharge, $payWay, $params); $transaction->commit(); util::success($post); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("充值失败原因:" . $e->getMessage()); util::fail('充值失败'); } } //充值记录 ssh 2021.2.21 public function actionList() { $get = Yii::$app->request->get(); $customId = $get['customId'] ?? 0; $custom = \bizHd\custom\classes\CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } if ($custom->shopId != $this->shopId) { util::fail('不是你的客户'); } $where = ['shopId' => $this->shopId, 'customId' => $customId]; $list = RechargeClass::getRechargeList($where); util::success($list); } //免费续期活动 ssh 2021.2.21 public function actionRenew() { $sj = $this->sj->attributes; $shopId = $sj['parentShopId'] ?? 0; $shopName = ''; $rechargeNum = getenv('RECHARGE_NUM') == false ? 268 : getenv('RECHARGE_NUM'); if (!empty($shopId)) { $shop = ShopClass::getShopInfo($shopId); if (!empty($shop)) { $shopName = $shop['shopName'] ?? ''; $num = $shop['rechargeNum'] ?? 0; $rechargeNum += $num; } } $data = [ 'renew' => getenv('RENEW_PRICE') == false ? 1980 : getenv('RENEW_PRICE'), 'recharge' => getenv('RECHARGE_PRICE') == false ? 5980 : getenv('RECHARGE_PRICE'), 'shopName' => $shopName, 'userNum' => $rechargeNum ]; util::success($data); } //续期充值付款 ssh 2021.2.21 public function actionRenewPay() { ini_set('date.timezone', 'Asia/Shanghai'); $wxPay = dict::getDict('payWay', 'wxPay'); $price = getenv('RECHARGE_PRICE') == false ? 5980 : getenv('RECHARGE_PRICE'); $shopAdmin = $this->shopAdmin->attributes; $shopAdminName = $shopAdmin['name'] ?? ''; $data = [ 'amount' => $price, 'payWay' => $wxPay, 'sjId' => $this->sjId, 'sjStyle' => SjClass::STYLE_RETAIL, 'shopId' => $this->shopId, 'modPrice' => 0, 'remark' => '免费续期充值', 'shopAdminId' => $this->shopAdminId, 'shopAdminName' => $shopAdminName, ]; $order = RechargeClass::addOrder($data, true); $orderSn = $order->orderSn; $name = $order->orderName ?? '充值'; $totalFee = $order->amount; if (isset($this->shopAdmin['super']) == false || $this->shopAdmin['super'] != 1) { util::fail('超级管理员才有权限操作'); } //强制使用小程序的miniOpenId $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : ''; if (empty($openId)) { util::fail('没有找到openId'); } $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id'); //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调 $wxPayType = 1; $ghsId = Yii::$app->request->get('ghsId', 0); $ghs = GhsClass::getById($ghsId); GhsClass::valid($ghs, $this->shopId); $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType . '&rechargeRenew=1&ghsId=' . $ghsId; //订单30分钟后过期 $now = time(); $expireTime = $now + 1800; $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)); $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); $merchantExtend = WxOpenClass::getWxInfo(); if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //强制使用小程序的AppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); util::success($newParams); } //充值送红包 ssh 2021.2.21 public function actionBalance() { ini_set('date.timezone', 'Asia/Shanghai'); $get = Yii::$app->request->get(); $hbId = $get['id'] ?? 0; $ghsId = $get['ghsId'] ?? 0; $ghsInfo = GhsClass::getById($ghsId, true); if (empty($ghsInfo)) { util::fail('没有找到供货商'); } GhsClass::valid($ghsInfo, $this->shopId); $ghsShopId = $ghsInfo['shopId'] ?? 0; $hbInfo = RechargeHbClass::getById($hbId, true); if (empty($hbInfo)) { util::fail('无效活动'); } if ($hbInfo->shopId != $ghsShopId) { util::fail('供货商与充值红包活动不一致'); } if ($hbInfo->delStatus == 1) { util::fail('红包已更新,请重新发起充值'); } $amount = $hbInfo->amount ?? 0; if ($amount <= 0) { util::fail('充值金额有问题'); } $customId = $ghsInfo['customId'] ?? 0; $custom = CustomClass::getById($customId, true); $customName = $custom->name ?? ''; $wxPay = dict::getDict('payWay', 'wxPay'); $shopAdmin = $this->shopAdmin->attributes; $shopAdminName = $shopAdmin['name'] ?? ''; $data = [ 'amount' => $amount, 'payWay' => $wxPay, 'sjId' => $this->sjId, 'sjStyle' => SjClass::STYLE_RETAIL, 'shopId' => $this->shopId, 'modPrice' => 0, 'remark' => '', 'shopAdminId' => $this->shopAdminId, 'shopAdminName' => $shopAdminName, 'hbId' => $hbInfo->id ?? 0, 'hbAmount' => $hbInfo->hbAmount ?? 0, 'hbNum' => $hbInfo->num, 'totalHb' => $hbInfo->totalHb, 'valid' => $hbInfo->valid, 'miniExpend' => $hbInfo->miniExpend, 'ghsId' => $ghsId, 'ghsShopId' => $ghsShopId, 'customId' => $customId, 'customName' => $customName, ]; $order = RechargeClass::addOrder($data, true); $orderSn = $order->orderSn; $name = $order->orderName ?? '充值'; $totalFee = $order->amount; //强制使用小程序的miniOpenId $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : ''; if (empty($openId)) { util::fail('没有找到openId'); } $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id'); //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调 $wxPayType = 1; $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType; //订单30分钟后过期 $now = time(); $expireTime = $now + 1800; $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)); $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); $merchantExtend = WxOpenClass::getWxInfo(); if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //强制使用小程序的AppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); util::success($newParams); } //续期成功 ssh 2021.2.21 public function actionRenewSuccess() { $sj = $this->sj->attributes; $deadline = date("Y-m-d H:i", strtotime($sj['deadline'])); util::success(['deadline' => $deadline]); } }