MainController.php 7.8 KB

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