ADD:添加后台管理端接口;

DEL:删除不必要的头部注释;
FIX:修正若干已知错误;
This commit is contained in:
2025-07-13 19:40:10 +08:00
parent 0a45e55cca
commit 270b881437
66 changed files with 8618 additions and 8129 deletions
+249 -358
View File
@@ -1,12 +1,4 @@
<?php
# @Author: 嗨噜客(三亚) <fm453>
# @Date: 2022-05-22T07:27:54+08:00
# @Email: fm453@lukegzs.com
# @Last modified by: fm453
# @Last modified time: 2024-08-09T09:17:02+08:00
# @Copyright: www.hiluker.cn
namespace api\controllers\gm\v1;
use Yii;
@@ -17,38 +9,85 @@
use addons\models\AcAlbumPics;
use addons\models\AcAlbumVersion;
//TD:未完成
class AlbumsController extends Common
{
//主界面
public function beforeAction($action)
{
if (!$this->pid) {
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
}
return parent::beforeAction($action);
}
public function actionIndex()
{
global $_HI, $_FM;
return $this->render('../layouts/dev', []);
$apis = [
'list'=>'相册列表',
'detail'=>'详情',
'add'=>'添加',
'edit'=>'编辑',
'delete'=>'删除',
'show'=>'显示',
'hide'=>'隐藏'
];
$this->result('您正使用CMTS-GM系统验车相册管理接口!', $apis, 200);
}
//相册列表
public function actionList()
{
return $this->render('../layouts/dev');
$s = $this->search();
$res = $s['res'];
if (!$res) {
$this->result('没有查询到相应的数据!', [], 0);
}
$data = $s['query'];
$this->showAlbums($res, $data);
}
public function actionDetail(){
$pid = $this->pid;
$post = $this->postdata;
global $_HI, $_FM;
$pid = Yii::$app->session->get('pid');
$session = Yii::$app->session;
$model = new AcAlbums();
$where = [];
$where[] = 'and';
$where[] = ['=', 'pid', $pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'acalbums::search';
if (isset($post['search'])) {
$search = $post['search'];
$session->set($searchSession, $search);
} else if ($session->get($searchSession)) {
$search = $session->get($searchSession);
$id = isset($post['id']) ? $post['id'] : 0;
if ($id <= 0) {
$this->result('查询参数错误!');
}
$model = new AcAlbums();
$detail = $model->findOne($id)->toArray();
if(!$detail) $this->result('未查询到相应数据');
$this->result('查询成功!', $detail, 200);
}
public function actionGetStatus(){
$status = Yii::$app->params['AlbumStatus'];
$this->result('获取相册状态字典', $status, 200);
}
public function actionAdd()
{
}
/*编辑相册*/
public function actionEdit()
{
}
private function search(){
$pid = $this->pid;
$return = [];
$model = new AcAlbums();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = $this->postdata;
$search = $post['search'] ?? [];
//关联指定车辆
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : '';
$CarModel = new AcCar();
if (empty($search['car_id'])) {
@@ -60,356 +99,208 @@
$search['car_title'] = isset($car->title) ? $car->title : '';
}
//关联指定手机
$search['phone'] = isset($search['phone']) ? trim($search['phone']) : '';
if (!empty($search['phone'])) {
$where[] = ['or', ['LIKE', 'phone1_1', $search['phone']], ['LIKE', 'phone1_2', $search['phone']], ['LIKE', 'phone2_1', $search['phone']], ['LIKE', 'phone2_2', $search['phone']]];
}
//排除软删数据
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted'] >= 0 ? 1 : 0) : 0;
}
$where[] = ['=', 'deleted', $deleted];
$page = $this->page;
$pageSize = $this->pageSize;
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
$pages->setPage($page-1, true); //设置分页的当前页面值
$_orderby = 'sign_date DESC,id DESC';
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->indexBy('id')->all();
return ['res'=>$res,'qeury'=>$data];
}
/*
* 数据更新前的预检查,返回对应关联数据
* 必须确保get与post数据中均包含需更新的数据id且一致
* */
private function preUpdate()
{
$id = (int)Yii::$app->request->get('id');
if(!$id) $this->result('请求错误,未携带ID参数');
$post = $this->postdata;
if($post['id'] != $id) $this->result('传参id与请求数据不匹配',[],403);
$model = new AcAlbums();
$res = $model->findOne($id);
if(!$res) $this->result('未查询到相应数据',[],404);
if($res->pid != $this->pid) $this->result('非本平台数据,不允许操作',[],401);
return $res;
}
/*
* 数据保存前的预检查(查重、参数校验等)
* 要保存的数据[],直接从post中取出
* @op,操作类型(add,edit……)
* @detail, 编辑模式下,要修改的数据对象
* 校验机制:
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
* 查重:禁止录入重复数据
* 返回:校验重组后的数据
* */
private function preSave($op,$detail=null)
{
$post = $this->postdata;
$data = [];
$_time = time();
$oid = (int)$post['order_id'] ?? 0;
//格式化数据
$_thumbs = $_logs = [];
//目标键=》POST键
switch ($op) {
case 'add':
if(!$oid || $oid != $post['order_id']) $this->result('未关联运单,禁止操作',[],403);
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($oid);
if (!$order) {
$this->result('未找到关联运单,请检查并重新选择运单!', [], 404);
}
$data['order_id'] = $oid;
$data['create_by'] = $this->user_id;
$data['create_at'] = $_time;
$data['update_at'] = $_time;
break;
case 'edit':
$id = (int)Yii::$app->request->get('id');
$_id = (int)$post['id'];
if($id != $_id) $this->result('id参数不匹配,请检查');
if($oid != $detail->order_id) $this->result('不允许更改运单关联,请检查');
if (isset($detail->logs)) {
$_logs = json_decode($detail->logs, TRUE);
}
if (isset($detail->thumbs)) {
$_thumbs = json_decode($detail->thumbs, TRUE);
}
$data['update_at'] = $_time;
break;
}
$data['pid'] = $this->pid;
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
$status = Yii::$app->params['AlbumStatus'];
//格式化数据 为空的项则不修改
$cols = ['pay_from' => '付款方', 'pay_to' => '收款人'];
foreach ($cols as $key => $ti) {
if (isset($post[$key]) && $post[$key] != '') {
$data[$key] = trim($post[$key]);
} else {
$msg = $ti . '不能为空,请检查并填写';
$this->result($msg, [], 100);
}
}
$orders = [];
$key = 'paytype';
if (isset($post[$key]) && $post[$key] != '') {
$data[$key] = (int)$post[$key];
} else {
$msg = '支付方式必须选择,请检查';
$this->result($msg, [], 100);
}
$cols = ['money1', 'money2', 'money3']; //金额换算,元角分
$is_minus = FALSE;
//考虑是否有负值情况
if (isset($post['money1']) && (int)$post['money1'] < 0) {
$is_minus = TRUE;
} else if (isset($post['money2']) && (int)$post['money2'] < 0) {
$is_minus = TRUE;
} else if (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]);
}
//图片组处理
$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) {
$msg = '支付凭证截图必须上传,请检查';
$this->result($msg, [], 100);
}
$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 = $this->user_info->username . '于' . date('Y-m-d H:i') . '备注-' . htmlspecialchars($post[$key]);
} else {
$log = $this->user_info->username . '于' . date('Y-m-d H:i') . '进行了调整';
}
if ($_logs) {
$logs = $_logs;
}
array_unshift($logs, $log);
$data['cwlogs'] = json_encode($logs, JSON_UNESCAPED_UNICODE);
return $data;
}
/*
* 数据显示格式化
* @res 数据源,查询的结果
* @query 数据表查询实例
* */
private function showAlbums($res,$query){
$datas = [];
foreach ($res as $s) {
$s = $s->toArray();
$orders[$s['id']] = $s;
$datas[$s['id']] = $s;
}
return $this->render('list', [
'orders' => $orders,
'pager' => $pages,
'status' => $status,
'search' => $search
]);
$data = [
'total'=>$query->count(),
'albums' => $datas,
'page'=>$this->page
];
$this->result('相册查询成功!', $data, 200);
}
//验新车
public function actionNewcar()
{
return $this->render('../layouts/dev');
$status = Yii::$app->params['AlbumStatus'];
$AcAlbum = new AcAlbums();
$AcAlbum->status_code = 0;
$detail = $AcAlbum->toArray();
return $this->render('modify', ['status' => $status, 'detail' => $detail]);
}
/*编辑相册*/
public function actionEdit()
{
return $this->render('../layouts/dev');
private function showAlbum($detail){
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$detail['thumbs'] = json_decode($detail['thumbs']);
$model = new AcStore();
$store = $model->findOne($detail['store_id']);
if ($store) {
$detail['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($detail['employee_id']);
if ($employee) {
$detail['employee_title'] = $employee->name;
}
$detail['car_owner_id'] = $detail['car_brand_id'] = $detail['car_series_id'] = 0;
$model = new AcCar();
$car = $model->findOne($detail['car_id']);
if ($car) {
$detail['car_owner_id'] = $car->owner_id;
$detail['car_brand_id'] = $car->brand_id;
$detail['car_series_id'] = $car->series_id;
$detail['car_number'] = $car->num_p . $car->num_area . $car->num_left;
$detail['car_number'] = $detail['car_number'] ? $detail['car_number'] : $car->num_frame;
}
$model = new User();
$user = $model->findOne($detail['from_mid']);
$model = new AcUserExt();
$exts = [];
$_exts = $model->find()->where(['mid' => $detail['from_mid'], 'pid' => $pid, 'deleted' => 0])->indexBy('id')->all();
foreach ($_exts as $ext) {
$ext = $ext->toArray();
if (isset($users[$s['id']])) {
if ($ext['mobile'] == $user->mobile) {
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
if ($owner) {
$_owner = User::findOne($detail['car_owner_id']);
$detail['car_owner'] = $_owner->username . '【' . $_owner->mobile . '】';
}
$AcCarBrand = new AcCarBrand();
$brand = $AcCarBrand->findOne($detail['car_brand_id']);
if ($brand) {
$detail['car_title'] = $brand->title;
}
$AcCarSeries = new AcCarSeries();
$where = [];
$series = $AcCarSeries->findOne($detail['car_series_id']);
if ($series) {
$detail['car_title'] .= $series->title;
}
$op = Yii::$app->request->get('op');
$tpl = 'modify';
if ($op == 'print') {
$tpl = 'print';
$sn = '00000000000'; //11位
$sn = substr($sn, 0, 11 - strlen($id));
$sn .= $id;
$detail['sn'] = $sn;
}
return $this->render(
$tpl,
[
'status' => $status,
'detail' => $detail,
'store' => $store,
'employee' => $employee,
'id' => $id
]
);
}
/*相册详情*/
public function actionDetail()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrder();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$detail['thumbs'] = json_decode($detail['thumbs']);
$model = new AcStore();
$store = $model->findOne($detail['store_id']);
if ($store) {
$detail['store_title'] = $store->title;
}
$model = new AcEmployee();
$employee = $model->findOne($detail['employee_id']);
if ($employee) {
$detail['employee_title'] = $employee->name;
}
$detail['car_owner_id'] = $detail['car_brand_id'] = $detail['car_series_id'] = 0;
$model = new AcCar();
$car = $model->findOne($detail['car_id']);
if ($car) {
$detail['car_owner_id'] = $car->owner_id;
$detail['car_brand_id'] = $car->brand_id;
$detail['car_series_id'] = $car->series_id;
$detail['car_number'] = $car->num_p . $car->num_area . $car->num_left;
$detail['car_number'] = $detail['car_number'] ? $detail['car_number'] : $car->num_frame;
}
$model = new User();
$user = $model->findOne($detail['from_mid']);
$model = new AcUserExt();
$exts = [];
$_exts = $model->find()->where(['mid' => $detail['from_mid'], 'pid' => $pid, 'deleted' => 0])->indexBy('id')->all();
foreach ($_exts as $ext) {
$ext = $ext->toArray();
if (isset($users[$s['id']])) {
if ($ext['mobile'] == $user->mobile) {
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($detail['car_owner_id']);
if ($owner) {
$_owner = User::findOne($detail['car_owner_id']);
$detail['car_owner'] = $_owner->username . '【' . $_owner->mobile . '】';
}
$AcCarBrand = new AcCarBrand();
$brand = $AcCarBrand->findOne($detail['car_brand_id']);
if ($brand) {
$detail['car_title'] = $brand->title;
}
$AcCarSeries = new AcCarSeries();
$where = [];
$series = $AcCarSeries->findOne($detail['car_series_id']);
if ($series) {
$detail['car_title'] .= $series->title;
}
$sn = '00000000000'; //11位
$sn = substr($sn, 0, 11 - strlen($id));
$sn .= $id;
$detail['sn'] = $sn;
return $this->render(
'detail',
[
'status' => $status,
'detail' => $detail,
'store' => $store,
'employee' => $employee,
'id' => $id
]
);
}
//站点验车
public function actionOrder()
{
return $this->render('../layouts/dev');
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
$AcOrder = new AcOrder();
if ($id) {
$order = $AcOrder->findOne($id);
if ($order->create_by != Yii::$app->user->identity->id) {
//不允许修改非本人操作的表单
$return['msg'] = '您不是该运单的制单人,不允许进行修改!';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
//格式化数据 为空的项则不修改
//目标键=》POST键
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city', 'signer' => 'signer', 'sender_name' => 'sender_name', 'sender_idcard' => 'sender_idcard', 'sender_mobiles' => 'sender_mobiles', 'receiver_name' => 'receiver_name', 'receiver_idcard' => 'receiver_idcard', 'receiver_mobiles' => 'receiver_mobiles', 'aim_address' => 'aim_address', 'thumb_f' => 'thumb_f', 'thumb_b' => 'thumb_b', 'thumb_l' => 'thumb_l', 'thumb_r' => 'thumb_r', 'car_extra' => 'car_extra', 'bind' => 'bind', 'driving_lisence' => 'driving_lisence'];
foreach ($cols as $col => $key) {
if (isset($post[$key]) && $post[$key] != '') {
$data[$col] = trim($post[$key]);
}
// $data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['car_id' => 'car_id', 'employee_id' => 'employee_id', 'car_value' => 'car_value', 'fee_insurance' => 'fee_insurance', 'fee_truck' => 'fee_truck', 'fee_deliver' => 'fee_deliver', 'fee_pickup' => 'fee_pickup', 'fee_urgent' => 'fee_urgent', 'fee_extra' => 'fee_extra', 'fee_total' => 'fee_total', 'pay_send' => 'pay_send', 'pay_receive' => 'pay_receive', 'is_checked' => 'is_checked', 'no_driving_lisence' => 'no_driving_lisence', 'start_km' => 'start_km', 'not_insurance' => 'not_insurance'];
foreach ($cols as $col => $key) {
if (isset($post[$key]) && $post[$key] != '') {
$data[$col] = (int)$post[$key];
}
// $data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
//图片组处理
$cols = ['thumbs' => 'thumbs'];
foreach ($cols as $col => $key) {
if (isset($post[$key]) && !empty($post[$key])) {
$imgs = $post[$key]; //数组格式
$imgs = array_unique($imgs);
$imgs = json_encode($imgs);
$data[$col] = $imgs;
}
}
$cols = ['remark' => 'editor'];
foreach ($cols as $col => $key) {
if (isset($post[$key]) && $post[$key] != '') {
$data[$col] = htmlspecialchars($post[$key]);
}
// $data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
}
$sign_date = isset($post['sign_date']) ? strtotime($post['sign_date']) : '';
if (!$id) {
$data['create_by'] = Yii::$app->user->identity->id;
$data['sign_date'] = $sign_date ? $sign_date : time();
}
//部分规则校验
$has_err = FALSE;
$data['is_cwqr'] = 0; //修改财务确认状态为待确认
if (!$id) {
$data['status_code'] = 1;
}
/*不投保的,保额不超过20W,保费为0*/
if ($data['not_insurance']) {
if ($data['fee_insurance']) {
$data['fee_insurance'] = 0;
\Yii::$app->getSession()->setFlash('warning', '勾选了不投保,已强制修改保费为0!');
}
if ($data['car_value'] > Yii::$app->params['DefaultCarInsuranceValueMax']) {
$has_err = TRUE;
$data['car_value'] = Yii::$app->params['DefaultCarInsuranceValueMax'];
\Yii::$app->getSession()->setFlash('danger', '勾选了不投保,默认最高赠送的运输险保额不超过' . Yii::$app->params['DefaultCarInsuranceValueMax'] . '万元,已自动强制校正');
}
}
$fee_total = $data['fee_truck'] + $data['fee_insurance'] + $data['fee_deliver'] + $data['fee_pickup'] + $data['fee_urgent'] + $data['fee_extra'];
$fee_pay = $data['pay_send'] + $data['pay_receive'];
if (!$data['fee_truck']) {
$has_err = TRUE;
\Yii::$app->getSession()->setFlash('danger', '请注意,运费未正确填写!');
}
if (!$data['pay_send'] && !$data['pay_receive']) {
$has_err = TRUE;
\Yii::$app->getSession()->setFlash('danger', '请注意,到收运费及起运地预收运费均未填写!');
}
if ($fee_total != $data['fee_total']) {
$has_err = TRUE;
\Yii::$app->getSession()->setFlash('danger', '请注意,所填运费、保费、提车费、送车费、额外费用、加急费等各项费用汇总的值与所填写的总费用不一致,请检查并更新');
}
if ($fee_pay != $data['fee_total']) {
$has_err = TRUE;
\Yii::$app->getSession()->setFlash('danger', '请注意,所填起运地预付运费、到收运费的汇总值与所填写的总费用不一致,请检查并更新');
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$model = new AcEmployee();
$employee = $model->findOne($data['employee_id']);
if ($employee) {
$data['store_id'] = $employee->store_id;
}
//保存资料
if ($id) {
unset($data['create_at']);
$res = $AcOrder->updateAll($data, ['id' => $id]);
} else {
foreach ($data as $key => $val) {
$AcOrder->$key = $val;
}
$res = $AcOrder->save();
$id = $AcOrder->attributes['id']; //获取插入后id
}
if ($res) {
if ($has_err) {
\Yii::$app->getSession()->setFlash('success', '订单保存成功,但有价格数据录入错误,请根据情况检查更新!');
} else {
\Yii::$app->getSession()->setFlash('success', '订单保存成功!');
}
return $this->redirect(['edit', 'id' => $id]);
} else {
\Yii::$app->getSession()->setFlash('warning', '订单保存失败!');
return $this->goBack();
}
}
}