MainController.php 9.6 KB

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