MainController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. namespace hd\controllers;
  3. use biz\main\classes\MainClass;
  4. use biz\stat\classes\StatCgClass;
  5. use bizHd\purchase\classes\PurchaseClass;
  6. use bizHd\shop\classes\ShopExtClass;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use bizHd\wx\services\WxOpenService;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\miniUtil;
  12. use common\components\stringUtil;
  13. use GatewayClient\Gateway;
  14. use bizHd\ad\services\AdService;
  15. use bizHd\goods\services\CategoryService;
  16. use bizHd\goods\services\GoodsCategoryService;
  17. use common\components\util;
  18. use biz\shop\classes\ShopClass;
  19. use bizGhs\product\classes\ProductClass;
  20. use bizHd\stat\classes\StatIncomeClass;
  21. use bizHd\stat\classes\StatOrderClass;
  22. use Yii;
  23. class MainController extends BaseController
  24. {
  25. public $guestAccess = ['my'];
  26. //获取商城的短链接 ssh 20250826
  27. public function actionGetShortUrl()
  28. {
  29. $shopId = $this->shopId;
  30. $merchant = WxOpenClass::getMallWxInfo();
  31. $ptStyle = dict::getDict('ptStyle', 'mall');
  32. if (getenv('YII_ENV') != 'production') {
  33. if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {
  34. util::success(['goodsUrl' => 'www.google.com', 'imgUrl' => 'www.google.com', 'itemUrl' => 'www.google.com']);
  35. }
  36. }
  37. $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
  38. $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
  39. $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
  40. $goodsUrl = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
  41. $imgUrl = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
  42. $itemUrl = Yii::$app->redis->executeCommand('GET', [$imageShortUrl]);
  43. if (empty($goodsUrl) || empty($imgUrl) || empty($itemUrl)) {
  44. $goods = miniUtil::generateShortLink($merchant, 'pages/home/category?account=' . $shopId, '', $ptStyle);
  45. $image = miniUtil::generateShortLink($merchant, 'pages/home/mall?account=' . $shopId, '', $ptStyle);
  46. $item = miniUtil::generateShortLink($merchant, 'pages/item/item?account=' . $shopId, '', $ptStyle);
  47. $goodsUrl = $goods['link'] ?? '';
  48. $imgUrl = $image['link'] ?? '';
  49. $itemUrl = $item['link'] ?? '';
  50. Yii::$app->redis->executeCommand('SETEX', [$goodsShortUrl, 86400 * 3, $goodsUrl]);
  51. Yii::$app->redis->executeCommand('SETEX', [$itemShortUrl, 86400 * 3, $imgUrl]);
  52. Yii::$app->redis->executeCommand('SETEX', [$imageShortUrl, 86400 * 3, $itemUrl]);
  53. }
  54. util::success(['goodsUrl' => $goodsUrl, 'imgUrl' => $imgUrl, 'itemUrl' => $itemUrl]);
  55. }
  56. //main信息 ssh 20230406
  57. public function actionInfo()
  58. {
  59. $main = $this->main;
  60. util::success(['info' => $main]);
  61. }
  62. //花束商城太阳 ssh 20210610
  63. public function actionGetMallPoster()
  64. {
  65. $shop = $this->shop;
  66. $shopId = $this->shopId;
  67. $pfShopId = $shop->pfShopId ?? 0;
  68. $merchant = WxOpenClass::getMallWxInfo();
  69. $goodsPage = 'pages/home/category';
  70. $ptStyle = dict::getDict('ptStyle', 'mall');
  71. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  72. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  73. $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle, $envVersion);
  74. $sjName = $shop->merchantName ?? '';
  75. $shopName = $shop->shopName ?? '';
  76. $name = $shopName == '首店' ? $sjName : $sjName . $shopName;
  77. $prefix = imgUtil::getPrefix();
  78. $titleBase64 = stringUtil::ossBase64($name);
  79. if ($pfShopId > 0) {
  80. $goodsUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  81. $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
  82. $goodsUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  83. $goodsUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  84. } else {
  85. $goodsUrl = imgUtil::groupImg($goodsImgUrl);
  86. }
  87. if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
  88. $goodsLink = 'www.google.com';
  89. } else {
  90. $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
  91. $goodsLink = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
  92. if (empty($goodsLink)) {
  93. $goods = miniUtil::generateShortLink($merchant, 'pages/home/category?account=' . $shopId, '', $ptStyle);
  94. $goodsLink = $goods['link'] ?? '';
  95. Yii::$app->redis->executeCommand('SETEX', [$goodsShortUrl, 86400 * 3, $goodsLink]);
  96. }
  97. }
  98. $respond = [
  99. 'goodsUrl' => $goodsUrl,
  100. 'goodsLink' => $goodsLink,
  101. ];
  102. util::success($respond);
  103. }
  104. //相册太阳码 ssh
  105. public function actionGetAlbumPoster()
  106. {
  107. $shop = $this->shop;
  108. $shopId = $this->shopId;
  109. $pfShopId = $shop->pfShopId ?? 0;
  110. $merchant = WxOpenClass::getMallWxInfo();
  111. $goodsPage = 'pages/home/mall';
  112. $ptStyle = dict::getDict('ptStyle', 'mall');
  113. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  114. $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle);
  115. $prefix = imgUtil::getPrefix();
  116. $titleBase64 = stringUtil::ossBase64('相册');
  117. if ($pfShopId > 0) {
  118. $albumUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  119. $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
  120. $albumUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  121. $albumUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  122. } else {
  123. $albumUrl = imgUtil::groupImg($goodsImgUrl);
  124. }
  125. if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
  126. $albumLink = 'www.google.com';
  127. } else {
  128. $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
  129. $albumLink = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
  130. if (empty($albumLink)) {
  131. $image = miniUtil::generateShortLink($merchant, 'pages/home/mall?account=' . $shopId, '', $ptStyle);
  132. $albumLink = $image['link'] ?? '';
  133. Yii::$app->redis->executeCommand('SETEX', [$itemShortUrl, 86400 * 3, $albumLink]);
  134. }
  135. }
  136. $respond = [
  137. 'albumUrl' => $albumUrl,
  138. 'albumLink' => $albumLink,
  139. ];
  140. util::success($respond);
  141. }
  142. //绿植花材的太阳码 ssh 20250925
  143. public function actionGetItemPoster()
  144. {
  145. $shop = $this->shop;
  146. $shopId = $this->shopId;
  147. $pfShopId = $shop->pfShopId ?? 0;
  148. $merchant = WxOpenClass::getMallWxInfo();
  149. $ptStyle = dict::getDict('ptStyle', 'mall');
  150. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  151. $flowerPage = 'pages/item/item';
  152. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  153. $flowerImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $flowerPage, $scene, $ptStyle, $envVersion);
  154. $sjName = $shop->merchantName ?? '';
  155. $shopName = $shop->shopName ?? '';
  156. $name = $shopName == '首店' ? $sjName : $sjName . $shopName;
  157. $prefix = imgUtil::getPrefix();
  158. $titleBase64 = stringUtil::ossBase64($name);
  159. if ($pfShopId > 0) {
  160. $flowerUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  161. $flowerMiniCodeBase64 = stringUtil::ossBase64($flowerImgUrl);
  162. $flowerUrl .= '/watermark,image_' . $flowerMiniCodeBase64 . ',g_north,x_0,y_40';
  163. $flowerUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  164. } else {
  165. $flowerUrl = imgUtil::groupImg($flowerImgUrl);
  166. }
  167. if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
  168. $flowerLink = 'www.google.com';
  169. } else {
  170. $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
  171. $flowerLink = Yii::$app->redis->executeCommand('GET', [$imageShortUrl]);
  172. if (empty($flowerLink)) {
  173. $item = miniUtil::generateShortLink($merchant, 'pages/item/item?account=' . $shopId, '', $ptStyle);
  174. $flowerLink = $item['link'] ?? '';
  175. Yii::$app->redis->executeCommand('SETEX', [$imageShortUrl, 86400 * 3, $flowerLink]);
  176. }
  177. }
  178. $respond = [
  179. 'flowerUrl' => $flowerUrl,
  180. 'flowerLink' => $flowerLink,
  181. ];
  182. util::success($respond);
  183. }
  184. //会员注册码 ssh 20220607
  185. public function actionGetMemberPoster()
  186. {
  187. $merchant = WxOpenClass::getMallWxInfo();
  188. $page = 'pages/login/index';
  189. $ptStyle = dict::getDict('ptStyle', 'mall');
  190. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  191. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  192. $prefix = imgUtil::getPrefix();
  193. $titleBase64 = stringUtil::ossBase64('扫码注册');
  194. $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  195. $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  196. $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40';
  197. $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  198. $respond = ['imgUrl' => $memberUrl];
  199. util::success($respond);
  200. }
  201. public function actionDemo()
  202. {
  203. return $this->renderPartial('demo');
  204. }
  205. //新客户 ssh 2019.12.29
  206. public function actionVisit()
  207. {
  208. $data = json_encode(array(
  209. 'type' => 'msg',
  210. 'msg' => 'aaaa',
  211. ));
  212. $id = 'merchantConsole_' . $this->sjId;
  213. $online = Gateway::getClientIdByUid($id);
  214. if ($online) {
  215. //直接发送
  216. Gateway::sendToUid($id, json_encode($data));
  217. } else {
  218. //保存
  219. }
  220. }
  221. //新订单 ssh 2019.12.29
  222. public function actionOrder()
  223. {
  224. $data = json_encode(array(
  225. 'type' => 'msg',
  226. 'msg' => 'aaaa',
  227. ));
  228. $id = 'merchantConsole_' . $this->sjId;
  229. $online = Gateway::getClientIdByUid($id);
  230. if ($online) {
  231. //直接发送
  232. Gateway::sendToUid($id, json_encode($data));
  233. } else {
  234. //保存
  235. }
  236. }
  237. //我的 ssh 2021.4.8
  238. public function actionMy()
  239. {
  240. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  241. $shop = $this->shop;
  242. $shopId = $this->shopId;
  243. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  244. $main = $this->main;
  245. $mainId = $main->id ?? 0;
  246. $balance = $main->balance ?? 0.00;
  247. $money = $main->money ?? 0;
  248. $txBalance = $main->txBalance ?? 0.00;
  249. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  250. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  251. if (isset($shop->avatar) && !empty($shop->avatar)) {
  252. $shopImg = Yii::$app->params['ghsImgHost'] . $shop->avatar;
  253. }
  254. $deadline = $sj['deadline'] ?? '';
  255. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  256. $adminName = $relation['name'] ?? '';
  257. $eId = $relation['id'] ?? 0;
  258. $mobile = $relation['mobile'] ?? '';
  259. $sjName = $sj['name'] ?? '';
  260. $shopName = $shop->shopName ?? '';
  261. $cashAccount = $main->cashAccount ?? '';
  262. $data = [
  263. 'balance' => $balance,
  264. 'txBalance' => $txBalance,
  265. 'shopImg' => $shopImg,
  266. 'deadline' => $deadline,
  267. 'adminName' => $adminName,
  268. 'adminMobile' => $mobile,
  269. 'sjName' => $sjName,
  270. 'shopName' => $shopName,
  271. 'cashAccount' => $cashAccount,
  272. 'shopAdminId' => $eId,
  273. 'shopId' => $this->shopId,
  274. 'sjId' => $this->sjId,
  275. 'shopInfo' => $shop,
  276. 'shopExt' => $ext,
  277. 'money' => $money,
  278. 'mainId' => $mainId,
  279. 'lookMoney' => $lookMoney,
  280. ];
  281. util::success($data);
  282. }
  283. //经营概况 ssh 2021.1.27
  284. public function actionProfile()
  285. {
  286. //余额
  287. $shopInfo = ShopClass::getById($this->shopId);
  288. //库存情况
  289. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  290. //今日销售金额
  291. $today = StatIncomeClass::getAmountToday($this->shopId);
  292. //近七天销售金额
  293. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  294. //30天销售金额
  295. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  296. $base = [
  297. 'balance' => $shopInfo['balance'],
  298. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  299. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  300. 'stockCost' => $stockInfo['stockCost'],
  301. 'stockNum' => 0,
  302. 'stockBigNum' => $stockInfo['stockBigNum'],
  303. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  304. 'stockWarning' => $stockInfo['stockWarning'],
  305. 'today' => $today,
  306. 'todayCompareYesterday' => 0,
  307. 'latestSeven' => $latestSeven,
  308. 'latestSevenSameTerm' => 0,
  309. 'latestThirty' => $latestThirty,
  310. 'latestThirtySameTerm' => 0,
  311. ];
  312. //今日订单数
  313. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  314. //今日销售金额
  315. $saleAmount = $today;
  316. //昨日订单数
  317. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  318. //昨日销售金额
  319. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  320. //7天订单数
  321. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  322. //7天销售金额
  323. $sevenSaleAmount = $latestSeven;
  324. //30天订单数
  325. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  326. //30天销售金额
  327. $thirtySaleAmount = $latestThirty;
  328. //今日采购
  329. $todayCg = StatCgClass::getTodayCg($this->shop);
  330. //昨日采购
  331. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  332. //7日采购
  333. $sevenCg = StatCgClass::getSevenCg($this->shop);
  334. //30日采购
  335. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  336. $more = [
  337. 'today' => [
  338. 'income' => 0,
  339. 'expend' => 0,
  340. 'saleNum' => $saleNum,
  341. 'saleAmount' => $saleAmount,
  342. 'purchaseNum' => $todayCg['num'] ?? 0,
  343. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  344. ],
  345. 'yesterday' => [
  346. 'income' => 0,
  347. 'expend' => 0,
  348. 'saleNum' => $ySaleNum,
  349. 'saleAmount' => $ySaleAmount,
  350. 'purchaseNum' => $yesCg['num'] ?? 0,
  351. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  352. ],
  353. 'latestSeven' => [
  354. 'income' => 0,
  355. 'expend' => 0,
  356. 'saleNum' => $sevenSaleNum,
  357. 'saleAmount' => $sevenSaleAmount,
  358. 'purchaseNum' => $sevenCg['num'] ?? 0,
  359. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  360. ],
  361. 'latestThirty' => [
  362. 'income' => 0,
  363. 'expend' => 0,
  364. 'saleNum' => $thirtySaleNum,
  365. 'saleAmount' => $thirtySaleAmount,
  366. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  367. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  368. ],
  369. ];
  370. util::success(['base' => $base, 'more' => $more]);
  371. }
  372. // 查询小程序的同城配送的微信门店编号
  373. public function actionWxStoreId()
  374. {
  375. $main = MainClass::getById($this->mainId, true, 'id, wxStoreId');
  376. util::success(['wx' => $main]);
  377. }
  378. }