| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- <?php
- namespace hd\controllers;
- use biz\main\classes\MainClass;
- use biz\stat\classes\StatCgClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\shop\classes\ShopExtClass;
- use bizHd\wx\classes\WxOpenClass;
- use bizHd\wx\services\WxOpenService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\stringUtil;
- use GatewayClient\Gateway;
- use bizHd\ad\services\AdService;
- use bizHd\goods\services\CategoryService;
- use bizHd\goods\services\GoodsCategoryService;
- use common\components\util;
- use biz\shop\classes\ShopClass;
- use bizGhs\product\classes\ProductClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatOrderClass;
- use Yii;
- class MainController extends BaseController
- {
- public $guestAccess = ['my'];
- //获取商城的短链接 ssh 20250826
- public function actionGetShortUrl()
- {
- $shopId = $this->shopId;
- $merchant = WxOpenClass::getMallWxInfo();
- $ptStyle = dict::getDict('ptStyle', 'mall');
- if (getenv('YII_ENV') != 'production') {
- if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {
- util::success(['goodsUrl' => 'www.google.com', 'imgUrl' => 'www.google.com', 'itemUrl' => 'www.google.com']);
- }
- }
- $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
- $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
- $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
- $goodsUrl = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
- $imgUrl = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
- $itemUrl = Yii::$app->redis->executeCommand('GET', [$imageShortUrl]);
- if (empty($goodsUrl) || empty($imgUrl) || empty($itemUrl)) {
- $goods = miniUtil::generateShortLink($merchant, 'pages/home/category?account=' . $shopId, '', $ptStyle);
- $image = miniUtil::generateShortLink($merchant, 'pages/home/mall?account=' . $shopId, '', $ptStyle);
- $item = miniUtil::generateShortLink($merchant, 'pages/item/item?account=' . $shopId, '', $ptStyle);
- $goodsUrl = $goods['link'] ?? '';
- $imgUrl = $image['link'] ?? '';
- $itemUrl = $item['link'] ?? '';
- Yii::$app->redis->executeCommand('SETEX', [$goodsShortUrl, 86400 * 3, $goodsUrl]);
- Yii::$app->redis->executeCommand('SETEX', [$itemShortUrl, 86400 * 3, $imgUrl]);
- Yii::$app->redis->executeCommand('SETEX', [$imageShortUrl, 86400 * 3, $itemUrl]);
- }
- util::success(['goodsUrl' => $goodsUrl, 'imgUrl' => $imgUrl, 'itemUrl' => $itemUrl]);
- }
- //main信息 ssh 20230406
- public function actionInfo()
- {
- $main = $this->main;
- util::success(['info' => $main]);
- }
- /**
- * 职责:生成并获取花束商城太阳码海报及商城短链接
- * 入参:HTTP GET (参数可选:env_version)
- * 返回:太阳码海报图片的完整 OSS 地址以及短链接 URL
- * 副作用:当没有缓存时,会触发向微信 API 请求并同步上传生成的图片至阿里 OSS。
- * 关键边界:引入了店员+门店+环境级别的最终海报数据 Redis 强缓存(3天有效期),避免每次高频无端向微信和 OSS 发起同步请求。
- */
- public function actionGetMallPoster()
- {
- $shop = $this->shop;
- $shopId = $this->shopId;
- $pfShopId = $shop->pfShopId ?? 0;
- $adminId = $this->shopAdminId;
- $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
- // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
- // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
- $posterCacheKey = "wx_mini_mall_poster_url_{$shopId}_{$adminId}_{$envVersion}";
- $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
- if (!empty($cachedPoster)) {
- $respond = json_decode($cachedPoster, true);
- if (!empty($respond['goodsUrl']) && !empty($respond['goodsLink'])) {
- util::success($respond); // 缓存直接命中,毫秒级快速返回!
- }
- }
- $merchant = WxOpenClass::getMallWxInfo();
- $goodsPage = 'pages/home/category';
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $scene = 'a=' . $adminId . '&s=' . $shopId;
- $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle, $envVersion);
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $name = $shopName == '首店' ? $sjName : $sjName . $shopName;
- $prefix = imgUtil::getPrefix();
- $titleBase64 = stringUtil::ossBase64($name);
- if ($pfShopId > 0) {
- $goodsUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
- $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
- $goodsUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
- $goodsUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
- } else {
- $goodsUrl = imgUtil::groupImg($goodsImgUrl);
- }
- if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
- $goodsLink = 'www.google.com';
- } else {
- $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
- $goodsLink = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
- if (empty($goodsLink)) {
- $goods = miniUtil::generateShortLink($merchant, 'pages/home/category?account=' . $shopId, '', $ptStyle);
- $goodsLink = $goods['link'] ?? '';
- Yii::$app->redis->executeCommand('SETEX', [$goodsShortUrl, 86400 * 3, $goodsLink]);
- }
- }
- $respond = [
- 'goodsUrl' => $goodsUrl,
- 'goodsLink' => $goodsLink,
- ];
- // ==================== 【性能优化】保存最终拼接和生成结果到 Redis 中,过期时间 3 天 ====================
- Yii::$app->redis->executeCommand('SETEX', [$posterCacheKey, 86400 * 3, json_encode($respond)]);
- util::success($respond);
- }
- //相册太阳码 ssh
- public function actionGetAlbumPoster()
- {
- $shop = $this->shop;
- $shopId = $this->shopId;
- $pfShopId = $shop->pfShopId ?? 0;
- $merchant = WxOpenClass::getMallWxInfo();
- $goodsPage = 'pages/home/mall';
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
- $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle);
- $prefix = imgUtil::getPrefix();
- $titleBase64 = stringUtil::ossBase64('相册');
- if ($pfShopId > 0) {
- $albumUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
- $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
- $albumUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
- $albumUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
- } else {
- $albumUrl = imgUtil::groupImg($goodsImgUrl);
- }
- if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
- $albumLink = 'www.google.com';
- } else {
- $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
- $albumLink = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
- if (empty($albumLink)) {
- $image = miniUtil::generateShortLink($merchant, 'pages/home/mall?account=' . $shopId, '', $ptStyle);
- $albumLink = $image['link'] ?? '';
- Yii::$app->redis->executeCommand('SETEX', [$itemShortUrl, 86400 * 3, $albumLink]);
- }
- }
- $respond = [
- 'albumUrl' => $albumUrl,
- 'albumLink' => $albumLink,
- ];
- util::success($respond);
- }
- /**
- * 职责:生成并获取绿植花材的太阳码海报及短链接
- * 入参:HTTP GET (参数可选:env_version)
- * 返回:太阳码海报图片的完整 OSS 地址以及短链接 URL
- * 副作用:当没有缓存时,会触发向微信 API 请求并同步上传生成的图片至阿里 OSS。
- * 关键边界:引入了店员+环境+门店级别的最终海报数据 Redis 强缓存(3天有效期),避免每次高频无端向微信和 OSS 发起同步请求。
- */
- public function actionGetItemPoster()
- {
- $shop = $this->shop;
- $shopId = $this->shopId;
- $pfShopId = $shop->pfShopId ?? 0;
- $adminId = $this->shopAdminId;
- $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
- // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
- // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
- $posterCacheKey = "wx_mini_item_poster_url_{$shopId}_{$adminId}_{$envVersion}";
- $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
- if (!empty($cachedPoster)) {
- $respond = json_decode($cachedPoster, true);
- if (!empty($respond['flowerUrl']) && !empty($respond['flowerLink'])) {
- util::success($respond); // 缓存直接命中,毫秒级快速返回!
- }
- }
- $merchant = WxOpenClass::getMallWxInfo();
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $scene = 'a=' . $adminId . '&s=' . $shopId;
- $flowerPage = 'pages/item/item';
- $flowerImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $flowerPage, $scene, $ptStyle, $envVersion);
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $name = $shopName == '首店' ? $sjName : $sjName . $shopName;
- $prefix = imgUtil::getPrefix();
- $titleBase64 = stringUtil::ossBase64($name);
- if ($pfShopId > 0) {
- $flowerUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
- $flowerMiniCodeBase64 = stringUtil::ossBase64($flowerImgUrl);
- $flowerUrl .= '/watermark,image_' . $flowerMiniCodeBase64 . ',g_north,x_0,y_40';
- $flowerUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
- } else {
- $flowerUrl = imgUtil::groupImg($flowerImgUrl);
- }
- if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
- $flowerLink = 'www.google.com';
- } else {
- $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
- $flowerLink = Yii::$app->redis->executeCommand('GET', [$imageShortUrl]);
- if (empty($flowerLink)) {
- $item = miniUtil::generateShortLink($merchant, 'pages/item/item?account=' . $shopId, '', $ptStyle);
- $flowerLink = $item['link'] ?? '';
- Yii::$app->redis->executeCommand('SETEX', [$imageShortUrl, 86400 * 3, $flowerLink]);
- }
- }
- $respond = [
- 'flowerUrl' => $flowerUrl,
- 'flowerLink' => $flowerLink,
- ];
- // ==================== 【性能优化】保存最终拼接和生成结果到 Redis 中,过期时间 3 天 ====================
- Yii::$app->redis->executeCommand('SETEX', [$posterCacheKey, 86400 * 3, json_encode($respond)]);
- util::success($respond);
- }
- //会员注册码 ssh 20220607
- public function actionGetMemberPoster()
- {
- $merchant = WxOpenClass::getMallWxInfo();
- $page = 'pages/login/index';
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
- $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $prefix = imgUtil::getPrefix();
- $titleBase64 = stringUtil::ossBase64('扫码注册');
- $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
- $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
- $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40';
- $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
- $respond = ['imgUrl' => $memberUrl];
- util::success($respond);
- }
- public function actionDemo()
- {
- return $this->renderPartial('demo');
- }
- //新客户 ssh 2019.12.29
- public function actionVisit()
- {
- $data = json_encode(array(
- 'type' => 'msg',
- 'msg' => 'aaaa',
- ));
- $id = 'merchantConsole_' . $this->sjId;
- $online = Gateway::getClientIdByUid($id);
- if ($online) {
- //直接发送
- Gateway::sendToUid($id, json_encode($data));
- } else {
- //保存
- }
- }
- //新订单 ssh 2019.12.29
- public function actionOrder()
- {
- $data = json_encode(array(
- 'type' => 'msg',
- 'msg' => 'aaaa',
- ));
- $id = 'merchantConsole_' . $this->sjId;
- $online = Gateway::getClientIdByUid($id);
- if ($online) {
- //直接发送
- Gateway::sendToUid($id, json_encode($data));
- } else {
- //保存
- }
- }
- //我的 ssh 2021.4.8
- public function actionMy()
- {
- $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
- $shop = $this->shop;
- $shopId = $this->shopId;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- $main = $this->main;
- $mainId = $main->id ?? 0;
- $balance = $main->balance ?? 0.00;
- $money = $main->money ?? 0;
- $txBalance = $main->txBalance ?? 0.00;
- $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
- $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
- if (isset($shop->avatar) && !empty($shop->avatar)) {
- $shopImg = Yii::$app->params['ghsImgHost'] . $shop->avatar;
- }
- // 到期时间取当前门店 xhShop.deadline(续费、业务校验均以此为准)
- $deadline = $shop->deadline ?? '';
- $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
- $adminName = $relation['name'] ?? '';
- $eId = $relation['id'] ?? 0;
- $mobile = $relation['mobile'] ?? '';
- $sjName = $sj['name'] ?? '';
- $shopName = $shop->shopName ?? '';
- $cashAccount = $main->cashAccount ?? '';
- $walletBalance = $main->walletBalance ?? '0.00';
- $data = [
- 'balance' => $balance,
- 'txBalance' => $txBalance,
- 'walletBalance' => $walletBalance,
- 'shopImg' => $shopImg,
- 'deadline' => $deadline,
- 'adminName' => $adminName,
- 'adminMobile' => $mobile,
- 'sjName' => $sjName,
- 'shopName' => $shopName,
- 'cashAccount' => $cashAccount,
- 'shopAdminId' => $eId,
- 'shopId' => $this->shopId,
- 'sjId' => $this->sjId,
- 'shopInfo' => $shop,
- 'shopExt' => $ext,
- 'money' => $money,
- 'mainId' => $mainId,
- 'lookMoney' => $lookMoney,
- ];
- util::success($data);
- }
- //经营概况 ssh 2021.1.27
- public function actionProfile()
- {
- //余额
- $shopInfo = ShopClass::getById($this->shopId);
- //库存情况
- $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
- //今日销售金额
- $today = StatIncomeClass::getAmountToday($this->shopId);
- //近七天销售金额
- $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
- //30天销售金额
- $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
- $base = [
- 'balance' => $shopInfo['balance'],
- 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
- 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
- 'stockCost' => $stockInfo['stockCost'],
- 'stockNum' => 0,
- 'stockBigNum' => $stockInfo['stockBigNum'],
- 'stockSmallNum' => $stockInfo['stockSmallNum'],
- 'stockWarning' => $stockInfo['stockWarning'],
- 'today' => $today,
- 'todayCompareYesterday' => 0,
- 'latestSeven' => $latestSeven,
- 'latestSevenSameTerm' => 0,
- 'latestThirty' => $latestThirty,
- 'latestThirtySameTerm' => 0,
- ];
- //今日订单数
- $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
- //今日销售金额
- $saleAmount = $today;
- //昨日订单数
- $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
- //昨日销售金额
- $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
- //7天订单数
- $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
- //7天销售金额
- $sevenSaleAmount = $latestSeven;
- //30天订单数
- $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
- //30天销售金额
- $thirtySaleAmount = $latestThirty;
- //今日采购
- $todayCg = StatCgClass::getTodayCg($this->shop);
- //昨日采购
- $yesCg = StatCgClass::getYesterdayCg($this->shop);
- //7日采购
- $sevenCg = StatCgClass::getSevenCg($this->shop);
- //30日采购
- $thirtyCg = StatCgClass::getThirtyCg($this->shop);
- $more = [
- 'today' => [
- 'income' => 0,
- 'expend' => 0,
- 'saleNum' => $saleNum,
- 'saleAmount' => $saleAmount,
- 'purchaseNum' => $todayCg['num'] ?? 0,
- 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
- ],
- 'yesterday' => [
- 'income' => 0,
- 'expend' => 0,
- 'saleNum' => $ySaleNum,
- 'saleAmount' => $ySaleAmount,
- 'purchaseNum' => $yesCg['num'] ?? 0,
- 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
- ],
- 'latestSeven' => [
- 'income' => 0,
- 'expend' => 0,
- 'saleNum' => $sevenSaleNum,
- 'saleAmount' => $sevenSaleAmount,
- 'purchaseNum' => $sevenCg['num'] ?? 0,
- 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
- ],
- 'latestThirty' => [
- 'income' => 0,
- 'expend' => 0,
- 'saleNum' => $thirtySaleNum,
- 'saleAmount' => $thirtySaleAmount,
- 'purchaseNum' => $thirtyCg['num'] ?? 0,
- 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
- ],
- ];
- util::success(['base' => $base, 'more' => $more]);
- }
- // 查询小程序的同城配送的微信门店编号
- public function actionWxStoreId()
- {
- $main = MainClass::getById($this->mainId, true, 'id, wxStoreId');
- util::success(['wx' => $main]);
- }
- }
|