MainController.php 6.4 KB

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