MainController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. namespace hd\controllers;
  3. use biz\stat\classes\StatCgClass;
  4. use bizHd\purchase\classes\PurchaseClass;
  5. use bizHd\wx\classes\WxOpenClass;
  6. use bizHd\wx\services\WxOpenService;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\miniUtil;
  10. use GatewayClient\Gateway;
  11. use bizHd\ad\services\AdService;
  12. use bizHd\goods\services\CategoryService;
  13. use bizHd\goods\services\GoodsCategoryService;
  14. use common\components\util;
  15. use biz\shop\classes\ShopClass;
  16. use bizGhs\product\classes\ProductClass;
  17. use bizHd\stat\classes\StatIncomeClass;
  18. use bizHd\stat\classes\StatOrderClass;
  19. use Yii;
  20. class MainController extends BaseController
  21. {
  22. public $guestAccess = ['index', 'my'];
  23. //商城海报 ssh 20210610
  24. public function actionGetMallPoster()
  25. {
  26. $merchant = WxOpenClass::getMallWxInfo();
  27. $page = 'pages/home/index';
  28. $ptStyle = dict::getDict('ptStyle', 'mall');
  29. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  30. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  31. $url = imgUtil::groupImg($imgUrl);
  32. $respond = [
  33. 'imgUrl' => $url,
  34. ];
  35. util::success($respond);
  36. }
  37. public function actionDemo()
  38. {
  39. return $this->renderPartial('demo');
  40. }
  41. //首页 ssh 2019.12.2
  42. public function actionIndex()
  43. {
  44. $where = ['sjId' => $this->sjId, 'type' => 0, 'status' => 1, 'delStatus' => 0];
  45. $adRespond = AdService::getAdList($where);
  46. $ad = [];
  47. if (isset($adRespond['list']) && !empty($adRespond['list'])) {
  48. foreach ($adRespond['list'] as $single) {
  49. $ad[] = ['adImg' => $single['adImgUrl'], 'url' => ''];
  50. }
  51. }
  52. $category = CategoryService::getTopThreeCategory($this->sjId);
  53. $categoryList = !empty($category) ? GoodsCategoryService::getAppointCategoryList($category) : [];
  54. $data = ['ad' => $ad, 'category' => $categoryList, 'columnStyle' => rand(1, 2)];
  55. util::success($data);
  56. }
  57. //新客户 ssh 2019.12.29
  58. public function actionVisit()
  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 2019.12.29
  74. public function actionOrder()
  75. {
  76. $data = json_encode(array(
  77. 'type' => 'msg',
  78. 'msg' => 'aaaa',
  79. ));
  80. $id = 'merchantConsole_' . $this->sjId;
  81. $online = Gateway::getClientIdByUid($id);
  82. if ($online) {
  83. //直接发送
  84. Gateway::sendToUid($id, json_encode($data));
  85. } else {
  86. //保存
  87. }
  88. }
  89. //我的 ssh 2021.4.8
  90. public function actionMy()
  91. {
  92. $shop = $this->shop;
  93. $main = $this->main;
  94. $balance = $main->balance ?? 0.00;
  95. $txBalance = $main->txBalance ?? 0.00;
  96. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  97. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  98. $deadline = $sj['deadline'] ?? '';
  99. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  100. $adminName = $relation['name'] ?? '';
  101. $eId = $relation['id'] ?? 0;
  102. $mobile = $relation['mobile'] ?? '';
  103. $sjName = $sj['name'] ?? '';
  104. $shopName = $shop->shopName ?? '';
  105. $cashAccount = $main->cashAccount ?? '';
  106. $data = [
  107. 'balance' => $balance,
  108. 'txBalance' => $txBalance,
  109. 'shopImg' => $shopImg,
  110. 'deadline' => $deadline,
  111. 'adminName' => $adminName,
  112. 'adminMobile' => $mobile,
  113. 'sjName' => $sjName,
  114. 'shopName' => $shopName,
  115. 'shopImg' => $shopImg,
  116. 'cashAccount' => $cashAccount,
  117. 'shopAdminId' => $eId,
  118. 'shopId' => $this->shopId,
  119. 'sjId' => $this->sjId,
  120. ];
  121. util::success($data);
  122. }
  123. //经营概况 ssh 2021.1.27
  124. public function actionProfile()
  125. {
  126. //余额
  127. $shopInfo = ShopClass::getById($this->shopId);
  128. //库存情况
  129. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  130. //今日销售金额
  131. $today = StatIncomeClass::getAmountToday($this->shopId);
  132. //近七天销售金额
  133. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  134. //30天销售金额
  135. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  136. $base = [
  137. 'balance' => $shopInfo['balance'],
  138. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  139. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  140. 'stockCost' => $stockInfo['stockCost'],
  141. 'stockNum' => 0,
  142. 'stockBigNum' => $stockInfo['stockBigNum'],
  143. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  144. 'stockWarning' => $stockInfo['stockWarning'],
  145. 'today' => $today,
  146. 'todayCompareYesterday' => 0,
  147. 'latestSeven' => $latestSeven,
  148. 'latestSevenSameTerm' => 0,
  149. 'latestThirty' => $latestThirty,
  150. 'latestThirtySameTerm' => 0,
  151. ];
  152. //今日订单数
  153. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  154. //今日销售金额
  155. $saleAmount = $today;
  156. //昨日订单数
  157. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  158. //昨日销售金额
  159. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  160. //7天订单数
  161. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  162. //7天销售金额
  163. $sevenSaleAmount = $latestSeven;
  164. //30天订单数
  165. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  166. //30天销售金额
  167. $thirtySaleAmount = $latestThirty;
  168. //今日采购
  169. $todayCg = StatCgClass::getTodayCg($this->shop);
  170. //昨日采购
  171. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  172. //7日采购
  173. $sevenCg = StatCgClass::getSevenCg($this->shop);
  174. //30日采购
  175. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  176. $more = [
  177. 'today' => [
  178. 'income' => 0,
  179. 'expend' => 0,
  180. 'saleNum' => $saleNum,
  181. 'saleAmount' => $saleAmount,
  182. 'purchaseNum' => $todayCg['num'] ?? 0,
  183. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  184. ],
  185. 'yesterday' => [
  186. 'income' => 0,
  187. 'expend' => 0,
  188. 'saleNum' => $ySaleNum,
  189. 'saleAmount' => $ySaleAmount,
  190. 'purchaseNum' => $yesCg['num'] ?? 0,
  191. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  192. ],
  193. 'latestSeven' => [
  194. 'income' => 0,
  195. 'expend' => 0,
  196. 'saleNum' => $sevenSaleNum,
  197. 'saleAmount' => $sevenSaleAmount,
  198. 'purchaseNum' => $sevenCg['num'] ?? 0,
  199. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  200. ],
  201. 'latestThirty' => [
  202. 'income' => 0,
  203. 'expend' => 0,
  204. 'saleNum' => $thirtySaleNum,
  205. 'saleAmount' => $thirtySaleAmount,
  206. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  207. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  208. ],
  209. ];
  210. util::success(['base' => $base, 'more' => $more]);
  211. }
  212. }