From 23dcd2787d7f0d8d245f74efeebd9e3ee1a1a42c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 26 Dec 2023 15:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E8=B4=A6=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/FinancialRecordTransferDao.php | 120 ++++ .../merchant/FinancialRecordTransfer.php | 47 ++ .../FinancialRecordTransferRepository.php | 588 ++++++++++++++++++ .../merchant/FinancialRecordTransfer.php | 169 +++++ crmeb/listens/RefundOrderAgreeListen.php | 2 +- route/merchant/accounts.php | 36 ++ 6 files changed, 961 insertions(+), 1 deletion(-) create mode 100644 app/common/dao/system/merchant/FinancialRecordTransferDao.php create mode 100644 app/common/model/system/merchant/FinancialRecordTransfer.php create mode 100644 app/common/repositories/system/merchant/FinancialRecordTransferRepository.php create mode 100644 app/controller/admin/system/merchant/FinancialRecordTransfer.php diff --git a/app/common/dao/system/merchant/FinancialRecordTransferDao.php b/app/common/dao/system/merchant/FinancialRecordTransferDao.php new file mode 100644 index 00000000..76c97f34 --- /dev/null +++ b/app/common/dao/system/merchant/FinancialRecordTransferDao.php @@ -0,0 +1,120 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\dao\system\merchant; + + +use app\common\dao\BaseDao; +use app\common\model\system\merchant\FinancialRecordTransfer; + +class FinancialRecordTransferDao extends BaseDao +{ + + const Outlay = 0; //支出 + const Income = 1; //收入 + + const TypeMerchant = 0; //商户 + const TypeCommon = 1; //公共 + const TypePlatform = 2; //平台 + + protected function getModel(): string + { + return FinancialRecordTransfer::class; + } + + /** + * @return string + * @author xaboy + * @day 2020/6/9 + */ + public function getSn() + { + list($msec, $sec) = explode(' ', microtime()); + $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); + $orderId = 'jy' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)); + return $orderId; + } + + public function inc(array $data, $merId) + { + $data['mer_id'] = $merId; + $data['financial_pm'] = 1; + $data['financial_record_sn'] = $this->getSn(); + return $this->create($data); + } + + public function dec(array $data, $merId) + { + $data['mer_id'] = $merId; + $data['financial_pm'] = 0; + $data['financial_record_sn'] = $this->getSn(); + return $this->create($data); + } + + public function search(array $where) + { + $query = $this->getModel()::getDB() + ->when(isset($where['financial_type']) && $where['financial_type'] !== '', function ($query) use ($where) { + $query->whereIn('financial_type', $where['financial_type']); + }) + ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) { + $query->where('mer_id', $where['mer_id']); + }) + ->when(isset($where['user_info']) && $where['user_info'] !== '', function ($query) use ($where) { + $query->where('user_info', $where['user_info']); + }) + ->when(isset($where['user_id']) && $where['user_id'] !== '', function ($query) use ($where) { + $query->where('user_id', $where['user_id']); + }) + ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) { + $query->whereLike('order_sn|user_info|financial_record_sn', "%{$where['keyword']}%"); + }) + ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) { + getModelTime($query, $where['date'], 'create_time'); + }) + ->when(isset($where['is_mer']) && $where['is_mer'] !== '', function ($query) use ($where) { + if($where['is_mer']){ + $query->where('mer_id',$where['is_mer'])->where('type','in',[0,1]); + }else{ + $query->where('type','in',[1,2]); + } + }); + return $query; + } + + /** + * TODO 根据条件和时间查询出相对类型的数量个金额 + * @param int $type + * @param array $where + * @param string $date + * @param array $financialType + * @return array + * @author Qinii + * @day 4/14/22 + */ + public function getDataByType(int $type, array $where, string $date, array $financialType) + { + if (empty($financialType)) return [0,0]; + $query = $this->search($where)->where('financial_type','in',$financialType); + + if($type == 1) { + $query->whereDay('create_time',$date); + } else { + $query->whereMonth('create_time',$date); + } + $count = $query->group('order_id')->where('number', '<>', 0)->count(); + $number = $query->where('number', '<>', 0)->sum('number'); + + return [$count,$number]; + } +} diff --git a/app/common/model/system/merchant/FinancialRecordTransfer.php b/app/common/model/system/merchant/FinancialRecordTransfer.php new file mode 100644 index 00000000..6a8269ae --- /dev/null +++ b/app/common/model/system/merchant/FinancialRecordTransfer.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\model\system\merchant; + + +use app\common\model\BaseModel; +use app\common\model\store\order\StoreOrderOther; +use app\common\model\user\User; + +class FinancialRecordTransfer extends BaseModel +{ + + public static function tablePk(): ?string + { + return 'financial_record_id'; + } + + public static function tableName(): string + { + return 'financial_record_transfer'; + } + + public function user() + { + return $this->hasOne(User::class,'uid','user_id'); + } + + public function merchant() + { + return $this->hasOne(Merchant::class,'mer_id','mer_id'); + } + public function orderInfo() + { + return $this->hasOne(StoreOrderOther::class,'order_sn','order_sn'); + } +} diff --git a/app/common/repositories/system/merchant/FinancialRecordTransferRepository.php b/app/common/repositories/system/merchant/FinancialRecordTransferRepository.php new file mode 100644 index 00000000..01a2bff9 --- /dev/null +++ b/app/common/repositories/system/merchant/FinancialRecordTransferRepository.php @@ -0,0 +1,588 @@ + +// +---------------------------------------------------------------------- + + +namespace app\common\repositories\system\merchant; + + +use app\common\dao\system\merchant\FinancialRecordTransferDao; +use app\common\repositories\BaseRepository; +use app\common\repositories\user\UserBillRepository; +use think\facade\Cache; +use think\facade\Db; + +/** + * Class FinancialRecordTransferRepository + * @package app\common\repositories\system\merchant + * @author xaboy + * @day 2020/8/5 + * @mixin FinancialRecordDao + */ +class FinancialRecordTransferRepository extends BaseRepository +{ + public function __construct(FinancialRecordTransferDao $dao) + { + $this->dao = $dao; + } + + /** + * TODO 列表 + * @param array $where + * @param int $page + * @param int $limit + * @return array + * @author Qinii + * @day 5/7/21 + */ + public function getList(array $where, int $page, int $limit) + { + $query = $this->dao->search($where)->order('create_time DESC'); + $count = $query->count(); + $list = $query->page($page, $limit)->select(); + return compact('count', 'list'); + } + + /** + * TODO 流水头部计算 + * @param int|null $merId + * @param array $where + * @return array + * @author Qinii + * @day 5/7/21 + */ + public function getFiniancialTitle(?int $merId, array $where) + { + /** + * 平台支出 + * 商户的收入 order_true + 佣金 brokerage_one,brokerage_two + 手续费 refund_charge + 商户预售收入 presell_true + * + * 商户支出 + * 退回收入 refund_order + (佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one ) + (手续费 order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge ) + */ + $where['is_mer'] = $merId; + if ($merId) { + //商户收入 + $income = $this->dao->search($where)->where('financial_type', 'in', ['order', 'mer_presell'])->sum('number'); + //商户支出 + $expend_ = $this->dao->search($where)->where('financial_type', 'in', ['refund_order', 'brokerage_one', 'brokerage_two', 'order_charge', 'presell_charge'])->sum('number'); + $_expend = $this->dao->search($where)->where('financial_type', 'in', ['refund_charge', 'refund_brokerage_two', 'refund_brokerage_one'])->sum('number'); + $expend = bcsub($expend_, $_expend, 2); + $msg = '商户'; + } else { + //平台收入 + $income = $this->dao->search($where)->where('financial_type', 'in', ['order', 'order_presell', 'presell'])->sum('number'); + //平台支出 + $expend = $this->dao->search($where)->where('financial_type', 'in', ['brokerage_one', 'brokerage_two', 'order_true', 'refund_charge', 'presell_true', 'order_platform_coupon', 'order_svip_coupon'])->sum('number'); + $msg = '平台'; + } + $data = [ + [ + 'className' => 'el-icon-s-goods', + 'count' => $income, + 'field' => '元', + 'name' => $msg . '收入' + ], + [ + 'className' => 'el-icon-s-order', + 'count' => $expend, + 'field' => '元', + 'name' => $msg . '支出' + ], + ]; + return $data; + } + + /** + * TODO 平台头部统计 + * @param $where + * @return array + * @author Qinii + * @day 3/23/21 + */ + public function getAdminTitle($where) + { + //订单收入总金额 + $count = $this->dao->search($where)->where('financial_type', 'in', ['order', 'order_presell', 'presell'])->sum('number'); + //佣金支出金额 + $brokerage_ = $this->dao->search($where)->where('financial_type', 'in', ['brokerage_one', 'brokerage_two'])->sum('number'); + $_brokerage = $this->dao->search($where)->where('financial_type', 'in', ['refund_brokerage_two', 'refund_brokerage_one'])->sum('number'); + $brokerage = bcsub($brokerage_, $_brokerage, 2); + + //入口店铺佣金 + $entry_merchant=$this->dao->search($where)->where('financial_type', 'commission_to_entry_merchant')->sum('number'); + $entry_merchant_refund=$this->dao->search($where)->where('financial_type', 'commission_to_entry_merchant_refund')->sum('number'); + + //平台手续费 + $charge_ = $this->dao->search($where)->where('financial_type', 'in', ['order_charge', 'presell_charge'])->sum('number'); + $_charge = $this->dao->search($where)->where('financial_type', 'refund_charge')->sum('number'); + $charge = bcsub($charge_, $_charge, 2); + + //产生交易的商户数 + $mer_number = $this->dao->search($where)->group('mer_id')->count(); + + $stat = [ + [ + 'className' => 'el-icon-s-goods', + 'count' => $count, + 'field' => '元', + 'name' => '订单收入总金额' + ], + + [ + 'className' => 'el-icon-s-cooperation', + 'count' => $brokerage, + 'field' => '元', + 'name' => '佣金支出金额' + ], + [ + 'className' => 'el-icon-s-cooperation', + 'count' => $charge, + 'field' => '元', + 'name' => '平台手续费' + ], + [ + 'className' => 'el-icon-s-goods', + 'count' => $mer_number, + 'field' => '个', + 'name' => '产生交易的商户数' + ],[ + 'className' => 'el-icon-s-order', + 'count' => bcsub($entry_merchant,$entry_merchant_refund,2), + 'field' => '元', + 'name' => '入口商户佣金' + ], + ]; + return compact('stat'); + } + + /** + * TODO 商户头部统计 + * @param $where + * @return array + * @author Qinii + * @day 5/6/21 + */ + public function getMerchantTitle($where) + { + //商户收入 + $count = $this->dao->search($where)->where('financial_type', 'in', ['order', 'mer_presell'])->sum('number'); + //押金 + $auto_margin = $this->dao->search($where)->where('financial_type', 'auto_margin')->sum('number'); + $auto_margin_refund = $this->dao->search($where)->where('financial_type', 'auto_margin_refund')->sum('number'); + //平台手续费 + $refund_true = $this->dao->search($where)->where('financial_type', 'in', ['order_charge', 'presell_charge'])->sum('number'); + $order_charge = $this->dao->search($where)->where('financial_type', 'refund_charge')->sum('number'); + $charge = bcsub($refund_true, $order_charge, 2); + $stat = [ + [ + 'className' => 'el-icon-s-goods', + 'count' => $count, + 'field' => '元', + 'name' => '商户收入' + ], + [ + 'className' => 'el-icon-s-cooperation', + 'count' => $charge, + 'field' => '元', + 'name' => '平台手续费' + ], [ + 'className' => 'el-icon-s-cooperation', + 'count' => bcsub($auto_margin,$auto_margin_refund,2), + 'field' => '元', + 'name' => '商户押金金额' + ], + ]; + return compact('stat'); + } + + /** + * TODO 月账单 + * @param array $where + * @param int $page + * @param int $limit + * @return array + * @author Qinii + * @day 3/23/21 + */ + public function getAdminList(array $where, int $page, int $limit, $merchant = []) + { + //日 + if ($where['type'] == 1) { + $field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m-%d\') as time'); + } else { + //月 + if (!empty($where['date'])) { + list($startTime, $endTime) = explode('-', $where['date']); + $firstday = date('Y/m/01', strtotime($startTime)); + $lastday_ = date('Y/m/01', strtotime($endTime)); + $lastday = date('Y/m/d', strtotime("$lastday_ +1 month -1 day")); + $where['date'] = $firstday . '-' . $lastday; + } + $field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m\') as time'); + } + $make = app()->make(UserBillRepository::class); + + $query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC'); + $count = $query->count(); + $list = $query->page($page, $limit)->select()->each(function ($item) use ($where, $merchant) { + $key = $where['is_mer'] ? $where['is_mer'] . '_financial_record_list_' . $item['time'] : 'sys_financial_record_list_' . $item['time']; + if (($where['type'] == 1 && ($item['time'] == date('Y-m-d', time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m', time())))) { + $income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number']; + $expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number']; + $ret = [ + 'income' => $income, + 'expend' => $expend, + 'charge' => bcsub($income, $expend, 2), + ]; + } else { + if (!$ret = Cache::get($key)) { + $income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number']; + $expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number']; + $ret = [ + 'income' => $income, + 'expend' => $expend, + 'charge' => bcsub($income, $expend, 2), + ]; + Cache::tag('system')->set($key, $ret, 24 * 3600); + } + } + $item['income'] = $ret['income']; + $item['expend'] = $ret['expend']; + $item['charge'] = $ret['charge']; + }); + + return compact('count', 'list'); + } + + /** + * TODO 平台详情 + * @param int $type + * @param array $where + * @return mixed + * @author Qinii + * @day 3/23/21 + */ + public function adminDetail(int $type, array $where) + { + $date_ = strtotime($where['date']); + unset($where['date']); + $date = ($type == 1) ? date('Y-m-d', $date_) : date('Y-m', $date_); + $income = $this->countIncome($type, $where, $date); + $bill = $this->countBill($type, $date); + $expend = $this->countExpend($type, $where, $date); + $charge = bcsub($income['number'], $expend['number'], 2); + $data['date'] = $date; + $data['income'] = [ + 'title' => '订单收入总金额', + 'number' => $income['number'], + 'count' => $income['count'] . '笔', + 'data' => [ + ['订单支付', $income['number_order'] . '元', $income['count_order'] . '笔'], + ['退回优惠券补贴', $income['number_coupon'] . '元', $income['count_coupon'] . '笔'], + ['退回会员优惠券补贴', $income['number_svipcoupon'] . '元', $income['count_svipcoupon'] . '笔'], + ] + ]; + $data['bill'] = [ + 'title' => '充值金额', + 'number' => $bill['number'], + 'count' => $bill['count'] . '笔', + 'data' => [] + ]; + $data['expend'] = [ + 'title' => '支出总金额', + 'number' => $expend['number'], + 'count' => $expend['count'] . '笔', + 'data' => [ + ['应付商户金额', $expend['number_order'] . '元', $expend['count_order'] . '笔'], + ['佣金', $expend['number_brokerage'] . '元', $expend['count_brokerage'] . '笔'], + ['返还手续费', $expend['number_charge'] . '元', $expend['count_charge'] . '笔'], + ['优惠券补贴', $expend['number_coupon'] . '元', $expend['count_coupon'] . '笔'], + ['会员优惠券补贴', $expend['number_svipcoupon'] . '元', $expend['count_svipcoupon'] . '笔'], + ] + ]; + $data['charge'] = [ + 'title' => '平台手续费收入总金额', + 'number' => $charge, + 'count' => '', + 'data' => [] + ]; + return $data; + } + + /** + * TODO 商户详情 + * @param int $type + * @param array $where + * @return mixed + * @author Qinii + * @day 5/6/21 + */ + public function merDetail(int $type, array $where,$merchant=[]) + { + $date_ = strtotime($where['date']); + unset($where['date']); + $date = ($type == 1) ? date('Y-m-d', $date_) : date('Y-m', $date_); + $income = $this->countIncome($type, $where, $date,$merchant); + $expend = $this->countExpend($type, $where, $date,$merchant); + $data['e'] = $expend; + $charge = bcsub($income['number'], $expend['number'], 2); + + $data['date'] = $date; + $data['income'] = [ + 'title' => '订单收入总金额', + 'number' => $income['number'], + 'count' => $income['count'] . '笔', + 'data' => [ + ['订单支付', $income['number_order'] . '元', $income['count_order'] . '笔'], + ['优惠券补贴', $income['number_coupon'] . '元', $income['count_coupon'] . '笔'], + ['会员优惠券补贴', $income['number_svipcoupon'] . '元', $income['count_svipcoupon'] . '笔'], + ] + ]; + $data['expend'] = [ + 'title' => '支出总金额', + 'number' => $expend['number'], + 'count' => $expend['count'] . '笔', + 'data' => [ + [ + '平台手续费', + bcsub($expend['number_order_charge'], $expend['number_charge'], 2). '元', + bcsub($expend['count_order_charge'], $expend['count_charge']). '笔', + ], + [ + '店铺押金', + $expend['number_auto_margin'] . '元', + $expend['count_auto_margin'] . '笔' + + ], + [ + '佣金', + bcsub($expend['number_brokerage'], $expend['number_refund_brokerage'], 2) . '元', + $expend['count_brokerage'] + $expend['count_refund_brokerage'] . '笔' + ], + [ + '商户退款', + $expend['number_refund'] . '元', + $expend['count_refund'] . '笔' + ], + [ + '退还优惠券补贴', + $expend['number_coupon'] . '元', + $expend['count_coupon'] . '笔' + ], + [ + '退还会员优惠券补贴', + $expend['number_svipcoupon'] . '元', + $expend['count_svipcoupon'] . '笔' + ], + ] + ]; + $data['charge'] = [ + 'title' => '应入账总金额', + 'number' => $charge, + 'count' => '', + 'data' => [] + ]; + + return $data; + } + + /** + * TODO 总收入 + * @param $type + * @param $date + * @return array + * @author Qinii + * @day 3/23/21 + */ + public function countIncome($type, $where, $date, $merchant = []) + { + $financialType = ['order', 'order_presell', 'presell', 'mer_presell']; + if ($merchant){ + switch ($merchant['type_id']) { + case 16: + $financialType1 = ['commission_to_town']; + break; + case 15: + $financialType1 = ['commission_to_village']; + break; + case 14: + $financialType1 = ['commission_to_service_team']; + break; + case 11: + $financialType1 = ['commission_to_cloud_warehouse']; + break; + case 10: + $financialType1 = ['commission_to_entry_merchant']; + break; + default: + $financialType1 = []; + } + + $financialType = array_merge($financialType, $financialType1); + } + [$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType); + if (!empty($financialType1)){ + $financialType1[0]=$financialType1[0].'_refund'; + [$data['count_refund'], $data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType1); + $data['count_order']-=$data['count_refund']; + $data['number_order']-=$data['number_refund']; + } + + if ($where['is_mer']) { + $financialType = ['order_platform_coupon']; + } else { + $financialType = ['refund_platform_coupon']; + } + [$data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + if ($where['is_mer']) { + $financialType = ['order_svip_coupon']; + } else { + $financialType = ['refund_svip_coupon']; + } + [$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + $data['count'] = $data['count_order']; + $data['number'] = bcadd($data['number_coupon'], $data['number_order'], 2); + return $data; + } + + + /** + * TODO 平台总支出 + * @param $type + * @param $date + * @return array + * @author Qinii + * @day 3/23/21 + */ + public function countExpend($type, $where, $date,$merchant=[]) + { + /** + * 平台支出 + * 商户的收入 order_true + 佣金 brokerage_one,brokerage_two + 手续费 refund_charge + 商户预售收入 presell_true + * + * 商户支出 + * 退回收入 refund_order + (佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one ) + (手续费 order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge ) + */ + // 退回佣金 + $financialType = ['brokerage_one', 'brokerage_two']; + [$data['count_brokerage'], $data['number_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + // 退回手续费 + $financialType = ['refund_charge']; + [$data['count_charge'], $data['number_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + if ($merchant){ + switch ($merchant['type_id']) { + case 16: + $financialType1 = ['commission_to_town_refund']; + break; + case 15: + $financialType1 = ['commission_to_village_refund']; + break; + case 14: + $financialType1 = ['commission_to_service_team_refund']; + break; + case 11: + $financialType1 = ['commission_to_cloud_warehouse_refund']; + break; + case 10: + $financialType1 = ['commission_to_entry_merchant_refund']; + break; + default: + $financialType1 = []; + } + }else{ + //退款的 + $refund=['commission_to_town_refund','commission_to_village_refund','commission_to_service_team_refund','commission_to_cloud_warehouse_refund','commission_to_entry_merchant_refund']; + //分成的 + $commission=['commission_to_town','commission_to_village','commission_to_service_team','commission_to_cloud_warehouse','commission_to_entry_merchant']; + } + if ($where['is_mer']) { //商户的 + //退回收入 + $financialType = ['refund_order']; + [$data['count_refund'], $data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + //平台手续费 + $financialType = ['order_charge', 'presell_charge']; + [$data['count_order_charge'], $data['number_order_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + //商户押金 + $financialType = ['auto_margin']; + [$data['count_auto_margin'], $data['number_auto_margin']] = $this->dao->getDataByType($type, $where, $date, $financialType); + //商户押金退回 + $financialType = ['auto_margin_refund']; + [$data['count_auto_margin_refund'], $data['number_auto_margin_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType); + $number3 = bcsub($data['number_auto_margin'], $data['number_auto_margin_refund'], 2); + $data['count_auto_margin'] = bcsub($data['count_auto_margin'], $data['count_auto_margin_refund']); + $data['number_auto_margin'] = $number3; + //退回佣金 + $financialType = ['refund_brokerage_two', 'refund_brokerage_one']; + [$data['count_refund_brokerage'], $data['number_refund_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + + //佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one ) + $number = bcsub($data['number_brokerage'], $data['number_refund_brokerage'], 2); + //平台手续费 =( order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge ) + $number_1 = bcsub($data['number_order_charge'], $data['number_charge'], 2); + + //退回收入 refund_order + 退回佣金 + $number_2 = bcadd(bcadd($data['number_refund'], $data['number_coupon'], 2), $data['number_svipcoupon'], 2); + $data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'] + $data['count_auto_margin']-$data['count_charge']; + $data['number'] = bcadd(bcadd($number3,bcadd($number_2, $number, 2),2), $number_1, 2); + + } else { //平台的 + // 退回 订单实际获得金额 + + $financialType = ['order_true', 'presell_true','auto_margin']; + [$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType); + + $financialType = ['commission_to_entry_merchant']; + [$data['count_merchant'], $data['number_merchant']] = $this->dao->getDataByType($type, $where, $date, $financialType); + $data['count_order']=bcsub($data['count_order'],$data['count_merchant']); + $data['number_order']=bcsub($data['number_order'],$data['number_merchant'], 2); + + + + //付给服务团队和其他的佣金 + [$data['count_refund'], $data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $refund); + [$data['count_commission'], $data['number_commission']] = $this->dao->getDataByType($type, $where, $date, $commission); + + $data['count_brokerage']+=$data['count_commission']-$data['count_refund']; + $data['number_brokerage']+=$data['number_commission']-$data['number_refund']; + + $number = bcadd($data['number_brokerage'], $data['number_order'], 2); + $number_1 = bcadd(bcadd($number, $data['number_coupon'], 2), $data['number_svipcoupon'], 2); + + $data['count'] = $data['count_brokerage'] + $data['count_order'] + $data['count_charge']; + $data['number'] = bcadd($number_1, $data['number_charge'], 2); + } + return $data; + } + + /** + * TODO 手续费 + * @param $where + * @param $date + * @return mixed + * @author Qinii + * @day 3/24/21 + */ + public function countCharge($type, $where, $date) + { + $financialType = ['order_charge']; + [$count, $number] = $this->dao->getDataByType($type, $where, $date, $financialType); + + return compact('count', 'number'); + } +} diff --git a/app/controller/admin/system/merchant/FinancialRecordTransfer.php b/app/controller/admin/system/merchant/FinancialRecordTransfer.php new file mode 100644 index 00000000..dea9bc37 --- /dev/null +++ b/app/controller/admin/system/merchant/FinancialRecordTransfer.php @@ -0,0 +1,169 @@ + +// +---------------------------------------------------------------------- + + +namespace app\controller\admin\system\merchant; + + +use app\common\repositories\store\ExcelRepository; +use app\common\repositories\system\merchant\FinancialRecordTransferRepository; +use crmeb\basic\BaseController; +use crmeb\services\ExcelService; +use think\App; + +class FinancialRecordTransfer extends BaseController +{ + protected $repository; + + public function __construct(App $app, FinancialRecordTransferRepository $repository) + { + parent::__construct($app); + $this->repository = $repository; + } + + public function lst() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['keyword', 'date', 'mer_id']); + $merId = $this->request->merId(); + if ($merId) { + $where['mer_id'] = $merId; + $where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon', + 'order_svip_coupon','commission_to_service_team','commission_to_service_team_refund','commission_to_platform','commission_to_platform_refund','commission_to_village','commission_to_village_refund','commission_to_town','commission_to_town_refund','commission_to_entry_merchant','commission_to_entry_merchant_refund' + ,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund']; + } else { + $where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon', + 'order_svip_coupon','commission_to_service_team','commission_to_service_team_refund','commission_to_platform','commission_to_platform_refund','commission_to_village','commission_to_village_refund','commission_to_town','commission_to_town_refund' + ,'commission_to_entry_merchant','commission_to_entry_merchant_refund' + ,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund']; + } + return app('json')->success($this->repository->getList($where, $page, $limit)); + } + + public function export() + { + $where = $this->request->params(['keyword', 'date', 'mer_id']); + $merId = $this->request->merId(); + if ($merId) { + $where['mer_id'] = $merId; + $where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon']; + } else { + $where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon','order_svip_coupon']; + } + + [$page, $limit] = $this->getPage(); + $data = app()->make(ExcelService::class)->financial($where,$page,$limit); + return app('json')->success($data); + } + + + /** + * TODO 头部统计 + * @return \think\response\Json + * @author Qinii + * @day 3/23/21 + */ + public function getTitle() + { + $where = $this->request->params(['date']); + $where['is_mer'] = $this->request->merId() ?? 0 ; + if($where['is_mer'] == 0){ + $data = $this->repository->getAdminTitle($where); + }else{ + $data = $this->repository->getMerchantTitle($where); + } + return app('json')->success($data); + } + + + /** + * TODO 列表 + * @return \think\response\Json + * @author Qinii + * @day 3/23/21 + */ + public function getList() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params([['type',1],'date']); + $where['is_mer'] = $this->request->merId() ?? 0 ; + try { + $merchant = $this->request->merchant(); + }catch (\Exception $e){ + $merchant = []; + } + $data = $this->repository->getAdminList($where,$page, $limit,$merchant); + return app('json')->success($data); + } + + + /** + * TODO 详情 + * @param $type + * @return \think\response\Json + * @author Qinii + * @day 3/23/21 + */ + public function detail($type) + { + $date = $this->request->param('date'); + $where['date'] = empty($date) ? date('Y-m-d',time()) : $date ; + $where['is_mer'] = $this->request->merId() ?? 0 ; + if($this->request->merId()){ + $merchant = $this->request->merchant(); + $data = $this->repository->merDetail($type,$where,$merchant); + }else{ + $data = $this->repository->adminDetail($type,$where); + } + + return app('json')->success($data); + } + + /** + * TODO 导出文件 + * @param $type + * @author Qinii + * @day 3/25/21 + */ + public function exportDetail($type) + { + [$page, $limit] = $this->getPage(); + $date = $this->request->param('date'); + $where['date'] = empty($date) ? date('Y-m-d',time()) : $date ; + $where['type'] = $type; + $where['is_mer'] = $this->request->merId() ?? 0 ; + try { + $merchant = $this->request->merchant(); + }catch (\Exception $e){ + $merchant = []; + } + $data = app()->make(ExcelService::class)->exportFinancial($where,$page,$limit,$merchant); +// app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'exportFinancial',$where['is_mer']); + return app('json')->success($data); + } + + /** + * TODO 流水统计 + * @return \think\response\Json + * @author Qinii + * @day 5/7/21 + */ + public function title() + { + $where = $this->request->params(['date']); + +// $data = $this->repository->getFiniancialTitle($this->request->merId(),$where); + $data = []; + return app('json')->success($data); + } + +} diff --git a/crmeb/listens/RefundOrderAgreeListen.php b/crmeb/listens/RefundOrderAgreeListen.php index 400805b2..2013ee2a 100644 --- a/crmeb/listens/RefundOrderAgreeListen.php +++ b/crmeb/listens/RefundOrderAgreeListen.php @@ -33,7 +33,7 @@ class RefundOrderAgreeListen extends TimerService implements ListenerInterface try { $make->adminRefund($id); } catch (\Exception $e) { - Log::info('自动退款失败' . var_export($id, true)); + Log::info('自动退款失败' . $e->getMessage()); } } }); diff --git a/route/merchant/accounts.php b/route/merchant/accounts.php index 56e1083b..60903088 100644 --- a/route/merchant/accounts.php +++ b/route/merchant/accounts.php @@ -162,6 +162,42 @@ Route::group(function () { ] ]); + + //转账账单管理 + Route::group('financial_record_transfer', function () { + //账单管理 + Route::get('lst', '/getList')->option([ + '_alias' => '列表', + ]); + Route::get('title', '/getTitle')->option([ + '_alias' => '统计', + ]); + Route::get('detail/:type', '/detail')->option([ + '_alias' => '详情', + ]); + Route::get('detail_export/:type', '/exportDetail')->option([ + '_alias' => '导出', + ]); + })->prefix('admin.system.merchant.FinancialRecordTransfer')->option([ + '_auth' => true, + '_path' => '/accounts/statement', + '_append'=> [ + [ + '_name' =>'merchantStoreExcelLst', + '_path' =>'/accounts/statement', + '_alias' => '导出列表', + '_auth' => true, + ], + [ + '_name' =>'merchantStoreExcelDownload', + '_path' =>'/accounts/statement', + '_alias' => '导出下载', + '_auth' => true, + ], + + ] + ]); + //发票 Route::group('store/receipt', function () { Route::get('lst', '/lst')->name('merchantOrderReceiptLst')->option([