MainController.php 12 KB

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