MainController.php 9.1 KB

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