StatKdClass.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. 'cash' => [
  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. 'aliPay' => [
  106. 'amount' => 0,
  107. 'num' => 0,
  108. 'name' => '线下支付宝',
  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. 'bankCard' => [
  117. 'amount' => 0,
  118. 'name' => '银行卡',
  119. 'num' => 0,
  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. 'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'],
  128. 'other' => [
  129. 'amount' => 0,
  130. 'num' => 0,
  131. 'name' => '其它',
  132. 'category' => [
  133. 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0],
  134. 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0],
  135. 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0],
  136. 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0],
  137. ],
  138. ],
  139. ];
  140. $staffAmountList = [];
  141. //批发开单
  142. $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
  143. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  144. $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
  145. if (!empty($ghsOrderList)) {
  146. foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
  147. $payWay = $ghsOrder['payWay'] ?? 0;
  148. $actPrice = $ghsOrder['actPrice'] ?? 0;
  149. $getStaffId = $ghsOrder['getStaffId'] ?? 0;
  150. $debtPrice = $ghsOrder['debtPrice'] ?? 0;
  151. $remainDebtPrice = $ghsOrder['remainDebtPrice'] ?? 0;
  152. $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not');
  153. $status = $ghsOrder['status'] ?? 0;
  154. $book = $ghsOrder['book'] ?? 0;
  155. $staffId = $ghsOrder['shopAdminId'] ?? 0;
  156. $staffName = $ghsOrder['shopAdminName'] ?? '';
  157. if ($status == 0 || $status == 5) {
  158. continue;
  159. }
  160. if ($book == 1 && $status == 2) {
  161. continue;
  162. }
  163. if (isset($staffAmountList[$staffId])) {
  164. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  165. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $actPrice, 2);
  166. } else {
  167. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $actPrice, 'staffName' => $staffName];
  168. }
  169. if ($debtPrice > 0) {
  170. if ($remainDebtPrice > 0) {
  171. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $actPrice, 2);
  172. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  173. $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $actPrice, 2);
  174. $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1);
  175. } else {
  176. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $actPrice, 2);
  177. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  178. $incomeList['debtClear']['category']['pf']['amount'] = bcadd($incomeList['debtClear']['category']['pf']['amount'], $actPrice, 2);
  179. $incomeList['debtClear']['category']['pf']['num'] = bcadd($incomeList['debtClear']['category']['pf']['num'], 1);
  180. }
  181. } else {
  182. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  183. //使用在线支付
  184. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
  185. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  186. $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2);
  187. $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1);
  188. } else {
  189. //使用非在线支付
  190. switch ($payWay) {
  191. case dict::getDict('payWay', 'wxPay'):
  192. //员工微信总共收了多少笔多少钱
  193. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  194. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  195. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  196. $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2);
  197. $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1);
  198. //每个客服总共收了多少笔多少钱
  199. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  200. $incomeList['kfWx']['class'][$getStaffId]['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2));
  201. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  202. }
  203. //每个客服收的明细
  204. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf'])) {
  205. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'], $actPrice, 2));
  206. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'], 1);
  207. }
  208. break;
  209. case dict::getDict('payWay', 'alipay'):
  210. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  211. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  212. $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2);
  213. $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1);
  214. break;
  215. case dict::getDict('payWay', 'cash'):
  216. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  217. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  218. $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2);
  219. $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1);
  220. break;
  221. case dict::getDict('payWay', 'bankCard'):
  222. $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $actPrice, 2);
  223. $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1);
  224. $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2);
  225. $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1);
  226. break;
  227. case dict::getDict('payWay', 'unknown'):
  228. $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $actPrice, 2);
  229. $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1);
  230. $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2);
  231. $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1);
  232. break;
  233. default:
  234. }
  235. }
  236. }
  237. }
  238. }
  239. //零售开单
  240. $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
  241. $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  242. $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
  243. foreach ($hdOrderList as $hdKey => $hdOrder) {
  244. $payWay = $hdOrder['payWay'] ?? 0;
  245. $mainPay = $hdOrder['mainPay'] ?? 0;
  246. $cash = $hdOrder['cash'] ?? 0;
  247. $actPrice = $hdOrder['mainPay'] ?? 0;
  248. $getStaffId = $hdOrder['getStaffId'] ?? 0;
  249. $debtPrice = $hdOrder['debtPrice'] ?? 0;
  250. $remainDebtPrice = $hdOrder['remainDebtPrice'] ?? 0;
  251. $onlinePay = $hdOrder['onlinePay'] ?? 0;
  252. $fromType = $hdOrder['fromType'] ?? 0;
  253. $staffId = $ghsOrder['shopAdminId'] ?? 0;
  254. $staffName = $ghsOrder['shopAdminName'] ?? '';
  255. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  256. if (isset($staffAmountList[$staffId])) {
  257. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  258. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $mainPay, 2);
  259. } else {
  260. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $mainPay, 'staffName' => $staffName];
  261. }
  262. //现金 和 微信支付宝付款,微信支付宝还存在退款情况
  263. $tkPrice = $hdOrder['tkPrice'] ?? 0;
  264. $mainPay = bcsub($mainPay, $tkPrice, 2);
  265. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2);
  266. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  267. $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2);
  268. $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1);
  269. if ($cash > 0) {
  270. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2);
  271. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  272. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2);
  273. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  274. }
  275. } else {
  276. if (isset($staffAmountList[$staffId])) {
  277. $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1);
  278. $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $actPrice, 2);
  279. } else {
  280. $staffAmountList[$staffId] = ['num' => 1, 'amount' => $actPrice, 'staffName' => $staffName];
  281. }
  282. if ($fromType == dict::getDict('fromType', 'mt')) {
  283. //美团!!!
  284. $incomeList['mt']['amount'] = bcadd($incomeList['mt']['amount'], $actPrice, 2);
  285. $incomeList['mt']['num'] = bcadd($incomeList['mt']['num'], 1);
  286. } else {
  287. //非美团!!!
  288. if ($debtPrice > 0) {
  289. if ($remainDebtPrice > 0) {
  290. $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $remainDebtPrice, 2);
  291. $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1);
  292. $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $remainDebtPrice, 2);
  293. $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1);
  294. }
  295. $clearDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  296. if ($clearDebt > 0) {
  297. $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $clearDebt, 2);
  298. $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1);
  299. $incomeList['debtClear']['category']['ls']['amount'] = bcadd($incomeList['debtClear']['category']['ls']['amount'], $clearDebt, 2);
  300. $incomeList['debtClear']['category']['ls']['num'] = bcadd($incomeList['debtClear']['category']['ls']['num'], 1);
  301. }
  302. $currentAmount = bcsub($mainPay, $debtPrice, 2);
  303. } else {
  304. $currentAmount = $mainPay;
  305. }
  306. if ($currentAmount > 0) {
  307. //使用非在线支付
  308. switch ($payWay) {
  309. case dict::getDict('payWay', 'wxPay'):
  310. //员工微信总共收了多少笔多少钱
  311. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $currentAmount, 2);
  312. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  313. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  314. $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $currentAmount, 2);
  315. $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1);
  316. //客1 客2 客3各收了多少钱
  317. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  318. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $currentAmount, 2);
  319. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  320. }
  321. //每个客服收的明细
  322. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls'])) {
  323. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'], $actPrice, 2));
  324. $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'], 1);
  325. }
  326. break;
  327. case dict::getDict('payWay', 'alipay'):
  328. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2);
  329. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  330. $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $currentAmount, 2);
  331. $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1);
  332. break;
  333. case dict::getDict('payWay', 'cash'):
  334. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $currentAmount, 2);
  335. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  336. $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $currentAmount, 2);
  337. $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1);
  338. break;
  339. case dict::getDict('payWay', 'bankCard'):
  340. $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $currentAmount, 2);
  341. $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1);
  342. $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $currentAmount, 2);
  343. $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1);
  344. break;
  345. case dict::getDict('payWay', 'unknown'):
  346. $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $currentAmount, 2);
  347. $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1);
  348. $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $currentAmount, 2);
  349. $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1);
  350. break;
  351. default:
  352. }
  353. }
  354. }
  355. }
  356. }
  357. if ($contain == 1) {
  358. //批发结帐收入
  359. $clearWhere = ['ghsShopId' => $ghsShopId, 'status' => 2];
  360. $clearWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  361. $clearList = ClearClass::getAllByCondition($clearWhere, null, '*');
  362. if (!empty($clearList)) {
  363. foreach ($clearList as $cKey => $clear) {
  364. $payWay = $clear['payWay'] ?? 0;
  365. $actPrice = $clear['actPrice'] ?? 0;
  366. $onlinePay = $clear['onlinePay'] ?? 0;
  367. $getStaffId = $clear['ghsShopAdminId'] ?? 0;
  368. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  369. $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2);
  370. $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1);
  371. $incomeList['system']['category']['pfJz']['amount'] = bcadd($incomeList['system']['category']['pfJz']['amount'], $actPrice, 2);
  372. $incomeList['system']['category']['pfJz']['num'] = bcadd($incomeList['system']['category']['pfJz']['num'], 1);
  373. } else {
  374. //使用非在线支付
  375. switch ($payWay) {
  376. case dict::getDict('payWay', 'wxPay'):
  377. //员工微信总共收了多少笔多少钱
  378. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  379. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  380. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  381. $incomeList['kfWx']['category']['pfJz']['amount'] = bcadd($incomeList['kfWx']['category']['pfJz']['amount'], $actPrice, 2);
  382. $incomeList['kfWx']['category']['pfJz']['num'] = bcadd($incomeList['kfWx']['category']['pfJz']['num'], 1);
  383. //客1 客2 客3各收了多少钱
  384. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  385. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2);
  386. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  387. }
  388. //每个客服收的明细
  389. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz'])) {
  390. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['amount'], $actPrice, 2));
  391. $incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pfJz']['num'], 1);
  392. }
  393. break;
  394. case dict::getDict('payWay', 'alipay'):
  395. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  396. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  397. $incomeList['aliPay']['category']['pfJz']['amount'] = bcadd($incomeList['aliPay']['category']['pfJz']['amount'], $actPrice, 2);
  398. $incomeList['aliPay']['category']['pfJz']['num'] = bcadd($incomeList['aliPay']['category']['pfJz']['num'], 1);
  399. break;
  400. case dict::getDict('payWay', 'cash'):
  401. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  402. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  403. $incomeList['cash']['category']['pfJz']['amount'] = bcadd($incomeList['cash']['category']['pfJz']['amount'], $actPrice, 2);
  404. $incomeList['cash']['category']['pfJz']['num'] = bcadd($incomeList['cash']['category']['pfJz']['num'], 1);
  405. break;
  406. case dict::getDict('payWay', 'bankCard'):
  407. $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  408. $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  409. $incomeList['bankCard']['category']['pfJz']['amount'] = bcadd($incomeList['bankCard']['category']['pfJz']['amount'], $actPrice, 2);
  410. $incomeList['bankCard']['category']['pfJz']['num'] = bcadd($incomeList['bankCard']['category']['pfJz']['num'], 1);
  411. break;
  412. case dict::getDict('payWay', 'unknown'):
  413. $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  414. $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  415. $incomeList['other']['category']['pfJz']['amount'] = bcadd($incomeList['other']['category']['pfJz']['amount'], $actPrice, 2);
  416. $incomeList['other']['category']['pfJz']['num'] = bcadd($incomeList['other']['category']['pfJz']['num'], 1);
  417. break;
  418. default:
  419. }
  420. }
  421. }
  422. }
  423. //零售尾款收入
  424. $settleWhere = ['shopId' => $lsShopId, 'status' => 2];
  425. $settleWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  426. $settleList = SettleClass::getAllByCondition($settleWhere, null, '*');
  427. if (!empty($settleList)) {
  428. foreach ($settleList as $sKey => $settle) {
  429. $payWay = $settle['payWay'] ?? 0;
  430. $actPrice = $settle['actPrice'] ?? 0;
  431. $getStaffId = $settle['hdShopAdminId'] ?? 0;
  432. $onlinePay = $settle['onlinePay'] ?? 0;
  433. if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
  434. } else {
  435. //使用非在线支付
  436. switch ($payWay) {
  437. case dict::getDict('payWay', 'wxPay'):
  438. //员工微信总共收了多少笔多少钱
  439. $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2);
  440. $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1);
  441. //批发开单、零售开单、批发结账、零售尾款各收了多少现金
  442. $incomeList['kfWx']['category']['lsWk']['amount'] = bcadd($incomeList['kfWx']['category']['lsWk']['amount'], $actPrice, 2);
  443. $incomeList['kfWx']['category']['lsWk']['num'] = bcadd($incomeList['kfWx']['category']['lsWk']['num'], 1);
  444. //客1 客2 客3各收了多少钱
  445. if (isset($incomeList['kfWx']['class'][$getStaffId])) {
  446. $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2);
  447. $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1);
  448. }
  449. //每个客服收的明细
  450. if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk'])) {
  451. $incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['amount'], $actPrice, 2));
  452. $incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['lsWk']['num'], 1);
  453. }
  454. break;
  455. case dict::getDict('payWay', 'alipay'):
  456. $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  457. $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  458. $incomeList['aliPay']['category']['lsWk']['amount'] = bcadd($incomeList['aliPay']['category']['lsWk']['amount'], $actPrice, 2);
  459. $incomeList['aliPay']['category']['lsWk']['num'] = bcadd($incomeList['aliPay']['category']['lsWk']['num'], 1);
  460. break;
  461. case dict::getDict('payWay', 'cash'):
  462. $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2);
  463. $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1);
  464. $incomeList['cash']['category']['lsWk']['amount'] = bcadd($incomeList['cash']['category']['lsWk']['amount'], $actPrice, 2);
  465. $incomeList['cash']['category']['lsWk']['num'] = bcadd($incomeList['cash']['category']['lsWk']['num'], 1);
  466. break;
  467. case dict::getDict('payWay', 'bankCard'):
  468. $incomeList['bankCard']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  469. $incomeList['bankCard']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  470. $incomeList['bankCard']['category']['lsWk']['amount'] = bcadd($incomeList['bankCard']['category']['lsWk']['amount'], $actPrice, 2);
  471. $incomeList['bankCard']['category']['lsWk']['num'] = bcadd($incomeList['bankCard']['category']['lsWk']['num'], 1);
  472. break;
  473. case dict::getDict('payWay', 'unknown'):
  474. $incomeList['other']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2);
  475. $incomeList['other']['num'] = bcadd($incomeList['aliPay']['num'], 1);
  476. $incomeList['other']['category']['lsWk']['amount'] = bcadd($incomeList['other']['category']['lsWk']['amount'], $actPrice, 2);
  477. $incomeList['other']['category']['lsWk']['num'] = bcadd($incomeList['other']['category']['lsWk']['num'], 1);
  478. break;
  479. default:
  480. }
  481. }
  482. }
  483. }
  484. }
  485. return ['incomeList' => $incomeList, 'staffAmountList' => $staffAmountList];
  486. }
  487. }