// +---------------------------------------------------------------------- namespace app\common\dao\system\financial; use app\common\dao\BaseDao; use app\common\model\system\financial\Financial; use app\common\model\system\merchant\FinancialRecord; use app\common\repositories\system\merchant\FinancialRecordRepository; class FinancialDao extends BaseDao { public $order; public $user; public $index = 0; public $financeSn; public $list = []; 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; } /** * 平台出账财务流水 * @param $number * @param $financialType * @param $merId */ public function platformOut($number, $financialType, $merId = 0) { $this->setData($number, $financialType, 0, 2, $merId); } /** * 平台入账财务流水 * @param $number * @param $financialType * @param $merId */ public function platformIn($number, $financialType, $merId = 0) { $this->setData($number, $financialType, 1, 2, $merId); } /** * 公共入账财务流水 * @param $number * @param $financialType * @param $merId */ public function publicOut($number, $financialType, $merId = '') { $this->setData($number, $financialType, 0, 1, $merId); } /** * 公共入账财务流水 * @param $number * @param $financialType * @param $merId */ public function publicIn($number, $financialType, $merId = '') { $this->setData($number, $financialType, 1, 1, $merId); } /** * 商户入账财务流水 * @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); } public function setData($number, $financialType, $pm, $type = 2, $merId = '') { if (empty($this->financeSn)) { $financialRecordRepository = app()->make(FinancialRecordRepository::class); $this->financeSn = $financialRecordRepository->getSn(); } $this->list[] = [ 'order_id' => $this->order['order_id'], 'order_sn' => $this->order['order_sn'], 'user_info' => $this->user['nickname'], 'user_id' => $this->user['uid'], 'financial_type' => $financialType, 'financial_pm' => $pm, 'type' => $type, 'number' => $number, 'mer_id' => $merId !== '' ? $merId : $this->order->mer_id, 'financial_record_sn' => $this->financeSn . ($this->index++) ]; } public function save() { if (count($this->list) > 0) { (new FinancialRecord())->insertAll($this->list); } } }