MainController.php 9.7 KB

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