MainController.php 6.2 KB

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