MainController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. //商城海报 shish 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. $balance = $shop->balance ?? 0.00;
  94. $txBalance = $shop->txBalance ?? 0.00;
  95. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  96. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  97. $deadline = $sj['deadline'] ?? '';
  98. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  99. $adminName = $relation['name'] ?? '';
  100. $eId = $relation['id'] ?? 0;
  101. $mobile = $relation['mobile'] ?? '';
  102. $sjName = $sj['name'] ?? '';
  103. $shopName = $shop->shopName ?? '';
  104. $cashAccount = $shop->cashAccount ?? '';
  105. $data = [
  106. 'balance' => $balance,
  107. 'txBalance' => $txBalance,
  108. 'shopImg' => $shopImg,
  109. 'deadline' => $deadline,
  110. 'adminName' => $adminName,
  111. 'adminMobile' => $mobile,
  112. 'sjName' => $sjName,
  113. 'shopName' => $shopName,
  114. 'shopImg' => $shopImg,
  115. 'cashAccount' => $cashAccount,
  116. 'shopAdminId' => $eId,
  117. 'shopId' => $this->shopId,
  118. 'sjId' => $this->sjId,
  119. ];
  120. util::success($data);
  121. }
  122. //经营概况 ssh 2021.1.27
  123. public function actionProfile()
  124. {
  125. //余额
  126. $shopInfo = ShopClass::getById($this->shopId);
  127. //库存情况
  128. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  129. //今日销售金额
  130. $today = StatIncomeClass::getAmountToday($this->shopId);
  131. //近七天销售金额
  132. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  133. //30天销售金额
  134. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  135. $base = [
  136. 'balance' => $shopInfo['balance'],
  137. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  138. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  139. 'stockCost' => $stockInfo['stockCost'],
  140. 'stockNum' => 0,
  141. 'stockBigNum' => $stockInfo['stockBigNum'],
  142. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  143. 'stockWarning' => $stockInfo['stockWarning'],
  144. 'today' => $today,
  145. 'todayCompareYesterday' => 0,
  146. 'latestSeven' => $latestSeven,
  147. 'latestSevenSameTerm' => 0,
  148. 'latestThirty' => $latestThirty,
  149. 'latestThirtySameTerm' => 0,
  150. ];
  151. //今日订单数
  152. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  153. //今日销售金额
  154. $saleAmount = $today;
  155. //昨日订单数
  156. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  157. //昨日销售金额
  158. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  159. //7天订单数
  160. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  161. //7天销售金额
  162. $sevenSaleAmount = $latestSeven;
  163. //30天订单数
  164. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  165. //30天销售金额
  166. $thirtySaleAmount = $latestThirty;
  167. //今日采购
  168. $todayCg = StatCgClass::getTodayCg($this->shop);
  169. //昨日采购
  170. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  171. //7日采购
  172. $sevenCg = StatCgClass::getSevenCg($this->shop);
  173. //30日采购
  174. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  175. $more = [
  176. 'today' => [
  177. 'income' => 0,
  178. 'expend' => 0,
  179. 'saleNum' => $saleNum,
  180. 'saleAmount' => $saleAmount,
  181. 'purchaseNum' => $todayCg['num'] ?? 0,
  182. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  183. ],
  184. 'yesterday' => [
  185. 'income' => 0,
  186. 'expend' => 0,
  187. 'saleNum' => $ySaleNum,
  188. 'saleAmount' => $ySaleAmount,
  189. 'purchaseNum' => $yesCg['num'] ?? 0,
  190. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  191. ],
  192. 'latestSeven' => [
  193. 'income' => 0,
  194. 'expend' => 0,
  195. 'saleNum' => $sevenSaleNum,
  196. 'saleAmount' => $sevenSaleAmount,
  197. 'purchaseNum' => $sevenCg['num'] ?? 0,
  198. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  199. ],
  200. 'latestThirty' => [
  201. 'income' => 0,
  202. 'expend' => 0,
  203. 'saleNum' => $thirtySaleNum,
  204. 'saleAmount' => $thirtySaleAmount,
  205. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  206. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  207. ],
  208. ];
  209. util::success(['base' => $base, 'more' => $more]);
  210. }
  211. }