MainController.php 10 KB

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