2024-01-26 09:39:36 +08:00

130 lines
4.4 KiB
PHP
Executable File

<?php
namespace app\controller\api\dataview;
use app\common\dao\user\UserBillDao;
use app\common\dao\user\UserExtractDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\merchant\FinancialRecordRepository;
use app\common\repositories\user\UserBillRepository;
use crmeb\basic\BaseController;
use think\App;
use think\facade\Db;
use think\exception\ValidateException;
class Finance extends BaseController
{
/**
* @var repository
*/
protected $repository;
public $areaCode; // 区县地区码
public $streetCode; // 镇街道地区码
public $token;
public function __construct(App $app, BaseRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
$this->token = trim($this->request->header('X-Token'));
$this->areaCode = $this->request->param('areaCode', '');
$this->streetCode = $this->request->param('streetCode', '');
if ($this->areaCode == '' && $this->streetCode == '') {
throw new ValidateException('请选择地区');
}
}
// 提现记录
public function withdrawList(UserExtractDao $dao)
{
[$page,$limit] = $this->getPage();
$where = $this->request->params(['status','keyword','date','extract_type']);
$query = $dao->search($where)->with(['user' => function ($query) {
$query->field('uid,avatar,nickname');
}]);
$query->join('user_address', 'user_address.uid = UserExtract.uid')->where(function ($query){
if ($this->streetCode != '') {
$query->where('user_address.street_code', $this->streetCode);
} else {
$query->where('user_address.district_code', $this->areaCode);
}
});
$count = $query->count();
$list = $query->page($page, $limit)->select();
return app('json')->success(compact('count', 'list'));
}
// 资金记录
public function billList(UserBillRepository $repository)
{
$dao = app()->make(UserBillDao::class);
[$page, $limit] = $this->getPage();
$where = $this->request->params(['keyword', 'date', 'type']);
$query = $dao->searchJoin($where)->field('ua.street')->leftJoin('user_address ua', 'b.uid = ua.uid')->where(function ($query){
if ($this->streetCode != '') {
$query->where('ua.street_code', $this->streetCode);
} else {
$query->where('ua.district_code', $this->areaCode);
}
})->order('a.create_time DESC');
$count = $query->count();
$list = $query->page($page, $limit)->select();
return app('json')->success(compact('count', 'list'));
}
// 账单管理统计标题
public function financialRecordTitle(FinancialRecordRepository $repository)
{
$where = $this->request->params(['date']);
$where['is_mer'] = $this->request->get('mer_id') ?? 0 ;
if($where['is_mer'] == 0){
$data = $repository->getAdminTitle($where);
}else{
$where['mer_id'] = $this->request->get('mer_id') ?? 0 ;
$data = $repository->getMerchantTitle($where);
}
return app('json')->success($data);
}
public function financialRecord(FinancialRecordRepository $repository)
{
[$page, $limit] = $this->getPage();
$where = $this->request->params([['type',1],'date']);
$where['is_mer'] = $this->request->get('mer_id') ?? 0 ;
$merchant = [];
if($where['is_mer'] != 0){
$where['mer_id'] = $this->request->get('mer_id') ?? 0 ;
$merchant = Db::name('merchant')->find($where['mer_id']);
}
$data = $repository->getAdminList($where,$page, $limit,$merchant);
return app('json')->success($data);
}
public function financialDetail($type)
{
$repository = app()->make(FinancialRecordRepository::class);
$date = $this->request->param('date');
$where['date'] = empty($date) ? date('Y-m-d',time()) : $date ;
$where['is_mer'] = $this->request->param('mer_id') ?? 0 ;
if($this->request->merId()){
$merchant = $this->request->merchant();
$data = $repository->merDetail($type,$where,$merchant);
}else{
$data = $repository->adminDetail($type,$where);
}
return app('json')->success($data);
}
}