MainController.php 7.6 KB

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