MainController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. //会员注册码 ssh 20220607
  38. public function actionGetMemberPoster()
  39. {
  40. $merchant = WxOpenClass::getMallWxInfo();
  41. $page = 'pages/login/index';
  42. $ptStyle = dict::getDict('ptStyle', 'mall');
  43. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  44. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  45. $url = imgUtil::groupImg($imgUrl);
  46. $respond = [
  47. 'imgUrl' => $url,
  48. ];
  49. util::success($respond);
  50. }
  51. public function actionDemo()
  52. {
  53. return $this->renderPartial('demo');
  54. }
  55. //首页 ssh 2019.12.2
  56. public function actionIndex()
  57. {
  58. $where = ['mainId' => $this->mainId, 'type' => 0, 'status' => 1, 'delStatus' => 0];
  59. $adRespond = AdService::getAdList($where);
  60. $ad = [];
  61. if (isset($adRespond['list']) && !empty($adRespond['list'])) {
  62. foreach ($adRespond['list'] as $single) {
  63. $ad[] = ['adImg' => $single['adImgUrl'], 'url' => ''];
  64. }
  65. }
  66. $category = CategoryService::getTopThreeCategory($this->mainId);
  67. $categoryList = !empty($category) ? GoodsCategoryService::getAppointCategoryList($category) : [];
  68. $data = ['ad' => $ad, 'category' => $categoryList, 'columnStyle' => rand(1, 2)];
  69. util::success($data);
  70. }
  71. //新客户 ssh 2019.12.29
  72. public function actionVisit()
  73. {
  74. $data = json_encode(array(
  75. 'type' => 'msg',
  76. 'msg' => 'aaaa',
  77. ));
  78. $id = 'merchantConsole_' . $this->sjId;
  79. $online = Gateway::getClientIdByUid($id);
  80. if ($online) {
  81. //直接发送
  82. Gateway::sendToUid($id, json_encode($data));
  83. } else {
  84. //保存
  85. }
  86. }
  87. //新订单 ssh 2019.12.29
  88. public function actionOrder()
  89. {
  90. $data = json_encode(array(
  91. 'type' => 'msg',
  92. 'msg' => 'aaaa',
  93. ));
  94. $id = 'merchantConsole_' . $this->sjId;
  95. $online = Gateway::getClientIdByUid($id);
  96. if ($online) {
  97. //直接发送
  98. Gateway::sendToUid($id, json_encode($data));
  99. } else {
  100. //保存
  101. }
  102. }
  103. //我的 ssh 2021.4.8
  104. public function actionMy()
  105. {
  106. $shop = $this->shop;
  107. $main = $this->main;
  108. $balance = $main->balance ?? 0.00;
  109. $txBalance = $main->txBalance ?? 0.00;
  110. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  111. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  112. $deadline = $sj['deadline'] ?? '';
  113. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  114. $adminName = $relation['name'] ?? '';
  115. $eId = $relation['id'] ?? 0;
  116. $mobile = $relation['mobile'] ?? '';
  117. $sjName = $sj['name'] ?? '';
  118. $shopName = $shop->shopName ?? '';
  119. $cashAccount = $main->cashAccount ?? '';
  120. $data = [
  121. 'balance' => $balance,
  122. 'txBalance' => $txBalance,
  123. 'shopImg' => $shopImg,
  124. 'deadline' => $deadline,
  125. 'adminName' => $adminName,
  126. 'adminMobile' => $mobile,
  127. 'sjName' => $sjName,
  128. 'shopName' => $shopName,
  129. 'shopImg' => $shopImg,
  130. 'cashAccount' => $cashAccount,
  131. 'shopAdminId' => $eId,
  132. 'shopId' => $this->shopId,
  133. 'sjId' => $this->sjId,
  134. ];
  135. util::success($data);
  136. }
  137. //经营概况 ssh 2021.1.27
  138. public function actionProfile()
  139. {
  140. //余额
  141. $shopInfo = ShopClass::getById($this->shopId);
  142. //库存情况
  143. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  144. //今日销售金额
  145. $today = StatIncomeClass::getAmountToday($this->shopId);
  146. //近七天销售金额
  147. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  148. //30天销售金额
  149. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  150. $base = [
  151. 'balance' => $shopInfo['balance'],
  152. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  153. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  154. 'stockCost' => $stockInfo['stockCost'],
  155. 'stockNum' => 0,
  156. 'stockBigNum' => $stockInfo['stockBigNum'],
  157. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  158. 'stockWarning' => $stockInfo['stockWarning'],
  159. 'today' => $today,
  160. 'todayCompareYesterday' => 0,
  161. 'latestSeven' => $latestSeven,
  162. 'latestSevenSameTerm' => 0,
  163. 'latestThirty' => $latestThirty,
  164. 'latestThirtySameTerm' => 0,
  165. ];
  166. //今日订单数
  167. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  168. //今日销售金额
  169. $saleAmount = $today;
  170. //昨日订单数
  171. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  172. //昨日销售金额
  173. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  174. //7天订单数
  175. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  176. //7天销售金额
  177. $sevenSaleAmount = $latestSeven;
  178. //30天订单数
  179. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  180. //30天销售金额
  181. $thirtySaleAmount = $latestThirty;
  182. //今日采购
  183. $todayCg = StatCgClass::getTodayCg($this->shop);
  184. //昨日采购
  185. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  186. //7日采购
  187. $sevenCg = StatCgClass::getSevenCg($this->shop);
  188. //30日采购
  189. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  190. $more = [
  191. 'today' => [
  192. 'income' => 0,
  193. 'expend' => 0,
  194. 'saleNum' => $saleNum,
  195. 'saleAmount' => $saleAmount,
  196. 'purchaseNum' => $todayCg['num'] ?? 0,
  197. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  198. ],
  199. 'yesterday' => [
  200. 'income' => 0,
  201. 'expend' => 0,
  202. 'saleNum' => $ySaleNum,
  203. 'saleAmount' => $ySaleAmount,
  204. 'purchaseNum' => $yesCg['num'] ?? 0,
  205. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  206. ],
  207. 'latestSeven' => [
  208. 'income' => 0,
  209. 'expend' => 0,
  210. 'saleNum' => $sevenSaleNum,
  211. 'saleAmount' => $sevenSaleAmount,
  212. 'purchaseNum' => $sevenCg['num'] ?? 0,
  213. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  214. ],
  215. 'latestThirty' => [
  216. 'income' => 0,
  217. 'expend' => 0,
  218. 'saleNum' => $thirtySaleNum,
  219. 'saleAmount' => $thirtySaleAmount,
  220. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  221. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  222. ],
  223. ];
  224. util::success(['base' => $base, 'more' => $more]);
  225. }
  226. }