MainController.php 10 KB

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