MainController.php 12 KB

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