| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- namespace app\admin\logic\finance;
- use app\common\basics\Logic;
- use app\common\model\DividendOrder;
- use app\common\model\WithdrawApply;
- use app\common\enum\WithdrawEnum;
- use app\common\server\ExportExcelServer;
- use app\common\model\AccountLog;
- use app\common\model\DividendCashLog;
- use app\common\model\DividendOrderLog;
- use think\facade\Db;
- use think\Exception;
- /**
- * Class
- * @package app\admin\logic\finance
- */
- class DividendCashLogic extends Logic
- {
- /**
- * @notes 分红池明细
- * @param $get
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author suny
- * @date 2021/7/14 10:01 上午
- */
- public static function cash($get, $is_export = false)
- {
- $where = [];
- if (isset($get['change_type']) && !empty($get['change_type'])) {
- $where[] = ['a.change_type', '=', $get['change_type']];
- }
- if (empty($get['start_time']) && empty($get['end_time'])) {
- $where[] = ['a.create_time', '>=', strtotime(date("Y-m-d", time()))];
- $where[] = ['a.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
- }
- //明细时间
- if (isset($get['start_time']) && $get['start_time'] != '') {
- $where[] = ['a.create_time', '>=', strtotime($get['start_time'])];
- }
- if (isset($get['end_time']) && $get['end_time'] != '') {
- $where[] = ['a.create_time', '<=', strtotime($get['end_time'])];
- }
- // 导出
- if (true === $is_export) {
- return self::cashExport($where);
- }
- $lists = DividendCashLog::alias('a')
- ->field('a.*,o.order_sn')
- ->join('order o', 'o.id = a.order_id')
- ->append(['change_type_desc'])
- ->where($where)
- ->page($get['page'], $get['limit'])
- ->order('a.id desc')
- ->select();
- foreach ($lists as &$v){
- if($v['change_type'] == 2){
- $v['order_sn'] = DividendOrder::where(['id'=>$v['order_id']])->value('sn');
- }
- }
- $count = DividendCashLog::alias('a')
- ->field('a.*')
- ->join('order o', 'o.id = a.order_id')
- ->where($where)
- ->order('a.id desc')
- ->count();
- return ['count' => $count, 'lists' => $lists];
- }
- /**
- * @notes 分红订单明细
- * @param $get
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author suny
- * @date 2021/7/14 10:01 上午
- */
- public static function order($get, $is_export = false)
- {
- $where = [];
- if (empty($get['start_time']) && empty($get['end_time'])) {
- $where[] = ['do.create_time', '>=', strtotime(date("Y-m-d", time()))];
- $where[] = ['do.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
- }
- //明细时间
- if (isset($get['start_time']) && $get['start_time'] != '') {
- $where[] = ['do.create_time', '>=', strtotime($get['start_time'])];
- }
- if (isset($get['end_time']) && $get['end_time'] != '') {
- $where[] = ['do.create_time', '<=', strtotime($get['end_time'])];
- }
- // 导出
- if (true === $is_export) {
- return self::orderExport($where);
- }
- $lists = DividendOrder::alias('do')
- ->field('do.*,o.order_sn')
- ->join('order o', 'o.id = do.order_id')
- ->append(['status_desc','is_exchange_desc'])
- ->where($where)
- ->page($get['page'], $get['limit'])
- ->order('do.id desc')
- ->select();
- $count = DividendOrder::alias('do')
- ->field('do.*,o.order_sn')
- ->join('order o', 'o.id = do.order_id')
- ->where($where)
- ->order('do.id desc')
- ->count();
- return ['count' => $count, 'lists' => $lists];
- }
- /**
- * @notes 会员佣金提现详情
- * @param $id
- * @return array|\think\Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author suny
- * @date 2021/7/14 10:01 上午
- */
- public static function detail($get, $is_export = false)
- {
- $where = [];
- if (isset($get['id']) && $get['id'] != '') {
- $where[] = ['dol.do_id', '=', $get['id']];
- }
- if (empty($get['start_time']) && empty($get['end_time'])) {
- $where[] = ['dol.create_time', '>=', strtotime(date("Y-m-d", time()))];
- $where[] = ['dol.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
- }
- //明细时间
- if (isset($get['start_time']) && $get['start_time'] != '') {
- $where[] = ['dol.create_time', '>=', strtotime($get['start_time'])];
- }
- if (isset($get['end_time']) && $get['end_time'] != '') {
- $where[] = ['dol.create_time', '<=', strtotime($get['end_time'])];
- }
- // 导出
- if (true === $is_export) {
- return self::detailExport($where);
- }
- $lists = DividendOrderLog::alias('dol')
- ->field('dol.*,o.order_sn')
- ->join('order o', 'o.id = dol.order_id')
- ->where($where)
- ->page($get['page'], $get['limit'])
- ->order('dol.id desc')
- ->select();
- $count = DividendOrderLog::alias('dol')
- ->field('dol.*,o.order_sn')
- ->join('order o', 'o.id = dol.order_id')
- ->where($where)
- ->order('dol.id desc')
- ->count();
- return ['count' => $count, 'lists' => $lists];
- }
- /**
- * @notes 导出Excel
- * @param array $where
- * @return array|false
- * @author 段誉
- * @date 2022/4/24 10:10
- */
- public static function orderExport($where)
- {
- try {
- $lists = DividendOrder::alias('do')
- ->field('do.*,o.order_sn')
- ->join('order o', 'o.id = do.order_id')
- ->append(['status_desc','is_exchange_desc'])
- ->where($where)
- ->order('do.id desc')
- ->select();
- $excelFields = [
- 'id' => 'ID',
- 'sn' => '排队单号',
- 'rated_money' => '目标金额',
- 'money' => '已得金额',
- 'status_desc' => '排队状态',
- 'is_exchange_desc' => '兑换状态',
- 'order_sn' => '来源单号',
- 'update_time' => '更新时间',
- 'create_time' => '记录时间',
- ];
- $export = new ExportExcelServer();
- $export->setFileName('排队订单信息');
- $result = $export->createExcel($excelFields, $lists);
- return ['url' => $result];
- } catch (\Exception $e) {
- self::$error = $e->getMessage();
- return false;
- }
- }
- /**
- * @notes 导出Excel
- * @param array $where
- * @return array|false
- * @author 段誉
- * @date 2022/4/24 10:10
- */
- public static function cashExport($where)
- {
- try {
- $lists = DividendCashLog::alias('a')
- ->field('a.*,o.order_sn')
- ->join('order o', 'o.id = a.order_id')
- ->append(['change_type_desc'])
- ->where($where)
- ->order('a.id desc')
- ->select();
- foreach ($lists as &$v){
- if($v['change_type'] == 2){
- $v['order_sn'] = DividendOrder::where(['id'=>$v['order_id']])->value('sn');
- }
- }
- $excelFields = [
- 'id' => 'ID',
- 'change_type_desc' => '变动类型',
- 'change_money' => '变动金额',
- 'total_money' => '剩余金额',
- 'order_sn' => '来源单号',
- 'create_time' => '记录时间',
- ];
- $export = new ExportExcelServer();
- $export->setFileName('分红订单列表信息');
- $result = $export->createExcel($excelFields, $lists);
- return ['url' => $result];
- } catch (\Exception $e) {
- self::$error = $e->getMessage();
- return false;
- }
- }
- /**
- * @notes 导出Excel
- * @param array $condition
- * @return array|false
- * @author 段誉
- * @date 2022/4/24 10:10
- */
- public static function detailExport($where)
- {
- try {
- $lists = DividendOrderLog::alias('dol')
- ->field('dol.*,o.order_sn')
- ->join('order o', 'o.id = dol.order_id')
- ->where($where)
- ->order('dol.id desc')
- ->select();
- $excelFields = [
- 'order_sn' => '来源单号',
- 'money' => '金额',
- 'create_time' => '发生时间',
- ];
- $export = new ExportExcelServer();
- $export->setFileName('分红订单明细记录');
- $result = $export->createExcel($excelFields, $lists);
- return ['url' => $result];
- } catch (\Exception $e) {
- self::$error = $e->getMessage();
- return false;
- }
- }
- }
|