ConsoleController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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\purchase\classes\PurchaseClass;
  10. use bizHd\stat\classes\StatVisitClass;
  11. use common\components\dict;
  12. use common\components\util;
  13. use Yii;
  14. class ConsoleController extends BaseController
  15. {
  16. public $guestAccess = ['init', 'profile', 'Stroke-count', 'stat'];
  17. //总览
  18. public function actionStat()
  19. {
  20. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  21. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  22. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  23. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  24. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  25. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  26. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost,virtualStock,delStatus', null, true);
  27. $totalItemNum = 0;
  28. $totalCost = 0;
  29. if (!empty($itemList)) {
  30. foreach ($itemList as $item) {
  31. if ($item->virtualStock == 0 && $item->delStatus == 0) {
  32. $stock = $item->stock ?? 0;
  33. $cost = $item->cost ?? 0;
  34. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  35. $currentCost = bcmul($stock, $cost, 2);
  36. $totalCost = bcadd($currentCost, $totalCost, 2);
  37. }
  38. }
  39. }
  40. $totalItemNum = floor($totalItemNum);
  41. $main = $this->main;
  42. $totalCustom = $main->totalUser ?? 0;
  43. $totalVisit = $main->totalVisit ?? 0;
  44. $totalOrder = $main->finishOrder ?? 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' => $totalDebt, 'type' => 1],
  49. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  50. ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  51. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, '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. //到期前10天提醒
  134. $deadline = $shop->deadline;
  135. $currentTime = time();
  136. $currentTime = $currentTime + 864000;
  137. $deadTime = strtotime($deadline);
  138. if ($currentTime > $deadTime) {
  139. if (time() > $deadTime) {
  140. $notice[] = ['title' => '系统已到期', 'action' => '查看', 'page' => '/admin/shop/renew'];
  141. } else {
  142. $notice[] = ['title' => '系统即将到期,请及时续费', 'action' => '查看', 'page' => '/admin/shop/renew'];
  143. }
  144. }
  145. }
  146. //$notice[] = ['title' => '节日期间官方技术服务电话2号:17189513228', 'action' => '', 'page' => ''];
  147. //$notice[] = ['title' => '今天11:30~12:00订单可能会漏打小票,请复查', 'action' => '', 'page' => ''];
  148. $mainId = $this->mainId;
  149. $respond = StatSaleClass::profile($mainId);
  150. $incomeList = $respond['income'] ?? [];
  151. $todaySale = 0;
  152. if (!empty($incomeList)) {
  153. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  154. foreach ($incomeList as $item) {
  155. if (isset($item['id']) && $item['id'] == 'allot') {
  156. continue;
  157. }
  158. $todaySale = bcadd($todaySale, $item['amount'], 2);
  159. }
  160. }
  161. $expendList = $respond['expend'] ?? [];
  162. $todayOut = 0;
  163. if (!empty($expendList)) {
  164. foreach ($expendList as $item) {
  165. $todayOut = bcadd($todayOut, $item['amount'], 2);
  166. }
  167. }
  168. $orderNum = $respond['totalOrderNum'] ?? 0;
  169. $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
  170. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  171. $cgNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => ['in', [3]]]);
  172. $menu = [
  173. ["name" => "商城", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  174. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  175. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  176. ["name" => "花材(简)", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/simple"],
  177. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock"],
  178. ["name" => "供货商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  179. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  180. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  181. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  182. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  183. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => $cgNum],
  184. ["name" => "库存总览", "img" => "ghs/home/kcyjs.png", "url" => "/admin/stat/stock"],
  185. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  186. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  187. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  188. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  189. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  190. ];
  191. if ($version == 2) {
  192. $menu = [
  193. ["name" => "商城", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  194. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
  195. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
  196. ["name" => "今日访客", "img" => "ghs/home/yggl.png", "url" => "/admin/custom/visit"],
  197. //["name" => "预订客户", "img" => "ghs/home/yggl.png", "url" => "/admin/book/custom"],
  198. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
  199. ["name" => "供货商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  200. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  201. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  202. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  203. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  204. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => $cgNum],
  205. ["name" => "库存总览", "img" => "ghs/home/kcyjs.png", "url" => "/admin/stat/stock"],
  206. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  207. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  208. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  209. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  210. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  211. //["name" => "预订明细", "img" => "ghs/home/yggl.png", "url" => "/admin/book/itemCustom"],
  212. //["name" => "新增预订", "img" => "ghs/home/yggl.png", "url" => "/admin/custom/selectCustom?style=1&book=1&getAll=1"],
  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. }
  218. //用于审核,不展示全部完整的功能,批发的功能不展示出来,否则要申请B2B类目!!!!!!!!
  219. if ($this->adminId == 17) {
  220. $menu = [
  221. ["name" => "商城", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
  222. ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
  223. ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  224. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  225. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  226. ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
  227. ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => $cgNum],
  228. ["name" => "库存总览", "img" => "ghs/home/kcyjs.png", "url" => "/admin/stat/stock"],
  229. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  230. ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
  231. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  232. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  233. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  234. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
  235. ];
  236. }
  237. //查看财务的权限
  238. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  239. $warning = '';
  240. $warningUrl = '';
  241. //$warning = '';
  242. //$warningUrl = '/admin/notice/warning';
  243. util::success([
  244. 'asset' => $this->main,
  245. 'notice' => $notice,
  246. 'warning' => $warning,
  247. 'warningUrl' => $warningUrl,
  248. 'todayData' => [
  249. 'income' => $todaySale,
  250. 'order' => $orderNum,
  251. 'expend' => $todayOut,
  252. 'visitCustom' => $visitCustom,
  253. 'wastage' => $wastage
  254. ],
  255. 'menu' => $menu,
  256. 'lookMoney' => $lookMoney,
  257. ]);
  258. }
  259. //常用初始化
  260. public function actionInit()
  261. {
  262. $dict = dict::get();
  263. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  264. util::success(['dict' => $dict, 'shop' => $shop]);
  265. }
  266. }