MainController.php 7.0 KB

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