ConsoleController.php 17 KB

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