Ver Fonte

Merge branch 'master' of http://git.qiniu1314.com/Kirin/shenying

Kirin há 1 ano atrás
pai
commit
6cd154ab34

+ 24 - 0
app/controller/admin/v1/other/export/ExportExcel.php

@@ -377,6 +377,30 @@ class ExportExcel extends AuthController
         return $this->success($this->service->extract($data));
     }
 
+
+    /**
+     * 订单列表导出
+     * @param UserExtractServices $services
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function extractMonthInfo(UserExtractServices $services)
+    {
+        $where = $this->request->getMore([
+            ['month', ''],
+        ]);
+        if ($where['month']) {
+            $time_start = strtotime($where['month'] . '-1');
+        } else {
+            $time_start = strtotime(date('Y-m') . '-1');
+        }
+        $time_end = strtotime('+1 month', $time_start) - 1;
+        $data = $services->getExportInfoList($time_start, $time_end);
+        return $this->success($this->service->extractInfo($data, 1, $where['month']));
+    }
+
     /**
      * 获取提货点
      * @return mixed

+ 12 - 8
app/controller/api/v1/user/UserExtractController.php

@@ -53,18 +53,21 @@ class UserExtractController
         $user = User::where('uid', $request->uid())->find();
         if ($user['is_auth'] != 2) return app('json')->fail('请先完成实名认证');
         $uids = User::where('card_id', $user['card_id'])->column('uid');
-        $sum_money = UserExtract::where('uid', 'in', $uids)
-            ->whereTime('add_time', 'month')
-            ->where('extract_type', '<>', 'balance')
-            ->where('status', 1)->sum('extract_price');
-        $sum_fee = UserExtract::where('uid', 'in', $uids)
-            ->whereTime('add_time', 'month')
-            ->where('extract_type', '<>', 'balance')
-            ->where('status', 1)->sum('extract_fee');
+
         $money = $request->post('money');
         $user_type = $request->post('user_type', 0);
         $extract_fee = 0;
         if ($user_type == 0) {
+            $sum_money = UserExtract::where('uid', 'in', $uids)
+                ->whereTime('add_time', 'month')
+                ->where('user_type', 0)
+                ->where('extract_type', '<>', 'balance')
+                ->where('status', 1)->sum('extract_price');
+            $sum_fee = UserExtract::where('uid', 'in', $uids)
+                ->whereTime('add_time', 'month')
+                ->where('user_type', 0)
+                ->where('extract_type', '<>', 'balance')
+                ->where('status', 1)->sum('extract_fee');
             $money_sum = bcadd((string)$sum_money, (string)$money, 2);
             $max_range = 0;
             $range = [];
@@ -83,6 +86,7 @@ class UserExtractController
                     $free = $range;
                 }
                 $the_fee = bcdiv(bcmul(bcsub((string)$money_sum, (string)$free, 2), (string)$range['fee']), '100', 2);
+                $the_fee = bcsub((string)$the_fee, (string)$range['dec'], 2);
                 $extract_fee = bcsub((string)$the_fee, (string)$sum_fee, 2);
             }
         }

+ 44 - 8
app/services/other/export/ExportServices.php

@@ -903,14 +903,50 @@ class ExportServices extends BaseServices
 //                        'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
 //                    ];
 //                } else
-                    $one_data = [
-                        'bank_code' => $item['bank_code'],
-                        'real_name' => $item['real_name'],
-                        'bank_address' => $item['bank_address'],
-                        'extract_price' => $item['extract_price'],
-                        'mark' => '工资发放',
-                        'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
-                    ];
+                $one_data = [
+                    'bank_code' => $item['bank_code'],
+                    'real_name' => $item['real_name'],
+                    'bank_address' => $item['bank_address'],
+                    'extract_price' => $item['extract_price'],
+                    'mark' => '工资发放',
+                    'status' => ($item['status'] == 1 ? '通过' : ($item['status'] == 0 ? '申请中' : '未通过'))
+                ];
+                if ($type == 1) {
+                    $export[] = $one_data;
+                    if ($i == 0) {
+                        $filekey = array_keys($one_data);
+                    }
+                } else {
+                    $export[] = array_values($one_data);
+                }
+                $i++;
+            }
+        }
+        if ($type == 1) {
+            return compact('header', 'filekey', 'export', 'filename');
+        } else {
+            return $this->export($header, $title, $export, $filename);
+        }
+    }
+
+
+    /**
+     * 商铺自提点导出
+     * @param array $data
+     * @param int $type
+     * @return array|mixed
+     */
+    public function extractInfo($data = [], $type = 1, $month = '')
+    {
+        $header = ['姓名', '证件号码', '所得项目', '收入', '费用', '免税收入', '扣除项目合计', '应纳税所得额', '税率/预扣率', '速算扣除数', '应纳税额', '减免税额', '应扣缴税额', '已缴税额', '应补(退)税额'];
+        $title = [($month ?: date('Y-m')) . '月用户提现统计', '用户提现统计' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
+        $filename = ($month ?: date('Y-m')) . '月用户提现统计_' . date('YmdHis', time());
+        $export = [];
+        $filekey = [];
+        if (!empty($data)) {
+            $i = 0;
+            foreach ($data as $index => $item) {
+                $one_data = $item;
                 if ($type == 1) {
                     $export[] = $one_data;
                     if ($i == 0) {

+ 65 - 0
app/services/user/UserExtractServices.php

@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\services\user;
 
 use app\jobs\system\CapitalFlowJob;
+use app\model\user\User;
 use app\model\user\UserExtract;
 use app\services\BaseServices;
 use app\dao\user\UserExtractDao;
@@ -290,6 +291,67 @@ class UserExtractServices extends BaseServices
         return $list;
     }
 
+
+    /**
+     * 显示资源列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getExportInfoList($start, $end)
+    {
+        $uids = UserExtract::whereBetween('add_time', [$start, $end])->where('extract_type', '<>', 'balance')->where('user_type', 0)->where('status', 1)->column('uid');
+        $idcards = User::where('uid', 'in', $uids)->where('is_auth', 2)->column('card_id,real_name', 'card_id');
+        $list = [];
+        foreach ($idcards as $v) {
+            $uids = User::where('card_id', $v['card_id'])->where('is_auth', 2)->column('uid');
+            $sum_money = UserExtract::where('uid', 'in', $uids)
+                ->whereBetween('add_time', [$start, $end])
+                ->where('extract_type', '<>', 'balance')
+                ->where('user_type', 0)
+                ->where('status', 1)
+                ->sum('extract_price');
+            $fee = sys_data('withdraw_fee');
+            $max_range = 0;
+            $range = [];
+            foreach ($fee as $vv) {
+                if ($sum_money > $vv['month_number']) {
+                    if ($max_range < $vv['month_number']) {
+                        $range = $vv;
+                        $max_range = $vv['month_number'];
+                    }
+                }
+            }
+            if ($range != []) {
+                if ($range['free_type'] == 1) {
+                    $free = bcdiv(bcmul((string)$sum_money, (string)$range['free']), '100', 2);
+                } else {
+                    $free = $range;
+                }
+                $the_fee = bcdiv(bcmul(bcsub((string)$sum_money, (string)$free, 2), (string)$range['fee']), '100', 2);
+                $the_fee = bcsub((string)$the_fee, (string)$range['dec'], 2);
+            }
+            $row['xingming'] = $v['card_id'];
+            $row['zhengjianhaoma'] = $v['real_name'];
+            $row['suodexiangmu'] = '一般劳务报酬所得';
+            $row['shouru'] = $sum_money;
+            $row['feiyong'] = $free ?? 0;
+            $row['mianshuishouru'] = 0;
+            $row['kouchuxiangmuheji'] = 0;
+            $row['yingnashuisuodee'] = bcsub((string)$sum_money, (string)($free ?? 0), 2);
+            $row['shuilv'] = $range['fee'];
+            $row['susuankouchushu'] = $range['dec'];
+            $row['yingnashuie'] = $the_fee ?? 0;
+            $row['jianmianshuie'] = 0;
+            $row['yingkoujiaoshuie'] = $the_fee ?? 0;
+            $row['yijiaoshuie'] = 0;
+            $row['yingbushuie'] = $the_fee ?? 0;
+            $list[] = $row;
+        }
+        return $list;
+    }
+
     /**
      * 显示编辑资源表单页.
      *
@@ -487,10 +549,12 @@ class UserExtractServices extends BaseServices
         krsort($fees, SORT_DESC);
         $sum_money = UserExtract::where('uid', 'in', $uids)
             ->whereTime('add_time', 'month')
+            ->where('user_type', 0)
             ->where('extract_type', '<>', 'balance')
             ->where('status', 1)->sum('extract_price');
         $sum_fee = UserExtract::where('uid', 'in', $uids)
             ->whereTime('add_time', 'month')
+            ->where('user_type', 0)
             ->where('extract_type', '<>', 'balance')
             ->where('status', 1)->sum('extract_fee');
         $money = $data['money'];
@@ -514,6 +578,7 @@ class UserExtractServices extends BaseServices
                     $free = $range;
                 }
                 $the_fee = bcdiv(bcmul(bcsub((string)$money_sum, (string)$free, 2), (string)$range['fee']), '100', 2);
+                $the_fee = bcsub((string)$the_fee, (string)$range['dec'], 2);
                 $extract_fee = bcsub((string)$the_fee, (string)$sum_fee, 2);
             }
         }

+ 1 - 0
route/admin.php

@@ -573,6 +573,7 @@ Route::group('adminapi', function () {
         //导出会员卡
         Route::get('memberCard/:id', 'v1.other.export.ExportExcel/memberCard')->option(['real_name' => '会员卡导出']);
         Route::get('extract', 'v1.other.export.ExportExcel/extract')->option(['real_name' => '提现导出']);
+        Route::get('extractInfo', 'v1.other.export.ExportExcel/extractMonthInfo')->option(['real_name' => '提现统计']);
         //导出批量发货记录
         Route::get('batchOrderDelivery/:id/:queueType/:cacheType', 'v1.other.export.ExportExcel/batchOrderDelivery')->option(['real_name' => '批量发货记录导出']);
         //物流公司对照表导出