MainController.php 8.9 KB

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