MainController.php 7.1 KB

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