StatKdClass.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <?php
  2. namespace bizGhs\stat\classes;
  3. use biz\shop\classes\ShopAdminClass;
  4. use bizGhs\order\classes\OrderClass;
  5. use bizGhs\order\classes\OrderItemClass;
  6. use bizGhs\order\classes\StockOutOrderClass;
  7. use bizHd\order\classes\SettleClass;
  8. use common\components\dateUtil;
  9. use common\components\dict;
  10. use bizHd\order\classes\OrderClass as HdOrderClass;
  11. use bizGhs\clear\classes\ClearClass;
  12. use bizGhs\base\classes\BaseClass;
  13. use common\components\noticeUtil;
  14. use Yii;
  15. class StatKdClass extends BaseClass
  16. {
  17. public static $baseFile = '\bizGhs\stat\models\StatKd';
  18. //当天各渠道收入 ssh 20220723
  19. public static function eachChannelIncome($mainId, $shop, $contain = 1)
  20. {
  21. $ghsShopId = $shop->id ?? 0;
  22. $lsShopId = $shop->lsShopId ?? 0;
  23. //批发开单 pf 零售开单 ls 批发结账 pfJz 零售尾款 lsWk
  24. $get = Yii::$app->request->get();
  25. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  26. $startTime = $get['startTime'] ?? '';
  27. $endTime = $get['endTime'] ?? '';
  28. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  29. $start = $period['startTime'];
  30. $end = $period['endTime'];
  31. $currentStartDate = date('Y-m-d', strtotime($start));
  32. $currentEndDate = date('Y-m-d', strtotime($end));
  33. $currentStartTime = $currentStartDate . ' 00:00:00';
  34. $currentEndTime = $currentEndDate . ' 23:59:59';
  35. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId, 'isPt' => 0], null, '*', 'id', true);
  36. $kf = [];
  37. if (!empty($staffList)) {
  38. foreach ($staffList as $staff) {
  39. $name = $staff->name ?? '';
  40. $staffId = $staff->id ?? 0;
  41. $kf[$staffId]['name'] = $name;
  42. $kf[$staffId]['key'] = $staffId;
  43. $kf[$staffId]['num'] = 0;
  44. $kf[$staffId]['amount'] = 0;
  45. $kf[$staffId]['itemList']['pf'] = ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0];
  46. $kf[$staffId]['itemList']['ls'] = ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0];
  47. $kf[$staffId]['itemList']['pfJz'] = ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0];
  48. $kf[$staffId]['itemList']['lsWk'] = ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0];
  49. }
  50. }
  51. $incomeList = [
  52. //系统收入
  53. 'system' => [
  54. 'amount' => 0,
  55. 'num' => 0,
  56. 'name' => '系统收款',
  57. 'category' => [
  58. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  59. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  60. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  61. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  62. ],
  63. ],
  64. 'kfWx' => [
  65. 'amount' => 0,
  66. 'num' => 0,
  67. 'name' => '线下微信',
  68. 'class' => $kf,
  69. 'category' => [
  70. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  71. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  72. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  73. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  74. ]
  75. ],
  76. 'debt' => [
  77. 'amount' => 0,
  78. 'num' => 0,
  79. 'name' => '赊账(未结)',
  80. 'category' => [
  81. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  82. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  83. ],
  84. ],
  85. 'debtClear' => [
  86. 'amount' => 0,
  87. 'num' => 0,
  88. 'name' => '赊账(已结)',
  89. 'category' => [
  90. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  91. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  92. ],
  93. ],
  94. 'balancePay' => [
  95. 'amount' => 0,
  96. 'name' => '余额支付',
  97. 'num' => 0,
  98. 'category' => [
  99. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  100. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  101. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  102. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  103. ],
  104. ],
  105. 'cash' => [
  106. 'amount' => 0,
  107. 'name' => '现金',
  108. 'num' => 0,
  109. 'category' => [
  110. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  111. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  112. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  113. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  114. ],
  115. ],
  116. 'aliPay' => [
  117. 'amount' => 0,
  118. 'num' => 0,
  119. 'name' => '线下支付宝',
  120. 'category' => [
  121. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  122. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  123. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  124. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  125. ],
  126. ],
  127. 'bankCard' => [
  128. 'amount' => 0,
  129. 'name' => '银行卡',
  130. 'num' => 0,
  131. 'category' => [
  132. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  133. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  134. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  135. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  136. ],
  137. ],
  138. 'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'],
  139. 'other' => [
  140. 'amount' => 0,
  141. 'num' => 0,
  142. 'name' => '其它',
  143. 'category' => [
  144. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  145. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  146. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  147. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  148. ],
  149. ],
  150. ];
  151. $staffAmountList = [];
  152. //批发开单
  153. $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  154. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  155. $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
  156. if (!empty($ghsOrderList)) {
  157. foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
  158. $payWay = $ghsOrder['payWay'] ?? 0;
  159. $actPrice = $ghsOrder['actPrice'] ?? 0;
  160. $getStaffId = $ghsOrder['getStaffId'] ?? 0;
  161. $debtPrice = $ghsOrder['debtPrice'] ?? 0;
  162. $remainDebtPrice = $ghsOrder['remainDebtPrice'] ?? 0;
  163. $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not');
  164. $status = $ghsOrder['status'] ?? 0;
  165. $book = $ghsOrder['book'] ?? 0;
  166. $staffId = $ghsOrder['shopAdminId'] ?? 0;
  167. $staffName = $ghsOrder['shopAdminName'] ?? '';
  168. if($staffId==0){
  169. $staffName = '系统';
  170. }
  171. if ($status == 0 || $status == 5) {
  172. continue;
  173. }
  174. if ($book == 1 && $status == 2) {
  175. continue;
  176. }
  177. if (isset($staffAmountList[$staffId])) {
  178. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  179. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $actPrice, 2);
  180. } else {
  181. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $actPrice, 'staffName' => $staffName,'staffId'=>$staffId];
  182. }
  183. if ($debtPrice > 0) {
  184. if ($remainDebtPrice > 0) {
  185. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $actPrice, 2);
  186. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  187. $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $actPrice, 2);
  188. $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1);
  189. } else {
  190. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $actPrice, 2);
  191. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  192. $incomeList['debtClear']['category']['pf']['amount'] = bcadd($incomeList['debtClear']['category']['pf']['amount'], $actPrice, 2);
  193. $incomeList['debtClear']['category']['pf']['num'] = bcadd($incomeList['debtClear']['category']['pf']['num'], 1);
  194. }
  195. } else {
  196. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  197. //使用在线支付
  198. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
  199. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  200. $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
  201. $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
  202. } else {
  203. //使用非在线支付
  204. switch ($payWay) {
  205. case dict::getDict('payWay', 'wxPay'):
  206. //员工微信总共收了多少笔多少钱
  207. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  208. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  209. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  210. $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2);
  211. $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1);
  212. //每个客服总共收了多少笔多少钱
  213. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  214. $incomeList['kfWx']['class'][$getStaffId]['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2));
  215. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  216. }
  217. //每个客服收的明细
  218. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf'])) {
  219. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'], $actPrice, 2));
  220. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'], 1);
  221. }
  222. break;
  223. case dict::getDict('payWay', 'alipay'):
  224. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  225. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  226. $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2);
  227. $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1);
  228. break;
  229. case dict::getDict('payWay', 'cash'):
  230. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  231. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  232. $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2);
  233. $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1);
  234. break;
  235. case dict::getDict('payWay', 'balancePay'):
  236. $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $actPrice, 2);
  237. $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1);
  238. $incomeList['balancePay']['category']['pf']['amount'] = bcadd($incomeList['balancePay']['category']['pf']['amount'], $actPrice, 2);
  239. $incomeList['balancePay']['category']['pf']['num'] = bcadd($incomeList['balancePay']['category']['pf']['num'], 1);
  240. break;
  241. case dict::getDict('payWay', 'bankCard'):
  242. $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $actPrice, 2);
  243. $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1);
  244. $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2);
  245. $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1);
  246. break;
  247. case dict::getDict('payWay', 'unknown'):
  248. $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $actPrice, 2);
  249. $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1);
  250. $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2);
  251. $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1);
  252. break;
  253. default:
  254. }
  255. }
  256. }
  257. }
  258. }
  259. //零售开单
  260. $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  261. $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  262. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  263. foreach ($hdOrderList as $hdKey => $hdOrder) {
  264. $payWay = $hdOrder['payWay'] ?? 0;
  265. $mainPay = $hdOrder['mainPay'] ?? 0;
  266. $cash = $hdOrder['cash'] ?? 0;
  267. $actPrice = $hdOrder['mainPay'] ?? 0;
  268. $getStaffId = $hdOrder['getStaffId'] ?? 0;
  269. $debtPrice = $hdOrder['debtPrice'] ?? 0;
  270. $remainDebtPrice = $hdOrder['remainDebtPrice'] ?? 0;
  271. $onlinePay = $hdOrder['onlinePay'] ?? 0;
  272. $fromType = $hdOrder['fromType'] ?? 0;
  273. $staffId = $ghsOrder['shopAdminId'] ?? 0;
  274. $staffName = $ghsOrder['shopAdminName'] ?? '';
  275. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  276. if (isset($staffAmountList[$staffId])) {
  277. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  278. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $mainPay, 2);
  279. } else {
  280. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $mainPay, 'staffName' => $staffName];
  281. }
  282. //现金 和 微信支付宝付款,微信支付宝还存在退款情况
  283. $tkPrice = $hdOrder['tkPrice'] ?? 0;
  284. $mainPay = bcsub($mainPay, $tkPrice, 2);
  285. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2);
  286. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  287. $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2);
  288. $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1);
  289. if ($cash > 0) {
  290. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2);
  291. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  292. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2);
  293. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  294. }
  295. } else {
  296. if (isset($staffAmountList[$staffId])) {
  297. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  298. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $actPrice, 2);
  299. } else {
  300. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $actPrice, 'staffName' => $staffName];
  301. }
  302. if ($fromType == dict::getDict('fromType', 'mt')) {
  303. //美团!!!
  304. $incomeList['mt']['amount'] = bcadd($incomeList['mt']['amount'], $actPrice, 2);
  305. $incomeList['mt']['num'] = bcadd($incomeList['mt']['num'], 1);
  306. } else {
  307. //非美团!!!
  308. if ($debtPrice > 0) {
  309. if ($remainDebtPrice > 0) {
  310. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $remainDebtPrice, 2);
  311. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  312. $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $remainDebtPrice, 2);
  313. $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1);
  314. }
  315. $clearDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  316. if ($clearDebt > 0) {
  317. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $clearDebt, 2);
  318. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  319. $incomeList['debtClear']['category']['ls']['amount'] = bcadd($incomeList['debtClear']['category']['ls']['amount'], $clearDebt, 2);
  320. $incomeList['debtClear']['category']['ls']['num'] = bcadd($incomeList['debtClear']['category']['ls']['num'], 1);
  321. }
  322. $currentAmount = bcsub($mainPay, $debtPrice, 2);
  323. } else {
  324. $currentAmount = $mainPay;
  325. }
  326. if ($currentAmount > 0) {
  327. //使用非在线支付
  328. switch ($payWay) {
  329. case dict::getDict('payWay', 'wxPay'):
  330. //员工微信总共收了多少笔多少钱
  331. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $currentAmount, 2);
  332. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  333. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  334. $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $currentAmount, 2);
  335. $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1);
  336. //客1 客2 客3各收了多少钱
  337. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  338. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $currentAmount, 2);
  339. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  340. }
  341. //每个客服收的明细
  342. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls'])) {
  343. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'], $actPrice, 2));
  344. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'], 1);
  345. }
  346. break;
  347. case dict::getDict('payWay', 'alipay'):
  348. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2);
  349. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  350. $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $currentAmount, 2);
  351. $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1);
  352. break;
  353. case dict::getDict('payWay', 'cash'):
  354. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $currentAmount, 2);
  355. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  356. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $currentAmount, 2);
  357. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  358. break;
  359. case dict::getDict('payWay', 'balancePay'):
  360. $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $currentAmount, 2);
  361. $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1);
  362. $incomeList['balancePay']['category']['ls']['amount'] = bcadd($incomeList['balancePay']['category']['ls']['amount'], $currentAmount, 2);
  363. $incomeList['balancePay']['category']['ls']['num'] = bcadd($incomeList['balancePay']['category']['ls']['num'], 1);
  364. break;
  365. case dict::getDict('payWay', 'bankCard'):
  366. $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $currentAmount, 2);
  367. $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1);
  368. $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $currentAmount, 2);
  369. $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1);
  370. break;
  371. case dict::getDict('payWay', 'unknown'):
  372. $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $currentAmount, 2);
  373. $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1);
  374. $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $currentAmount, 2);
  375. $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1);
  376. break;
  377. default:
  378. }
  379. }
  380. }
  381. }
  382. }
  383. if ($contain == 1) {
  384. //批发结帐收入
  385. $clearWhere = ['ghsShopId' => $ghsShopId, 'status' => 2];
  386. $clearWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  387. $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
  388. if (!empty($clearList)) {
  389. foreach ($clearList as $cKey => $clear) {
  390. $payWay = $clear['payWay'] ?? 0;
  391. $actPrice = $clear['actPrice'] ?? 0;
  392. $onlinePay = $clear['onlinePay'] ?? 0;
  393. $getStaffId = $clear['ghsShopAdminId'] ?? 0;
  394. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  395. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
  396. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  397. $incomeList['system']['category']['pfJz']['amount'] = bcadd($incomeList['system']['category']['pfJz']['amount'], $actPrice, 2);
  398. $incomeList['system']['category']['pfJz']['num'] = bcadd($incomeList['system']['category']['pfJz']['num'], 1);
  399. } else {
  400. //使用非在线支付
  401. switch ($payWay) {
  402. case dict::getDict('payWay', 'wxPay'):
  403. //员工微信总共收了多少笔多少钱
  404. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  405. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  406. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  407. $incomeList['kfWx']['category']['pfJz']['amount'] = bcadd($incomeList['kfWx']['category']['pfJz']['amount'], $actPrice, 2);
  408. $incomeList['kfWx']['category']['pfJz']['num'] = bcadd($incomeList['kfWx']['category']['pfJz']['num'], 1);
  409. //客1 客2 客3各收了多少钱
  410. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  411. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2);
  412. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  413. }
  414. //每个客服收的明细
  415. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz'])) {
  416. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['amount'], $actPrice, 2));
  417. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['num'], 1);
  418. }
  419. break;
  420. case dict::getDict('payWay', 'alipay'):
  421. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  422. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  423. $incomeList['aliPay']['category']['pfJz']['amount'] = bcadd($incomeList['aliPay']['category']['pfJz']['amount'], $actPrice, 2);
  424. $incomeList['aliPay']['category']['pfJz']['num'] = bcadd($incomeList['aliPay']['category']['pfJz']['num'], 1);
  425. break;
  426. case dict::getDict('payWay', 'cash'):
  427. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  428. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  429. $incomeList['cash']['category']['pfJz']['amount'] = bcadd($incomeList['cash']['category']['pfJz']['amount'], $actPrice, 2);
  430. $incomeList['cash']['category']['pfJz']['num'] = bcadd($incomeList['cash']['category']['pfJz']['num'], 1);
  431. break;
  432. case dict::getDict('payWay', 'balancePay'):
  433. $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $actPrice, 2);
  434. $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1);
  435. $incomeList['balancePay']['category']['pfJz']['amount'] = bcadd($incomeList['balancePay']['category']['pfJz']['amount'], $actPrice, 2);
  436. $incomeList['balancePay']['category']['pfJz']['num'] = bcadd($incomeList['balancePay']['category']['pfJz']['num'], 1);
  437. break;
  438. case dict::getDict('payWay', 'bankCard'):
  439. $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  440. $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  441. $incomeList['bankCard']['category']['pfJz']['amount'] = bcadd($incomeList['bankCard']['category']['pfJz']['amount'], $actPrice, 2);
  442. $incomeList['bankCard']['category']['pfJz']['num'] = bcadd($incomeList['bankCard']['category']['pfJz']['num'], 1);
  443. break;
  444. case dict::getDict('payWay', 'unknown'):
  445. $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  446. $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  447. $incomeList['other']['category']['pfJz']['amount'] = bcadd($incomeList['other']['category']['pfJz']['amount'], $actPrice, 2);
  448. $incomeList['other']['category']['pfJz']['num'] = bcadd($incomeList['other']['category']['pfJz']['num'], 1);
  449. break;
  450. default:
  451. }
  452. }
  453. }
  454. }
  455. //零售尾款收入
  456. $settleWhere = ['shopId' => $lsShopId, 'status' => 2];
  457. $settleWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  458. $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
  459. if (!empty($settleList)) {
  460. foreach ($settleList as $sKey => $settle) {
  461. $payWay = $settle['payWay'] ?? 0;
  462. $actPrice = $settle['actPrice'] ?? 0;
  463. $getStaffId = $settle['hdShopAdminId'] ?? 0;
  464. $onlinePay = $settle['onlinePay'] ?? 0;
  465. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  466. } else {
  467. //使用非在线支付
  468. switch ($payWay) {
  469. case dict::getDict('payWay', 'wxPay'):
  470. //员工微信总共收了多少笔多少钱
  471. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  472. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  473. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  474. $incomeList['kfWx']['category']['lsWk']['amount'] = bcadd($incomeList['kfWx']['category']['lsWk']['amount'], $actPrice, 2);
  475. $incomeList['kfWx']['category']['lsWk']['num'] = bcadd($incomeList['kfWx']['category']['lsWk']['num'], 1);
  476. //客1 客2 客3各收了多少钱
  477. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  478. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2);
  479. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  480. }
  481. //每个客服收的明细
  482. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk'])) {
  483. $incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['amount'], $actPrice, 2));
  484. $incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['num'], 1);
  485. }
  486. break;
  487. case dict::getDict('payWay', 'alipay'):
  488. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  489. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  490. $incomeList['aliPay']['category']['lsWk']['amount'] = bcadd($incomeList['aliPay']['category']['lsWk']['amount'], $actPrice, 2);
  491. $incomeList['aliPay']['category']['lsWk']['num'] = bcadd($incomeList['aliPay']['category']['lsWk']['num'], 1);
  492. break;
  493. case dict::getDict('payWay', 'cash'):
  494. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  495. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  496. $incomeList['cash']['category']['lsWk']['amount'] = bcadd($incomeList['cash']['category']['lsWk']['amount'], $actPrice, 2);
  497. $incomeList['cash']['category']['lsWk']['num'] = bcadd($incomeList['cash']['category']['lsWk']['num'], 1);
  498. break;
  499. case dict::getDict('payWay', 'balancePay'):
  500. $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $actPrice, 2);
  501. $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1);
  502. $incomeList['balancePay']['category']['lsWk']['amount'] = bcadd($incomeList['balancePay']['category']['lsWk']['amount'], $actPrice, 2);
  503. $incomeList['balancePay']['category']['lsWk']['num'] = bcadd($incomeList['balancePay']['category']['lsWk']['num'], 1);
  504. break;
  505. case dict::getDict('payWay', 'bankCard'):
  506. $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  507. $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  508. $incomeList['bankCard']['category']['lsWk']['amount'] = bcadd($incomeList['bankCard']['category']['lsWk']['amount'], $actPrice, 2);
  509. $incomeList['bankCard']['category']['lsWk']['num'] = bcadd($incomeList['bankCard']['category']['lsWk']['num'], 1);
  510. break;
  511. case dict::getDict('payWay', 'unknown'):
  512. $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  513. $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  514. $incomeList['other']['category']['lsWk']['amount'] = bcadd($incomeList['other']['category']['lsWk']['amount'], $actPrice, 2);
  515. $incomeList['other']['category']['lsWk']['num'] = bcadd($incomeList['other']['category']['lsWk']['num'], 1);
  516. break;
  517. default:
  518. }
  519. }
  520. }
  521. }
  522. }
  523. return ['incomeList' => $incomeList, 'staffAmountList' => $staffAmountList];
  524. }
  525. }