MainController.php 7.5 KB

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