MainController.php 16 KB

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