MainController.php 12 KB

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