MainController.php 16 KB

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