ConsoleController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. $actTotalDebt = 0;
  45. if($totalDebt > $totalBalance){
  46. $actTotalDebt = bcsub($totalDebt, $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' => $actTotalDebt, '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. //获取昨天的收入 ssh 20240830
  111. public function actionGetYesterdayIncome()
  112. {
  113. $mainId = $this->mainId;
  114. $respond = StatSaleClass::profile($mainId);
  115. $incomeList = $respond['income'] ?? [];
  116. $sale = 0;
  117. if (!empty($incomeList)) {
  118. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  119. foreach ($incomeList as $item) {
  120. if (isset($item['id']) && $item['id'] == 'allot') {
  121. continue;
  122. }
  123. $sale = bcadd($sale, $item['amount'], 2);
  124. }
  125. }
  126. util::success(['income' => $sale]);
  127. }
  128. //今日概况 ssh 20220723
  129. public function actionProfile()
  130. {
  131. $get = Yii::$app->request->get();
  132. $version = $get['version'] ?? 1;
  133. $notice = [];
  134. $shop = $this->shop;
  135. if (!empty($shop)) {
  136. //到期前25天提醒
  137. $deadline = $shop->deadline;
  138. $currentTime = time();
  139. $deadTime = strtotime($deadline);
  140. $remainingSeconds = $deadTime - $currentTime;
  141. $remainingDays = ceil($remainingSeconds / 86400);
  142. // 到期前7天提醒
  143. if ($remainingSeconds <= 604800) {
  144. if ($remainingSeconds <= 0) {
  145. $notice[] = ['title' => '系统已到期', 'action' => '续费', 'page' => '/admin/shop/renew'];
  146. } else {
  147. $notice[] = ['title' => "系统{$remainingDays}天后到期,请及时续费", 'action' => '续费', 'page' => '/admin/shop/renew'];
  148. }
  149. }
  150. }
  151. //$notice[] = ['title' => '客户多个订单开始支持一键分享', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
  152. //$notice[] = ['title' => '急事请连续打二次电话 15280215347', 'action' => '', 'page' => ''];
  153. //$notice[] = ['title' => '新功能:客户端和后台使用跑腿的流程', 'action' => '', 'page' => '/admin/book/detail?id=use_pt'];
  154. //$notice[] = ['title' => '分享订单打不开的解决办法', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
  155. $mainId = $this->mainId;
  156. $respond = StatSaleClass::profile($mainId);
  157. $incomeList = $respond['income'] ?? [];
  158. $todaySale = 0;
  159. if (!empty($incomeList)) {
  160. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  161. foreach ($incomeList as $item) {
  162. if (isset($item['id']) && $item['id'] == 'allot') {
  163. continue;
  164. }
  165. $todaySale = bcadd($todaySale, $item['amount'], 2);
  166. }
  167. }
  168. $expendList = $respond['expend'] ?? [];
  169. $todayOut = 0;
  170. if (!empty($expendList)) {
  171. foreach ($expendList as $item) {
  172. $todayOut = bcadd($todayOut, $item['amount'], 2);
  173. }
  174. }
  175. $orderNum = $respond['totalOrderNum'] ?? 0;
  176. $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
  177. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  178. $menu = [
  179. ["name" => "商城", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  180. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  181. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  182. ["name" => "花材(简)", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/simple"],
  183. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock"],
  184. ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  185. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  186. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  187. ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
  188. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  189. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
  190. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  191. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  192. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  193. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  194. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  195. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  196. ];
  197. if ($version == 2) {
  198. $menu = [
  199. ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  200. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
  201. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
  202. ["name" => "配送片区", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/orderListByDist"],
  203. //["name" => "预订客户", "img" => "ghs/home/yggl.png", "url" => "/admin/book/custom"],
  204. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
  205. ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  206. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  207. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  208. ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
  209. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  210. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
  211. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  212. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  213. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  214. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  215. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  216. ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  217. //["name" => "预订明细", "img" => "ghs/home/yggl.png", "url" => "/admin/book/itemCustom"],
  218. //["name" => "新增预订", "img" => "ghs/home/yggl.png", "url" => "/admin/custom/selectCustom?style=1&book=1&getAll=1"],
  219. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
  220. ["name" => "收款码流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
  221. ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
  222. ];
  223. }
  224. //查看财务的权限
  225. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  226. $warning = '';
  227. $warningUrl = '';
  228. //$warning = '';
  229. //$warningUrl = '/admin/notice/warning';
  230. util::success([
  231. 'asset' => $this->main,
  232. 'notice' => $notice,
  233. 'warning' => $warning,
  234. 'warningUrl' => $warningUrl,
  235. 'todayData' => [
  236. 'income' => $todaySale,
  237. 'order' => $orderNum,
  238. 'expend' => $todayOut,
  239. 'visitCustom' => $visitCustom,
  240. 'wastage' => $wastage
  241. ],
  242. 'menu' => $menu,
  243. 'lookMoney' => $lookMoney,
  244. ]);
  245. }
  246. //常用初始化
  247. public function actionInit()
  248. {
  249. $dict = dict::get();
  250. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  251. util::success(['dict' => $dict, 'shop' => $shop]);
  252. }
  253. }