shop-php/app/common/dao/system/financial/FinancialDao.php

184 lines
6.6 KiB
PHP
Raw Normal View History

2023-05-10 13:38:51 +08:00
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\financial;
use app\common\dao\BaseDao;
use app\common\model\system\financial\Financial;
2024-01-30 13:56:27 +08:00
use app\common\model\system\merchant\FinancialRecord;
2024-01-30 11:39:10 +08:00
use app\common\repositories\system\merchant\FinancialRecordRepository;
2023-05-10 13:38:51 +08:00
class FinancialDao extends BaseDao
{
2024-01-30 11:39:10 +08:00
public $order;
public $user;
2024-01-30 13:56:27 +08:00
public $index = 0;
public $financeSn;
public $list = [];
2024-01-30 11:39:10 +08:00
2023-05-10 13:38:51 +08:00
protected function getModel(): string
{
return Financial::class;
}
public function search(array $where)
{
$query = Financial::hasWhere('merchant',function($query) use ($where){
$query->when(isset($where['is_trader']) && $where['is_trader'] !=='',function($query) use($where){
$query->where('is_trader',$where['is_trader']);
});
$query->when(isset($where['type_id']) && $where['type_id'] !=='',function($query) use($where){
$query->where('type_id',$where['type_id']);
});
$query->when(isset($where['category_id']) && $where['category_id'] !=='',function($query) use($where){
$query->where('category_id',$where['category_id']);
});
$query->where('is_del',0);
});
$query->when(isset($where['status']) && $where['status'] !=='',function($query) use($where){
$query->where('Financial.status',$where['status']);
})
->when(isset($where['financial_type']) && $where['financial_type'] !=='',function($query) use($where){
$query->where('Financial.financial_type',$where['financial_type']);
})
->when(isset($where['mer_id']) && $where['mer_id'] !=='',function($query) use($where){
$query->where('Financial.mer_id',$where['mer_id']);
})
->when(isset($where['financial_status']) && $where['financial_status'] !=='',function($query) use($where){
$query->where('Financial.financial_status',$where['financial_status']);
})
->when(isset($where['keyword']) && $where['keyword'] !=='',function($query) use($where){
$query->join('SystemAdmin A','Financial.admin_id = A.admin_id')
->field('A.real_name,A.admin_id,A.account')
->whereLike('A.real_name|A.account',"%{$where['keyword']}%");
})
->when(isset($where['keywords_']) && $where['keywords_'] !=='',function($query) use($where){
$query->join('MerchantAdmin M','Financial.mer_admin_id = M.merchant_admin_id')
->field('M.real_name,M.account,M.merchant_admin_id')
->whereLike('M.real_name|M.account',"%{$where['keywords_']}%");
})
->when(isset($where['financial_id']) && $where['financial_id'] !=='',function($query) use($where){
$query->where('Financial.financial_id',$where['financial_id']);
})
->when(isset($where['date']) && $where['date'] !=='',function($query) use($where){
getModelTime($query,$where['date'],'Financial.create_time');
})
->when(isset($where['is_del']) && $where['is_del'] !=='',function($query) use($where){
$query->where('Financial.is_del',$where['is_del']);
})
->when(isset($where['type']) && $where['type'] !=='',function($query) use($where){
$query->where('Financial.type',$where['type']);
});;
$query->order('Financial.create_time DESC');
return $query;
}
2024-01-30 11:39:10 +08:00
/**
* 平台出账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function platformOut($number, $financialType, $merId = 0)
2024-01-30 11:39:10 +08:00
{
2024-01-30 13:56:27 +08:00
$this->setData($number, $financialType, 0, 2, $merId);
2024-01-30 11:39:10 +08:00
}
/**
* 平台入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function platformIn($number, $financialType, $merId = 0)
2024-01-30 11:39:10 +08:00
{
2024-01-30 13:56:27 +08:00
$this->setData($number, $financialType, 1, 2, $merId);
2024-01-30 11:39:10 +08:00
}
/**
* 公共入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
2024-01-30 13:56:27 +08:00
public function publicOut($number, $financialType, $merId = '')
2024-01-30 11:39:10 +08:00
{
2024-01-30 13:56:27 +08:00
$this->setData($number, $financialType, 0, 1, $merId);
2024-01-30 11:39:10 +08:00
}
/**
* 公共入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
2024-01-30 13:56:27 +08:00
public function publicIn($number, $financialType, $merId = '')
2024-01-30 11:39:10 +08:00
{
2024-01-30 13:56:27 +08:00
$this->setData($number, $financialType, 1, 1, $merId);
2024-01-30 11:39:10 +08:00
}
2024-02-27 18:05:17 +08:00
/**
* 商户入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function merchantOut($number, $financialType, $merId = '')
{
$this->setData($number, $financialType, 0, 0, $merId);
}
/**
* 商户入账财务流水
* @param $number
* @param $financialType
* @param $merId
*/
public function merchantIn($number, $financialType, $merId = '')
{
$this->setData($number, $financialType, 1, 0, $merId);
}
2024-01-30 13:56:27 +08:00
public function setData($number, $financialType, $pm, $type = 2, $merId = '')
2024-01-30 11:39:10 +08:00
{
2024-01-30 13:56:27 +08:00
if (empty($this->financeSn)) {
2024-01-30 11:39:10 +08:00
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
2024-01-30 13:56:27 +08:00
$this->financeSn = $financialRecordRepository->getSn();
2024-01-30 11:39:10 +08:00
}
2024-01-30 13:56:27 +08:00
$this->list[] = [
2024-02-02 17:45:50 +08:00
'order_id' => $this->order['order_id'],
'order_sn' => $this->order['order_sn'],
2024-01-30 11:39:10 +08:00
'user_info' => $this->user['nickname'],
'user_id' => $this->user['uid'],
'financial_type' => $financialType,
'financial_pm' => $pm,
'type' => $type,
'number' => $number,
2024-02-01 16:08:15 +08:00
'mer_id' => $merId !== '' ? $merId : $this->order->mer_id,
2024-01-30 13:56:27 +08:00
'financial_record_sn' => $this->financeSn . ($this->index++)
2024-01-30 11:39:10 +08:00
];
}
2024-01-30 13:56:27 +08:00
public function save()
{
if (count($this->list) > 0) {
(new FinancialRecord())->insertAll($this->list);
}
}
2023-05-10 13:38:51 +08:00
}