REAPI/app/setting/controller/ChannelAccount.php

132 lines
4.5 KiB
PHP
Raw Permalink Normal View History

2024-09-29 15:43:18 +08:00
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\setting\controller;
use think\admin\Controller;
use app\order\service\OrderService;
use app\channel\service\AccountService;
/**
* 渠道账户统计列表
* Class Order
* @package app\order\controller
*/
class ChannelAccount extends Controller
{
/**
* 绑定数据表
* @var string
*/
public $table = 'stat_chnanel_account';
/**
* 订单列表
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
$this->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();
}
}
/**
* 数据列表处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _page_filter(&$data)
{
$this->clist = OrderService::instance()->getChannelList(false, false);
$this->mlist = OrderService::instance()->getMerchantList(false, false);
$this->plist = OrderService::instance()->getProductList(false, false);
$service = AccountService::instance();
foreach ($data as &$vo) {
//$vo['channel_yue'] = $service->db()->where(array('cid' => $vo['cid'], 'day' => $vo['day']))->sum('num');
$vo['order'] = $this->order_table($vo);
$vo['account'] = $this->account_table($vo);
$vo['cname'] = $this->clist[$vo['cid']]['name'];
//$vo['pname'] = $this->plist[$vo['pid']]['name'];
}
}
private function order_table($data)
{
$table = '<table class="layui-table margin-top-10">';
$table .= '<tr>
<td class="text-left nowrap">订单总金额</td>
<td class="text-left nowrap">订单失败金额</td>
<td class="text-left nowrap">订单成功金额</td>
<td class="text-left nowrap">渠道折扣金额</td>';
$table .= '<tr><td class="text-left nowrap">'.$data['order_total'].'</td>
<td class="text-left nowrap">'.$data['order_fail'].'</td>
<td class="text-left nowrap">'.$data['order_success'].'</td>
<td class="text-left nowrap">'.$data['order_channel_cash'].'</td></tr>';
$table .= '</table>';
return $table;
}
private function account_table($data)
{
$table = '<table class="layui-table margin-top-10">';
$table .= '<tr>
<td class="text-left nowrap">商户折扣金额</td>
<td class="text-left nowrap">渠道折扣金额</td>
<td class="text-left nowrap">账单利润</td>';
$table .= '<tr>
<td class="text-left nowrap">'.$data['account_success'].'</td>
<td class="text-left nowrap">'.$data['account_product_success'].'</td>
<td class="text-left nowrap">'.$data['account_profit'].'</td></tr>';
$table .= '</table>';
return $table;
}
}