StatController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\PurchaseOrderClass;
  4. use bizGhs\order\classes\StockWastageOrderClass;
  5. use bizGhs\order\classes\StockWastageOrderItemClass;
  6. use bizGhs\shop\classes\ShopAdminClass;
  7. use bizGhs\stat\classes\StatSaleClass;
  8. use common\components\arrayUtil;
  9. use common\components\imgUtil;
  10. use Yii;
  11. use common\components\util;
  12. use common\components\dateUtil;
  13. class StatController extends BaseController
  14. {
  15. //采购运费统计 ssh 20230427
  16. public function actionCgFreight()
  17. {
  18. $get = Yii::$app->request->get();
  19. $where = [];
  20. $where['mainId'] = $this->mainId;
  21. $where['status'] = 4;
  22. $searchTime = $get['searchTime'] ?? 'today';
  23. if (!empty($searchTime)) {
  24. $startTime = $get['startTime'] ?? '';
  25. $endTime = $get['endTime'] ?? '';
  26. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  27. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  28. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  29. $where['entryTime'] = ['between', [$start, $end]];
  30. }
  31. $cgList = PurchaseOrderClass::getAllByCondition($where, 'entryTime ASC', '*', null, true);
  32. $packingCharge = 0;
  33. $shortCharge = 0;
  34. $longCharge = 0;
  35. $pickCharge = 0;
  36. $localCharge = 0;
  37. if (!empty($cgList)) {
  38. foreach ($cgList as $cg) {
  39. $pack = $cg->packingCharge ?? 0;
  40. $short = $cg->shortCharge ?? 0;
  41. $long = $cg->longCharge ?? 0;
  42. $pick = $cg->pickCharge ?? 0;
  43. $local = $cg->localCharge ?? 0;
  44. $packingCharge = bcadd($packingCharge, $pack, 2);
  45. $shortCharge = bcadd($shortCharge, $short, 2);
  46. $longCharge = bcadd($longCharge, $long, 2);
  47. $pickCharge = bcadd($pickCharge, $pick, 2);
  48. $localCharge = bcadd($localCharge, $local, 2);
  49. }
  50. }
  51. $total = [
  52. 'packingCharge' => $packingCharge,
  53. 'shortCharge' => $shortCharge,
  54. 'longCharge' => $longCharge,
  55. 'pickCharge' => $pickCharge,
  56. 'localCharge' => $localCharge,
  57. 'num' => count($cgList)
  58. ];
  59. util::success(['list' => $cgList, 'total' => $total]);
  60. }
  61. //按分类统计收入 ssh 20231111
  62. public function actionClassProfit()
  63. {
  64. ini_set('memory_limit', '2045M');
  65. set_time_limit(0);
  66. //查看财务的权限
  67. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  68. $hasPower = 0;
  69. if (getenv('YII_ENV') == 'production') {
  70. //小向花卉
  71. if ($this->mainId == 23390) {
  72. if (in_array($this->adminId, [28456, 31105, 52528])) {
  73. $hasPower = 1;
  74. }
  75. }
  76. } else {
  77. if ($this->mainId == 644) {
  78. if (in_array($this->adminId, [1230])) {
  79. $hasPower = 1;
  80. }
  81. }
  82. }
  83. if ($lookMoney == 0 && $hasPower == 0) {
  84. util::fail('没有财务权限哦');
  85. }
  86. $mainId = $this->mainId;
  87. StatSaleClass::classProfile($mainId);
  88. }
  89. //配送业绩 ssh 20240824
  90. public function actionSend()
  91. {
  92. ini_set('memory_limit', '2045M');
  93. set_time_limit(0);
  94. $mainId = $this->mainId;
  95. $arr = StatSaleClass::send($mainId);
  96. util::success(['list' => $arr]);
  97. }
  98. public function actionIncomeOutItem()
  99. {
  100. ini_set('memory_limit', '2045M');
  101. set_time_limit(0);
  102. //查看财务的权限
  103. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  104. if ($lookMoney == 0) {
  105. util::fail('无法查看');
  106. }
  107. $mainId = $this->mainId;
  108. StatSaleClass::incomeOutItem($mainId);
  109. }
  110. public function actionProfit()
  111. {
  112. ini_set('memory_limit', '2045M');
  113. set_time_limit(0);
  114. //查看财务的权限
  115. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  116. if ($lookMoney == 0) {
  117. util::fail('无法查看');
  118. }
  119. $mainId = $this->mainId;
  120. $respond = StatSaleClass::profile($mainId);
  121. $income = $respond['income'] ?? 0;
  122. $expend = $respond['expend'] ?? 0;
  123. $balance = $respond['balance'] ?? 0;
  124. $payCodeIncome = $respond['payCodeIncome'] ?? 0;
  125. //由于损耗而造成少赚的钱
  126. $wastageRespond = StatSaleClass::wastage($mainId);
  127. $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
  128. $wastagePrice = floatval($wastagePrice);
  129. $wastageCost = $wastageRespond['totalCost'] ?? 0;
  130. $wastageCost = floatval($wastageCost);
  131. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice,'wastageCost'=>$wastageCost, 'payCodeIncome' => $payCodeIncome]);
  132. }
  133. //按月统计损耗情况
  134. public function actionWaste()
  135. {
  136. ini_set('memory_limit', '2045M');
  137. set_time_limit(0);
  138. $mainId = $this->mainId;
  139. $list = StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*');
  140. $arr = [];
  141. $totalNum = 0;
  142. $totalCost = 0;
  143. $totalPrice = 0;
  144. if (!empty($list)) {
  145. foreach ($list as $order) {
  146. $addTime = $order['addTime'];
  147. $time = date("Ym", strtotime($addTime));
  148. $date = date("Y年n月", strtotime($addTime));
  149. $bigNum = $order['bigNum'] ?? 0;
  150. $cost = $order['cost'] ?? 0;
  151. $price = $order['price'] ?? 0;
  152. if (isset($arr[$time])) {
  153. $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
  154. $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
  155. $arr[$time]['price'] = bcadd($arr[$time]['price'], $price, 2);
  156. $arr[$time]['time'] = $date;
  157. } else {
  158. $arr[$time]['num'] = $bigNum;
  159. $arr[$time]['cost'] = $cost;
  160. $arr[$time]['price'] = $price;
  161. $arr[$time]['time'] = $date;
  162. }
  163. $totalNum = bcadd($totalNum, $bigNum);
  164. $totalCost = bcadd($totalCost, $cost, 2);
  165. $totalPrice = bcadd($totalPrice, $price, 2);
  166. }
  167. }
  168. $totalCost = floatval($totalCost);
  169. $totalPrice = floatval($totalPrice);
  170. util::success(['list' => $arr, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalPrice' => $totalPrice]);
  171. }
  172. //损耗花材
  173. public function actionWastage()
  174. {
  175. $get = Yii::$app->request->get();
  176. $where = [];
  177. $where['mainId'] = $this->mainId;
  178. $searchTime = $get['searchTime'] ?? 'today';
  179. if (!empty($searchTime)) {
  180. $startTime = $get['startTime'] ?? '';
  181. $endTime = $get['endTime'] ?? '';
  182. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  183. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  184. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  185. $where['addTime'] = ['between', [$start, $end]];
  186. }
  187. $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true);
  188. $stat = [];
  189. $totalCost = 0;
  190. $totalNum = 0;
  191. if (!empty($wastageList)) {
  192. foreach ($wastageList as $waste) {
  193. $name = $waste->name ?? '';
  194. $shortCover = $waste->cover ?? '';
  195. $cover = imgUtil::groupImg($shortCover);
  196. $num = $waste->itemNum ?? 0;
  197. $cost = $waste->itemCost ?? 0;
  198. $currentCost = bcmul($cost, $num, 2);
  199. $productId = $waste->productId ?? 0;
  200. if (isset($stat[$productId]) == false) {
  201. $stat[$productId]['name'] = $name;
  202. $stat[$productId]['cover'] = $cover;
  203. $stat[$productId]['num'] = 0;
  204. $stat[$productId]['amount'] = 0;
  205. }
  206. $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
  207. $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2);
  208. $totalNum = bcadd($totalNum, $num, 2);
  209. $totalCost = bcadd($totalCost, $currentCost, 2);
  210. }
  211. $stat = array_values($stat);
  212. $stat = arrayUtil::arraySort($stat, 'num');
  213. }
  214. util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]);
  215. }
  216. }