Commit 61025ec9 authored by hujun's avatar hujun

分佣提成汇总表

parent 0877db97
......@@ -13,6 +13,7 @@ use app\api_broker\service\OrderLogService;
use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil;
use app\model\AAgents;
use app\model\AStore;
use app\model\OBargainModel;
use app\model\OFee;
use app\model\OPartialCommission;
......@@ -702,4 +703,111 @@ class Finance extends Basic
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 分佣提成汇总表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList() {
if (!$this->request->isAjax()) {
return view('commission_total');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$whereOr = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$fields = 'a.id,a.agent_id,sum(b.fee) as fee,sum(c.practical_fee) as practical_fee,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,sum(c.tallage) as tallage,sum(c.real_fee) as real_fee,';
$fields .= 'd.name,d.phone';
$where['c.is_del'] = 0; //订单状态
$where['a.status'] = ['in', 10,11]; //10已提交 11审核成功
/**收佣日期 start**/
if(!empty($this->params['commission_start_date']) && empty($this->params['commission_end_date'])) {
$where['b.operation_date'] = ['> time', $this->params['commission_start_time']];
}
if(!empty($this->params['commission_end_date']) && empty($this->params['commission_start_date'])) {
$where['b.operation_date'] = ['< time', $this->params['commission_end_time']];
}
if (!empty($this->params['commission_start_date']) && !empty($this->params['commission_end_date'])) {
$where['b.operation_date'] = ['between time', [$this->params['commission_start_date'], $this->params['commission_end_date']]];
}
/**收佣日期 end**/
/**提交成交报告日期 start**/
if (!empty($this->params['deal_start_date']) && empty($this->params['deal_end_date'])) {
$where['a.create_time'] = ['> time', $this->params['deal_start_date']] . ' 00:00:00';
}
if (!empty($this->params['deal_end_date']) && empty($this->params['deal_start_date'])) {
$where['a.create_time'] = ['< time', $this->params['deal_end_date']] . '23:59:59';
}
if (!empty($this->params['deal_start_date']) && !empty($this->params['deal_end_date'])) {
$where['a.create_time'] = ['between time', [$this->params['deal_start_date'] . ' 00:00:00', $this->params['deal_end_date']. '23:59:59']];
}
/**提交成交报告日期 end**/
/**开票日期 start**/
if (!empty($this->params['operation_start_date']) && empty($this->params['operation_end_date'])) {
$where_fee['operation_date'] = ['> time', $this->params['operation_start_date']];
}
if (!empty($this->params['operation_end_date']) && empty($this->params['operation_start_date'])) {
$where_fee['operation_date'] = ['> time', $this->params['operation_start_date']];
}
if (!empty($this->params['operation_start_date']) && !empty($this->params['operation_end_date'])) {
$where_fee['operation_date'] = ['between time', [$this->params['operation_start_date'] , $this->params['operation_end_date']]];
}
if (isset($where_fee['operation_date'])) {
$m_fee = new OFee();
$where_fee['type'] = 1;
$bargain_id = $m_fee->getFeeListColumn('bargain_id', $where_fee);
if (!empty($bargain_id)) {
$whereOr['a.id'] = implode(',',$bargain_id);
}
}
/**开票日期 end**/
/**经纪人手机号**/
if (!empty($this->params['phone'])) {
$where['b.phone'] = ['like', '%'.$this->params['phone'].'%'];
}
/**经纪人姓名**/
if (!empty($this->params['name'])) {
$where['d.name'] = ['like', '%'.$this->params['name'].'%'];
}
/**部门id**/
if (!empty($this->params['district_id'])) {
$where['d.district_id'] = $this->params['district_id'];
}
/**门店名**/
if (!empty($this->params['store_name'])) {
$m_store = new AStore();
$store_id = $m_store->findStore('id', ['store_name' => ['like', '%'.$this->params['store_name'].'%']]);
$where['d.store_id'] = $store_id['id'];
}
$m_bargain = new OBargainModel();
$data['data']['list'] = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
$data['data']['total'] = $m_bargain->getCommissionTotalListTotal($where, $whereOr);
return $this->response($data['code'], $data['msg'], $data['data']);
}
}
{layout name="global/frame_tpl" /}
分佣提成汇总表
\ No newline at end of file
......@@ -195,4 +195,20 @@ class AStore extends BaseModel
return $this->where($where)
->value($field);
}
/**
* 查询门店信息
*
* @param $fields
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function findStore($fields, $where) {
return $this->field($fields)
->where($where)
->find();
}
}
\ No newline at end of file
......@@ -599,4 +599,65 @@ class OBargainModel extends Model
}
return $result;
}
/**
* 分佣提成汇总表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '', $whereOr) {
$data = $this->alias('a')
->field($field)
->join('o_fee b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->where($params)
->whereOr($whereOr)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group('d.id')
->select();
$m_agent = new AAgents();
$m_fee = new OFee();
foreach ($data as $k => $v) {
if (isset($v['agent_id'])) {
$district_store = $m_agent->getStoreDistrict('store_name,district_name', ['a.id'=>$v['agent_id']]);
$data[$k]['district_store'] = $district_store['district_name'] .'-'. $district_store['store_name'];
}
$data[$k]['tax_fee'] = $m_fee->where(['bargain_id'=>$v['id'], 'type'=>1])->sum('fee');
}
return $data;
}
/**
* 分佣提成汇总表总数
*
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalListTotal($params, $whereOr) {
return $this->alias('a')
->join('o_fee b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->where($params)
->whereOr($whereOr)
->group('d.id')
->count();
}
}
\ No newline at end of file
......@@ -138,5 +138,15 @@ class OFee extends BaseModel
->count();
}
/**
* 查询分佣或开票
*
* @param string $field
* @param array $where
* @return array
*/
public function getFeeListColumn(string $field, array $where) {
return $this->where($where)
->column($field);
}
}
\ No newline at end of file
......@@ -222,6 +222,7 @@ Route::group('index', [
'addTallAge' => ['index/Finance/addTallAge', [ 'method' => 'POST' ] ], //新增和编辑开票税费
'searchBargainAgents' => ['index/Finance/searchBargainAgents', [ 'method' => 'GET' ] ], //新增和编辑开票税费
'getTallAgeList' => ['index/Finance/getTallAgeList', [ 'method' => 'GET' ] ], //税费承担明细表
'getCommissionTotalList' => ['index/Finance/getCommissionTotalList', [ 'method' => 'GET' ] ], //分佣提成汇总表
'test123' => ['index/WatchShop/test123', [ 'method' => 'get|post' ] ], //时间轴
'agent_zhuan_aagent' => [ 'index/agent/agent_zhuan_aagent', [ 'method' => 'post|get' ] ],//经纪人
'shop_a_store' => [ 'index/agent/shop_a_store', [ 'method' => 'post|get' ] ],//经纪人
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment