MainController.php 6.8 KB

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