ConsoleController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\stat\classes\StatSaleClass;
  4. use bizHd\custom\classes\CustomClass;
  5. use bizHd\goods\classes\GoodsClass;
  6. use bizHd\order\classes\OrderClass;
  7. use bizHd\stat\classes\StatVisitClass;
  8. use bizGhs\item\classes\ItemClass;
  9. use common\components\dateUtil;
  10. use common\components\dict;
  11. use common\components\util;
  12. class ConsoleController extends BaseController
  13. {
  14. public $guestAccess = ['init', 'profile'];
  15. //总览
  16. public function actionStat()
  17. {
  18. //不要用缓存!!!
  19. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,avCost,cost,virtualStock,delStatus', null, true);
  20. $totalItemNum = 0;
  21. $totalCost = 0;
  22. if (!empty($itemList)) {
  23. foreach ($itemList as $item) {
  24. if ($item->virtualStock == 0 && $item->delStatus == 0) {
  25. $stock = $item->stock ?? 0;
  26. $cost = $item->avCost ?? 0;
  27. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  28. $currentCost = bcmul($stock, $cost, 2);
  29. $totalCost = bcadd($currentCost, $totalCost, 2);
  30. }
  31. }
  32. }
  33. $totalItemNum = floor($totalItemNum);
  34. $goodsCount = GoodsClass::getCount(['mainId'=>$this->mainId]);
  35. $customCount = CustomClass::getCount(['shopId'=>$this->shopId]);
  36. $orderCount = OrderClass::getCount(['mainId'=>$this->mainId, 'status'=>4]);
  37. $debtCount = OrderClass::debtCount($this->mainId);
  38. $overview = [
  39. ['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  40. ['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  41. ['name' => "花束", "url" => '/admin/goods/list', 'value' => $goodsCount, 'type' => 1],
  42. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $customCount, 'type' => 1],
  43. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $orderCount, 'type' => 4],
  44. ['name' => "总赊账", "url" => '/admin/home/order', 'value' => $debtCount, 'type' => 4],
  45. ];
  46. util::success(['overview' => $overview]);
  47. }
  48. //概况
  49. public function actionProfile()
  50. {
  51. //查看财务的权限
  52. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  53. $lsIncome = 0;
  54. $orderCount = 0;
  55. $yesterdayIncome = 0;
  56. if ($lookMoney == 1) {
  57. $mainId = $this->mainId;
  58. $todayStr = date('Y-m-d');
  59. // 今天零售订单总数与收入
  60. $cacheKey = 'hd_console_profile:' . 'today_'.$todayStr.'_income_' . $this->shopId;
  61. $cache = \Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  62. if ($cache) {
  63. $cacheData = json_decode($cache, true);
  64. $lsIncome = $cacheData['lsIncome'];
  65. $orderCount = $cacheData['orderCount'];
  66. } else {
  67. $period = dateUtil::formatTime('today', '', '', true);
  68. $start = $period['startTime'];
  69. $end = $period['endTime'];
  70. $currentStartDate = date('Y-m-d', strtotime($start));
  71. $currentEndDate = date('Y-m-d', strtotime($end));
  72. $currentStartTime = $currentStartDate . ' 00:00:00';
  73. $currentEndTime = $currentEndDate . ' 23:59:59';
  74. $where['time'] = ['between', [$start, $end]];
  75. $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  76. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  77. $orderCount = OrderClass::getCount($where);
  78. // $lsIncome = 0;
  79. // $hdOrderList = OrderClass::getAllByCondition($where, null, 'mainPay, forward, cash');
  80. // foreach ($hdOrderList as $hdKey => $hdOrder) {
  81. // $actPrice = $hdOrder['mainPay'] ?? 0;
  82. // $forward = $hdOrder['forward'] ?? 0;
  83. // if ($forward == 1) { //零售售后付款
  84. // // $lsAfterSale = bcadd($lsAfterSale, $actPrice, 2);
  85. // } else {
  86. // $cash = $hdOrder['cash'] ?? 0;
  87. // $lsIncome = bcadd($actPrice, $lsIncome, 2);
  88. // $lsIncome = bcadd($lsIncome, $cash, 2);
  89. // }
  90. // }
  91. $mainId = $this->mainId;
  92. $respond = StatSaleClass::profile($mainId);
  93. $incomeList = $respond['income'] ?? [];
  94. $todaySale = 0;
  95. if (!empty($incomeList)) {
  96. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  97. foreach ($incomeList as $item) {
  98. if (isset($item['id']) && $item['id'] == 'allot') {
  99. continue;
  100. }
  101. $todaySale = bcadd($todaySale, $item['amount'], 2);
  102. }
  103. }
  104. $cacheData = [
  105. 'lsIncome' => $todaySale,
  106. 'orderCount' => $orderCount,
  107. ];
  108. \Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1800, json_encode($cacheData, JSON_UNESCAPED_UNICODE)]);
  109. }
  110. // 昨天零售收入
  111. $cacheKey = 'hd_console_profile:' . 'yesterday_'.$todayStr.'_income_' . $this->shopId;
  112. $cache = \Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  113. if ($cache) {
  114. $cacheData = json_decode($cache, true);
  115. $yesterdayIncome = $cacheData['yesterdayIncome'];
  116. } else {
  117. // $period = dateUtil::formatTime('yesterday', '', '', true);
  118. // $start = $period['startTime'];
  119. // $end = $period['endTime'];
  120. // $currentStartDate = date('Y-m-d', strtotime($start));
  121. // $currentEndDate = date('Y-m-d', strtotime($end));
  122. // $currentStartTime = $currentStartDate . ' 00:00:00';
  123. // $currentEndTime = $currentEndDate . ' 23:59:59';
  124. // $where['time'] = ['between', [$start, $end]];
  125. // $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  126. // $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  127. // $yesterdayIncome = 0;
  128. // $hdOrderList = OrderClass::getAllByCondition($where, null, 'mainPay, forward, cash');
  129. // foreach ($hdOrderList as $hdKey => $hdOrder) {
  130. // $actPrice = $hdOrder['mainPay'] ?? 0;
  131. // $forward = $hdOrder['forward'] ?? 0;
  132. // if ($forward == 1) { //零售售后付款
  133. // // $lsAfterSale = bcadd($lsAfterSale, $actPrice, 2);
  134. // } else {
  135. // $cash = $hdOrder['cash'] ?? 0;
  136. // $yesterdayIncome = bcadd($actPrice, $yesterdayIncome, 2);
  137. // $yesterdayIncome = bcadd($yesterdayIncome, $cash, 2);
  138. // }
  139. // }
  140. $mainId = $this->mainId;
  141. $_GET['searchTime'] = 'yesterday'; // 必须要有的,让其获取昨天的收入
  142. $respond = StatSaleClass::profile($mainId);
  143. $incomeList = $respond['income'] ?? [];
  144. $yesterdayIncome = 0;
  145. if (!empty($incomeList)) {
  146. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  147. foreach ($incomeList as $item) {
  148. if (isset($item['id']) && $item['id'] == 'allot') {
  149. continue;
  150. }
  151. $yesterdayIncome = bcadd($yesterdayIncome, $item['amount'], 2);
  152. }
  153. }
  154. $cacheData = [
  155. 'yesterdayIncome' => $yesterdayIncome,
  156. ];
  157. \Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 86400, json_encode($cacheData, JSON_UNESCAPED_UNICODE)]);
  158. }
  159. }
  160. //访客数
  161. $visitCustom = StatVisitClass::getVisitNum($this->shopId);
  162. // $wastage = \bizGhs\order\classes\StockWastageOrderClass::getTodayWaste($this->mainId);
  163. // $hsReturn = StatOrderClass::statHsNum($this->mainId);
  164. // $hsNum = $hsReturn['num'] ?? 0;
  165. $menu = [
  166. ["name" => "商城", "img" => "ghs/home/shop2.png", "url" => "/admin/cg/mall", 'pf' => 1,],
  167. ["name" => "改价", "img" => "ghs/home/gj2.png", "url" => "/admin/changePrice/list2", 'pf' => 1,],
  168. ["name" => "绿植花材", "img" => "ghs/home/hcgl2.png", "url" => "/admin/item/list2", 'pf' => 1,],
  169. ["name" => "接花束", "img" => "ghs/home/shop2.png", "url" => "/admin/order/workOrder", 'pf' => 1,],
  170. ["name" => "拆散", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/part/list", 'pf' => 1,],
  171. ["name" => "损耗", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/breakage/list", 'pf' => 1,],
  172. ["name" => "任务", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/work/list", 'pf' => 1,],
  173. ["name" => "买花", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/order", 'pf' => 1,],
  174. ["name" => "买花记录", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,],
  175. ["name" => "花束", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/goods/list", 'pf' => 1,],
  176. ["name" => "客户充值", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/recharge/rechargeCode", 'pf' => 1,],
  177. ];
  178. $warning = '';
  179. //$warning = '本月4号凌晨4点~5点系统升级,暂停使用';
  180. util::success([
  181. 'warning' => $warning,
  182. 'todayData' => [
  183. 'visit' => $visitCustom,
  184. 'income' => $lsIncome, //$todaySale,
  185. 'order' => $orderCount, //$orderNum,
  186. // 'wastage' => $wastage,
  187. // 'bouquet' => $hsNum
  188. ],
  189. 'yesterdayIncome' => $yesterdayIncome,
  190. 'menu' => $menu,
  191. 'lookMoney' => $lookMoney,
  192. ]);
  193. }
  194. //常用初始化
  195. public function actionInit()
  196. {
  197. $dict = dict::get($this->mainId);
  198. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  199. util::success(['dict' => $dict, 'shop' => $shop]);
  200. }
  201. //系统收入、客服收入、欠款
  202. public function actionStrokeCount()
  203. {
  204. if (empty($this->mainId)) {
  205. util::success([
  206. 'systemIncome' => 0,
  207. 'systemCount' => 0,
  208. 'debtCount' => 0,
  209. 'debtIncome' => 0,
  210. 'kfWxCount' => 0,
  211. 'kfWxIncome' => 0,
  212. 'cashCount' => 0,
  213. 'cashIncome' => 0,
  214. ]);
  215. }
  216. $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  217. $incomeList = $return['incomeList'];
  218. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  219. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  220. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  221. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  222. $systemCount = bcadd($systemCount1, $systemCount2);
  223. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  224. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  225. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  226. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  227. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  228. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  229. $debtCount = bcadd($debtCount1, $debtCount2);
  230. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  231. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  232. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  233. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  234. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  235. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  236. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  237. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  238. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  239. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  240. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  241. $cashCount = bcadd($cashCount1, $cashCount2);
  242. util::success([
  243. 'systemIncome' => $systemIncome,
  244. 'systemCount' => $systemCount,
  245. 'debtCount' => $debtCount,
  246. 'debtIncome' => $debtIncome,
  247. 'kfWxCount' => $kfWxCount,
  248. 'kfWxIncome' => $kfWxIncome,
  249. 'cashCount' => $cashCount,
  250. 'cashIncome' => $cashIncome,
  251. ]);
  252. }
  253. }