MainController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 bizHd\stat\classes\StatIncomeClass;
  7. use bizHd\stat\classes\StatOrderClass;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\miniUtil;
  12. use common\components\stringUtil;
  13. use common\components\util;
  14. use Yii;
  15. use GatewayClient\Gateway;
  16. class MainController extends BaseController
  17. {
  18. public $guestAccess = ['my'];
  19. //修改运费标准 ssh 20230406
  20. public function actionModifyFreight()
  21. {
  22. $post = Yii::$app->request->post();
  23. $main = $this->main;
  24. $baseFee = $post['baseFee'] ?? 5.5;
  25. $shortDistanceFee = $post['shortDistanceFee'] ?? 2;
  26. $longDistanceFee = $post['longDistanceFee'] ?? 2;
  27. $smallWeightFee = $post['smallWeightFee'] ?? 6;
  28. $bigWeightFee = $post['bigWeightFee'] ?? 10;
  29. $onePeriodFee = $post['onePeriodFee'] ?? 4;
  30. $twoPeriodFee = $post['twoPeriodFee'] ?? 1;
  31. $threePeriodFee = $post['threePeriodFee'] ?? 2;
  32. $lsFee = $post['lsFee'] ?? 0;
  33. $main->baseFee = $baseFee;
  34. $main->shortDistanceFee = $shortDistanceFee;
  35. $main->longDistanceFee = $longDistanceFee;
  36. $main->smallWeightFee = $smallWeightFee;
  37. $main->bigWeightFee = $bigWeightFee;
  38. $main->onePeriodFee = $onePeriodFee;
  39. $main->twoPeriodFee = $twoPeriodFee;
  40. $main->threePeriodFee = $threePeriodFee;
  41. $main->lsFee = $lsFee;
  42. $main->save();
  43. util::complete();
  44. }
  45. //main信息 ssh 20230406
  46. public function actionInfo()
  47. {
  48. $main = $this->main;
  49. util::success(['info' => $main]);
  50. }
  51. //采购商城海报 ssh 20230217
  52. public function actionGetMallPoster()
  53. {
  54. $merchant = WxOpenClass::getWxInfo();
  55. $page = 'pagesPurchase/ghsProduct';
  56. $ptStyle = dict::getDict('ptStyle', 'hd');
  57. //scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
  58. $scene = "sId={$this->shopId}&id=0&gId=" . $this->shopAdminId;
  59. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  60. $titleBase64 = stringUtil::ossBase64('扫码买花');
  61. $prefix = imgUtil::getPrefix();
  62. $url = $prefix . 'shop/miniCodeBg.jpg?x-oss-process=image';
  63. $goodsMiniCodeBase64 = stringUtil::ossBase64($imgUrl);
  64. $url .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
  65. $url .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
  66. $respond = ['imgUrl' => $url];
  67. util::success($respond);
  68. }
  69. public function actionDemo()
  70. {
  71. return $this->renderPartial('demo');
  72. }
  73. public function actionIndex()
  74. {
  75. return $this->renderPartial('index');
  76. }
  77. //新客户 ssh 2019.12.29
  78. public function actionVisit()
  79. {
  80. $data = json_encode(array(
  81. 'type' => 'msg',
  82. 'msg' => 'aaaa',
  83. ));
  84. $id = 'merchantConsole_' . $this->sjId;
  85. $online = Gateway::getClientIdByUid($id);
  86. if ($online) {
  87. //直接发送
  88. Gateway::sendToUid($id, json_encode($data));
  89. } else {
  90. //保存
  91. }
  92. }
  93. //新订单 ssh 2019.12.29
  94. public function actionOrder()
  95. {
  96. $data = json_encode(array(
  97. 'type' => 'msg',
  98. 'msg' => 'aaaa',
  99. ));
  100. $id = 'merchantConsole_' . $this->sjId;
  101. $online = Gateway::getClientIdByUid($id);
  102. if ($online) {
  103. //直接发送
  104. Gateway::sendToUid($id, json_encode($data));
  105. } else {
  106. //保存
  107. }
  108. }
  109. //经营概况 ssh 2021.1.27
  110. public function actionProfile()
  111. {
  112. //余额
  113. $shopInfo = ShopClass::getById($this->shopId);
  114. //库存情况
  115. $stockInfo = ProductClass::getProductStockByShopId($this->sjId, $this->shopId);
  116. //今日销售金额
  117. $today = StatIncomeClass::getAmountToday($this->shopId);
  118. //近七天销售金额
  119. $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
  120. //30天销售金额
  121. $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
  122. $base = [
  123. 'balance' => $shopInfo['balance'],
  124. 'mayGathering' => $shopInfo['mayGathering'] ?? 0.00,
  125. 'mayPay' => $shopInfo['mayPay'] ?? 0.00,
  126. 'stockCost' => $stockInfo['stockCost'],
  127. 'stockNum' => 0,
  128. 'stockBigNum' => $stockInfo['stockBigNum'],
  129. 'stockSmallNum' => $stockInfo['stockSmallNum'],
  130. 'stockWarning' => $stockInfo['stockWarning'],
  131. 'today' => $today,
  132. 'todayCompareYesterday' => 0,
  133. 'latestSeven' => $latestSeven,
  134. 'latestSevenSameTerm' => 0,
  135. 'latestThirty' => $latestThirty,
  136. 'latestThirtySameTerm' => 0,
  137. ];
  138. //今日订单数
  139. $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
  140. //今日销售金额
  141. $saleAmount = $today;
  142. //昨日订单数
  143. $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
  144. //昨日销售金额
  145. $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
  146. //7天订单数
  147. $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
  148. //7天销售金额
  149. $sevenSaleAmount = $latestSeven;
  150. //30天订单数
  151. $thirtySaleNum = StatOrderClass::getRiseNumThirty($this->shopId);
  152. //30天销售金额
  153. $thirtySaleAmount = $latestThirty;
  154. //今日采购
  155. $todayCg = StatCgClass::getTodayCg($this->shop);
  156. //昨日采购
  157. $yesCg = StatCgClass::getYesterdayCg($this->shop);
  158. //7日采购
  159. $sevenCg = StatCgClass::getSevenCg($this->shop);
  160. //30日采购
  161. $thirtyCg = StatCgClass::getThirtyCg($this->shop);
  162. $more = [
  163. 'today' => [
  164. 'income' => 0,
  165. 'expend' => 0,
  166. 'saleNum' => $saleNum,
  167. 'saleAmount' => $saleAmount,
  168. 'purchaseNum' => $todayCg['num'] ?? 0,
  169. 'purchaseAmount' => $todayCg['amount'] ?? 0.00,
  170. ],
  171. 'yesterday' => [
  172. 'income' => 0,
  173. 'expend' => 0,
  174. 'saleNum' => $ySaleNum,
  175. 'saleAmount' => $ySaleAmount,
  176. 'purchaseNum' => $yesCg['num'] ?? 0,
  177. 'purchaseAmount' => $yesCg['amount'] ?? 0.00,
  178. ],
  179. 'latestSeven' => [
  180. 'income' => 0,
  181. 'expend' => 0,
  182. 'saleNum' => $sevenSaleNum,
  183. 'saleAmount' => $sevenSaleAmount,
  184. 'purchaseNum' => $sevenCg['num'] ?? 0,
  185. 'purchaseAmount' => $sevenCg['amount'] ?? 0.00,
  186. ],
  187. 'latestThirty' => [
  188. 'income' => 0,
  189. 'expend' => 0,
  190. 'saleNum' => $thirtySaleNum,
  191. 'saleAmount' => $thirtySaleAmount,
  192. 'purchaseNum' => $thirtyCg['num'] ?? 0,
  193. 'purchaseAmount' => $thirtyCg['amount'] ?? 0.00,
  194. ],
  195. ];
  196. util::success(['base' => $base, 'more' => $more]);
  197. }
  198. //我的 ssh 2021.1.30
  199. public function actionMy()
  200. {
  201. $shop = $this->shop ?? null;
  202. $main = $this->main ?? null;
  203. $balance = $main->balance ?? 0.00;
  204. $txBalance = $main->txBalance ?? 0.00;
  205. $money = $main->money ?? 0;
  206. $cashAccount = $main->cashAccount ?? '';
  207. $sj = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  208. $shopImg = Yii::$app->params['ghsImgHost'] . 'retail/default-img.png';
  209. $deadline = $sj['deadline'] ?? '';
  210. $relation = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  211. $adminName = $relation['name'] ?? '';
  212. $shopAdminId = $relation['id'] ?? 0;
  213. $mobile = $relation['mobile'] ?? '';
  214. $sjName = $sj['name'] ?? '';
  215. $shopName = $shop->shopName ?? '';
  216. $data = [
  217. 'balance' => $balance,
  218. 'txBalance' => $txBalance,
  219. 'deadline' => $deadline,
  220. 'adminName' => $adminName,
  221. 'adminMobile' => $mobile,
  222. 'sjName' => $sjName,
  223. 'shopName' => $shopName,
  224. 'shopImg' => $shopImg,
  225. 'cashAccount' => $cashAccount,
  226. 'shopAdminId' => $shopAdminId,
  227. 'shopId' => $this->shopId,
  228. 'sjId' => $this->sjId,
  229. 'adminId' => $this->adminId,
  230. 'money' => $money,
  231. 'shopInfo' => $shop,
  232. ];
  233. util::success($data);
  234. }
  235. }