MainController.php 7.8 KB

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