MainController.php 16 KB

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