MainController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 common\components\stringUtil;
  11. use GatewayClient\Gateway;
  12. use bizHd\ad\services\AdService;
  13. use bizHd\goods\services\CategoryService;
  14. use bizHd\goods\services\GoodsCategoryService;
  15. use common\components\util;
  16. use biz\shop\classes\ShopClass;
  17. use bizGhs\product\classes\ProductClass;
  18. use bizHd\stat\classes\StatIncomeClass;
  19. use bizHd\stat\classes\StatOrderClass;
  20. use Yii;
  21. class MainController extends BaseController
  22. {
  23. public $guestAccess = ['index', 'my'];
  24. //商城海报 ssh 20210610
  25. public function actionGetMallPoster()
  26. {
  27. $shop = $this->shop;
  28. $pfShopId = $shop->pfShopId ?? 0;
  29. $merchant = WxOpenClass::getMallWxInfo();
  30. $goodsPage = 'pages/home/category';
  31. $ptStyle = dict::getDict('ptStyle', 'mall');
  32. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  33. $goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle);
  34. $flowerPage = 'pages/item/item';
  35. $flowerImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $flowerPage, $scene, $ptStyle);
  36. $prefix = imgUtil::getPrefix();
  37. $titleBase64 = stringUtil::ossBase64('个人买花入口');
  38. if ($pfShopId > 0) {
  39. $goodsUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  40. $goodsMiniCodeBase64 = stringUtil::ossBase64($goodsImgUrl);
  41. $goodsUrl .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  42. $goodsUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  43. $flowerUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  44. $flowerMiniCodeBase64 = stringUtil::ossBase64($flowerImgUrl);
  45. $flowerUrl .= '/watermark,image_' . $flowerMiniCodeBase64 . ',g_north,x_0,y_40';
  46. $flowerUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  47. $respond = [
  48. 'imgUrl' => $goodsUrl,
  49. 'flowerImgUrl' => $flowerUrl,
  50. ];
  51. } else {
  52. $goodsUrl = imgUtil::groupImg($goodsImgUrl);
  53. $flowerUrl = imgUtil::groupImg($flowerImgUrl);
  54. $respond = [
  55. 'imgUrl' => $goodsUrl,
  56. 'flowerImgUrl' => $flowerUrl,
  57. ];
  58. }
  59. util::success($respond);
  60. }
  61. //会员注册码 ssh 20220607
  62. public function actionGetMemberPoster()
  63. {
  64. $shop = $this->shop;
  65. $pfShopId = $shop->pfShopId ?? 0;
  66. $merchant = WxOpenClass::getMallWxInfo();
  67. $page = 'pages/login/index';
  68. $ptStyle = dict::getDict('ptStyle', 'mall');
  69. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  70. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  71. if ($pfShopId > 0) {
  72. $prefix = imgUtil::getPrefix();
  73. $titleBase64 = stringUtil::ossBase64('注册会员');
  74. $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  75. $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  76. $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40';
  77. $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  78. $respond = ['imgUrl' => $memberUrl];
  79. } else {
  80. $url = imgUtil::groupImg($imgUrl);
  81. $respond = ['imgUrl' => $url];
  82. }
  83. util::success($respond);
  84. }
  85. public function actionDemo()
  86. {
  87. return $this->renderPartial('demo');
  88. }
  89. //新客户 ssh 2019.12.29
  90. public function actionVisit()
  91. {
  92. $data = json_encode(array(
  93. 'type' => 'msg',
  94. 'msg' => 'aaaa',
  95. ));
  96. $id = 'merchantConsole_' . $this->sjId;
  97. $online = Gateway::getClientIdByUid($id);
  98. if ($online) {
  99. //直接发送
  100. Gateway::sendToUid($id, json_encode($data));
  101. } else {
  102. //保存
  103. }
  104. }
  105. //新订单 ssh 2019.12.29
  106. public function actionOrder()
  107. {
  108. $data = json_encode(array(
  109. 'type' => 'msg',
  110. 'msg' => 'aaaa',
  111. ));
  112. $id = 'merchantConsole_' . $this->sjId;
  113. $online = Gateway::getClientIdByUid($id);
  114. if ($online) {
  115. //直接发送
  116. Gateway::sendToUid($id, json_encode($data));
  117. } else {
  118. //保存
  119. }
  120. }
  121. //我的 ssh 2021.4.8
  122. public function actionMy()
  123. {
  124. $shop = $this->shop;
  125. $main = $this->main;
  126. $balance = $main->balance ?? 0.00;
  127. $money = $main->money ?? 0;
  128. $txBalance = $main->txBalance ?? 0.00;
  129. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  130. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  131. $deadline = $sj['deadline'] ?? '';
  132. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  133. $adminName = $relation['name'] ?? '';
  134. $eId = $relation['id'] ?? 0;
  135. $mobile = $relation['mobile'] ?? '';
  136. $sjName = $sj['name'] ?? '';
  137. $shopName = $shop->shopName ?? '';
  138. $cashAccount = $main->cashAccount ?? '';
  139. $data = [
  140. 'balance' => $balance,
  141. 'txBalance' => $txBalance,
  142. 'shopImg' => $shopImg,
  143. 'deadline' => $deadline,
  144. 'adminName' => $adminName,
  145. 'adminMobile' => $mobile,
  146. 'sjName' => $sjName,
  147. 'shopName' => $shopName,
  148. 'shopImg' => $shopImg,
  149. 'cashAccount' => $cashAccount,
  150. 'shopAdminId' => $eId,
  151. 'shopId' => $this->shopId,
  152. 'sjId' => $this->sjId,
  153. 'money' => $money,
  154. ];
  155. util::success($data);
  156. }
  157. //经营概况 ssh 2021.1.27
  158. public function actionProfile()
  159. {
  160. //余额
  161. $shopInfo = ShopClass::getById($this->shopId);
  162. //库存情况
  163. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  164. //今日销售金额
  165. $today = StatIncomeClass::getAmountToday($this->shopId);
  166. //近七天销售金额
  167. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  168. //30天销售金额
  169. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  170. $base = [
  171. 'balance' => $shopInfo['balance'],
  172. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  173. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  174. 'stockCost' => $stockInfo['stockCost'],
  175. 'stockNum' => 0,
  176. 'stockBigNum' => $stockInfo['stockBigNum'],
  177. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  178. 'stockWarning' => $stockInfo['stockWarning'],
  179. 'today' => $today,
  180. 'todayCompareYesterday' => 0,
  181. 'latestSeven' => $latestSeven,
  182. 'latestSevenSameTerm' => 0,
  183. 'latestThirty' => $latestThirty,
  184. 'latestThirtySameTerm' => 0,
  185. ];
  186. //今日订单数
  187. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  188. //今日销售金额
  189. $saleAmount = $today;
  190. //昨日订单数
  191. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  192. //昨日销售金额
  193. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  194. //7天订单数
  195. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  196. //7天销售金额
  197. $sevenSaleAmount = $latestSeven;
  198. //30天订单数
  199. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  200. //30天销售金额
  201. $thirtySaleAmount = $latestThirty;
  202. //今日采购
  203. $todayCg = StatCgClass::getTodayCg($this->shop);
  204. //昨日采购
  205. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  206. //7日采购
  207. $sevenCg = StatCgClass::getSevenCg($this->shop);
  208. //30日采购
  209. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  210. $more = [
  211. 'today' => [
  212. 'income' => 0,
  213. 'expend' => 0,
  214. 'saleNum' => $saleNum,
  215. 'saleAmount' => $saleAmount,
  216. 'purchaseNum' => $todayCg['num'] ?? 0,
  217. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  218. ],
  219. 'yesterday' => [
  220. 'income' => 0,
  221. 'expend' => 0,
  222. 'saleNum' => $ySaleNum,
  223. 'saleAmount' => $ySaleAmount,
  224. 'purchaseNum' => $yesCg['num'] ?? 0,
  225. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  226. ],
  227. 'latestSeven' => [
  228. 'income' => 0,
  229. 'expend' => 0,
  230. 'saleNum' => $sevenSaleNum,
  231. 'saleAmount' => $sevenSaleAmount,
  232. 'purchaseNum' => $sevenCg['num'] ?? 0,
  233. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  234. ],
  235. 'latestThirty' => [
  236. 'income' => 0,
  237. 'expend' => 0,
  238. 'saleNum' => $thirtySaleNum,
  239. 'saleAmount' => $thirtySaleAmount,
  240. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  241. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  242. ],
  243. ];
  244. util::success(['base' => $base, 'more' => $more]);
  245. }
  246. }