MainController.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. //采购商城海报 ssh 20230217
  53. public function actionGetMallPoster()
  54. {
  55. $merchant = WxOpenClass::getWxInfo();
  56. $page = 'pagesPurchase/ghsProduct';
  57. $ptStyle = dict::getDict('ptStyle', 'hd');
  58. //scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
  59. $scene = "sId={$this->shopId}&id=0&gId=" . $this->shopAdminId;
  60. $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
  61. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
  62. $titleBase64 = stringUtil::ossBase64('扫码买花');
  63. $prefix = imgUtil::getPrefix();
  64. $url = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  65. $goodsMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  66. $url .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  67. $url .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  68. $respond = ['imgUrl' => $url];
  69. util::success($respond);
  70. }
  71. public function actionDemo()
  72. {
  73. return $this->renderPartial('demo');
  74. }
  75. public function actionIndex()
  76. {
  77. return $this->renderPartial('index');
  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.1.27
  112. public function actionProfile()
  113. {
  114. //余额
  115. $shopInfo = ShopClass::getById($this->shopId);
  116. //库存情况
  117. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  118. //今日销售金额
  119. $today = StatIncomeClass::getAmountToday($this->shopId);
  120. //近七天销售金额
  121. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  122. //30天销售金额
  123. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  124. $base = [
  125. 'balance' => $shopInfo['balance'],
  126. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  127. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  128. 'stockCost' => $stockInfo['stockCost'],
  129. 'stockNum' => 0,
  130. 'stockBigNum' => $stockInfo['stockBigNum'],
  131. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  132. 'stockWarning' => $stockInfo['stockWarning'],
  133. 'today' => $today,
  134. 'todayCompareYesterday' => 0,
  135. 'latestSeven' => $latestSeven,
  136. 'latestSevenSameTerm' => 0,
  137. 'latestThirty' => $latestThirty,
  138. 'latestThirtySameTerm' => 0,
  139. ];
  140. //今日订单数
  141. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  142. //今日销售金额
  143. $saleAmount = $today;
  144. //昨日订单数
  145. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  146. //昨日销售金额
  147. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  148. //7天订单数
  149. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  150. //7天销售金额
  151. $sevenSaleAmount = $latestSeven;
  152. //30天订单数
  153. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  154. //30天销售金额
  155. $thirtySaleAmount = $latestThirty;
  156. //今日采购
  157. $todayCg = StatCgClass::getTodayCg($this->shop);
  158. //昨日采购
  159. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  160. //7日采购
  161. $sevenCg = StatCgClass::getSevenCg($this->shop);
  162. //30日采购
  163. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  164. $more = [
  165. 'today' => [
  166. 'income' => 0,
  167. 'expend' => 0,
  168. 'saleNum' => $saleNum,
  169. 'saleAmount' => $saleAmount,
  170. 'purchaseNum' => $todayCg['num'] ?? 0,
  171. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  172. ],
  173. 'yesterday' => [
  174. 'income' => 0,
  175. 'expend' => 0,
  176. 'saleNum' => $ySaleNum,
  177. 'saleAmount' => $ySaleAmount,
  178. 'purchaseNum' => $yesCg['num'] ?? 0,
  179. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  180. ],
  181. 'latestSeven' => [
  182. 'income' => 0,
  183. 'expend' => 0,
  184. 'saleNum' => $sevenSaleNum,
  185. 'saleAmount' => $sevenSaleAmount,
  186. 'purchaseNum' => $sevenCg['num'] ?? 0,
  187. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  188. ],
  189. 'latestThirty' => [
  190. 'income' => 0,
  191. 'expend' => 0,
  192. 'saleNum' => $thirtySaleNum,
  193. 'saleAmount' => $thirtySaleAmount,
  194. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  195. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  196. ],
  197. ];
  198. util::success(['base' => $base, 'more' => $more]);
  199. }
  200. //我的 ssh 2021.1.30
  201. public function actionMy()
  202. {
  203. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  204. $shop = $this->shop ?? null;
  205. $main = $this->main ?? null;
  206. $balance = $main->balance ?? 0.00;
  207. $txBalance = $main->txBalance ?? 0.00;
  208. $money = $main->money ?? 0;
  209. $cashAccount = $main->cashAccount ?? '';
  210. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  211. $shopImg = imgUtil::groupImg('');
  212. if (!empty($shop)) {
  213. $shopImg = imgUtil::groupImg($shop->avatar);
  214. }
  215. $smallShopImg = $shopImg . "?x-oss-process=image/resize,m_fill,h_180,w_180";
  216. //是否显示推荐广告
  217. $showAd = 0;
  218. //用于审核的账号不要显示广告
  219. if ($this->mainId == 58) {
  220. $showAd = 0;
  221. }
  222. //没有登录不显示广告
  223. if (empty($this->mainId)) {
  224. $showAd = 0;
  225. }
  226. //是否展示终身版套餐
  227. $lifelong = 1;
  228. $deadline = $sj['deadline'] ?? '';
  229. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  230. $adminName = $relation['name'] ?? '';
  231. $shopAdminId = $relation['id'] ?? 0;
  232. $mobile = $relation['mobile'] ?? '';
  233. $sjName = $sj['name'] ?? '';
  234. $shopName = $shop->shopName ?? '';
  235. $data = [
  236. 'balance' => $balance,
  237. 'txBalance' => $txBalance,
  238. 'deadline' => $deadline,
  239. 'adminName' => $adminName,
  240. 'adminMobile' => $mobile,
  241. 'sjName' => $sjName,
  242. 'shopName' => $shopName,
  243. 'shopImg' => $shopImg,
  244. 'smallShopImg' => $smallShopImg,
  245. 'cashAccount' => $cashAccount,
  246. 'shopAdminId' => $shopAdminId,
  247. 'shopId' => $this->shopId,
  248. 'sjId' => $this->sjId,
  249. 'adminId' => $this->adminId,
  250. 'money' => $money,
  251. 'shopInfo' => $shop,
  252. 'lookMoney' => $lookMoney,
  253. 'fast1' => '17189513228',
  254. 'fast2' => '15280215347',
  255. 'showAd' => $showAd,
  256. 'lifelong' => $lifelong,
  257. ];
  258. util::success($data);
  259. }
  260. }