MainController.php 8.2 KB

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