|
|
@@ -1569,4 +1569,576 @@ where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMo
|
|
1569
|
1569
|
}
|
|
1570
|
1570
|
}
|
|
1571
|
1571
|
}
|
|
|
1572
|
+
|
|
|
1573
|
+ //定时任务写日账单,月账单
|
|
|
1574
|
+ public function cron($day,$mer_id=496)
|
|
|
1575
|
+ {
|
|
|
1576
|
+
|
|
|
1577
|
+ Db::name('enterprise_day_bill')->where('mer_id', $mer_id)->where('day', $day)->delete();
|
|
|
1578
|
+
|
|
|
1579
|
+ $day_flow_query = Db::name('enterprise_platform_income_detail')
|
|
|
1580
|
+ ->where('mer_id', $mer_id)
|
|
|
1581
|
+ ->when($mer_id, function ($query) use ($mer_id) {
|
|
|
1582
|
+ $query->where('deal_type', -1);//没有流水
|
|
|
1583
|
+ }, function ($query) use ($mer_id) {
|
|
|
1584
|
+ $query->whereIn('deal_type', [3]);
|
|
|
1585
|
+ })
|
|
|
1586
|
+
|
|
|
1587
|
+ ->where('deal_type', 4)
|
|
|
1588
|
+ ->where('pm', 1);
|
|
|
1589
|
+ $day_flow_query_month = clone $day_flow_query;
|
|
|
1590
|
+ // 日订单流水
|
|
|
1591
|
+ $day_flow = $day_flow_query->where("DATE(deal_time) = '" . $day . "'")->sum('money');
|
|
|
1592
|
+
|
|
|
1593
|
+ $accounting_query = Db::name('enterprise_platform_income_detail')
|
|
|
1594
|
+ ->where('mer_id', $mer_id)
|
|
|
1595
|
+ ->when($mer_id, function ($query) use ($mer_id) {
|
|
|
1596
|
+ $query->where('deal_type', 1);
|
|
|
1597
|
+ }, function ($query) use ($mer_id) {
|
|
|
1598
|
+ $query->whereIn('deal_type', [6,7]);
|
|
|
1599
|
+ })
|
|
|
1600
|
+ ->where('pm', 1);
|
|
|
1601
|
+ $accounting_query_month = clone $accounting_query;
|
|
|
1602
|
+ // 入账金额
|
|
|
1603
|
+ $day_accounting = $accounting_query->where("DATE(deal_time) = '" . $day . "'")->sum('money');
|
|
|
1604
|
+
|
|
|
1605
|
+ $expenditure_query = Db::name('enterprise_platform_income_detail')
|
|
|
1606
|
+ ->when($mer_id, function ($query) use ($mer_id) {
|
|
|
1607
|
+ $query->where('mer_id', $mer_id)
|
|
|
1608
|
+ ->where('deal_type', -1);//没有流水
|
|
|
1609
|
+ }, function ($query) use ($mer_id) {
|
|
|
1610
|
+ $query->whereIn('deal_type', [4,5]);
|
|
|
1611
|
+ });
|
|
|
1612
|
+ $expenditure_query_month = clone $expenditure_query;
|
|
|
1613
|
+ // 日支出总额
|
|
|
1614
|
+ $day_expenditure = 0;
|
|
|
1615
|
+ if($mer_id==0){
|
|
|
1616
|
+ $day_expenditure = $expenditure_query->where("DATE(deal_time) = '" . $day . "'")
|
|
|
1617
|
+ ->whereIn('deal_type', [4,5])
|
|
|
1618
|
+ ->where('mer_id',0)
|
|
|
1619
|
+ ->sum('money');
|
|
|
1620
|
+ }
|
|
|
1621
|
+
|
|
|
1622
|
+ $insert = [];
|
|
|
1623
|
+ $insert['mer_id'] = $mer_id;
|
|
|
1624
|
+ $insert['day'] = $day;
|
|
|
1625
|
+ $insert['flow'] = $day_flow;
|
|
|
1626
|
+ $insert['expenditure'] = $day_expenditure;
|
|
|
1627
|
+ $insert['accounting'] = $day_accounting;
|
|
|
1628
|
+
|
|
|
1629
|
+ $previousDate = date('Y-m-d', strtotime($day . ' -1 day'));
|
|
|
1630
|
+ $balance_zuotian = Db::name('enterprise_day_bill')->where('day', $previousDate)->where('mer_id', $mer_id)->value('balance');
|
|
|
1631
|
+ $balance = $balance_zuotian ? $balance_zuotian : 0;
|
|
|
1632
|
+
|
|
|
1633
|
+ if($mer_id){
|
|
|
1634
|
+ $tixian = Db::name('user_extract')->where("DATE(status_time) = '" . $day . "'")->where('mer_id', $mer_id)->where('status', 1)->sum('extract_price');
|
|
|
1635
|
+ $service_money = Db::name('user_extract')->where("DATE(status_time) = '" . $day . "'")->where('mer_id', $mer_id)->where('status', 1)->sum('service_money');
|
|
|
1636
|
+ $tixian -= $service_money;
|
|
|
1637
|
+ $ylj = Db::name('user_bill')->where('mer_id', $mer_id)->where('status', 1)->where("DATE(take_time) = '" . $day . "'")->sum('number');
|
|
|
1638
|
+ $insert['balance'] = $day_accounting - $tixian + $balance - $ylj;
|
|
|
1639
|
+ }else{
|
|
|
1640
|
+ $tixian = Db::name('enterprise_platform_income_detail')
|
|
|
1641
|
+ ->where("deal_time >'$day'")
|
|
|
1642
|
+ ->where("deal_time <'$day 23:59:59'")
|
|
|
1643
|
+ ->where('deal_type', 5)
|
|
|
1644
|
+ ->sum('money');
|
|
|
1645
|
+ $insert['balance'] = $day_accounting - $tixian + $balance ;
|
|
|
1646
|
+ }
|
|
|
1647
|
+
|
|
|
1648
|
+
|
|
|
1649
|
+
|
|
|
1650
|
+ Db::name('enterprise_day_bill')->insertGetId($insert);
|
|
|
1651
|
+
|
|
|
1652
|
+
|
|
|
1653
|
+ $month_list[] = date('Y-m', strtotime('-4 month'));
|
|
|
1654
|
+ $month_list[] = date('Y-m', strtotime('-3 month'));
|
|
|
1655
|
+ $month_list[] = date('Y-m', strtotime('-2 month'));
|
|
|
1656
|
+ $month_list[] = date('Y-m', strtotime('-1 month'));
|
|
|
1657
|
+ $month_list[] = date('Y-m');
|
|
|
1658
|
+ foreach ($month_list as $month) {
|
|
|
1659
|
+ Db::name('enterprise_month_bill')->where('mer_id',$mer_id)->where('month', $month)->delete();
|
|
|
1660
|
+
|
|
|
1661
|
+ $flow_query_month_clone = clone $day_flow_query_month;
|
|
|
1662
|
+ $accounting_query_month_clone = clone $accounting_query_month;
|
|
|
1663
|
+ $expenditure_query_month_clone = clone $expenditure_query_month;
|
|
|
1664
|
+
|
|
|
1665
|
+ $startDate = date('Y-m-01 00:00:00', strtotime($month));
|
|
|
1666
|
+ $endDate = date("Y-m-d 00:00:00", strtotime('+1 month', strtotime($month)));
|
|
|
1667
|
+
|
|
|
1668
|
+ // 月订单流水
|
|
|
1669
|
+ $money_flow = $flow_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
|
|
|
1670
|
+
|
|
|
1671
|
+ // 月入账总额
|
|
|
1672
|
+ $money_accounting = $accounting_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
|
|
|
1673
|
+
|
|
|
1674
|
+ // 月支出总额
|
|
|
1675
|
+ $money_expenditure = $expenditure_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
|
|
|
1676
|
+
|
|
|
1677
|
+ $insert2 = [];
|
|
|
1678
|
+ $insert2['month'] = $month;
|
|
|
1679
|
+ $insert2['mer_id'] = $mer_id;
|
|
|
1680
|
+ $insert2['flow'] = $money_flow;
|
|
|
1681
|
+ $insert2['expenditure'] = $money_expenditure;
|
|
|
1682
|
+ $insert2['accounting'] = $money_accounting;
|
|
|
1683
|
+ Db::name('enterprise_month_bill')->insertGetId($insert2);
|
|
|
1684
|
+ }
|
|
|
1685
|
+
|
|
|
1686
|
+ }
|
|
|
1687
|
+
|
|
|
1688
|
+ /**
|
|
|
1689
|
+ * 生成平台收支明细,从而生成 日账单 月账单
|
|
|
1690
|
+ * 平台收入:线上订单表、线下订单表、话费表
|
|
|
1691
|
+ * 平台支出:用户提现、商户分账
|
|
|
1692
|
+ * @return mixed
|
|
|
1693
|
+ * @throws DataNotFoundException
|
|
|
1694
|
+ * @throws DbException
|
|
|
1695
|
+ * @throws ModelNotFoundException
|
|
|
1696
|
+ */
|
|
|
1697
|
+ public function platform_income_detail_get_new()
|
|
|
1698
|
+ {
|
|
|
1699
|
+
|
|
|
1700
|
+ // 1、获取所有 商户 商户名称非空, 状态为正常、商户状态为开启
|
|
|
1701
|
+ $merchant_list = Db::name('merchant')
|
|
|
1702
|
+ ->where('status', 1)
|
|
|
1703
|
+ ->where('mer_state', 1)
|
|
|
1704
|
+ ->where("mer_name != ''")
|
|
|
1705
|
+ ->column('mer_id');
|
|
|
1706
|
+
|
|
|
1707
|
+ // 2、获取 已有的 平台收支明细,并创建 唯一的 key
|
|
|
1708
|
+ $unique_list = [];
|
|
|
1709
|
+ // $enterprise_platform_income_detail_list = Db::name('enterprise_platform_income_detail')
|
|
|
1710
|
+ // ->select()
|
|
|
1711
|
+ // ->toArray();
|
|
|
1712
|
+ // foreach ($enterprise_platform_income_detail_list as $item) {
|
|
|
1713
|
+ // // deal_type : '交易类型 1自营订单入账(商户) 2佣金提现到账(商户) 3订单支付 4商户佣金提现 5用户佣金提现 6订单入账 7 创客自营订单让利 '
|
|
|
1714
|
+ // // user_extra_id : 提现表id
|
|
|
1715
|
+ // $unique_list[] = $item['deal_type'] . $item['uid'] . $item['order_sn'] . $item['order_id'] . $item['user_extra_id'] . $item['mer_id'];
|
|
|
1716
|
+ // }
|
|
|
1717
|
+
|
|
|
1718
|
+ // 3、获取订单信息
|
|
|
1719
|
+ // 查询 该商户 所有的 平台订单(已支付、平台订单、已结算)
|
|
|
1720
|
+ $store_order_list = Db::name('store_order')
|
|
|
1721
|
+ ->whereIn('mer_id', $merchant_list)
|
|
|
1722
|
+ ->where('paid', 1)
|
|
|
1723
|
+ ->where('douhuomall', 0)
|
|
|
1724
|
+ ->where('is_settlement', 1)
|
|
|
1725
|
+ ->order('order_id', 'desc')
|
|
|
1726
|
+ ->select()
|
|
|
1727
|
+ ->toArray();
|
|
|
1728
|
+ $store_order_map = array_reduce($store_order_list, function($result, $order) {
|
|
|
1729
|
+ // 根据 mer_id 进行分组
|
|
|
1730
|
+ $result[$order['mer_id']][] = $order;
|
|
|
1731
|
+ return $result;
|
|
|
1732
|
+ }, []);
|
|
|
1733
|
+ // 京豆
|
|
|
1734
|
+ $jingdou_list_by_online = Db::name("user_sign_jingdou")
|
|
|
1735
|
+ ->where('order_type', '=','0')
|
|
|
1736
|
+ ->where('status', '=',1)
|
|
|
1737
|
+ ->whereIn('order_id', array_column($store_order_list,'order_id'))
|
|
|
1738
|
+ ->select()
|
|
|
1739
|
+ ->toArray();
|
|
|
1740
|
+ $jingdou_map_by_online = array_reduce($jingdou_list_by_online, function($result, $jingdou_by_online) {
|
|
|
1741
|
+ // 根据 mer_id 进行分组
|
|
|
1742
|
+ $result[$jingdou_by_online['order_id']][] = $jingdou_by_online;
|
|
|
1743
|
+ return $result;
|
|
|
1744
|
+ }, []);
|
|
|
1745
|
+
|
|
|
1746
|
+ // 线下扫码
|
|
|
1747
|
+ $order_merchant_list = Db::name('order_merchant')
|
|
|
1748
|
+ ->whereIn('mer_id', $merchant_list)
|
|
|
1749
|
+ ->where('status', 1) // '0待支付,1已支付,2申请退款,3退款完成 5 已失效',
|
|
|
1750
|
+ // ->where('arrive', 1) // 是否到账,系统应该是没对该字段进行维护 全是0
|
|
|
1751
|
+ ->where('paid', 1)
|
|
|
1752
|
+ ->where('binds', 0)
|
|
|
1753
|
+ ->whereNotNull('pay_time')
|
|
|
1754
|
+ ->order('id', 'desc')
|
|
|
1755
|
+ ->select()
|
|
|
1756
|
+ ->toArray();
|
|
|
1757
|
+ $order_merchant_map = array_reduce($order_merchant_list, function($result, $order) {
|
|
|
1758
|
+ // 根据 mer_id 进行分组
|
|
|
1759
|
+ $result[$order['mer_id']][] = $order;
|
|
|
1760
|
+ return $result;
|
|
|
1761
|
+ }, []);
|
|
|
1762
|
+ // 京豆
|
|
|
1763
|
+ $jingdou_list_by_offline = Db::name("user_sign_jingdou")
|
|
|
1764
|
+ ->where('order_type', '=','10')
|
|
|
1765
|
+ ->where('status', '=',1)
|
|
|
1766
|
+ ->whereIn('order_id', array_column($order_merchant_list,'id'))
|
|
|
1767
|
+ ->select()
|
|
|
1768
|
+ ->toArray();
|
|
|
1769
|
+ $jingdou_map_by_offline = array_reduce($jingdou_list_by_offline, function($result, $jingdou_by_offline) {
|
|
|
1770
|
+ // 根据 mer_id 进行分组
|
|
|
1771
|
+ $result[$jingdou_by_offline['order_id']][] = $jingdou_by_offline;
|
|
|
1772
|
+ return $result;
|
|
|
1773
|
+ }, []);
|
|
|
1774
|
+
|
|
|
1775
|
+ // 话费
|
|
|
1776
|
+ $order_huafei_list = Db::name('order_huafei')
|
|
|
1777
|
+ ->where('status', 2) // '订单状态 0 待支付 1 已付 充值中 2充值成功 3充值失败 需要退款 4退款成功 5已超时 6待充值 7 已匹配 8已存单 9 已取消 10返销 11部分到账 12取消中'
|
|
|
1778
|
+ // ->where('arrive', 1) // 是否到账,系统应该是没对该字段进行维护 全是0
|
|
|
1779
|
+ // ->whereNotNull('finish_time')
|
|
|
1780
|
+ ->order('order_huafei_id', 'desc')
|
|
|
1781
|
+ ->select()
|
|
|
1782
|
+ ->toArray();
|
|
|
1783
|
+
|
|
|
1784
|
+ // 清空数据表
|
|
|
1785
|
+ Db::execute("TRUNCATE TABLE `rrx_enterprise_platform_income_detail`");
|
|
|
1786
|
+
|
|
|
1787
|
+ // 4、循环所有商户ID
|
|
|
1788
|
+ /** @var OrderMerchantRepository $OrderMerchantRepository */
|
|
|
1789
|
+ $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
|
|
|
1790
|
+ foreach ($merchant_list as $mer_id) {
|
|
|
1791
|
+ // 线上订单
|
|
|
1792
|
+ if (!empty($store_order_map[$mer_id])) {
|
|
|
1793
|
+ $online_data_list = [];
|
|
|
1794
|
+ foreach ($store_order_map[$mer_id] as $store_order) {
|
|
|
1795
|
+ // 判断该笔订单是否已 存在 平台收支明细表 的记录中
|
|
|
1796
|
+ if (!in_array('1' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) {
|
|
|
1797
|
+ // 经过和领导确认,入账 金额为 订单金额 - 让利金额 - 手续费
|
|
|
1798
|
+ $money = 0.00;
|
|
|
1799
|
+ $vr = 0.00;
|
|
|
1800
|
+ $jd = 0.00;
|
|
|
1801
|
+ $fg = 0.00;
|
|
|
1802
|
+ $fenrun = $store_order['con_pri'] ?: 0.00;
|
|
|
1803
|
+ if (!empty($store_order['fzone_pay_type'])) {
|
|
|
1804
|
+ $cost = bcsub($store_order['total_price'], $fenrun, 2);
|
|
|
1805
|
+ if (in_array($store_order['fzone_pay_type'], ['a2', 'a3', 'b2', 'b4', 'b6'])) {
|
|
|
1806
|
+ $money = $cost;
|
|
|
1807
|
+ } else if (in_array($store_order['fzone_pay_type'], ['a1', 'b1', 'b5'])) {
|
|
|
1808
|
+ $vr = $cost;
|
|
|
1809
|
+ } else if (in_array($store_order['fzone_pay_type'], ['c1'])) {
|
|
|
1810
|
+ $fg = $cost;
|
|
|
1811
|
+ }
|
|
|
1812
|
+ }
|
|
|
1813
|
+ if (!empty($jingdou_map_by_online[$store_order['order_id']])) {
|
|
|
1814
|
+ $jd = array_sum(array_column($jingdou_map_by_online[$store_order['order_id']], 'number'));
|
|
|
1815
|
+ }
|
|
|
1816
|
+
|
|
|
1817
|
+
|
|
|
1818
|
+ $online_data_list[] = [
|
|
|
1819
|
+ 'mer_id' => $mer_id,
|
|
|
1820
|
+ 'uid' => $store_order['uid'],
|
|
|
1821
|
+ 'title' => '订单入账',
|
|
|
1822
|
+ 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
|
|
|
1823
|
+ 'deal_time' => $store_order['pay_time'] ?: date('Y-m-d H:i:s'),
|
|
|
1824
|
+ 'money' => $money,
|
|
|
1825
|
+ 'deal_type' => 1,
|
|
|
1826
|
+ 'order_type' => 0,
|
|
|
1827
|
+ 'order_id' => $store_order['order_id'],
|
|
|
1828
|
+ 'order_sn' => $store_order['order_sn'],
|
|
|
1829
|
+ 'user_extra_id' => '',
|
|
|
1830
|
+ 'pm' => 1,
|
|
|
1831
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
1832
|
+ 'vr' => $vr,
|
|
|
1833
|
+ 'jingdou' => $jd,
|
|
|
1834
|
+ 'fg' => $fg,
|
|
|
1835
|
+ 'fenrun' => $fenrun, // 让利
|
|
|
1836
|
+ ];
|
|
|
1837
|
+ }
|
|
|
1838
|
+ }
|
|
|
1839
|
+ if (!empty($online_data_list)) {
|
|
|
1840
|
+ Db::name('enterprise_platform_income_detail')
|
|
|
1841
|
+ ->insertAll($online_data_list);
|
|
|
1842
|
+ }
|
|
|
1843
|
+ }
|
|
|
1844
|
+
|
|
|
1845
|
+ // 线下订单 0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上 9话费 10 线下
|
|
|
1846
|
+ if (!empty($order_merchant_map[$mer_id])) {
|
|
|
1847
|
+ $offline_data_list = [];
|
|
|
1848
|
+ foreach ($order_merchant_map[$mer_id] as $order_merchant) {
|
|
|
1849
|
+ // 判断该笔订单是否已 存在 平台收支明细表 的记录中
|
|
|
1850
|
+ if (!in_array('1' . $order_merchant['uid'] . $order_merchant['out_trade_no'] . $order_merchant['id'] . '0' . $mer_id, $unique_list)) {
|
|
|
1851
|
+ // 经过和领导确认,入账 金额为 订单金额 - 让利金额 - 手续费
|
|
|
1852
|
+
|
|
|
1853
|
+ $money = $order_merchant['mer_money'] ?: 0.00;
|
|
|
1854
|
+ $vr = 0.00;
|
|
|
1855
|
+ $jd = 0.00;
|
|
|
1856
|
+ $fg = 0.00;
|
|
|
1857
|
+ $fenrun = $order_merchant['mer_fanyong'] ?: 0.00;
|
|
|
1858
|
+ if (!empty($jingdou_map_by_offline[$order_merchant['id']])) {
|
|
|
1859
|
+ $jd = array_sum(array_column($jingdou_map_by_offline[$order_merchant['id']], 'number'));
|
|
|
1860
|
+ }
|
|
|
1861
|
+
|
|
|
1862
|
+ $offline_data_list[] = [
|
|
|
1863
|
+ 'mer_id' => $mer_id,
|
|
|
1864
|
+ 'uid' => $order_merchant['uid'],
|
|
|
1865
|
+ 'title' => '订单入账',
|
|
|
1866
|
+ 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
|
|
|
1867
|
+ 'deal_time' => $order_merchant['pay_time'] ?: date('Y-m-d H:i:s'),
|
|
|
1868
|
+ 'money' => $money,
|
|
|
1869
|
+ 'deal_type' => 1,
|
|
|
1870
|
+ 'order_type' => 10,
|
|
|
1871
|
+ 'order_id' => $order_merchant['id'],
|
|
|
1872
|
+ 'order_sn' => $order_merchant['out_trade_no'],
|
|
|
1873
|
+ 'user_extra_id' => '',
|
|
|
1874
|
+ 'pm' => 1,
|
|
|
1875
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
1876
|
+ 'vr' => $vr,
|
|
|
1877
|
+ 'jingdou' => $jd,
|
|
|
1878
|
+ 'fg' => $fg,
|
|
|
1879
|
+ 'fenrun' => $fenrun,
|
|
|
1880
|
+ ];
|
|
|
1881
|
+ }
|
|
|
1882
|
+ }
|
|
|
1883
|
+ if (!empty($offline_data_list)) {
|
|
|
1884
|
+ Db::name('enterprise_platform_income_detail')
|
|
|
1885
|
+ ->insertAll($offline_data_list);
|
|
|
1886
|
+ }
|
|
|
1887
|
+ }
|
|
|
1888
|
+
|
|
|
1889
|
+ }
|
|
|
1890
|
+
|
|
|
1891
|
+ $mer_id = 0;
|
|
|
1892
|
+
|
|
|
1893
|
+ $order_huafei_data_list = [];
|
|
|
1894
|
+ foreach ($order_huafei_list as $order_huafei) {
|
|
|
1895
|
+ if (!in_array('1' . $order_huafei['uid'] . $order_huafei['order_sn'] . $order_huafei['order_huafei_id'] . '0' . $mer_id, $unique_list)) {
|
|
|
1896
|
+ $order_huafei_data_list[] = [
|
|
|
1897
|
+ 'mer_id' => $mer_id,
|
|
|
1898
|
+ 'uid' => $order_huafei['uid'],
|
|
|
1899
|
+ 'title' => '订单入账',
|
|
|
1900
|
+ 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
|
|
|
1901
|
+ 'deal_time' => $order_huafei['finish_time'] ?: date('Y-m-d H:i:s'),
|
|
|
1902
|
+ 'money' => $order_huafei['cost_price'],
|
|
|
1903
|
+ 'deal_type' => 1,
|
|
|
1904
|
+ 'order_type' => 9,
|
|
|
1905
|
+ 'order_id' => $order_huafei['order_huafei_id'],
|
|
|
1906
|
+ 'order_sn' => $order_huafei['order_sn'],
|
|
|
1907
|
+ 'user_extra_id' => '',
|
|
|
1908
|
+ 'pm' => 1,
|
|
|
1909
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
1910
|
+ 'vr' => 0.00,
|
|
|
1911
|
+ 'jingdou' => 0.00,
|
|
|
1912
|
+ 'fg' => 0.00,
|
|
|
1913
|
+ 'fenrun' => $order_huafei['fanli_price'] // 让利
|
|
|
1914
|
+ ];
|
|
|
1915
|
+ }
|
|
|
1916
|
+ }
|
|
|
1917
|
+ if (!empty($order_huafei_data_list)) {
|
|
|
1918
|
+ Db::name('enterprise_platform_income_detail')
|
|
|
1919
|
+ ->insertAll($order_huafei_data_list);
|
|
|
1920
|
+ }
|
|
|
1921
|
+
|
|
|
1922
|
+ // 5用户佣金提现
|
|
|
1923
|
+ $user_extract_list = Db::name('user_extract')
|
|
|
1924
|
+ ->field('extract_id,uid,extract_type,extract_price,service_money,order_sn,status_time')
|
|
|
1925
|
+ ->where('status', 1)
|
|
|
1926
|
+ ->order('extract_id', 'desc')
|
|
|
1927
|
+ ->select()
|
|
|
1928
|
+ ->toArray();
|
|
|
1929
|
+ foreach ($user_extract_list as $user_extract) {
|
|
|
1930
|
+ if (in_array('5' . $user_extract['uid'] . $user_extract['order_sn'] . '0' . $user_extract['extract_id'] . $mer_id, $unique_list)) continue;
|
|
|
1931
|
+ Db::name('enterprise_platform_income_detail')
|
|
|
1932
|
+ ->insert([
|
|
|
1933
|
+ 'mer_id' => $mer_id,
|
|
|
1934
|
+ 'uid' => $user_extract['uid'],
|
|
|
1935
|
+ 'title' => '用户佣金提现',
|
|
|
1936
|
+ 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
|
|
|
1937
|
+ 'deal_time' => $user_extract['status_time'],
|
|
|
1938
|
+ 'money' => bcsub($user_extract['extract_price'], $user_extract['service_money'], 2),
|
|
|
1939
|
+ 'deal_type' => 5,
|
|
|
1940
|
+ 'order_id' => '',
|
|
|
1941
|
+ 'order_sn' => $user_extract['order_sn'],
|
|
|
1942
|
+ 'user_extra_id' => $user_extract['extract_id'],
|
|
|
1943
|
+ 'pm' => 0,
|
|
|
1944
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
1945
|
+ ]);
|
|
|
1946
|
+ }
|
|
|
1947
|
+
|
|
|
1948
|
+ // // 查询分账信息
|
|
|
1949
|
+ // $store_split_order = Db::name('store_split_order')
|
|
|
1950
|
+ // ->where('status', 1)
|
|
|
1951
|
+ // ->select()
|
|
|
1952
|
+ // ->toArray();
|
|
|
1953
|
+ // $store_split_order_map = array_column($store_split_order, null, 'group_order_id');
|
|
|
1954
|
+ // 待完善
|
|
|
1955
|
+ $this->set_enterprise_bill();
|
|
|
1956
|
+
|
|
|
1957
|
+ return app('json')->success('获取平台收支明细成功');
|
|
|
1958
|
+ }
|
|
|
1959
|
+
|
|
|
1960
|
+ public function set_enterprise_bill()
|
|
|
1961
|
+ {
|
|
|
1962
|
+ // 1、查出 时间范围内的 平台收支明细
|
|
|
1963
|
+ $enterprise_platform_income_detail_list = Db::name('enterprise_platform_income_detail')
|
|
|
1964
|
+ // deal_time格式 2025-03-10 10:44:34
|
|
|
1965
|
+ // ->whereBetween('deal_time', [$start_time, $end_time])
|
|
|
1966
|
+ ->select()
|
|
|
1967
|
+ ->toArray();
|
|
|
1968
|
+
|
|
|
1969
|
+ // 2、根据时间进行分组
|
|
|
1970
|
+ $enterprise_platform_income_detail_map = array_reduce($enterprise_platform_income_detail_list, function ($result, $enterprise_platform_income_detail) {
|
|
|
1971
|
+ // 根据 mer_id 进行分组
|
|
|
1972
|
+ $result[date('Y-m', strtotime($enterprise_platform_income_detail['deal_time']))][date('Y-m-d', strtotime($enterprise_platform_income_detail['deal_time']))][] = $enterprise_platform_income_detail;
|
|
|
1973
|
+ return $result;
|
|
|
1974
|
+ }, []);
|
|
|
1975
|
+
|
|
|
1976
|
+ // 3、清空表数据
|
|
|
1977
|
+ Db::execute("TRUNCATE TABLE `rrx_enterprise_day_bill`");
|
|
|
1978
|
+ Db::execute("TRUNCATE TABLE `rrx_enterprise_month_bill`");
|
|
|
1979
|
+
|
|
|
1980
|
+ // 4、循环计算平台当天内的 收支流水
|
|
|
1981
|
+ $month_bill_map = [];
|
|
|
1982
|
+ $day_bill_map = [];
|
|
|
1983
|
+ foreach ($enterprise_platform_income_detail_map as $month => $enterprise_platform_income_detail_list_by_month) {
|
|
|
1984
|
+ // 平台的日账单
|
|
|
1985
|
+ $month_bill_map[$month . '-0'] = [
|
|
|
1986
|
+ 'mer_id' => 0,
|
|
|
1987
|
+ 'month' => $month,
|
|
|
1988
|
+ 'flow' => 0.00,
|
|
|
1989
|
+ 'expenditure' => 0.00,
|
|
|
1990
|
+ 'accounting' => 0.00,
|
|
|
1991
|
+ 'balance' => 0.00,
|
|
|
1992
|
+ 'jingdou' => 0.00,
|
|
|
1993
|
+ 'fenrun' => 0.00,
|
|
|
1994
|
+ 'vr' => 0.00,
|
|
|
1995
|
+ 'fg' => 0.00
|
|
|
1996
|
+ ];
|
|
|
1997
|
+ foreach ($enterprise_platform_income_detail_list_by_month as $day => $enterprise_platform_income_detail_list_by_day) {
|
|
|
1998
|
+ // 平台的日账单
|
|
|
1999
|
+ $day_bill_map[$day . '-0'] = [
|
|
|
2000
|
+ 'mer_id' => 0,
|
|
|
2001
|
+ 'day' => $day,
|
|
|
2002
|
+ 'flow' => 0.00,
|
|
|
2003
|
+ 'expenditure' => 0.00,
|
|
|
2004
|
+ 'accounting' => 0.00,
|
|
|
2005
|
+ 'balance' => 0.00,
|
|
|
2006
|
+ 'jingdou' => 0.00,
|
|
|
2007
|
+ 'fenrun' => 0.00,
|
|
|
2008
|
+ 'vr' => 0.00,
|
|
|
2009
|
+ 'fg' => 0.00
|
|
|
2010
|
+ ];
|
|
|
2011
|
+ foreach ($enterprise_platform_income_detail_list_by_day as $enterprise_platform_income_detail) {
|
|
|
2012
|
+ if (!isset($day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']])) {
|
|
|
2013
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']] = [
|
|
|
2014
|
+ 'mer_id' => $enterprise_platform_income_detail['mer_id'],
|
|
|
2015
|
+ 'day' => $day,
|
|
|
2016
|
+ 'flow' => 0.00,
|
|
|
2017
|
+ 'expenditure' => 0.00,
|
|
|
2018
|
+ 'accounting' => 0.00,
|
|
|
2019
|
+ 'balance' => 0.00,
|
|
|
2020
|
+ 'jingdou' => 0.00,
|
|
|
2021
|
+ 'fenrun' => 0.00,
|
|
|
2022
|
+ 'vr' => 0.00,
|
|
|
2023
|
+ 'fg' => 0.00
|
|
|
2024
|
+ ];
|
|
|
2025
|
+ }
|
|
|
2026
|
+ if (!isset($month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']])) {
|
|
|
2027
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']] = [
|
|
|
2028
|
+ 'mer_id' => $enterprise_platform_income_detail['mer_id'],
|
|
|
2029
|
+ 'month' => $month,
|
|
|
2030
|
+ 'flow' => 0.00,
|
|
|
2031
|
+ 'expenditure' => 0.00,
|
|
|
2032
|
+ 'accounting' => 0.00,
|
|
|
2033
|
+ 'balance' => 0.00,
|
|
|
2034
|
+ 'jingdou' => 0.00,
|
|
|
2035
|
+ 'fenrun' => 0.00,
|
|
|
2036
|
+ 'vr' => 0.00,
|
|
|
2037
|
+ 'fg' => 0.00
|
|
|
2038
|
+ ];
|
|
|
2039
|
+ }
|
|
|
2040
|
+ if($enterprise_platform_income_detail['pm'] == 1) {
|
|
|
2041
|
+ // 订单总价
|
|
|
2042
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['flow'] += ($enterprise_platform_income_detail['money'] + $enterprise_platform_income_detail['vr'] + $enterprise_platform_income_detail['fg'] + $enterprise_platform_income_detail['fenrun']);
|
|
|
2043
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['flow'] += ($enterprise_platform_income_detail['money'] + $enterprise_platform_income_detail['vr'] + $enterprise_platform_income_detail['fg'] + $enterprise_platform_income_detail['fenrun']);
|
|
|
2044
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2045
|
+ $day_bill_map[$day . '-0']['flow'] += ($enterprise_platform_income_detail['money'] + $enterprise_platform_income_detail['vr'] + $enterprise_platform_income_detail['fg'] + $enterprise_platform_income_detail['fenrun']);
|
|
|
2046
|
+ $month_bill_map[$month . '-0']['flow'] += ($enterprise_platform_income_detail['money'] + $enterprise_platform_income_detail['vr'] + $enterprise_platform_income_detail['fg'] + $enterprise_platform_income_detail['fenrun']);
|
|
|
2047
|
+ }
|
|
|
2048
|
+ // 入账现金
|
|
|
2049
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['accounting'] += $enterprise_platform_income_detail['money'];
|
|
|
2050
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['accounting'] += $enterprise_platform_income_detail['money'];
|
|
|
2051
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2052
|
+ $day_bill_map[$day . '-0']['accounting'] += $enterprise_platform_income_detail['money'];
|
|
|
2053
|
+ $month_bill_map[$month . '-0']['accounting'] += $enterprise_platform_income_detail['money'];
|
|
|
2054
|
+ }
|
|
|
2055
|
+ // VR
|
|
|
2056
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['vr'] += $enterprise_platform_income_detail['vr'];
|
|
|
2057
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['vr'] += $enterprise_platform_income_detail['vr'];
|
|
|
2058
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2059
|
+ $day_bill_map[$day . '-0']['vr'] += $enterprise_platform_income_detail['vr'];
|
|
|
2060
|
+ $month_bill_map[$month . '-0']['vr'] += $enterprise_platform_income_detail['vr'];
|
|
|
2061
|
+ }
|
|
|
2062
|
+ // 复购
|
|
|
2063
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['fg'] += $enterprise_platform_income_detail['fg'];
|
|
|
2064
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['fg'] += $enterprise_platform_income_detail['fg'];
|
|
|
2065
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2066
|
+ $day_bill_map[$day . '-0']['fg'] += $enterprise_platform_income_detail['fg'];
|
|
|
2067
|
+ $month_bill_map[$month . '-0']['fg'] += $enterprise_platform_income_detail['fg'];
|
|
|
2068
|
+ }
|
|
|
2069
|
+ // 分润
|
|
|
2070
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['fenrun'] += $enterprise_platform_income_detail['fenrun'];
|
|
|
2071
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['fenrun'] += $enterprise_platform_income_detail['fenrun'];
|
|
|
2072
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2073
|
+ $day_bill_map[$day . '-0']['fenrun'] += $enterprise_platform_income_detail['fenrun'];
|
|
|
2074
|
+ $month_bill_map[$month . '-0']['fenrun'] += $enterprise_platform_income_detail['fenrun'];
|
|
|
2075
|
+ }
|
|
|
2076
|
+ // 获得的京豆
|
|
|
2077
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['jingdou'] += $enterprise_platform_income_detail['jingdou'];
|
|
|
2078
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['jingdou'] += $enterprise_platform_income_detail['jingdou'];
|
|
|
2079
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2080
|
+ $day_bill_map[$day . '-0']['jingdou'] += $enterprise_platform_income_detail['jingdou'];
|
|
|
2081
|
+ $month_bill_map[$month . '-0']['jingdou'] += $enterprise_platform_income_detail['jingdou'];
|
|
|
2082
|
+ }
|
|
|
2083
|
+ // 现金结余
|
|
|
2084
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['balance'] += $enterprise_platform_income_detail['money'];
|
|
|
2085
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['balance'] += $enterprise_platform_income_detail['money'];
|
|
|
2086
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2087
|
+ $day_bill_map[$day . '-0']['balance'] += $enterprise_platform_income_detail['money'];
|
|
|
2088
|
+ $month_bill_map[$month . '-0']['balance'] += $enterprise_platform_income_detail['money'];
|
|
|
2089
|
+ }
|
|
|
2090
|
+ }
|
|
|
2091
|
+ if($enterprise_platform_income_detail['pm'] == 0) {
|
|
|
2092
|
+
|
|
|
2093
|
+ // 支出现金
|
|
|
2094
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['expenditure'] += $enterprise_platform_income_detail['money'];
|
|
|
2095
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['expenditure'] += $enterprise_platform_income_detail['money'];
|
|
|
2096
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2097
|
+ $day_bill_map[$day . '-0']['expenditure'] += $enterprise_platform_income_detail['money'];
|
|
|
2098
|
+ $month_bill_map[$month . '-0']['expenditure'] += $enterprise_platform_income_detail['money'];
|
|
|
2099
|
+ }
|
|
|
2100
|
+ // VR
|
|
|
2101
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['vr'] -= $enterprise_platform_income_detail['vr'];
|
|
|
2102
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['vr'] -= $enterprise_platform_income_detail['vr'];
|
|
|
2103
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2104
|
+ $day_bill_map[$day . '-0']['vr'] -= $enterprise_platform_income_detail['vr'];
|
|
|
2105
|
+ $month_bill_map[$month . '-0']['vr'] -= $enterprise_platform_income_detail['vr'];
|
|
|
2106
|
+ }
|
|
|
2107
|
+ // 复购
|
|
|
2108
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['fg'] -= $enterprise_platform_income_detail['fg'];
|
|
|
2109
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['fg'] -= $enterprise_platform_income_detail['fg'];
|
|
|
2110
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2111
|
+ $day_bill_map[$day . '-0']['fg'] -= $enterprise_platform_income_detail['fg'];
|
|
|
2112
|
+ $month_bill_map[$month . '-0']['fg'] -= $enterprise_platform_income_detail['fg'];
|
|
|
2113
|
+ }
|
|
|
2114
|
+ // 分润
|
|
|
2115
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['fenrun'] -= $enterprise_platform_income_detail['fenrun'];
|
|
|
2116
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['fenrun'] -= $enterprise_platform_income_detail['fenrun'];
|
|
|
2117
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2118
|
+ $day_bill_map[$day . '-0']['fenrun'] -= $enterprise_platform_income_detail['fenrun'];
|
|
|
2119
|
+ $month_bill_map[$month . '-0']['fenrun'] -= $enterprise_platform_income_detail['fenrun'];
|
|
|
2120
|
+ }
|
|
|
2121
|
+ // 获得的京豆
|
|
|
2122
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['jingdou'] -= $enterprise_platform_income_detail['jingdou'];
|
|
|
2123
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['jingdou'] -= $enterprise_platform_income_detail['jingdou'];
|
|
|
2124
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2125
|
+ $day_bill_map[$day . '-0']['jingdou'] -= $enterprise_platform_income_detail['jingdou'];
|
|
|
2126
|
+ $month_bill_map[$month . '-0']['jingdou'] -= $enterprise_platform_income_detail['jingdou'];
|
|
|
2127
|
+ }
|
|
|
2128
|
+ // 现金结余
|
|
|
2129
|
+ $day_bill_map[$day . '-' . $enterprise_platform_income_detail['mer_id']]['balance'] -= $enterprise_platform_income_detail['money'];
|
|
|
2130
|
+ $month_bill_map[$month . '-' . $enterprise_platform_income_detail['mer_id']]['balance'] -= $enterprise_platform_income_detail['money'];
|
|
|
2131
|
+ if ($enterprise_platform_income_detail['mer_id'] != 0) {
|
|
|
2132
|
+ $day_bill_map[$day . '-0']['balance'] -= $enterprise_platform_income_detail['money'];
|
|
|
2133
|
+ $month_bill_map[$month . '-0']['balance'] -= $enterprise_platform_income_detail['money'];
|
|
|
2134
|
+ }
|
|
|
2135
|
+ }
|
|
|
2136
|
+ }
|
|
|
2137
|
+ }
|
|
|
2138
|
+ }
|
|
|
2139
|
+
|
|
|
2140
|
+ // 5、写入数据
|
|
|
2141
|
+ Db::name('enterprise_day_bill')->insertAll(array_values($day_bill_map));
|
|
|
2142
|
+ Db::name('enterprise_month_bill')->insertAll(array_values($month_bill_map));
|
|
|
2143
|
+ }
|
|
1572
|
2144
|
}
|