ctms/ctms-admin/controllers/FeeorderController.php
2025-04-10 23:19:13 +08:00

1408 lines
57 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 08:15:37
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcFeeOrder;
use addons\models\AcFeeDriver;
use addons\models\AcOrder;
use addons\models\AcOrderStatus;
use addons\models\AcStore;
use addons\models\AcEmployee;
use addons\models\AcPlat;
use common\models\CVcode;
class FeeorderController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
/*费用列表*/
public function actionIndex()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$oid = Yii::$app->request->get('oid');
$where = [];
$search = isset($post['search'])?$post['search']:[];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','deleted',0];
$where[] = ['=','is_chonghong',0];
if($oid){
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
$order = $order->toArray();
$model = new AcStore();
$store = $model->findOne($order['store_id']);
if($store){
$order['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($order['employee_id']);
if($employee){
$order['employee_title'] = $employee->name;
$order['employee_mobile'] = $employee->mobile;
}
$orderStatus = Yii::$app->params['OrderStatus'];
$order['status_title'] = $orderStatus[$order['status_code']];
$sn = '00000000000'; //11位
$sn = substr($sn,0,11-strlen($oid));
$sn .=$oid;
$order['sn'] = $sn;
$where[] = ['=','order_id',$oid];
}else{
$order = [];
}
$AcFeeOrder = new AcFeeOrder();
$_fees = $AcFeeOrder->find()->where($where)->all();
return $this->render('list',[
'fees'=>$_fees,
'paytypes'=>$paytypes,
'status'=>$status,
'search'=>$search,
'oid'=>$oid,
'order'=>$order,
]);
}
public function actionNew()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$oid = Yii::$app->request->get('oid');
if($oid){
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
$order = $order->toArray();
$model = new AcStore();
$store = $model->findOne($order['store_id']);
if($store){
$order['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($order['employee_id']);
if($employee){
$order['employee_title'] = $employee->name;
$order['employee_mobile'] = $employee->mobile;
}
$orderStatus = Yii::$app->params['OrderStatus'];
$order['status_title'] = $orderStatus[$order['status_code']];
$sn = '00000000000'; //11位
$sn = substr($sn,0,11-strlen($oid));
$sn .=$oid;
$order['sn'] = $sn;
}else{
$return = [];
$return['msg'] = '操作失败,请先选择一张运单';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['order/list',$post]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
return $this->render('modify',[
'paytypes'=>$paytypes,
'status'=>$status,
'oid'=>$oid,
'order'=>$order,
]);
}
public function actionEdit()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcFeeOrder = new AcFeeOrder();
$detail = $AcFeeOrder->findOne($id);
if(!$detail){
$return = [];
$return['msg'] = '明细单获取失败';
$return['url'] = '';
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}else{
$detail = $detail->toArray();
$thumbs = isset($detail['thumbs'])?json_decode($detail['thumbs'],true):[];
$detail['thumbs'] = $thumbs;
$logs = isset($detail['logs'])?json_decode($detail['logs'],true):[];
$detail['logs'] = '';
if($logs){
foreach($logs as $log){
$detail['logs'] .= $log."<br>";
}
}
$money = (int)($detail['fee']/100);
$detail['money1'] = $money;
$detail['money2'] = (int)(($detail['fee']- $money*100)/10);
$detail['money3'] = $detail['fee']-$detail['money1']*100-$detail['money2']*10;
//转换一下角分的正负值
$detail['money2'] = abs($detail['money2']);
$detail['money3'] = abs($detail['money3']);
}
$oid = isset($detail['order_id'])?$detail['order_id']:0;
if($oid){
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
$order = $order->toArray();
$model = new AcStore();
$store = $model->findOne($order['store_id']);
if($store){
$order['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($order['employee_id']);
if($employee){
$order['employee_title'] = $employee->name;
$order['employee_mobile'] = $employee->mobile;
}
$orderStatus = Yii::$app->params['OrderStatus'];
$order['status_title'] = $orderStatus[$order['status_code']];
$sn = '00000000000'; //11位
$sn = substr($sn,0,11-strlen($oid));
$sn .=$oid;
$order['sn'] = $sn;
}else{
$return = [];
$return['msg'] = '操作失败,请先选择一张运单';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['order/list',$post]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
return $this->render('modify',[
'paytypes'=>$paytypes,
'status'=>$status,
'oid'=>$oid,
'order'=>$order,
'detail'=>$detail
]);
}
//保存费用信息
public function actionSave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
$AcFeeModel = new AcFeeOrder();
if($id){
$fee = $AcFeeModel->findOne($id);
if($fee->create_by != Yii::$app->user->identity->id){
//不允许修改非本人操作的表单
$return['msg'] = '您不是该费用单的制单人,不允许进行修改!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(in_array($fee->status_code,[1,-2,99])){
//不允许修改已被财务确认的表单
$return['msg'] = '订单已被财务确认,不可修改!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
//格式化数据 为空的项则不修改
$cols = ['pay_from'=>'支付人','pay_to'=>'收款人'];
foreach($cols as $key=>$ti){
if(isset($post[$key]) && $post[$key] !=''){
$data[$key] = trim($post[$key]);
}else{
$return['msg'] = $ti.'不能为空,请检查并填写';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$key = 'paytype';
if(isset($post[$key]) && $post[$key] !=''){
$data[$key] = (int)$post[$key];
}else{
$return['msg'] = '支付方式必须选择,请检查';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$cols = ['money1','money2','money3']; //金额换算
$is_minus = false;
//考虑是否有负值情况
if(isset($post['money1']) && (int)$post['money1'] <0){
$is_minus = true;
}elseif(isset($post['money2']) && (int)$post['money2'] <0){
$is_minus = true;
}elseif(isset($post['money3']) && (int)$post['money3'] <0){
$is_minus = true;
}
foreach($cols as $key){
if(isset($post[$key]) && $post[$key] !=''){
$money[$key] = abs((int)$post[$key]); //取绝对值
}else{
$money[$key] = 0;
}
}
//角、分 数值必须个位数
if($money['money2']){
$money['money2'] = min($money['money2'],9);
}
if($money['money3']){
$money['money3'] = min($money['money3'],9);
}
$data['fee'] = 100*$money['money1']+10*$money['money2']+$money['money3'];
if($is_minus){
$data['fee'] = 0-$data['fee'];
}
$key = 'sn';
if(isset($post[$key]) && $post[$key] !=''){
$data[$key] = trim($post[$key]);
}
//补充说明
$_thumbs = $_logs = [];
if($id){
if(isset($fee->logs)){
$_logs = json_decode($feeOrder->logs, true);
}
if(isset($fee->thumbs)){
$_thumbs = json_decode($feeOrder->thumbs, true);
}
}
//图片组处理
$key = 'thumbs';
$imgs = [];
if(isset($post[$key]) && !empty($post[$key])){
$imgs = $post[$key]; //数组格式
$imgs = array_unique($imgs);
}
if($imgs){
if($_thumbs){
$imgs = array_merge($imgs,$_thumbs);
$imgs = array_unique($imgs);
}
}
if(!$imgs){
$return['msg'] = '支付凭证截图必须上传,请检查';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$data[$key] = json_encode($imgs,JSON_UNESCAPED_UNICODE);
//操作日志处理
$key = 'logs';
$logs = [];
if(isset($post[$key]) && $post[$key] !=''){
$data['remark'] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'备注-'.htmlspecialchars($post[$key]);
}else{
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'进行了调整';
}
if($_logs){
$logs = $_logs;
}
array_unshift($logs,$log);
$data['cwlogs'] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$_time = time();
$pay_at = isset($post['pay_at']) ? strtotime($post['pay_at']) : $_time;
$data['pay_at'] = $pay_at;
if(!$id){
$data['create_by'] = Yii::$app->user->identity->id;
$data['create_at'] = $_time;
}
$data['update_at'] = $_time;
$data['pid'] = $pid;
//剩余规则校验
$oid = Yii::$app->request->get('oid');
if(!$oid){
$return['msg'] = '未指定有效的运单进行关联,请先去选择运单!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
if(!$order){
$return['msg'] = '未找到关联运单,请检查并重新选择运单!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$data['order_id'] = $oid;
if($id){
$res = $AcFeeModel->updateAll($data,['id'=>$id]);
}else{
foreach($data as $key=>$val){
$AcFeeModel->$key = $val;
}
$res = $AcFeeModel->save();
$id = $AcFeeModel->attributes['id']; //获取插入后id
}
if($res){
$return['msg'] = '保存成功;可提醒财务人员进行审核操作!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '保存失败,请重新检查!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
//财务审核
public function actionCaiwu()
{
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
if(!$id){
$return = [];
$return['msg'] = '操作失败,请先选择一个费用单据';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['feeorder/list',$post]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
$AcFeeModel = new AcFeeOrder();
$feeOrder = $AcFeeModel->findOne($id);
if(!$feeOrder){
$return = [];
$return['msg'] = '操作失败,费用单据未找到,请重新选择';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['feeorder/list',$post]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
$detail = $feeOrder->toArray();
$logs = isset($detail['cwlogs'])?json_decode($detail['cwlogs'],true):[];
$detail['logs'] = '';
if($logs){
foreach($logs as $log){
$detail['logs'] .= $log."<br>";
}
}
if($detail['fee']<0){
//如果是支出类单据,先默认支付发生地为起运地
$detail['is_pay_send'] = 1;
}
//金额转换
$money = (int)($detail['fee']/100);
$detail['money1'] = $money;
$detail['money2'] = (int)(($detail['fee']- $money*100)/10);
$detail['money3'] = $detail['fee']-$detail['money1']*100-$detail['money2']*10;
//转换一下角分的正负值
$detail['money2'] = abs($detail['money2']);
$detail['money3'] = abs($detail['money3']);
return $this->render('check',[
'id'=>$id,
'detail'=>$detail,
]);
}
//申请冲红
public function actionCancel()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$return = [];
$return['timeout'] = 1; //几秒后自动跳转
$AcFeeOrder = new AcFeeOrder();
$detail = $AcFeeOrder->findOne($id);
if(!$detail){
$return['msg'] = '申请失败,单据数据不存在,请重新选择单据!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$status = isset($detail->status_code)?$detail->status_code:0;
if($status==0||$status==-1){
$return['msg'] = '该单据尚未通过财务审核,无需冲红!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($status==99){
$return['msg'] = '该单据仅确认并不入库,无需冲红!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*已是冲红票的,不允许再次冲红*/
if($detail->is_chonghong){
$return['msg'] = '该单据已经其他费用单的冲红单,不允许被冲红!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$oid = isset($detail->order_id)?$detail->order_id:0;
if(!$oid){
$return['msg'] = '申请失败,未关联运单数据,暂不允许操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
if(!$order){
$return['msg'] = '申请失败,关联运单数据异常,暂不允许操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*修改票据状态*/
$saveData = [];
//操作日志处理
$key = 'cwlogs';
$logs = $detail->cwlogs?json_decode($detail->cwlogs,true):[];
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'申请冲红;冲红前状态码['.$status.']';
array_unshift($logs,$log);
$saveData['cwlogs'] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$saveData['update_at'] = time();
$saveData['status_code'] = 2;
$res = $detail->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '申请失败,票据数据保存不成功!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$return = [];
$return['url'] = Url::toRoute(['feeorder/chonghong','cid'=>$id]);
$return['timeout'] = 1; //3秒后自动跳转
$return['msg'] = '申请成功,即将为您跳转到冲红单填写界面!';
$return['errorcode'] = 200;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//填写冲红单
public function actionChonghong()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$chonghong_id = Yii::$app->request->get('cid');
$AcFeeOrder = new AcFeeOrder();
$detail = $AcFeeOrder->findOne($chonghong_id);
if(!$detail){
$return = [];
$return['msg'] = '待冲明细单获取失败';
$return['url'] = '';
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}else{
$detail = $detail->toArray();
$thumbs = isset($detail['thumbs'])?json_decode($detail['thumbs'],true):[];
$detail['thumbs'] = $thumbs;
$logs = isset($detail['cwlogs'])?json_decode($detail['cwlogs'],true):[];
$detail['logs'] = '';
if($logs){
foreach($logs as $log){
$detail['logs'] .= $log."<br>";
}
}
$money = (int)($detail['fee']/100);
$detail['money1'] = $money;
$detail['money2'] = (int)(($detail['fee']- $money*100)/10);
$detail['money3'] = $detail['fee']-$detail['money1']*100-$detail['money2']*10;
//转换一下角分的正负值
$detail['money2'] = abs($detail['money2']);
$detail['money3'] = abs($detail['money3']);
$detail['chonghong_id'] = $chonghong_id;
}
$oid = isset($detail['order_id'])?$detail['order_id']:0;
if(!$oid){
$return = [];
$return['msg'] = '未关联运单数据,操作失败';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute('feeorder/list');
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
if(!$order){
$return = [];
$return['msg'] = '关联运单数据异常,操作失败';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['feeorder/list','oid'=>$oid]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
];
$return['content'] = $return['msg'];
$return['class'] = 'warning';
Yii::$app->request->setBodyParams($return);
return Yii::$app->runAction('index/msg');
}
$order = $order->toArray();
$model = new AcStore();
$store = $model->findOne($order['store_id']);
if($store){
$order['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($order['employee_id']);
if($employee){
$order['employee_title'] = $employee->name;
$order['employee_mobile'] = $employee->mobile;
}
$orderStatus = Yii::$app->params['OrderStatus'];
$order['status_title'] = $orderStatus[$order['status_code']];
$sn = '00000000000'; //11位
$sn = substr($sn,0,11-strlen($oid));
$sn .=$oid;
$order['sn'] = $sn;
//找出关联单据的所有冲红申请
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','deleted',0];
$where[] = ['=','chonghong_id',$chonghong_id];
$where[] = ['=','is_chonghong',1];
$res = $AcFeeOrder->find()->where($where)->all();
$totalCh = $AcFeeOrder->find()->where($where)->sum('fee');
$detail['totalCh'] = $totalCh;
$list = [];
if($res){
foreach($res as $r){
$list[$r->id] = $r->toArray();
$list[$r->id]['logs'] = '';
$logs = json_decode($r->logs,true);
if($logs){
foreach($logs as $l){
$list[$r->id]['logs'] .= $l.'<br>';
}
}
}
}
return $this->render('chonghong',[
'order'=>$order,
'paytypes'=>$paytypes,
'status'=>$status,
'oid'=>$oid,
'detail'=>$detail,
'list'=>$list
]);
}
//删除冲红申请
public function actionDelete()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$return = [];
$return['timeout'] = 1; //几秒后自动跳转
$AcFeeOrder = new AcFeeOrder();
$detail = $AcFeeOrder->findOne($id);
if(!$detail){
$return['msg'] = '操作失败,单据数据不存在,请重新选择单据!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($detail->pid!=$pid){
$return['msg'] = '非本平台单据,不允许删除!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($detail->deleted!=0){
$return['msg'] = '单据已经被删除过了,操作失败!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($detail->status_code!=2){
$return['msg'] = '该单据状态不允许删除!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($detail->create_by != Yii::$app->user->identity->id){
//不允许修改非本人操作的表单
$return['msg'] = '您不是该费用单的制单人,不允许进行修改!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*只有冲红票的且未确认的才能被删除*/
if($detail->is_chonghong!=1){
$return['msg'] = '只有未被确认的冲红类票据可被删除!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*修改票据状态*/
$saveData = [];
//操作日志处理
$key = 'cwlogs';
$logs = $detail->cwlogs?json_decode($detail->cwlogs,true):[];
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'删除';
array_unshift($logs,$log);
$saveData['cwlogs'] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$saveData['update_at'] = time();
$saveData['deleted'] = 1;
$res = $detail->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '删除失败,票据数据保存不成功!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$return = [];
// $return['url'] = Url::toRoute(['feeorder/chonghong','cid'=>$id]);
$return['timeout'] = 1; //几秒后自动跳转
$return['msg'] = '删除成功!';
$return['errorcode'] = 200;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//结束冲红申请
public function actionFinishch()
{
$pid = Yii::$app->session->get('pid');
$paytypes = Yii::$app->params['Paytype'];
$status = Yii::$app->params['PayStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$return = [];
$return['timeout'] = 1; //几秒后自动跳转
$AcFeeOrder = new AcFeeOrder();
$detail = $AcFeeOrder->findOne($id);
if(!$detail){
$return['msg'] = '操作失败,单据数据不存在,请重新选择单据!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($detail->create_by != Yii::$app->user->identity->id){
//不允许修改非本人操作的表单
$return['msg'] = '您不是该费用单的制单人,不允许进行修改!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$status = isset($detail->status_code)?$detail->status_code:0;
if($status!=2){
$return['msg'] = '该单据并非申请冲红状态,无需结束冲红!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*已是冲红票的,不做结束冲红操作*/
if($detail->is_chonghong){
$return['msg'] = '该单据已经其他费用单的冲红单,没有所谓的结束冲红操作!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*修改票据状态*/
$saveData = [];
//操作日志处理
$key = 'cwlogs';
$logs = $detail->cwlogs?json_decode($detail->cwlogs,true):[];
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'结束冲红';
array_unshift($logs,$log);
$saveData['cwlogs'] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$saveData['update_at'] = time();
$saveData['status_code'] = -2;
$res = $detail->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '申请失败,票据数据保存不成功!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$return = [];
$return['timeout'] = 1; //3秒后自动跳转
$return['msg'] = '结束冲红操作成功!';
$return['errorcode'] = 200;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//保存冲红信息
public function actionChonghongsave()
{
$post = Yii::$app->request->post();
$cid = (int)$post['chonghong_id'];
$cid =1;
$pid = Yii::$app->session->get('pid');
$AcFeeModel = new AcFeeOrder();
if(!$cid){
$return['msg'] = '未指定要冲红的票据,不可继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$feeOrder = $AcFeeModel->findOne($cid);
if($feeOrder->pid !=$pid){
$return['msg'] = '非本平台票据,不可继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->deleted !=0){
$return['msg'] = '票据已标记删除,不可继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->create_by != Yii::$app->user->identity->id){
//不允许修改非本人操作的表单
$return['msg'] = '您不是该费用单的制单人,不允许进行冲红操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->status_code !=2){
//检查原票据单是否仍为待冲红状态
$return['msg'] = '原费用单不是待冲红状态,不可继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($feeOrder->order_id);
if(!$order){
$return['msg'] = '关联运单数据异常,不可继续操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//屏蔽频繁操作
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','deleted',0];
$where[] = ['=','chonghong_id',$cid];
$where[] = ['=','is_chonghong',1];
$AcFeeOrder = clone $AcFeeModel;
$res = $AcFeeOrder->find()->where($where)->orderby('create_at ASC')->one();
$lasttime = time();
if($res){
$t = time() - $res->create_at;
if($t<60){
$return['msg'] = '操作太频繁同1冲红申请在1分钟内仅可提交一次';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$data = $feeOrder->toArray();
//格式化数据
/*需要清除的部分*/
$cols = ['id','remark','thumbs','cwlogs','update_at','create_at','status_code'];
foreach($cols as $key){
unset($data[$key]);
}
$cols = ['money1','money2','money3']; //金额换算
$is_minus = false;
//考虑是否有负值情况
if(isset($post['money1']) && (int)$post['money1'] <0){
$is_minus = true;
}elseif(isset($post['money2']) && (int)$post['money2'] <0){
$is_minus = true;
}elseif(isset($post['money3']) && (int)$post['money3'] <0){
$is_minus = true;
}
foreach($cols as $key){
if(isset($post[$key]) && $post[$key] !=''){
$money[$key] = abs((int)$post[$key]); //取绝对值
}else{
$money[$key] = 0;
}
}
//角、分 数值必须个位数
if($money['money2']){
$money['money2'] = min($money['money2'],9);
}
if($money['money3']){
$money['money3'] = min($money['money3'],9);
}
$data['fee'] = 100*$money['money1']+10*$money['money2']+$money['money3']; //需冲红金额
if($is_minus){
$data['fee'] = 0-$data['fee'];
}
//补充说明
//图片组处理
$key = 'thumbs';
$imgs = [];
if(isset($post[$key]) && !empty($post[$key])){
$imgs = $post[$key]; //数组格式
$imgs = array_unique($imgs);
}
$data[$key] = json_encode($imgs,JSON_UNESCAPED_UNICODE);
//操作日志处理
$key = 'logs';
$logs = [];
if(isset($post[$key]) && $post[$key] !=''){
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'备注-'.htmlspecialchars($post[$key]);
}else{
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'进行了修改';
}
array_unshift($logs,$log);
$data[$key] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$_time = time();
$data['create_by'] = Yii::$app->user->identity->id;
$data['create_at'] = $_time;
$data['update_at'] = $_time;
$data['is_chonghong'] = 1;
$data['chonghong_id'] = $cid;
$data['status_code'] = 2;
$AcFeeModel = clone $AcFeeModel;
foreach($data as $key=>$val){
$AcFeeModel->$key = $val;
}
$res = $AcFeeModel->insert();
$id = $AcFeeModel->attributes['id']; //获取插入后id
if($res){
$return['msg'] = '保存成功;可提醒财务人员进行审核操作!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '保存失败,请稍后再试!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
public function actionCaiwusave()
{
$post = Yii::$app->request->post();
$return = [];
if(!isset($post['id'])){
$return['msg'] = '请先重新选择单据!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$id = $post['id'];
$pid = Yii::$app->session->get('pid');
$AcFeeModel = new AcFeeOrder();
$feeOrder = $AcFeeModel->findOne($id);
if(!$feeOrder){
$return['msg'] = '单据数据不存在,请重新选择单据!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->pid != $pid){
$return['msg'] = '单据不属于本平台,无权操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->is_chonghong == 1 && $feeOrder->status_code==-2){
$return['msg'] = '该单据为已冲红票据,不可编辑修改!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$is_pay_send = isset($post['is_pay_send']) ? $post['is_pay_send']:0;
$is_pay_receive = isset($post['is_pay_receive']) ? $post['is_pay_receive']:0;
if($is_pay_send && $is_pay_receive){
$return['msg'] = '支付发生地为二选一,起运地或目的地必须选一个!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$_time = time();
if(!isset($post['vcode'])){
$return['msg'] = '填写财务操作验证码才能继续!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}elseif($post['vcode']==''){
$return['msg'] = '填写财务操作验证码才能继续!';
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
// 校验验证码
$plat = AcPlat::findOne($pid);
$platExt = json_decode($plat->remark,true);
$vcodeModel = new CVcode();
//查询上次发送记录
$where=[];
$where['mobile'] = $platExt['cw_phone'];
$where['deleted'] = 0;
$where['type'] = 'caiwu';
$res = $vcodeModel->find()->where($where)->orderby('id DESC')->one();
if($res){
if(($_time-$res->create_at)>7200){
$return['msg'] = '验证码已超时,请重新获取后再填写提交!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
if($post['vcode']!=$res->code){
$return['msg'] = '财务操作验证码校验失败,请检查并重新输入验证码!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
}else{
$return['msg'] = '财务操作验证码校验失败,请确认是否配置了财务手机号或发送了验证码!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$status = Yii::$app->params['PayStatus'];
$statuscode = $feeOrder->status_code;
$saveData = [];
//操作日志处理
$key = 'logs';
$logs = $feeOrder->cwlogs?json_decode($feeOrder->cwlogs,true):[];
if(isset($post[$key]) && $post[$key] !=''){
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'批复-'.htmlspecialchars($post[$key]);
}else{
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'进行了审核操作';
}
array_unshift($logs,$log);
$saveData['cwlogs'] = json_encode($logs,JSON_UNESCAPED_UNICODE);
$saveData['update_at'] = $_time;
/*驳回
*要求状态为 待确认、申请冲红
*/
if(isset($post['disagree'])){
if(!in_array($statuscode,Yii::$app->params['PayStatusRequireArr']['-1'])){
$_status = isset($status[$statuscode])?$status[$statuscode]:'未知';
$return['msg'] = '当前状态为'.$_status.';不可做驳回操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$saveData['status_code'] = -1; //驳回状态
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '操作失败,单据数据更新没有成功!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$return['msg'] = '操作完成,费用单据已经驳回!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*确认但不入账
*要求状态为 待确认、驳回
*/
if(isset($post['agree99'])){
if(!in_array($statuscode,Yii::$app->params['PayStatusRequireArr']['99'])){
$_status = isset($status[$statuscode])?$status[$statuscode]:'未知';
$return['msg'] = '当前状态为'.$_status.';不可确认!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->is_chonghong==1){
$return['msg'] = '当前为冲红票据,只支持“确认冲红”、“驳回”两种操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//查询关联运单并更新运单数据
$oid = $feeOrder->order_id;
$orderModel = new AcOrder();
$order = $orderModel->findOne($oid);
if(!$order){
$return['msg'] = '关联运单不存在!';
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if($res){
$return['msg'] = '操作完成!但'.$return['msg'];
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '操作失败!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$saveData['status_code'] = 99; //确认但不入账
$fee = round($feeOrder->fee/100,2); //换算为 元 单位
//是否为佣金
$is_commission = isset($post['is_commission']) ? $post['is_commission']:0;
if($is_commission){
$commission = $fee; //换算为 元 单位
if(!$order->commission || $order->commission<0){
$return['msg'] = '关联运单未计提佣金,不可标记为佣金单据,请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($commission>0){
$return['msg'] = '确认入账情况下,佣金必须为负值(即单据为支出单),请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '操作失败,单据数据更新没有成功!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$return['msg'] = '操作完成,费用单据已更新!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*确认并且入账
*要求状态为 待确认、驳回、仅确认不入账
*/
if(isset($post['agree1'])){
if(!in_array($statuscode,Yii::$app->params['PayStatusRequireArr']['1'])){
$_status = isset($status[$statuscode])?$status[$statuscode]:'未知';
$return['msg'] = '当前状态为'.$_status.';不可确认入账!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->is_chonghong==1){
$return['msg'] = '当前为冲红票据,只支持“确认冲红”、“驳回”两种操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//查询关联运单并更新运单数据
$oid = $feeOrder->order_id;
$orderModel = new AcOrder();
$order = $orderModel->findOne($oid);
if(!$order){
$return['msg'] = '关联运单不存在,入账失败,已自动变更为“仅确认不入账”!';
$saveData['status_code'] = 99; //仅确认不入账
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if($res){
$return['msg'] = '操作完成!但'.$return['msg'];
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '操作失败!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
/*财务未确认运单的,无法入账*/
if(!$order->is_cwqr){
$return['msg'] = '关联运单尚未通过财务审核,无法做相应的费用票据入账操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*运单标记为完结的,无法入账*/
if($order->is_over){
$return['msg'] = '关联运单已经标记完结,无法再做相应的费用票据入账操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$saveData['status_code'] = 1; //确认入账
$fee = round($feeOrder->fee/100,2); //换算为 元 单位
//是否为佣金
$is_commission = isset($post['is_commission']) ? $post['is_commission']:0;
if($is_commission){
$commission = $fee; //换算为 元 单位
if(!$order->commission || $order->commission<0){
$return['msg'] = '关联运单未计提佣金,不可作佣金入账,请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(!$order->commission_left || $order->commission_left<0){
$return['msg'] = '关联运单已无剩余待支付佣金,不可作佣金入账,请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($commission>0){
$return['msg'] = '确认入账情况下,佣金必须为负值(即单据为支出单),请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(($commission+$order->commission_left)>($order->commission+Yii::$app->params['DefaultCommissionMoreMax'])){
$return['msg'] = '本次佣金超出关联运单中记录核定的佣金金额,且超出部分超过了平台容错上限('.Yii::$app->params['DefaultCommissionMoreMax'].'元),入账失败,请检查操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '操作失败,单据数据更新没有成功!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$orderData = [];
$orderData['update_at'] = $_time;
$payids = [];
$_k = false;
if($is_pay_send){
$_k = 'pay_send_pids';
}elseif($is_pay_receive){
$_k = 'pay_receive_pids';
}
if($_k){
$payids = json_decode($order->$_k,true);
if(!$payids){
$payids = [$id];
}else{
array_unshift($payids,$id);
array_unique($payids);
}
$orderData[$_k] = json_encode($payids,JSON_UNESCAPED_UNICODE);
}
if($is_commission){
$orderData['commission_left'] = $order->commission_left+$commission;
}
/*
*负值支出时,总收入减少 支出增加
*正值收入时,总收入增加 支出不变
*总收入income始终加fee
*/
$orderData['income'] = $order->income+$feeOrder->fee;
if($feeOrder->fee<0){
$orderData['expense'] = $order->expense-$feeOrder->fee;
}
//写入到订单数据中
$res = $order->updateAll($orderData,['id'=>$id]);
if(!$res){
$feeOrder->updateAll(['status_code'=>0],['id'=>$id]);
$return['msg'] = '操作完成,但关联运单的数据更新没有成功,已修改本费用单状态为初始状态;可以晚些再重新尝试操作!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '操作完成,运单数据与费用单据均已更新!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
/*确认冲红
*要求状态为 申请冲红、标记冲红单、有冲红单关联
*/
if(isset($post['agree-2'])){
if(!in_array($statuscode,Yii::$app->params['PayStatusRequireArr']['2'])){
$_status = isset($status[$statuscode])?$status[$statuscode]:'未知';
$return['msg'] = '当前状态为'.$_status.';不可冲红!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($feeOrder->is_chonghong!=1){
$return['msg'] = '当前并非冲红票据,不支持“确认冲红”操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(!$feeOrder->chonghong_id){
$return['msg'] = '标记了冲红但未关联相应的对冲票据,不能继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//校验对冲票据有效性
$chonghong = $AcFeeModel->findOne($feeOrder->chonghong_id);
if(!$chonghong){
$return['msg'] = '关联对冲票据的数据获取异常,操作中断!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($chonghong->deleted){
$return['msg'] = '关联对冲票据已标记删除,不能继续操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//查询关联运单并更新运单数据
$oid = $feeOrder->order_id;
$orderModel = new AcOrder();
$order = $orderModel->findOne($oid);
if(!$order){
$return['msg'] = '关联运单数据获取异常,操作中断!';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$saveData['status_code'] = -2; //确认冲红
$cols = ['money1','money2','money3'];
$is_minus = false;
foreach($cols as $key){
if(isset($post[$key]) && $post[$key] !=''){
if((int)$post[$key]<0){
$is_minus = true; //考虑是否有负值情况
}
$money[$key] = abs((int)$post[$key]); //取绝对值
}else{
$money[$key] = 0;
}
}
//角、分 数值必须个位数
if($money['money2']){
$money['money2'] = min($money['money2'],9);
}
if($money['money3']){
$money['money3'] = min($money['money3'],9);
}
$ch_fee = 100*$money['money1']+10*$money['money2']+$money['money3']; //要冲红的金额
if($is_minus){
$ch_fee = 0-$ch_fee;
}
$saveData['fee'] = $ch_fee; //本票据实际冲红金额
$chData = [];
$saveData['update_at'] = $_time;;
$fee = $chonghong->fee - $ch_fee; //差值即为原单据更新后的金额
$fee = round($fee/100,2); //换算为 元 单位
//是否为佣金
$is_commission = isset($post['is_commission']) ? $post['is_commission']:0;
if($is_commission){
$commission = $fee; //换算为 元 单位
if(!$order->commission || $order->commission<0){
$return['msg'] = '关联运单未计提佣金,不可作佣金入账,请检查操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(!$order->commission_left || $order->commission_left<0){
$return['msg'] = '关联运单已无剩余待支付佣金,不可作佣金入账,请检查操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($commission>0){
$return['msg'] = '实际支出佣金必须为负值(即单据为支出单),请检查操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(($commission+$order->commission_left)>($order->commission+Yii::$app->params['DefaultCommissionMoreMax'])){
$return['msg'] = '本次佣金超出关联运单中记录核定的佣金金额,且超出部分超过了平台容错上限('.Yii::$app->params['DefaultCommissionMoreMax'].'元),入账失败,请检查操作!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$res = $feeOrder->updateAll($saveData,['id'=>$id]);
if(!$res){
$return['msg'] = '冲红失败,单据数据更新没有成功!';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$chData['status_code'] = 2; //避免不可预知的逻辑错误,原对冲票状态仍然应标记为申请冲红状态
$res = $chonghong->updateAll($chData,['id'=>$chonghong->id]); //对冲票为原始数据,不作其他修改
$orderData = [];
$orderData['update_at'] = $_time;
if($is_commission){
$orderData['commission_left'] = $order->commission_left+$commission;
}
/*
*负值支出时,总收入减少 支出增加
*正值收入时,总收入增加 支出不变
*总收入income始终加fee
*/
$orderData['income'] = $order->income+$fee;
if($fee<0){
$orderData['expense'] = $order->expense-$fee;
}
//写入到订单数据中
$res = $order->updateAll($orderData,['id'=>$id]);
if(!$res){
$res2 = $feeOrder->updateAll(['status_code'=>2],['id'=>$id]);
if($res2){
$return['msg'] = '操作完成,但关联运单的数据更新没有成功,已修改冲红费用单状态为申请冲红状态;可以晚些再重新尝试操作!';
}else{
$return['msg'] = '操作完成,但关联运单的数据更新没有成功,冲红费用单状态重置失败;请联系技术管理员修复后再重新尝试操作!';
}
$return['errorcode'] = 100;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}else{
$return['msg'] = '操作完成,运单数据与费用单据均已更新!';
$return['errorcode'] = 0;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
}
}