MainController.php 16 KB

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