MainController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatCgClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use bizHd\stat\classes\StatIncomeClass;
  8. use bizHd\stat\classes\StatOrderClass;
  9. use bizHd\wx\classes\WxOpenClass;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\miniUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use Yii;
  16. use GatewayClient\Gateway;
  17. class MainController extends BaseController
  18. {
  19. public $guestAccess = ['my'];
  20. //修改运费标准 ssh 20230406
  21. public function actionModifyFreight()
  22. {
  23. $post = Yii::$app->request->post();
  24. $main = $this->main;
  25. $baseFee = $post['baseFee'] ?? 5.5;
  26. $shortDistanceFee = $post['shortDistanceFee'] ?? 2;
  27. $longDistanceFee = $post['longDistanceFee'] ?? 2;
  28. $smallWeightFee = $post['smallWeightFee'] ?? 6;
  29. $bigWeightFee = $post['bigWeightFee'] ?? 10;
  30. $onePeriodFee = $post['onePeriodFee'] ?? 4;
  31. $twoPeriodFee = $post['twoPeriodFee'] ?? 1;
  32. $threePeriodFee = $post['threePeriodFee'] ?? 2;
  33. $lsFee = $post['lsFee'] ?? 0;
  34. $main->baseFee = $baseFee;
  35. $main->shortDistanceFee = $shortDistanceFee;
  36. $main->longDistanceFee = $longDistanceFee;
  37. $main->smallWeightFee = $smallWeightFee;
  38. $main->bigWeightFee = $bigWeightFee;
  39. $main->onePeriodFee = $onePeriodFee;
  40. $main->twoPeriodFee = $twoPeriodFee;
  41. $main->threePeriodFee = $threePeriodFee;
  42. $main->lsFee = $lsFee;
  43. $main->save();
  44. util::complete();
  45. }
  46. //main信息 ssh 20230406
  47. public function actionInfo()
  48. {
  49. $main = $this->main;
  50. util::success(['info' => $main]);
  51. }
  52. /**
  53. * 职责:生成并获取采购商城太阳码海报
  54. * 入参:HTTP GET (参数可选:env_version)
  55. * 返回:太阳码海报图片的完整 OSS 地址 JSON
  56. * 副作用:当没有缓存时,会触发向微信 API 请求并同步上传生成的图片至阿里 OSS。
  57. * 关键边界:引入了店员+环境+门店级别的最终海报数据 Redis 强缓存(3天有效期),避免每次高频无端向微信和 OSS 发起同步请求。
  58. */
  59. public function actionGetMallPoster()
  60. {
  61. $shopId = $this->shopId;
  62. $adminId = $this->shopAdminId;
  63. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  64. // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
  65. // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
  66. $posterCacheKey = "wx_mini_purchase_mall_poster_url_{$shopId}_{$adminId}_{$envVersion}";
  67. $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
  68. if (!empty($cachedPoster)) {
  69. $respond = json_decode($cachedPoster, true);
  70. if (!empty($respond['imgUrl'])) {
  71. util::success($respond); // 缓存直接命中,毫秒级快速返回!
  72. }
  73. }
  74. $merchant = WxOpenClass::getWxInfo();
  75. $page = 'pagesPurchase/ghsProduct';
  76. $ptStyle = dict::getDict('ptStyle', 'hd');
  77. //scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
  78. $scene = "sId={$shopId}&id=0&gId=" . $adminId;
  79. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
  80. $titleBase64 = stringUtil::ossBase64('扫码买花');
  81. $prefix = imgUtil::getPrefix();
  82. $url = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  83. $goodsMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  84. $url .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  85. $url .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  86. $respond = ['imgUrl' => $url];
  87. // ==================== 【性能优化】保存最终拼接和生成结果到 Redis 中,过期时间 3 天 ====================
  88. Yii::$app->redis->executeCommand('SETEX', [$posterCacheKey, 86400 * 3, json_encode($respond)]);
  89. util::success($respond);
  90. }
  91. public function actionDemo()
  92. {
  93. return $this->renderPartial('demo');
  94. }
  95. public function actionIndex()
  96. {
  97. return $this->renderPartial('index');
  98. }
  99. //新客户 ssh 2019.12.29
  100. public function actionVisit()
  101. {
  102. $data = json_encode(array(
  103. 'type' => 'msg',
  104. 'msg' => 'aaaa',
  105. ));
  106. $id = 'merchantConsole_' . $this->sjId;
  107. $online = Gateway::getClientIdByUid($id);
  108. if ($online) {
  109. //直接发送
  110. Gateway::sendToUid($id, json_encode($data));
  111. } else {
  112. //保存
  113. }
  114. }
  115. //新订单 ssh 2019.12.29
  116. public function actionOrder()
  117. {
  118. $data = json_encode(array(
  119. 'type' => 'msg',
  120. 'msg' => 'aaaa',
  121. ));
  122. $id = 'merchantConsole_' . $this->sjId;
  123. $online = Gateway::getClientIdByUid($id);
  124. if ($online) {
  125. //直接发送
  126. Gateway::sendToUid($id, json_encode($data));
  127. } else {
  128. //保存
  129. }
  130. }
  131. //经营概况 ssh 2021.1.27
  132. public function actionProfile()
  133. {
  134. //余额
  135. $shopInfo = ShopClass::getById($this->shopId);
  136. //库存情况
  137. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  138. //今日销售金额
  139. $today = StatIncomeClass::getAmountToday($this->shopId);
  140. //近七天销售金额
  141. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  142. //30天销售金额
  143. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  144. $base = [
  145. 'balance' => $shopInfo['balance'],
  146. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  147. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  148. 'stockCost' => $stockInfo['stockCost'],
  149. 'stockNum' => 0,
  150. 'stockBigNum' => $stockInfo['stockBigNum'],
  151. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  152. 'stockWarning' => $stockInfo['stockWarning'],
  153. 'today' => $today,
  154. 'todayCompareYesterday' => 0,
  155. 'latestSeven' => $latestSeven,
  156. 'latestSevenSameTerm' => 0,
  157. 'latestThirty' => $latestThirty,
  158. 'latestThirtySameTerm' => 0,
  159. ];
  160. //今日订单数
  161. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  162. //今日销售金额
  163. $saleAmount = $today;
  164. //昨日订单数
  165. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  166. //昨日销售金额
  167. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  168. //7天订单数
  169. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  170. //7天销售金额
  171. $sevenSaleAmount = $latestSeven;
  172. //30天订单数
  173. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  174. //30天销售金额
  175. $thirtySaleAmount = $latestThirty;
  176. //今日采购
  177. $todayCg = StatCgClass::getTodayCg($this->shop);
  178. //昨日采购
  179. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  180. //7日采购
  181. $sevenCg = StatCgClass::getSevenCg($this->shop);
  182. //30日采购
  183. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  184. $more = [
  185. 'today' => [
  186. 'income' => 0,
  187. 'expend' => 0,
  188. 'saleNum' => $saleNum,
  189. 'saleAmount' => $saleAmount,
  190. 'purchaseNum' => $todayCg['num'] ?? 0,
  191. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  192. ],
  193. 'yesterday' => [
  194. 'income' => 0,
  195. 'expend' => 0,
  196. 'saleNum' => $ySaleNum,
  197. 'saleAmount' => $ySaleAmount,
  198. 'purchaseNum' => $yesCg['num'] ?? 0,
  199. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  200. ],
  201. 'latestSeven' => [
  202. 'income' => 0,
  203. 'expend' => 0,
  204. 'saleNum' => $sevenSaleNum,
  205. 'saleAmount' => $sevenSaleAmount,
  206. 'purchaseNum' => $sevenCg['num'] ?? 0,
  207. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  208. ],
  209. 'latestThirty' => [
  210. 'income' => 0,
  211. 'expend' => 0,
  212. 'saleNum' => $thirtySaleNum,
  213. 'saleAmount' => $thirtySaleAmount,
  214. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  215. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  216. ],
  217. ];
  218. util::success(['base' => $base, 'more' => $more]);
  219. }
  220. //我的 ssh 2021.1.30
  221. public function actionMy()
  222. {
  223. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  224. $shop = $this->shop ?? null;
  225. $main = $this->main ?? null;
  226. $balance = $main->balance ?? 0.00;
  227. $txBalance = $main->txBalance ?? 0.00;
  228. $money = $main->money ?? 0;
  229. $cashAccount = $main->cashAccount ?? '';
  230. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  231. $shopImg = imgUtil::groupImg('');
  232. if (!empty($shop)) {
  233. $shopImg = imgUtil::groupImg($shop->avatar);
  234. }
  235. $smallShopImg = $shopImg . "?x-oss-process=image/resize,m_fill,h_180,w_180";
  236. //是否显示推荐广告
  237. $showAd = 0;
  238. //用于审核的账号不要显示广告
  239. if ($this->mainId == 58) {
  240. $showAd = 0;
  241. }
  242. //没有登录不显示广告
  243. if (empty($this->mainId)) {
  244. $showAd = 0;
  245. }
  246. //是否展示终身版套餐
  247. $lifelong = 1;
  248. $deadline = $sj['deadline'] ?? '';
  249. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  250. $adminName = $relation['name'] ?? '';
  251. $shopAdminId = $relation['id'] ?? 0;
  252. $mobile = $relation['mobile'] ?? '';
  253. $sjName = $sj['name'] ?? '';
  254. $shopName = $shop->shopName ?? '';
  255. $data = [
  256. 'balance' => $balance,
  257. 'txBalance' => $txBalance,
  258. 'deadline' => $deadline,
  259. 'adminName' => $adminName,
  260. 'adminMobile' => $mobile,
  261. 'sjName' => $sjName,
  262. 'shopName' => $shopName,
  263. 'shopImg' => $shopImg,
  264. 'smallShopImg' => $smallShopImg,
  265. 'cashAccount' => $cashAccount,
  266. 'shopAdminId' => $shopAdminId,
  267. 'shopId' => $this->shopId,
  268. 'sjId' => $this->sjId,
  269. 'adminId' => $this->adminId,
  270. 'money' => $money,
  271. 'shopInfo' => $shop,
  272. 'lookMoney' => $lookMoney,
  273. 'fast1' => '17189513228',
  274. 'fast2' => '15280215347',
  275. 'showAd' => $showAd,
  276. 'lifelong' => $lifelong,
  277. ];
  278. util::success($data);
  279. }
  280. }