You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
8.1 KiB
PHTML

<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
/**
* 推广查询控制器
* @author 王贺
*/
class StatementMangementController extends ThinkController
{
public function lists() {
$map = [];
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$map['create_time'] = ['between', [strtotime(I('time_start')), strtotime(I('time_end')) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['create_time'] = ['GT', strtotime(I('time_start'))];
} elseif (isset($_REQUEST['time_end'])) {
$map['create_time'] = ['LT', strtotime(I('time_end')) + 86399];
}
if ($_REQUEST['statement_type']||$_REQUEST['statement_type']=='0') {
if($_REQUEST['statement_type']=='2') {
$map['second_party_info'] = ['like','%"order_type":1%'];
} else {
$map['statement_type'] = $_REQUEST['statement_type'];
if ($_REQUEST['statement_type']=='1') {
$map['second_party_info'] = ['like','%"order_type":0%'];
}
}
// dump($map['second_party_info']);die();
}
// var_dump($map);die();
if ($_REQUEST['company_id']) {
$map['company_name'] = $_REQUEST['company_id'];
}
$data = M("statement","tab_")
->where($map)
->order("create_time Desc")
->select();
// var_dump($data);die();
foreach ($data as $key => $value) {
$data[$key]['order'] = json_decode($value['second_party_info'],true)['order_type'];
var_dump($data[$key]['order']);
}
$sumData = M("statement","tab_")
->field('sum(`statement_money`) as sum_money,statement_type')
->where($map)
->group('statement_type')
->select();
$handleSumData = [];
foreach ($sumData as $key => $value) {
$handleSumData[$value['statement_type']] = $value['sum_money'];
}
if (!$handleSumData[1]) {
$handleSumData[1] = 0;
}
if (!$handleSumData[0]) {
$handleSumData[0] = 0;
}
$this->assign('sum',$handleSumData);
// dump($sumData);die();
foreach($data as $key => $value) {
$data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
$data[$key]['statement_begin_time'] = date('Y-m-d H:i:s',$value['statement_begin_time']);
$data[$key]['statement_end_time'] = date('Y-m-d H:i:s',$value['statement_end_time']+86399);
// $data[$key]['is_confirm'] = $data[$key]['is_confirm']?'确认':'未确认';
// $data[$key]['statement_type'] = $value['statement_type']?'公会对账单':'CP对账单';
}
$this->meta_title = '结算单管理';
$this->assign('data',$data);
$this->display();
}
public function createDownstreamOrder() {
$this->display();
}
public function saveDownstreamOrder() {
$second_party_info = $_REQUEST['second_party_info'];
$first_party_info = $_REQUEST['first_party_info'];
$statement_info = $_REQUEST['statement_info'];
$sumData = $_REQUEST['sum_data'];
if ($second_party_info['settlement_type']=='补点订单') {
$second_party_info['order_type'] = 1;
} else {
$second_party_info['order_type'] = 0;
}
if (!$second_party_info||!$first_party_info||!$statement_info||!$statement_info) {
$this->ajaxReturn(['code'=>0, 'msg'=>'数据错误' ]);
}
$insert['statement_type'] = 1;
$insert['company_id'] = $_REQUEST['company_id'];
$insert['company_name'] = $second_party_info['partner'];
$insert['link_phone'] = $second_party_info['link_phone'];;
$statement_begin_time = strtotime($statement_info[0]['statement_begin_time']);
$statement_end_time = strtotime($statement_info[0]['statement_end_time']);
foreach($statement_info as $key => $value) {
if ($statement_begin_time>strtotime($value['statement_begin_time'])&&$value['statement_begin_time']) {
$statement_begin_time = strtotime($value['statement_begin_time']);
}
// var_dump(strtotime($value['statement_begin_time']);
if ($statement_end_time<strtotime($value['statement_end_time'])&&$value['statement_end_time']) {
$statement_end_time=strtotime($value['statement_end_time']);
}
}
$insert['statement_begin_time'] = $statement_begin_time;
$insert['statement_end_time'] = $statement_end_time;
$insert['create_time'] = time();
$insert['statement_money'] =$sumData['statement_money'];
$insert['pay_amount'] = $sumData['pay_amount'];
$insert['ext_field'] = $_REQUEST['ext_field'];
$insert['first_party_info'] = json_encode($first_party_info);
$insert['second_party_info'] = json_encode($second_party_info);
$insert['statement_info'] = json_encode($statement_info);
if (!(M('statement','tab_')->where(['ext_field'=>$_REQUEST['ext_field']])->find())) {
M('statement','tab_')->add($insert);
$this->ajaxReturn(['code'=>1, 'msg'=>'生成结算单成功']);
} else {
$this->ajaxReturn(['code'=>0, 'msg'=>'生成结算单失败,结算单已经存在']);
}
}
public function editDownstreamOrder() {
$this->display('edit');
}
public function editDownstreamOrderSave() {
$second_party_info = $_REQUEST['second_party_info'];
$first_party_info = $_REQUEST['first_party_info'];
$statement_info = $_REQUEST['statement_info'];
$sumData = $_REQUEST['sum_data'];
if (!$second_party_info||!$first_party_info||!$statement_info||!$statement_info) {
$this->ajaxReturn(['code'=>0, 'msg'=>'数据错误' ]);
}
$insert['statement_type'] = 1;
$insert['company_id'] = $_REQUEST['company_id'];
$insert['company_name'] = $second_party_info['partner'];
$insert['link_phone'] = $second_party_info['link_phone'];;
$statement_begin_time = strtotime($statement_info[0]['statement_begin_time']);
$statement_end_time = strtotime($statement_info[0]['statement_end_time']);
foreach($statement_info as $key => $value) {
if ($statement_begin_time>strtotime($value['statement_begin_time'])&&$value['statement_begin_time']) {
$statement_begin_time = strtotime($value['statement_begin_time']);
}
// var_dump(strtotime($value['statement_begin_time']);
if ($statement_end_time<strtotime($value['statement_end_time'])&&$value['statement_end_time']) {
$statement_end_time=strtotime($value['statement_end_time']);
}
}
$insert['statement_begin_time'] = $statement_begin_time;
$insert['statement_end_time'] = $statement_end_time;
$insert['create_time'] = time();
$insert['statement_money'] =$sumData['statement_money'];
$insert['pay_amount'] = $sumData['pay_amount'];
$insert['ext_field'] = $_REQUEST['ext_field'];
$insert['first_party_info'] = json_encode($first_party_info);
$insert['second_party_info'] = json_encode($second_party_info);
$insert['statement_info'] = json_encode($statement_info);
if ((M('statement','tab_')->where(['ext_field'=>$_REQUEST['ext_field']])->save($insert))) {
$this->ajaxReturn(['code'=>1, 'msg'=>'结算单编辑成功']);
} else {
$this->ajaxReturn(['code'=>0, 'msg'=>'结算单编辑失败']);
}
}
public function delStatementData() {
$id = $_REQUEST['id'];
if (!$id) {
$this->ajaxReturn(['code'=>2000,'error'=>'no']);
}
$is_del = M('statement','tab_')->where(['id'=>$id])->delete();
if ($is_del) {
$this->ajaxReturn(['code'=>0,'success'=>'ok']);
} else {
$this->ajaxReturn(['code'=>2000,'error'=>'no']);
}
}
}