ConsoleController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizGhs\order\classes\StockWastageOrderClass;
  7. use bizGhs\shop\classes\ShopAdminClass;
  8. use bizGhs\stat\classes\StatKdClass;
  9. use bizGhs\stat\classes\StatSaleClass;
  10. use bizHd\purchase\classes\PurchaseClass;
  11. //use bizHd\stat\classes\StatVisitClass;
  12. use bizGhs\stat\classes\StatVisitClass;
  13. use common\components\dict;
  14. use common\components\util;
  15. use Yii;
  16. class ConsoleController extends BaseController
  17. {
  18. public $guestAccess = ['init', 'profile', 'Stroke-count', 'stat'];
  19. //总览
  20. public function actionStat()
  21. {
  22. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  23. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  24. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  25. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  26. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  27. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  28. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,avCost,cost,virtualStock,delStatus', null, true);
  29. $totalItemNum = 0;
  30. $totalCost = 0;
  31. if (!empty($itemList)) {
  32. foreach ($itemList as $item) {
  33. if ($item->virtualStock == 0 && $item->delStatus == 0) {
  34. $stock = $item->stock ?? 0;
  35. $cost = $item->avCost ?? 0;
  36. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  37. $currentCost = bcmul($stock, $cost, 2);
  38. $totalCost = bcadd($currentCost, $totalCost, 2);
  39. }
  40. }
  41. }
  42. $totalItemNum = floor($totalItemNum);
  43. $totalBalance = CustomClass::sum(['ownMainId'=>$this->mainId],'balance');
  44. $totalBalance = abs($totalBalance);
  45. $overview = [
  46. ['name' => "库存数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  47. ['name' => "库存值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  48. ['name' => "实际应收", "url" => '/admin/shop/debtChange', 'value' => $totalDebt, 'type' => 1],
  49. ['name' => "应收款", "url" => '/admin/home/member', 'value' => $totalBalance, 'type' => 4],
  50. ['name' => "总访客", "url" => '/admin/home/member', 'value' => 0, 'type' => 4],
  51. ['name' => "总订单", "url" => '/admin/home/order', 'value' => 0, 'type' => 4],
  52. ];
  53. util::success(['overview' => $overview]);
  54. }
  55. //系统收入、客服收入、欠款
  56. public function actionStrokeCount()
  57. {
  58. if (empty($this->mainId)) {
  59. util::success([
  60. 'systemIncome' => 0,
  61. 'systemCount' => 0,
  62. 'debtCount' => 0,
  63. 'debtIncome' => 0,
  64. 'kfWxCount' => 0,
  65. 'kfWxIncome' => 0,
  66. 'cashCount' => 0,
  67. 'cashIncome' => 0,
  68. ]);
  69. }
  70. $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  71. $incomeList = $return['incomeList'];
  72. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  73. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  74. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  75. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  76. $systemCount = bcadd($systemCount1, $systemCount2);
  77. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  78. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  79. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  80. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  81. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  82. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  83. $debtCount = bcadd($debtCount1, $debtCount2);
  84. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  85. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  86. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  87. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  88. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  89. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  90. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  91. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  92. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  93. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  94. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  95. $cashCount = bcadd($cashCount1, $cashCount2);
  96. util::success([
  97. 'systemIncome' => $systemIncome,
  98. 'systemCount' => $systemCount,
  99. 'debtCount' => $debtCount,
  100. 'debtIncome' => $debtIncome,
  101. 'kfWxCount' => $kfWxCount,
  102. 'kfWxIncome' => $kfWxIncome,
  103. 'cashCount' => $cashCount,
  104. 'cashIncome' => $cashIncome,
  105. ]);
  106. }
  107. //获取昨天的收入 ssh 20240830
  108. public function actionGetYesterdayIncome()
  109. {
  110. $mainId = $this->mainId;
  111. $respond = StatSaleClass::profile($mainId);
  112. $incomeList = $respond['income'] ?? [];
  113. $sale = 0;
  114. if (!empty($incomeList)) {
  115. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  116. foreach ($incomeList as $item) {
  117. if (isset($item['id']) && $item['id'] == 'allot') {
  118. continue;
  119. }
  120. $sale = bcadd($sale, $item['amount'], 2);
  121. }
  122. }
  123. util::success(['income' => $sale]);
  124. }
  125. //今日概况 ssh 20220723
  126. public function actionProfile()
  127. {
  128. $get = Yii::$app->request->get();
  129. $version = $get['version'] ?? 1;
  130. $notice = [];
  131. $shop = $this->shop;
  132. if (!empty($shop)) {
  133. //到期前25天提醒
  134. $deadline = $shop->deadline;
  135. $currentTime = time();
  136. $deadTime = strtotime($deadline);
  137. $remainingSeconds = $deadTime - $currentTime;
  138. $remainingDays = ceil($remainingSeconds / 86400);
  139. // 到期前7天提醒
  140. if ($remainingSeconds <= 604800) {
  141. if ($remainingSeconds <= 0) {
  142. $notice[] = ['title' => '系统已到期', 'action' => '续费', 'page' => '/admin/shop/renew'];
  143. } else {
  144. $notice[] = ['title' => "系统{$remainingDays}天后到期,请及时续费", 'action' => '续费', 'page' => '/admin/shop/renew'];
  145. }
  146. }
  147. }
  148. //$notice[] = ['title' => '客户多个订单开始支持一键分享', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
  149. //$notice[] = ['title' => '如果你发现一个问题很重要,一直没给你处理,在小群多反应几次,用反应次数强调重要性,目前批发店多反应问题多,都在排队。', 'action' => '', 'page' => ''];
  150. //$notice[] = ['title' => '新功能:客户端和后台使用跑腿的流程', 'action' => '', 'page' => '/admin/book/detail?id=use_pt'];
  151. //$notice[] = ['title' => '分享订单打不开的解决办法', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
  152. //$notice[] = ['title' => '急事请连续打二次电话 15280215347', 'action' => '', 'page' => ''];
  153. $mainId = $this->mainId;
  154. $respond = StatSaleClass::profile($mainId);
  155. $incomeList = $respond['income'] ?? [];
  156. $todaySale = 0;
  157. if (!empty($incomeList)) {
  158. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  159. foreach ($incomeList as $item) {
  160. if (isset($item['id']) && $item['id'] == 'allot') {
  161. continue;
  162. }
  163. $todaySale = bcadd($todaySale, $item['amount'], 2);
  164. }
  165. }
  166. $expendList = $respond['expend'] ?? [];
  167. $todayOut = 0;
  168. if (!empty($expendList)) {
  169. foreach ($expendList as $item) {
  170. $todayOut = bcadd($todayOut, $item['amount'], 2);
  171. }
  172. }
  173. $orderNum = $respond['totalOrderNum'] ?? 0;
  174. $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
  175. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  176. $menu = [
  177. ["name" => "商城", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  178. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  179. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  180. ["name" => "花材(简)", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/simple"],
  181. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock"],
  182. ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  183. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  184. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  185. ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
  186. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  187. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
  188. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  189. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  190. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  191. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  192. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  193. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  194. ];
  195. $menuV2 = [
  196. ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  197. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
  198. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
  199. ["name" => "配送片区", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/orderListByDist"],
  200. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
  201. ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  202. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  203. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  204. ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
  205. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  206. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
  207. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  208. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  209. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  210. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  211. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  212. ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  213. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
  214. ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
  215. ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
  216. ];
  217. $menuV3 = [
  218. ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  219. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
  220. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
  221. ["name" => "配送片区", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/orderListByDist"],
  222. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
  223. ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  224. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  225. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  226. ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
  227. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  228. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
  229. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  230. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  231. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  232. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/warning"],
  233. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  234. ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  235. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
  236. ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
  237. ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
  238. ];
  239. $menuIconMap = [
  240. '商城码' => 'mall_code',
  241. '改价' => 'modify_price',
  242. '花材' => 'item',
  243. '配送片区' => 'send_dist',
  244. '改库存' => 'modify_stock',
  245. '采购' => 'purchase',
  246. '采购记录' => 'purchase_record',
  247. '调拨入库' => 'in_stock',
  248. '计算器' => 'calculator',
  249. '买花' => 'stock_in',
  250. '买花记录' => 'stock_in_record',
  251. '调拨出库' => 'out_stock',
  252. '支出' => 'expend',
  253. '员工' => 'staff',
  254. '库存预警' => 'stock_warning',
  255. '盘点' => 'check',
  256. '报损' => 'breakage',
  257. '损耗' => 'breakage',
  258. '拆散' => 'break_up',
  259. '收款流水' => 'gather_record',
  260. '收款码' => 'gather_code',
  261. '商城' => 'mall_code',
  262. '花材(简)' => 'item',
  263. ];
  264. if ($version == 2) {
  265. $menu = $menuV2;
  266. } elseif ($version == 3) {
  267. $menu = [];
  268. foreach ($menuV2 as $item) {
  269. $menuItem = $item;
  270. unset($menuItem['img']);
  271. $menuItem['icon'] = $menuIconMap[$item['name']] ?? 'item';
  272. $menu[] = $menuItem;
  273. }
  274. }elseif($version == 4) {
  275. $menu = [];
  276. foreach ($menuV3 as $item) {
  277. $menuItem = $item;
  278. unset($menuItem['img']);
  279. $menuItem['icon'] = $menuIconMap[$item['name']] ?? 'item';
  280. $menu[] = $menuItem;
  281. }
  282. }
  283. //查看财务的权限
  284. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  285. $warning = '';
  286. $warningUrl = '';
  287. //$warning = '挂账和结账重大调整(已上线) 查看 >';
  288. //$warningUrl = '/admin/notice/warning';
  289. util::success([
  290. 'asset' => $this->main,
  291. 'notice' => $notice,
  292. 'warning' => $warning,
  293. 'warningUrl' => $warningUrl,
  294. 'todayData' => [
  295. 'income' => $todaySale,
  296. 'order' => $orderNum,
  297. 'expend' => $todayOut,
  298. 'visitCustom' => $visitCustom,
  299. 'wastage' => $wastage
  300. ],
  301. 'menu' => $menu,
  302. 'lookMoney' => $lookMoney,
  303. ]);
  304. }
  305. //常用数据初始化
  306. public function actionInit()
  307. {
  308. $dict = dict::get();
  309. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  310. util::success(['dict' => $dict, 'shop' => $shop]);
  311. }
  312. }