MainController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 GatewayClient\Gateway;
  11. use bizHd\ad\services\AdService;
  12. use bizHd\goods\services\CategoryService;
  13. use bizHd\goods\services\GoodsCategoryService;
  14. use common\components\util;
  15. use biz\shop\classes\ShopClass;
  16. use bizGhs\product\classes\ProductClass;
  17. use bizHd\stat\classes\StatIncomeClass;
  18. use bizHd\stat\classes\StatOrderClass;
  19. class MainController extends BaseController
  20. {
  21. public $guestAccess = ['index'];
  22. //商城海报 shish 20210610
  23. public function actionGetMallPoster()
  24. {
  25. $merchant = WxOpenClass::getMallWxInfo();
  26. $page = 'pages/home/index';
  27. $ptStyle = dict::getDict('ptStyle', 'mall');
  28. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  29. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  30. $url = imgUtil::groupImg($imgUrl);
  31. $respond = [
  32. 'imgUrl' => $url,
  33. ];
  34. util::success($respond);
  35. }
  36. public function actionDemo()
  37. {
  38. return $this->renderPartial('demo');
  39. }
  40. //首页 ssh 2019.12.2
  41. public function actionIndex()
  42. {
  43. $where = ['sjId' => $this->sjId, 'type' => 0, 'status' => 1, 'delStatus' => 0];
  44. $adRespond = AdService::getAdList($where);
  45. $ad = [];
  46. if (isset($adRespond['list']) && !empty($adRespond['list'])) {
  47. foreach ($adRespond['list'] as $single) {
  48. $ad[] = ['adImg' => $single['adImgUrl'], 'url' => ''];
  49. }
  50. }
  51. $category = CategoryService::getTopThreeCategory($this->sjId);
  52. $categoryList = !empty($category) ? GoodsCategoryService::getAppointCategoryList($category) : [];
  53. $data = ['ad' => $ad, 'category' => $categoryList, 'columnStyle' => rand(1, 2)];
  54. util::success($data);
  55. }
  56. //新客户 ssh 2019.12.29
  57. public function actionVisit()
  58. {
  59. $data = json_encode(array(
  60. 'type' => 'msg',
  61. 'msg' => 'aaaa',
  62. ));
  63. $id = 'merchantConsole_' . $this->sjId;
  64. $online = Gateway::getClientIdByUid($id);
  65. if ($online) {
  66. //直接发送
  67. Gateway::sendToUid($id, json_encode($data));
  68. } else {
  69. //保存
  70. }
  71. }
  72. //新订单 ssh 2019.12.29
  73. public function actionOrder()
  74. {
  75. $data = json_encode(array(
  76. 'type' => 'msg',
  77. 'msg' => 'aaaa',
  78. ));
  79. $id = 'merchantConsole_' . $this->sjId;
  80. $online = Gateway::getClientIdByUid($id);
  81. if ($online) {
  82. //直接发送
  83. Gateway::sendToUid($id, json_encode($data));
  84. } else {
  85. //保存
  86. }
  87. }
  88. //我的 ssh 2021.4.8
  89. public function actionMy()
  90. {
  91. $shop = $this->shop;
  92. $balance = $shop->balance ?? 0.00;
  93. $txBalance = $shop->txBalance ?? 0.00;
  94. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  95. $shopImg = $shop->avatar ?? '';
  96. $deadline = $sj['deadline'] ?? '';
  97. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  98. $adminName = $relation['name'];
  99. $eId = $relation['id'];
  100. $mobile = $relation['mobile'] ?? '';
  101. $sjName = $sj['name'] ?? '';
  102. $shopName = $shop->shopName ?? '';
  103. $cashAccount = $shop->cashAccount ?? '';
  104. $data = [
  105. 'balance' => $balance,
  106. 'txBalance' => $txBalance,
  107. 'deadline' => $deadline,
  108. 'adminName' => $adminName,
  109. 'adminMobile' => $mobile,
  110. 'sjName' => $sjName,
  111. 'shopName' => $shopName,
  112. 'shopImg' => $shopImg,
  113. 'cashAccount' => $cashAccount,
  114. 'shopAdminId' => $eId,
  115. 'shopId' => $this->shopId,
  116. 'sjId' => $this->sjId,
  117. ];
  118. util::success($data);
  119. }
  120. //经营概况 ssh 2021.1.27
  121. public function actionProfile()
  122. {
  123. //余额
  124. $shopInfo = ShopClass::getById($this->shopId);
  125. //库存情况
  126. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  127. //今日销售金额
  128. $today = StatIncomeClass::getAmountToday($this->shopId);
  129. //近七天销售金额
  130. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  131. //30天销售金额
  132. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  133. $base = [
  134. 'balance' => $shopInfo['balance'],
  135. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  136. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  137. 'stockCost' => $stockInfo['stockCost'],
  138. 'stockNum' => 0,
  139. 'stockBigNum' => $stockInfo['stockBigNum'],
  140. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  141. 'stockWarning' => $stockInfo['stockWarning'],
  142. 'today' => $today,
  143. 'todayCompareYesterday' => 0,
  144. 'latestSeven' => $latestSeven,
  145. 'latestSevenSameTerm' => 0,
  146. 'latestThirty' => $latestThirty,
  147. 'latestThirtySameTerm' => 0,
  148. ];
  149. //今日订单数
  150. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  151. //今日销售金额
  152. $saleAmount = $today;
  153. //昨日订单数
  154. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  155. //昨日销售金额
  156. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  157. //7天订单数
  158. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  159. //7天销售金额
  160. $sevenSaleAmount = $latestSeven;
  161. //30天订单数
  162. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  163. //30天销售金额
  164. $thirtySaleAmount = $latestThirty;
  165. //今日采购
  166. $todayCg = StatCgClass::getTodayCg($this->shop);
  167. //昨日采购
  168. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  169. //7日采购
  170. $sevenCg = StatCgClass::getSevenCg($this->shop);
  171. //30日采购
  172. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  173. $more = [
  174. 'today' => [
  175. 'income' => 0,
  176. 'expend' => 0,
  177. 'saleNum' => $saleNum,
  178. 'saleAmount' => $saleAmount,
  179. 'purchaseNum' => $todayCg['num'] ?? 0,
  180. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  181. ],
  182. 'yesterday' => [
  183. 'income' => 0,
  184. 'expend' => 0,
  185. 'saleNum' => $ySaleNum,
  186. 'saleAmount' => $ySaleAmount,
  187. 'purchaseNum' => $yesCg['num'] ?? 0,
  188. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  189. ],
  190. 'latestSeven' => [
  191. 'income' => 0,
  192. 'expend' => 0,
  193. 'saleNum' => $sevenSaleNum,
  194. 'saleAmount' => $sevenSaleAmount,
  195. 'purchaseNum' => $sevenCg['num'] ?? 0,
  196. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  197. ],
  198. 'latestThirty' => [
  199. 'income' => 0,
  200. 'expend' => 0,
  201. 'saleNum' => $thirtySaleNum,
  202. 'saleAmount' => $thirtySaleAmount,
  203. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  204. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  205. ],
  206. ];
  207. util::success(['base' => $base, 'more' => $more]);
  208. }
  209. }