1183 lines
47 KiB
PHP
Executable File
1183 lines
47 KiB
PHP
Executable File
<?php
|
||
|
||
# @Author: 嗨噜客(三亚) <fm453>
|
||
# @Date: 2022-05-22T07:33:08+08:00
|
||
# @Email: fm453@lukegzs.com
|
||
# @Last modified by: fm453
|
||
# @Last modified time: 2022-05-22T07:33:08+08:00
|
||
# @Copyright: www.hiluker.cn
|
||
|
||
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\AcDriver;
|
||
use addons\models\AcTruckOnline;
|
||
use addons\models\AcTruckCars;
|
||
use addons\models\AcPlat;
|
||
use common\models\CVcode;
|
||
|
||
class FeedriverController extends Common
|
||
{
|
||
//主界面,费用列表
|
||
public function actionIndex()
|
||
{
|
||
// return $this->render('@app/views/layouts/dev',[]);
|
||
$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('online_id');
|
||
$where = [];
|
||
$search = isset($post['search']) ? $post['search'] : [];
|
||
$where[] = 'and';
|
||
$where[] = ['=','pid',$pid];
|
||
$where[] = ['=','deleted',0];
|
||
$where[] = ['=','is_chonghong',0];
|
||
if ($oid) {
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckonline = $AcTruckOnline->findOne($oid);
|
||
$truckonline = $truckonline->toArray();
|
||
|
||
$onlineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||
$truckonline['online_status_title'] = $onlineStatus[$truckonline['status_code']];
|
||
|
||
$where[] = ['=','online_id',$oid];
|
||
} else {
|
||
$truckonline = [];
|
||
}
|
||
$AcFeeDriver = new AcFeeDriver();
|
||
$_fees = $AcFeeDriver->find()->where($where)->all();
|
||
|
||
return $this->render('list', [
|
||
'fees'=>$_fees,
|
||
'paytypes'=>$paytypes,
|
||
'status'=>$status,
|
||
'search'=>$search,
|
||
'oid'=>$oid,
|
||
'truckol'=>$truckonline,
|
||
]);
|
||
}
|
||
|
||
public function actionNew()
|
||
{
|
||
$pid = Yii::$app->session->get('pid');
|
||
$paytypes = Yii::$app->params['Paytype'];
|
||
$status = Yii::$app->params['PayStatus'];
|
||
$post = Yii::$app->request->post();
|
||
|
||
$where = [];
|
||
$search = isset($post['search']) ? $post['search'] : [];
|
||
$where[] = 'and';
|
||
$where[] = ['=','pid',$pid];
|
||
$where[] = ['=','deleted',0];
|
||
|
||
$oid = Yii::$app->request->get('online_id');
|
||
if ($oid) {
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckonline = $AcTruckOnline->findOne($oid);
|
||
$truckonline = $truckonline->toArray();
|
||
|
||
$onlineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||
$truckonline['online_status_title'] = $onlineStatus[$truckonline['status_code']];
|
||
|
||
$sn = '00000000000'; //11位
|
||
$sn = substr($sn, 0, 11-strlen($oid));
|
||
$sn .=$oid;
|
||
$truckonline['sn'] = $sn;
|
||
} else {
|
||
$return = [];
|
||
$return['msg'] = '操作失败,请先选择一张出车单';
|
||
$return['errorcode'] = 0;
|
||
$return['url'] = Url::toRoute(['truckonline/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,
|
||
'truckol'=>$truckonline,
|
||
]);
|
||
}
|
||
|
||
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');
|
||
|
||
$AcFeeDriver = new AcFeeDriver();
|
||
$detail = $AcFeeDriver->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['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']);
|
||
}
|
||
|
||
$oid = isset($detail['online_id']) ? $detail['online_id'] : 0;
|
||
if ($oid) {
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckonline = $AcTruckOnline->findOne($oid);
|
||
$truckonline = $truckonline->toArray();
|
||
|
||
$onlineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||
$truckonline['online_status_title'] = $onlineStatus[$truckonline['status_code']];
|
||
|
||
$sn = '00000000000'; //11位
|
||
$sn = substr($sn, 0, 11-strlen($oid));
|
||
$sn .=$oid;
|
||
$truckonline['sn'] = $sn;
|
||
} else {
|
||
$return = [];
|
||
$return['msg'] = '操作失败,费用明细与出车单的关联出错';
|
||
$return['errorcode'] = 0;
|
||
$return['url'] = Url::toRoute(['truckonline/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,
|
||
'truckol'=>$truckonline,
|
||
'detail'=>$detail
|
||
]);
|
||
}
|
||
|
||
//保存费用信息
|
||
public function actionSave()
|
||
{
|
||
$post = Yii::$app->request->post();
|
||
$id = (int)$post['id'];
|
||
$pid = Yii::$app->session->get('pid');
|
||
|
||
$AcFeeModel = new AcFeeDriver();
|
||
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->cwlogs)) {
|
||
$_logs = json_decode($fee->cwlogs, true);
|
||
}
|
||
if (isset($fee->thumbs)) {
|
||
$_thumbs = json_decode($fee->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));
|
||
}
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckonline = $AcTruckOnline->findOne($oid);
|
||
if (!$truckonline) {
|
||
$return['msg'] = '未找到关联出车单!';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
$data['online_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(['feedriver/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 AcFeeDriver();
|
||
$fee = $AcFeeModel->findOne($id);
|
||
if (!$fee) {
|
||
$return = [];
|
||
$return['msg'] = '操作失败,费用单据未找到,请重新选择';
|
||
$return['errorcode'] = 0;
|
||
$return['url'] = Url::toRoute(['feedriver/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 = $fee->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; //几秒后自动跳转
|
||
|
||
$AcFeeModel = new AcFeeDriver();
|
||
$detail = $AcFeeModel->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->online_id) ? $detail->online_id : 0;
|
||
if (!$oid) {
|
||
$return['msg'] = '申请失败,未关联出车单数据,暂不允许操作!';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckol = $AcTruckOnline->findOne($oid);
|
||
if (!$truckol) {
|
||
$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(['feedriver/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');
|
||
|
||
$AcFeeModel = new AcFeeDriver();
|
||
$detail = $AcFeeModel->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['online_id']) ? $detail['online_id'] : 0;
|
||
if (!$oid) {
|
||
$return = [];
|
||
$return['msg'] = '未关联出车单数据,操作失败';
|
||
$return['errorcode'] = 0;
|
||
$return['url'] = Url::toRoute('feedriver/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');
|
||
}
|
||
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckol = $AcTruckOnline->findOne($oid);
|
||
if (!$truckol) {
|
||
$return = [];
|
||
$return['msg'] = '关联出车单数据异常,操作失败';
|
||
$return['errorcode'] = 0;
|
||
$return['url'] = Url::toRoute(['feedriver/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 = $truckol->toArray();
|
||
|
||
$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 = $AcFeeModel->find()->where($where)->all();
|
||
$totalCh = $AcFeeModel->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->cwlogs, 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; //几秒后自动跳转
|
||
|
||
$AcFeeModel = new AcFeeDriver();
|
||
$detail = $AcFeeModel->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(['feedriver/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; //几秒后自动跳转
|
||
|
||
$AcFeeModel = new AcFeeDriver();
|
||
$detail = $AcFeeModel->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 AcFeeDriver();
|
||
if (!$cid) {
|
||
$return['msg'] = '未指定要冲红的票据,不可继续操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
} else {
|
||
$fee = $AcFeeModel->findOne($cid);
|
||
if ($fee->pid !=$pid) {
|
||
$return['msg'] = '非本平台票据,不可继续操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($fee->deleted !=0) {
|
||
$return['msg'] = '票据已标记删除,不可继续操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($fee->create_by != Yii::$app->user->identity->id) {
|
||
//不允许修改非本人操作的表单
|
||
$return['msg'] = '您不是该费用单的制单人,不允许进行冲红操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($fee->status_code !=2) {
|
||
//检查原票据单是否仍为待冲红状态
|
||
$return['msg'] = '原费用单不是待冲红状态,不可继续操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
}
|
||
$AcTruckOnline = new AcTruckOnline();
|
||
$truckol = $AcTruckOnline->findOne($feeOrder->order_id);
|
||
if (!$truckol) {
|
||
$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];
|
||
$AcFee = clone $AcFeeModel;
|
||
$res = $AcFee->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 = $fee->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]);
|
||
$data['remark'] = htmlspecialchars($post[$key]);
|
||
} else {
|
||
$log = Yii::$app->user->identity->username.'于'.date('Y-m-d H:i').'进行了修改';
|
||
}
|
||
array_unshift($logs, $log);
|
||
$data['cwlogs'] = 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;
|
||
|
||
$AcFee = clone $AcFeeModel;
|
||
foreach ($data as $key=>$val) {
|
||
$AcFee->$key = $val;
|
||
}
|
||
$res = $AcFee->insert();
|
||
$id = $AcFee->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 AcFeeDriver();
|
||
$fee = $AcFeeModel->findOne($id);
|
||
if (!$fee) {
|
||
$return['msg'] = '单据数据不存在,请重新选择单据!';
|
||
$return['errorcode'] = 404;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($fee->pid != $pid) {
|
||
$return['msg'] = '单据不属于本平台,无权操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if ($fee->is_chonghong == 1 && $fee->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 = $fee->status_code;
|
||
$saveData = [];
|
||
//操作日志处理
|
||
$key = 'logs';
|
||
$logs = $fee->cwlogs ? json_decode($fee->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 = $fee->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 ($fee->is_chonghong==1) {
|
||
$return['msg'] = '当前为冲红票据,只支持“确认冲红”、“驳回”两种操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
//查询关联出车单
|
||
$TruckOnlineModel = new AcTruckOnline();
|
||
$truckol = $TruckOnlineModel->findOne($oid);
|
||
if (!$truckol) {
|
||
$return['msg'] = '关联出车单不存在!';
|
||
$res = $fee->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; //确认但不入账
|
||
$res = $fee->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 ($fee->is_chonghong==1) {
|
||
$return['msg'] = '当前为冲红票据,只支持“确认冲红”、“驳回”两种操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
//查询关联出车单
|
||
$oid = $fee->online_id;
|
||
$TruckOnlineModel = new AcTruckOnline();
|
||
$truckol = $TruckOnlineModel->findOne($oid);
|
||
if (!$truckol) {
|
||
$return['msg'] = '关联出车单不存在,入账失败,已自动变更为“仅确认不入账”!';
|
||
$saveData['status_code'] = 99; //仅确认不入账
|
||
$res = $fee->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));
|
||
}
|
||
}
|
||
|
||
$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 ($fee->is_chonghong!=1) {
|
||
$return['msg'] = '当前并非冲红票据,不支持“确认冲红”操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
if (!$fee->chonghong_id) {
|
||
$return['msg'] = '标记了冲红但未关联相应的对冲票据,不能继续操作!';
|
||
$return['errorcode'] = 400;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
//校验对冲票据有效性
|
||
$chonghong = $AcFeeModel->findOne($fee->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));
|
||
}
|
||
|
||
$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; //差值即为原单据更新后的金额
|
||
|
||
$res = $fee->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;
|
||
|
||
$return['msg'] = '操作完成,运单数据与费用单据均已更新!';
|
||
$return['errorcode'] = 0;
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||
}
|
||
}
|
||
}
|