ConsoleController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\item\classes\ItemClass;
  4. use bizGhs\order\classes\OrderClass;
  5. use bizGhs\order\classes\StockWastageOrderClass;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use bizGhs\stat\classes\StatKdClass;
  8. use bizGhs\stat\classes\StatSaleClass;
  9. use bizHd\stat\classes\StatVisitClass;
  10. use common\components\dict;
  11. use common\components\util;
  12. use Yii;
  13. class ConsoleController extends BaseController
  14. {
  15. public $guestAccess = ['init', 'profile', 'Stroke-count', 'stat'];
  16. //总览
  17. public function actionStat()
  18. {
  19. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  20. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  21. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  22. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  23. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  24. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  25. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  26. $totalItemNum = 0;
  27. $totalCost = 0;
  28. if (!empty($itemList)) {
  29. foreach ($itemList as $item) {
  30. $stock = $item->stock ?? 0;
  31. $cost = $item->cost ?? 0;
  32. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  33. $currentCost = bcmul($stock, $cost, 2);
  34. $totalCost = bcadd($currentCost, $totalCost, 2);
  35. }
  36. }
  37. $totalItemNum = floor($totalItemNum);
  38. $main = $this->main;
  39. $totalCustom = $main->totalUser ?? 0;
  40. $totalVisit = $main->totalVisit ?? 0;
  41. $totalOrder = $main->finishOrder ?? 0;
  42. $overview = [
  43. ['name' => "库存(扎)", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  44. ['name' => "库存(元)", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  45. ['name' => "总赊账", "url" => '/admin/shop/debtChange', 'value' => $totalDebt, 'type' => 1],
  46. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  47. ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  48. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
  49. ];
  50. util::success(['overview' => $overview]);
  51. }
  52. //系统收入、客服收入、欠款
  53. public function actionStrokeCount()
  54. {
  55. if (empty($this->mainId)) {
  56. util::success([
  57. 'systemIncome' => 0,
  58. 'systemCount' => 0,
  59. 'debtCount' => 0,
  60. 'debtIncome' => 0,
  61. 'kfWxCount' => 0,
  62. 'kfWxIncome' => 0,
  63. 'cashCount' => 0,
  64. 'cashIncome' => 0,
  65. ]);
  66. }
  67. $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  68. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  69. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  70. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  71. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  72. $systemCount = bcadd($systemCount1, $systemCount2);
  73. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  74. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  75. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  76. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  77. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  78. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  79. $debtCount = bcadd($debtCount1, $debtCount2);
  80. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  81. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  82. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  83. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  84. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  85. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  86. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  87. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  88. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  89. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  90. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  91. $cashCount = bcadd($cashCount1, $cashCount2);
  92. util::success([
  93. 'systemIncome' => $systemIncome,
  94. 'systemCount' => $systemCount,
  95. 'debtCount' => $debtCount,
  96. 'debtIncome' => $debtIncome,
  97. 'kfWxCount' => $kfWxCount,
  98. 'kfWxIncome' => $kfWxIncome,
  99. 'cashCount' => $cashCount,
  100. 'cashIncome' => $cashIncome,
  101. ]);
  102. }
  103. //今日概况 ssh 20220723
  104. public function actionProfile()
  105. {
  106. $notice = [];
  107. $notice = [['title' => '请按提示更新应用;苹果手机请到应用市场更新', 'action' => '查看', 'page' => '/admin/book/detail?id=wastage']];
  108. $mainId = $this->mainId;
  109. $respond = StatSaleClass::profile($mainId);
  110. $incomeList = $respond['income'] ?? [];
  111. $todaySale = 0;
  112. if (!empty($incomeList)) {
  113. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  114. foreach ($incomeList as $item) {
  115. if (isset($item['id']) && $item['id'] == 'allot') {
  116. continue;
  117. }
  118. $todaySale = bcadd($todaySale, $item['amount'], 2);
  119. }
  120. }
  121. $expendList = $respond['expend'] ?? [];
  122. $todayOut = 0;
  123. if (!empty($expendList)) {
  124. foreach ($expendList as $item) {
  125. $todayOut = bcadd($todayOut, $item['amount'], 2);
  126. }
  127. }
  128. $orderNum = $respond['totalOrderNum'] ?? 0;
  129. $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
  130. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  131. $menu = [
  132. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  133. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  134. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  135. ["name" => "采购", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  136. ["name" => "外采", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/wcOrder"],
  137. ["name" => "供货商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  138. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  139. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  140. ["name" => "结账记录", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  141. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  142. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  143. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  144. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  145. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock"],
  146. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  147. ["name" => "教学视频", "img" => "ghs/home/kcyjs.png", "url" => "/admin/book/index"],
  148. ];
  149. //查看财务的权限
  150. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  151. util::success([
  152. 'asset' => $this->main,
  153. 'notice' => $notice,
  154. 'todayData' => [
  155. 'income' => $todaySale,
  156. 'order' => $orderNum,
  157. 'expend' => $todayOut,
  158. 'visitCustom' => $visitCustom,
  159. 'wastage' => $wastage
  160. ],
  161. 'menu' => $menu,
  162. 'lookMoney' => $lookMoney,
  163. ]);
  164. }
  165. //常用初始化
  166. public function actionInit()
  167. {
  168. $dict = dict::get();
  169. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  170. util::success(['dict' => $dict, 'shop' => $shop]);
  171. }
  172. }