MainController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. $pfShopId = $shop->pfShopId ?? 0;
  67. $merchant = WxOpenClass::getMallWxInfo();
  68. $goodsPage = 'pages/home/category';
  69. $ptStyle = dict::getDict('ptStyle', 'mall');
  70. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  71. $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle);
  72. $flowerPage = 'pages/item/item';
  73. $flowerImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $flowerPage, $scene, $ptStyle);
  74. $prefix = imgUtil::getPrefix();
  75. $titleBase64 = stringUtil::ossBase64('扫码买花');
  76. if ($pfShopId > 0) {
  77. $goodsUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  78. $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
  79. $goodsUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  80. $goodsUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  81. $flowerUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  82. $flowerMiniCodeBase64 = stringUtil::ossBase64($flowerImgUrl);
  83. $flowerUrl .= '/watermark,image_' . $flowerMiniCodeBase64 . ',g_north,x_0,y_40';
  84. $flowerUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  85. $respond = [
  86. 'imgUrl' => $goodsUrl,
  87. 'flowerImgUrl' => $flowerUrl,
  88. ];
  89. } else {
  90. $goodsUrl = imgUtil::groupImg($goodsImgUrl);
  91. $flowerUrl = imgUtil::groupImg($flowerImgUrl);
  92. $respond = [
  93. 'imgUrl' => $goodsUrl,
  94. 'flowerImgUrl' => $flowerUrl,
  95. ];
  96. }
  97. //零交会
  98. $merchant = WxOpenClass::getWxInfo();
  99. $page = 'admin/ljh/info';
  100. $ptStyle = dict::getDict('ptStyle', 'hd');
  101. $scene = "sw=1";
  102. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  103. $apiHost = Yii::$app->params['hdImgHost'];
  104. $ljh = $apiHost . $imgUrl;
  105. $respond['ljhUrl'] = $ljh;
  106. util::success($respond);
  107. }
  108. //会员注册码 ssh 20220607
  109. public function actionGetMemberPoster()
  110. {
  111. $merchant = WxOpenClass::getMallWxInfo();
  112. $page = 'pages/login/index';
  113. $ptStyle = dict::getDict('ptStyle', 'mall');
  114. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  115. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  116. $prefix = imgUtil::getPrefix();
  117. $titleBase64 = stringUtil::ossBase64('扫码注册');
  118. $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  119. $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  120. $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40';
  121. $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  122. $respond = ['imgUrl' => $memberUrl];
  123. util::success($respond);
  124. }
  125. public function actionDemo()
  126. {
  127. return $this->renderPartial('demo');
  128. }
  129. //新客户 ssh 2019.12.29
  130. public function actionVisit()
  131. {
  132. $data = json_encode(array(
  133. 'type' => 'msg',
  134. 'msg' => 'aaaa',
  135. ));
  136. $id = 'merchantConsole_' . $this->sjId;
  137. $online = Gateway::getClientIdByUid($id);
  138. if ($online) {
  139. //直接发送
  140. Gateway::sendToUid($id, json_encode($data));
  141. } else {
  142. //保存
  143. }
  144. }
  145. //新订单 ssh 2019.12.29
  146. public function actionOrder()
  147. {
  148. $data = json_encode(array(
  149. 'type' => 'msg',
  150. 'msg' => 'aaaa',
  151. ));
  152. $id = 'merchantConsole_' . $this->sjId;
  153. $online = Gateway::getClientIdByUid($id);
  154. if ($online) {
  155. //直接发送
  156. Gateway::sendToUid($id, json_encode($data));
  157. } else {
  158. //保存
  159. }
  160. }
  161. //我的 ssh 2021.4.8
  162. public function actionMy()
  163. {
  164. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  165. $shop = $this->shop;
  166. $shopId = $this->shopId;
  167. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  168. $main = $this->main;
  169. $mainId = $main->id ?? 0;
  170. $balance = $main->balance ?? 0.00;
  171. $money = $main->money ?? 0;
  172. $txBalance = $main->txBalance ?? 0.00;
  173. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  174. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  175. if (isset($shop->avatar) && !empty($shop->avatar)) {
  176. $shopImg = Yii::$app->params['ghsImgHost'] . $shop->avatar;
  177. }
  178. $deadline = $sj['deadline'] ?? '';
  179. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  180. $adminName = $relation['name'] ?? '';
  181. $eId = $relation['id'] ?? 0;
  182. $mobile = $relation['mobile'] ?? '';
  183. $sjName = $sj['name'] ?? '';
  184. $shopName = $shop->shopName ?? '';
  185. $cashAccount = $main->cashAccount ?? '';
  186. $data = [
  187. 'balance' => $balance,
  188. 'txBalance' => $txBalance,
  189. 'shopImg' => $shopImg,
  190. 'deadline' => $deadline,
  191. 'adminName' => $adminName,
  192. 'adminMobile' => $mobile,
  193. 'sjName' => $sjName,
  194. 'shopName' => $shopName,
  195. 'cashAccount' => $cashAccount,
  196. 'shopAdminId' => $eId,
  197. 'shopId' => $this->shopId,
  198. 'sjId' => $this->sjId,
  199. 'shopInfo' => $shop,
  200. 'shopExt' => $ext,
  201. 'money' => $money,
  202. 'mainId' => $mainId,
  203. 'lookMoney' => $lookMoney,
  204. ];
  205. util::success($data);
  206. }
  207. //经营概况 ssh 2021.1.27
  208. public function actionProfile()
  209. {
  210. //余额
  211. $shopInfo = ShopClass::getById($this->shopId);
  212. //库存情况
  213. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  214. //今日销售金额
  215. $today = StatIncomeClass::getAmountToday($this->shopId);
  216. //近七天销售金额
  217. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  218. //30天销售金额
  219. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  220. $base = [
  221. 'balance' => $shopInfo['balance'],
  222. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  223. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  224. 'stockCost' => $stockInfo['stockCost'],
  225. 'stockNum' => 0,
  226. 'stockBigNum' => $stockInfo['stockBigNum'],
  227. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  228. 'stockWarning' => $stockInfo['stockWarning'],
  229. 'today' => $today,
  230. 'todayCompareYesterday' => 0,
  231. 'latestSeven' => $latestSeven,
  232. 'latestSevenSameTerm' => 0,
  233. 'latestThirty' => $latestThirty,
  234. 'latestThirtySameTerm' => 0,
  235. ];
  236. //今日订单数
  237. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  238. //今日销售金额
  239. $saleAmount = $today;
  240. //昨日订单数
  241. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  242. //昨日销售金额
  243. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  244. //7天订单数
  245. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  246. //7天销售金额
  247. $sevenSaleAmount = $latestSeven;
  248. //30天订单数
  249. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  250. //30天销售金额
  251. $thirtySaleAmount = $latestThirty;
  252. //今日采购
  253. $todayCg = StatCgClass::getTodayCg($this->shop);
  254. //昨日采购
  255. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  256. //7日采购
  257. $sevenCg = StatCgClass::getSevenCg($this->shop);
  258. //30日采购
  259. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  260. $more = [
  261. 'today' => [
  262. 'income' => 0,
  263. 'expend' => 0,
  264. 'saleNum' => $saleNum,
  265. 'saleAmount' => $saleAmount,
  266. 'purchaseNum' => $todayCg['num'] ?? 0,
  267. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  268. ],
  269. 'yesterday' => [
  270. 'income' => 0,
  271. 'expend' => 0,
  272. 'saleNum' => $ySaleNum,
  273. 'saleAmount' => $ySaleAmount,
  274. 'purchaseNum' => $yesCg['num'] ?? 0,
  275. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  276. ],
  277. 'latestSeven' => [
  278. 'income' => 0,
  279. 'expend' => 0,
  280. 'saleNum' => $sevenSaleNum,
  281. 'saleAmount' => $sevenSaleAmount,
  282. 'purchaseNum' => $sevenCg['num'] ?? 0,
  283. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  284. ],
  285. 'latestThirty' => [
  286. 'income' => 0,
  287. 'expend' => 0,
  288. 'saleNum' => $thirtySaleNum,
  289. 'saleAmount' => $thirtySaleAmount,
  290. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  291. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  292. ],
  293. ];
  294. util::success(['base' => $base, 'more' => $more]);
  295. }
  296. // 查询小程序的同城配送的微信门店编号
  297. public function actionWxStoreId()
  298. {
  299. $main = MainClass::getById($this->mainId, true, 'id, wxStoreId');
  300. util::success(['wx' => $main]);
  301. }
  302. }