MainController.php 7.5 KB

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