ConsoleController.php 17 KB

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