MainController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. $merchant = WxOpenClass::getMallWxInfo();
  65. $page = 'pages/login/index';
  66. $ptStyle = dict::getDict('ptStyle', 'mall');
  67. $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
  68. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  69. $prefix = imgUtil::getPrefix();
  70. $titleBase64 = stringUtil::ossBase64('扫码注册会员');
  71. $memberUrl = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  72. $memberMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  73. $memberUrl .= '/watermark,image_' . $memberMiniCodeBase64 . ',g_north,x_0,y_40';
  74. $memberUrl .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  75. $respond = ['imgUrl' => $memberUrl];
  76. util::success($respond);
  77. }
  78. public function actionDemo()
  79. {
  80. return $this->renderPartial('demo');
  81. }
  82. //新客户 ssh 2019.12.29
  83. public function actionVisit()
  84. {
  85. $data = json_encode(array(
  86. 'type' => 'msg',
  87. 'msg' => 'aaaa',
  88. ));
  89. $id = 'merchantConsole_' . $this->sjId;
  90. $online = Gateway::getClientIdByUid($id);
  91. if ($online) {
  92. //直接发送
  93. Gateway::sendToUid($id, json_encode($data));
  94. } else {
  95. //保存
  96. }
  97. }
  98. //新订单 ssh 2019.12.29
  99. public function actionOrder()
  100. {
  101. $data = json_encode(array(
  102. 'type' => 'msg',
  103. 'msg' => 'aaaa',
  104. ));
  105. $id = 'merchantConsole_' . $this->sjId;
  106. $online = Gateway::getClientIdByUid($id);
  107. if ($online) {
  108. //直接发送
  109. Gateway::sendToUid($id, json_encode($data));
  110. } else {
  111. //保存
  112. }
  113. }
  114. //我的 ssh 2021.4.8
  115. public function actionMy()
  116. {
  117. $shop = $this->shop;
  118. $main = $this->main;
  119. $balance = $main->balance ?? 0.00;
  120. $money = $main->money ?? 0;
  121. $txBalance = $main->txBalance ?? 0.00;
  122. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  123. $shopImg = Yii::$app->params['hdImgHost'] . 'retail/default-img.png';
  124. $deadline = $sj['deadline'] ?? '';
  125. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  126. $adminName = $relation['name'] ?? '';
  127. $eId = $relation['id'] ?? 0;
  128. $mobile = $relation['mobile'] ?? '';
  129. $sjName = $sj['name'] ?? '';
  130. $shopName = $shop->shopName ?? '';
  131. $cashAccount = $main->cashAccount ?? '';
  132. $data = [
  133. 'balance' => $balance,
  134. 'txBalance' => $txBalance,
  135. 'shopImg' => $shopImg,
  136. 'deadline' => $deadline,
  137. 'adminName' => $adminName,
  138. 'adminMobile' => $mobile,
  139. 'sjName' => $sjName,
  140. 'shopName' => $shopName,
  141. 'shopImg' => $shopImg,
  142. 'cashAccount' => $cashAccount,
  143. 'shopAdminId' => $eId,
  144. 'shopId' => $this->shopId,
  145. 'sjId' => $this->sjId,
  146. 'money' => $money,
  147. ];
  148. util::success($data);
  149. }
  150. //经营概况 ssh 2021.1.27
  151. public function actionProfile()
  152. {
  153. //余额
  154. $shopInfo = ShopClass::getById($this->shopId);
  155. //库存情况
  156. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  157. //今日销售金额
  158. $today = StatIncomeClass::getAmountToday($this->shopId);
  159. //近七天销售金额
  160. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  161. //30天销售金额
  162. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  163. $base = [
  164. 'balance' => $shopInfo['balance'],
  165. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  166. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  167. 'stockCost' => $stockInfo['stockCost'],
  168. 'stockNum' => 0,
  169. 'stockBigNum' => $stockInfo['stockBigNum'],
  170. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  171. 'stockWarning' => $stockInfo['stockWarning'],
  172. 'today' => $today,
  173. 'todayCompareYesterday' => 0,
  174. 'latestSeven' => $latestSeven,
  175. 'latestSevenSameTerm' => 0,
  176. 'latestThirty' => $latestThirty,
  177. 'latestThirtySameTerm' => 0,
  178. ];
  179. //今日订单数
  180. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  181. //今日销售金额
  182. $saleAmount = $today;
  183. //昨日订单数
  184. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  185. //昨日销售金额
  186. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  187. //7天订单数
  188. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  189. //7天销售金额
  190. $sevenSaleAmount = $latestSeven;
  191. //30天订单数
  192. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  193. //30天销售金额
  194. $thirtySaleAmount = $latestThirty;
  195. //今日采购
  196. $todayCg = StatCgClass::getTodayCg($this->shop);
  197. //昨日采购
  198. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  199. //7日采购
  200. $sevenCg = StatCgClass::getSevenCg($this->shop);
  201. //30日采购
  202. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  203. $more = [
  204. 'today' => [
  205. 'income' => 0,
  206. 'expend' => 0,
  207. 'saleNum' => $saleNum,
  208. 'saleAmount' => $saleAmount,
  209. 'purchaseNum' => $todayCg['num'] ?? 0,
  210. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  211. ],
  212. 'yesterday' => [
  213. 'income' => 0,
  214. 'expend' => 0,
  215. 'saleNum' => $ySaleNum,
  216. 'saleAmount' => $ySaleAmount,
  217. 'purchaseNum' => $yesCg['num'] ?? 0,
  218. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  219. ],
  220. 'latestSeven' => [
  221. 'income' => 0,
  222. 'expend' => 0,
  223. 'saleNum' => $sevenSaleNum,
  224. 'saleAmount' => $sevenSaleAmount,
  225. 'purchaseNum' => $sevenCg['num'] ?? 0,
  226. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  227. ],
  228. 'latestThirty' => [
  229. 'income' => 0,
  230. 'expend' => 0,
  231. 'saleNum' => $thirtySaleNum,
  232. 'saleAmount' => $thirtySaleAmount,
  233. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  234. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  235. ],
  236. ];
  237. util::success(['base' => $base, 'more' => $more]);
  238. }
  239. }