title = '订单统计';
$query = $this->_query($this->table);
$date = input('date');
if ($date) {
$date = str_replace('-', '', $date);
$temp = explode('~', $date);
$query->whereRaw('(replace(day, "-", "")+0) >= '. $temp[0] . ' and (replace(day, "-", "")+0) <= ' . $temp[1]);
}
$query->equal('day')->dateBetween('create_at');
$field = '*,(replace(day, "-", "")+0) as day_num';
$order = 'day_num desc,id desc';
$query->field($field);
if (input('output') === 'json') {
$result = $query->order($order)->page(true, false);
$this->success('获取数据列表成功', $result);
} else {
$query->order($order)->page();
}
}
/**
* 统计信息查看
* @login true
* @auth true
* @param integer $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function info()
{
$this->_applyFormToken();
$id = input('id');
$this->_form($this->table, 'info', 'id', [], ['id' => $id]);
}
/**
* 表单数据处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _form_filter(&$data)
{
$this->clist = OrderService::instance()->getChannelList(false, false);
$this->mlist = OrderService::instance()->getMerchantList(false, false);
$this->plist = OrderService::instance()->getProductList(false, false);
$this->slist = OrderService::instance()->getServiceList(false, false);
$data['data'] = $this->table(json_decode($data['data'], true));
}
/**
* 数据列表处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _page_filter(&$data)
{
$this->total = StatService::instance()->total();
foreach ($data as $k => $v) {
if (isset($v['success']) && $v['success'] > 0) {
$data[$k]['chengben'] = round($v['product_cash'] / $v['success'], 4);
$data[$k]['success_lv'] = round(($v['success']/$v['total']) * 100, 2) . '%';
} else {
$data[$k]['chengben'] = 0;
}
}
}
private function stat($data)
{
$table = '
';
$table .= '
项目 |
数值 |
';
$table .= '
总金额 |
'.$data['total'].' |
';
$table .= '
成功金额 |
'.$data['success'].' |
';
$table .= '
失败金额 |
'.$data['fail'].' |
';
if ($data['actual_cash']) {
$table .= '
商户成功金额 |
'.$data['actual_cash'].' |
';
}
if ($data['product_cash']) {
$table .= '
渠道成功金额 |
'.$data['product_cash'].' |
';
}
$table .= '
利润 |
'.$data['profit'].' |
';
$table .= '
';
return $table;
}
private function table($data)
{
$table = '';
if (isset($data['merchant_total'])) {
$table .= '';
}
if (isset($data['merchant'])) {
$table .= '';
}
if (isset($data['product'])) {
$table .= '';
}
return $table;
}
/*
private function table($data)
{
$table = '';
if (isset($data['product'])) {
$table .= '
渠道 |
产品 |
金额 |
分成 |
利润 |
';
foreach ($data['product'] as $k => $v) {
if (isset($this->plist[$k]) && $this->plist[$k]) {
if (isset($v['percent_type']) && $v['percent_type'] == 2) {
$v['profit'] = '-' . $v['profit'];
} else {
$v['profit'] = '+' . $v['profit'];
}
$cid = $this->plist[$k]['cid'];
$table .= ''.$this->clist[$cid]['name'].' |
'.$this->plist[$k]['name'].' |
'.$v['num'].' |
'.$v['percent'].' |
'.$v['profit'].' |
';
}
}
}
$table .= '
';
$table .= '';
if (isset($data['merchant'])) {
$table .= '
商户 |
产品 |
金额 |
返点 |
分成 |
利润 |
';
foreach ($data['merchant'] as $k => $v) {
foreach ($v as $k1 => $v1) {
if (isset($this->mlist[$k]) && $this->mlist[$k] && isset($this->plist[$k1]) && isset($v1['num'])) {
if (isset($v1['percent_type']) && $v1['percent_type'] == 2) {
$v1['profit'] = '+' . $v1['profit'];
} else {
$v1['profit'] = '-' . $v1['profit'];
}
$table .= '
'.$this->mlist[$k]['name'].' |
'.$this->plist[$k1]['name'].'('.$this->clist[$this->plist[$k1]['cid']]['name'].') |
'.$v1['num'].' |
'.$v1['rebate'].' |
'.$v1['percent'].' |
'.$v1['profit'].' |
';
}
}
}
}
$table .= '
';
return $table;
}
*/
}