MainController.php 6.9 KB

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