ADD:添加后台管理端接口;
DEL:删除不必要的头部注释; FIX:修正若干已知错误;
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:29:34+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:16+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
@@ -21,51 +14,189 @@
|
||||
|
||||
class CarController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list'=>'车辆列表',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统车辆管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//车辆列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$AcCar = new AcCar();
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '车辆查询成功!';
|
||||
$return['data']= [
|
||||
'total'=>$s['query']->count(),
|
||||
'cars' => $res,
|
||||
'series' => $s['series'],
|
||||
'brands' => $s['brands'],
|
||||
'owners' => $s['owners'],
|
||||
'users' => $s['users'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcCar();
|
||||
$res = $model->findOne($id)->toArray();
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
$car = $this->showCar($res);
|
||||
$this->result('车辆信息查询完成', $car, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcCar();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑客车资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除车辆
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '车型数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '车型数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '车型隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '车型隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '车型显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '车型显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcCar();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'cars::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
// }elseif($session->get($searchSession)){
|
||||
// $search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'car_no', $search['title']];
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
$where2[] = ['LIKE', 'num_frame', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$search['series_id'] = isset($search['series_id']) ? (int)$search['series_id'] : 0;
|
||||
if (!empty($search['series_id'])) {
|
||||
$where['series_id'] = $search['series_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcCar->find()->where($where);
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
|
||||
|
||||
$oids = $mids = $bids = $sids = [];
|
||||
@@ -77,7 +208,6 @@
|
||||
$sids[] = $r->series_id;
|
||||
}
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
@@ -135,337 +265,86 @@
|
||||
$brands[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$cars = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$car = $r->toArray();
|
||||
$t = '';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $brands[$r->brand_id]['title'];
|
||||
}
|
||||
$t .= '-';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $series[$r->series_id]['title'];
|
||||
}
|
||||
$car['title2'] = $t;
|
||||
$car['numbers'] = $car['num_p'] . $car['num_area'] . $car['num_left'];
|
||||
$car['numbers'] = $car['numbers'] ? $car['numbers'] : $car['num_frame'];
|
||||
$car['numbers'] = $car['num_p'] ? $car['numbers'] : $car['num_frame'];
|
||||
$cars[$r->id] = $car;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'cars' => $cars,
|
||||
'pager' => $pages,
|
||||
'owners' => $owners,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
return ['res'=>$cars,'query'=>$data,'owners'=>$owners,'users'=>$users,'brands'=>$brands,'series'=>$series];
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$AcCar = new AcCar();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'cars::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
// }elseif($session->get($searchSession)){
|
||||
// $search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
$where2[] = ['LIKE', 'num_frame', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcCar->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andWhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby(' id DESC')->all();
|
||||
|
||||
$oids = $mids = $bids = $sids = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$oids[] = $r->owner_id;
|
||||
$mids[] = $r->mid;
|
||||
$bids[] = $r->brand_id;
|
||||
$sids[] = $r->series_id;
|
||||
}
|
||||
}
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$_owners = $AcCarOwner->find()->where($where)->andwhere(['in', 'id', $oids])->all();
|
||||
$owners = [];
|
||||
foreach ($_owners as $s) {
|
||||
$owners[$s->id] = $s->toArray();
|
||||
}
|
||||
$User = new User();
|
||||
$where = [];
|
||||
$_users = $User->find()->where($where)->andwhere(['in', 'id', $mids])->all();
|
||||
$users = [];
|
||||
foreach ($_users as $s) {
|
||||
$users[$s->id] = $s->toArray();
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExts = $AcUserExt->find()->where(['pid' => $pid, 'deleted' => 0])->andWhere(['in', 'mid', $mids])->all();
|
||||
$exts = [];
|
||||
if ($userExts) {
|
||||
foreach ($userExts as $v) {
|
||||
$exts[$v->mid][$v->key] = $v->value;
|
||||
}
|
||||
foreach ($exts as $i => $ext) {
|
||||
$_owner = $users[$i] ? $users[$i] : [];
|
||||
if ($ext['title']) {
|
||||
$_owner['owner_title'] = $ext['title'];
|
||||
}
|
||||
if ($ext['nickname']) {
|
||||
$_owner['owner_title'] = $ext['nickname'];
|
||||
}
|
||||
if ($ext['realname']) {
|
||||
$_owner['owner_title'] = $ext['realname'];
|
||||
}
|
||||
$users[$i]['username'] = $_owner['owner_title'] . '【' . $users[$i]['mobile'] . '】';
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$where = [];
|
||||
$series = [];
|
||||
$_series = $AcCarSeries->find()->where($where)->andwhere(['in', 'id', $sids])->all();
|
||||
if ($_series) {
|
||||
foreach ($_series as $r) {
|
||||
$series[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$where = [];
|
||||
$_brands = $AcCarBrand->find()->where($where)->andwhere(['in', 'id', $bids])->all();
|
||||
if ($_brands) {
|
||||
foreach ($_brands as $r) {
|
||||
$brands[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
$cars = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$car = $r->toArray();
|
||||
$t = '';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $brands[$r->brand_id]['title'];
|
||||
}
|
||||
$t .= '-';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $series[$r->series_id]['title'];
|
||||
}
|
||||
$car['title2'] = $t;
|
||||
$car['numbers'] = $car['num_p'] . $car['num_area'] . $car['num_left'];
|
||||
$car['numbers'] = $car['numbers'] ? $car['numbers'] : $car['num_frame'];
|
||||
$cars[$r->id] = $car;
|
||||
}
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truck';
|
||||
return $this->render('select', [
|
||||
'cars' => $cars,
|
||||
'pager' => $pages,
|
||||
'owners' => $owners,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCar = new AcCar();
|
||||
$AcCar->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCar]);
|
||||
}
|
||||
|
||||
//编辑客车资料
|
||||
public function actionEdit()
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保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 AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->find()->where(['id' => $res['owner_id']])->one();
|
||||
if ($owner) {
|
||||
$mid = $owner->mid;
|
||||
$User = new User();
|
||||
$user = $User->find()->where(['id' => $mid])->one();
|
||||
if ($user) {
|
||||
$res['owner_title'] = $user->username . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExt = $AcUserExt->find()->where(['pid' => $pid, 'mid' => $res['mid'], 'deleted' => 0])->all();
|
||||
$exts = [];
|
||||
if ($userExt) {
|
||||
foreach ($userExt as $v) {
|
||||
$exts[$v->key] = $v->value;
|
||||
}
|
||||
if ($exts['title']) {
|
||||
$res['owner_title'] = $exts['title'];
|
||||
}
|
||||
if ($exts['nickname']) {
|
||||
$res['owner_title'] = $exts['nickname'];
|
||||
}
|
||||
if ($exts['realname']) {
|
||||
$res['owner_title'] = $exts['realname'];
|
||||
}
|
||||
$res['owner_title'] = $res['owner_title'] . '【' . $user->mobile . '】';
|
||||
}
|
||||
}
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
//复制客车资料后新建
|
||||
public function actionCopy()
|
||||
{
|
||||
$model = new AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$res['id'] = 0;
|
||||
$res['num_p'] = $res['num_area'] = $res['num_left'] = $res['num_frame'] = '';
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//浏览客车详情
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->find()->where(['id' => $res['owner_id']])->one();
|
||||
$User = new User();
|
||||
$user = $User->find()->where(['id' => $res['mid']])->one();
|
||||
if ($user) {
|
||||
$res['owner_title'] = $user->username . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExt = $AcUserExt->find()->where(['pid' => $pid, 'mid' => $res['mid'], 'deleted' => 0])->all();
|
||||
$exts = [];
|
||||
if ($userExt) {
|
||||
foreach ($userExt as $v) {
|
||||
$exts[$v->key] = $v->value;
|
||||
}
|
||||
if ($exts['title']) {
|
||||
$res['owner_title'] = $exts['title'];
|
||||
}
|
||||
if ($exts['nickname']) {
|
||||
$res['owner_title'] = $exts['nickname'];
|
||||
}
|
||||
if ($exts['realname']) {
|
||||
$res['owner_title'] = $exts['realname'];
|
||||
}
|
||||
$res['owner_title'] = $res['owner_title'] . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('detail', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//保存车辆资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$car_no = trim($post['car_no']) ?? '';//车牌号
|
||||
$num_frame = trim($post['num_frame']) ?? '';//车架号
|
||||
if(!$car_no && !$num_frame) $this->result('请传入车牌/架号');
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['title' => 'title', 'num_frame' => 'num_frame', 'num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left'];
|
||||
$cols = ['title' => 'title', 'num_frame' => 'num_frame', 'num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left','car_no'=>'car_no'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询车牌号是否在库
|
||||
$hasCar = FALSE;
|
||||
if (!$data['num_frame']) {
|
||||
$hasCar = AcCar::find()->where(['num_p' => $data['num_p'], 'num_area' => $data['num_area'], 'num_left' => $data['num_left']])->one();
|
||||
}
|
||||
|
||||
if ($hasCar) {
|
||||
if ($id && $id != $hasCar->id) {
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该车牌号已在库!');
|
||||
return $this->goBack();
|
||||
} else {
|
||||
$id = $hasCar->id;
|
||||
}
|
||||
$model = new AcCar();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
if(!$num_frame){
|
||||
$error = "车牌号已存在";
|
||||
$hasOne = $model->find()->where(['deleted'=>0,'pid'=>$this->pid,'car_no'=>$car_no])->one();
|
||||
}else{
|
||||
$error = "车架/牌号已存在";
|
||||
$hasOne = $model->find()->where(['deleted'=>0,'pid'=>$this->pid])->andWhere(['OR',['LIKE', 'car_no', $car_no],['LIKE', 'num_frame', $num_frame]])->one();
|
||||
}
|
||||
if ($hasOne) {
|
||||
$this->result($error);
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$hasOne = $model->find()->select('id')->where(['car_no'=>$car_no,'id'<>$id,'pid'=>$this->pid,'deleted'=>0])->indexBy('id')->one();
|
||||
if ($hasOne) {
|
||||
$this->result('车牌号重复,请检查');
|
||||
}
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['brand_id' => 'brand_id', 'series_id' => 'series_id', 'owner_id' => 'owner_id', 'status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
@@ -474,131 +353,55 @@
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
// $data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//填补mid参数
|
||||
if($data['owner_id']){
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->findOne($data['owner_id']);
|
||||
if ($owner) {
|
||||
$data['mid'] = $owner->mid;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//格式化显示车辆信息 @car 车辆信息原始数据 []
|
||||
private function showCar($car){
|
||||
$oid = $car['owner_id'];
|
||||
$mid = $car['mid'];
|
||||
$bid = $car['brand_id'];
|
||||
$sid = $car['series_id'];
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->findOne($sid);
|
||||
$car['series'] = $series;
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->findOne($bid);
|
||||
$car['brand'] = $brand;
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->findOne($data['owner_id']);
|
||||
if ($owner) {
|
||||
$data['mid'] = $owner->mid;
|
||||
}
|
||||
$owner = $AcCarOwner->findOne($oid);
|
||||
$car['owner'] = $owner;
|
||||
|
||||
//保存车辆资料
|
||||
$AcCar = new AcCar();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCar->$key = $val;
|
||||
$CUser = new User();
|
||||
$user = $CUser->findOne($mid)->toArray();
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExts = $AcUserExt->find()->where(['pid' => $this->pid, 'deleted' => 0,'mid'=>$mid])->all();
|
||||
$ext = [];
|
||||
foreach ($userExts as $v) {
|
||||
$ext[$v->key] = $v->value;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcCar->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCar->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCar->save();
|
||||
$id = $AcCar->attributes['id']; //获取插入后id
|
||||
if ($ext['title']) {
|
||||
$user['owner_title'] = $ext['title'];
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车辆资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车辆资料保存失败!');
|
||||
return $this->goBack();
|
||||
if ($ext['nickname']) {
|
||||
$user['owner_title'] = $ext['nickname'];
|
||||
}
|
||||
}
|
||||
|
||||
//删除车辆
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcCar();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
if ($ext['realname']) {
|
||||
$user['owner_title'] = $ext['realname'];
|
||||
}
|
||||
$car['user'] = $user;
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('car/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '车辆删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCar();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
// $return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '车辆数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '车辆隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆显示记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '车辆显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$car['numbers'] = $car['num_p'] . $car['num_area'] . $car['num_left'];
|
||||
$car['numbers'] = $car['num_p'] ? $car['numbers'] : $car['num_frame'];
|
||||
return $car;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,266 +1,248 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:28:54+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:11+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCarBrand;
|
||||
|
||||
class CarbrandController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list'=>'品牌列表',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统车辆品牌管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//车品牌列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$model = new AcCarBrand();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$brands = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'brands' => $brands,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '车辆品牌查询成功!';
|
||||
$return['data']= [
|
||||
'total'=>$s['query']->count(),
|
||||
'brands' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
|
||||
//车品牌列表
|
||||
public function actionSelect()
|
||||
//品牌详情
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcCarBrand();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$brands = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'car';
|
||||
return $this->render('select', [
|
||||
'brands' => $brands,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$res = $model->findOne($id)->toArray();
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
$this->result('品牌信息查询完成', $res, 200);
|
||||
}
|
||||
|
||||
//新增车品牌
|
||||
public function actionNew()
|
||||
public function actionAdd()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$AcCarBrand->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCarBrand->toArray()]);
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//格式化数据 为空的项则不修改
|
||||
$data['title'] = trim($post['title']);
|
||||
if(!$data['title']) $this->result('请传入品牌名称');
|
||||
$data['status_code'] = 1; //状态代码:1可用
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
|
||||
//数据预检查
|
||||
$res = $this->preSave($data,'add');
|
||||
if(!$res) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcCarBrand();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//更新车品牌
|
||||
public function actionEdit()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$model = new AcCarBrand();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', [
|
||||
'detail' => $res,
|
||||
'status' => $status,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
//保存车品牌资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$detail = $this->preUpdate();
|
||||
$post = $this->postdata;
|
||||
|
||||
//格式化数据
|
||||
$data = [];
|
||||
//格式化数据
|
||||
$data['title'] = trim($post['title']);
|
||||
if(!$data['title']) $this->result('请传入品牌名称');
|
||||
//目标键=》POST键
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//格式化资料
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCarBrand->$key = $val;
|
||||
}
|
||||
|
||||
//资料入库
|
||||
if ($id) {
|
||||
$AcCarBrand->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCarBrand->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCarBrand->save();
|
||||
$id = $AcCarBrand->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车主资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车主资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
$data['update_at'] = time();
|
||||
//数据预检查
|
||||
$res = $this->preSave($data,'edit');
|
||||
if(!$res) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '品牌数据更新失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '品牌数据更新成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除用户
|
||||
public function actionDelete($id)
|
||||
//删除
|
||||
public function actionDelete()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
$model = new AcCarBrand();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '品牌数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('carbrand/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$msg = '品牌数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCarBrand();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '品牌数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '品牌隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
$msg = '品牌隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '品牌隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '品牌隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '品牌显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
$msg = '品牌显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '品牌显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '品牌显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcCarBrand();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
// $where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$brands = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
return ['res'=>$brands,'query'=>$data];
|
||||
}
|
||||
|
||||
//数据更新前的预检查,返回对应关联数据
|
||||
private function preUpdate()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$post = $this->postdata;
|
||||
if($post['id'] != $id) $this->result('传参与请求数据不匹配',[],403);
|
||||
$model = new AcCarBrand();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* @data,要保存的数据[]
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验结果,true,false
|
||||
* */
|
||||
private function preSave($data,$op)
|
||||
{
|
||||
$title = trim($data['title']);
|
||||
$model = new AcCarBrand();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$hasOne = $model->find()->where(['title'=>$title])->one();
|
||||
if ($hasOne) {
|
||||
$this->result('品牌名称重复,请检查重录');
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)$data['id'];
|
||||
$origin = $model->findOne($id);
|
||||
if(!$origin) $this->result('指定id('.$id.')的数据不存在,请检查');
|
||||
$hasOne = $model->find()->select('id')->where(['title'=>$title,'id'<>$id])->indexBy('id')->one();
|
||||
if ($hasOne) {
|
||||
$this->result('品牌名称重复,请检查重录');
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,9 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:30:22+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:27+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
|
||||
@@ -20,320 +12,271 @@
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list'=>'车型列表',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统品牌车型管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//车型列表
|
||||
public function actionList()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$model = new AcCarSeries();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where2[] = ['in', 'pid', [0, $pid]];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'carseries::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
$series = $bids = [];
|
||||
foreach ($res as $r) {
|
||||
$r = $r->toArray();
|
||||
$series[$r['id']] = $r;
|
||||
$bids[] = $r['brand_id'];
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brands = [];
|
||||
$_brands = $AcCarBrand->find()->where(['in', 'id', $bids])->indexBy('id')->all();
|
||||
foreach ($_brands as $s) {
|
||||
$brands[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'series' => $series,
|
||||
'pager' => $pages,
|
||||
'brands' => $brands,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '车型查询成功!';
|
||||
$return['data']= [
|
||||
'total'=>$s['query']->count(),
|
||||
'series' => $res,
|
||||
'brands' => $s['brands'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
|
||||
//车型列表
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcCarSeries();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where2[] = ['in', 'pid', [0, $pid]];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'carseries::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
// $search['brand'] = isset($search['brand']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
$series = $bids = [];
|
||||
foreach ($res as $r) {
|
||||
$r = $r->toArray();
|
||||
$series[$r['id']] = $r;
|
||||
$bids[$r['brand_id']] = $r['brand_id'];
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brands = [];
|
||||
$_brands = $AcCarBrand->find()->where(['in', 'id', $bids])->indexBy('id')->all();
|
||||
foreach ($_brands as $s) {
|
||||
$brands[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'car';
|
||||
return $this->render('select', [
|
||||
'series' => $series,
|
||||
'pager' => $pages,
|
||||
'brands' => $brands,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$res = $model->findOne($id)->toArray();
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
$this->result('车型信息查询完成', $res, 200);
|
||||
}
|
||||
|
||||
//新增车型
|
||||
public function actionNew()
|
||||
public function actionAdd()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$AcCarSeries->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCarSeries->toArray()]);
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//格式化数据 为空的项则不修改
|
||||
$data['title'] = trim($post['title']);
|
||||
if(!$data['title']) $this->result('请传入车型名称');
|
||||
$data['brand_id'] = (int)$post['brand_id'];
|
||||
if(!$data['brand_id']) $this->result('请传入所属品牌');
|
||||
|
||||
$data['params'] = $post['params'] ?? [];
|
||||
$data['status_code'] = 1; //状态代码:1可用
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave($data,'add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcCarSeries();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//更新车型
|
||||
public function actionEdit()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$model = new AcCarSeries();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$parmas = [];
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
$parmas = json_decode($res['params'], TRUE);
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
$detail = $this->preUpdate();
|
||||
$post = $this->postdata;
|
||||
|
||||
//查询对应的品牌
|
||||
$brand = AcCarBrand::find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
|
||||
return $this->render('modify', [
|
||||
'detail' => $res,
|
||||
'params' => $parmas,
|
||||
'status' => $status,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
//保存车型资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
$data = [];
|
||||
$data['title'] = trim($post['title']);
|
||||
//目标键=》POST键
|
||||
$cols = ['brand_id' => 'brand_id', 'status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$params = $post['p'];
|
||||
$cols = ['height', 'length', 'width', 'kg', 'seat'];
|
||||
foreach ($cols as $col) {
|
||||
$params[$col] = isset($params[$col]) ? (int)$params[$col] : 0;
|
||||
}
|
||||
$data['params'] = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
//格式化数据 为空的项则不修改
|
||||
$data['title'] = trim($post['title']);
|
||||
if(!$data['title']) $this->result('请传入车型名称');
|
||||
$data['brand_id'] = (int)$post['brand_id'];
|
||||
if(!$data['brand_id']) $this->result('请传入所属品牌');
|
||||
|
||||
//格式化车型资料
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCarSeries->$key = $val;
|
||||
}
|
||||
$data['params'] = $post['params'] ?? [];
|
||||
$data['status_code'] = 1; //状态代码:1可用
|
||||
$data['update_at'] = time();
|
||||
$data = $this->preSave($data,'edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//车型资料入库
|
||||
if ($id) {
|
||||
$AcCarSeries->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCarSeries->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCarSeries->save();
|
||||
$id = $AcCarSeries->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车型资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车型资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '车型数据更新失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '车型数据更新成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除车型
|
||||
public function actionDelete($id)
|
||||
public function actionDelete()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
$model = new AcCarSeries();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '车型数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('carowner/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$msg = '车型数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCarSeries();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '车型数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '车型隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
$msg = '车型隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '车型隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '车型隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '车型显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
$msg = '车型显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '车型显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '车型显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcCarSeries();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
// $where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
|
||||
$series = $bids = [];
|
||||
foreach ($res as &$s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brands = [];
|
||||
$_brands = $AcCarBrand->find()->where(['in', 'id', $bids])->indexBy('id')->all();
|
||||
unset($s);
|
||||
foreach ($_brands as $s) {
|
||||
$brands[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return ['res'=>$res,'query'=>$data,'brands'=>$brands];
|
||||
}
|
||||
|
||||
//数据更新前的预检查,返回对应关联数据
|
||||
private function preUpdate()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$post = $this->postdata;
|
||||
if($post['id'] != $id) $this->result('传参与请求数据不匹配',[],403);
|
||||
$model = new AcCarSeries();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* @data,要保存的数据[]
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的data
|
||||
* */
|
||||
private function preSave($data,$op)
|
||||
{
|
||||
$title = trim($data['title']);
|
||||
$id = 0;
|
||||
$model = new AcCarBrand();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$hasOne = $model->find()->where(['title'=>$title])->one();
|
||||
if ($hasOne) {
|
||||
$this->result('品牌名称重复,请检查重录');
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)$data['id'];
|
||||
$origin = $model->findOne($id);
|
||||
if(!$origin) $this->result('指定id('.$id.')的数据不存在,请检查');
|
||||
$hasOne = $model->find()->select('id')->where(['title'=>$title,'id'<>$id])->indexBy('id')->one();
|
||||
if ($hasOne) {
|
||||
$this->result('品牌名称重复,请检查重录');
|
||||
}
|
||||
break;
|
||||
}
|
||||
//处理车型相关参数(数组内检查完成后,转json)
|
||||
$params = $data['params'];
|
||||
$arr = ['length','width','height','kg'];
|
||||
foreach ($arr as $v) {
|
||||
$params[$v] = isset($params[$v]) ? (int)$params[$v] : 0;
|
||||
}
|
||||
$arr = ['gas'=>'汽油','diesel'=>'柴油','e-power'=>'纯电','hybrid'=>'混动'];
|
||||
$arr_keys = array_keys($arr);
|
||||
//设置默认能源类型为 汽油
|
||||
$energy = $params['energy'] ?? '';
|
||||
if(!empty($energy) && array_key_exists($energy,$arr_keys)){
|
||||
$params['energy'] = $energy;
|
||||
}else{
|
||||
$params['energy'] = 'gas';
|
||||
}
|
||||
$data['params'] = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,51 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:30:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:33+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
|
||||
// use backend\models\Citys;
|
||||
|
||||
class CityController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list'=>'城市列表',
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统车主管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '查询成功!';
|
||||
$return['data']= [
|
||||
'total'=>count($res),
|
||||
'citys' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$pager = new Pagination(['totalCount' => count($citys), 'pageSize' => '100']);
|
||||
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'city';
|
||||
$search = [];
|
||||
return $this->render('select', [
|
||||
'citys' => $citys,
|
||||
'pager' => $pager,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
|
||||
return ['res'=>$citys];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-15 20:22:03
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-07-08T16:02:30+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
//平台用户入口
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
@@ -16,6 +10,8 @@
|
||||
use addons\models\AcUserExt;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcPlat;
|
||||
use common\models\CVcode;
|
||||
|
||||
class Common extends Controller
|
||||
{
|
||||
@@ -91,7 +87,7 @@
|
||||
$this->pageSize = $pageSize <= 0 ? 10 : $pageSize;
|
||||
}
|
||||
|
||||
public function result($msg, $data = NULL, $code = 0)
|
||||
public function result($msg, $data = [], $code = 0)
|
||||
{
|
||||
$return = [];
|
||||
$return['code'] = $code;
|
||||
@@ -118,4 +114,77 @@
|
||||
$user['tokenExpired'] = $tokenExpired;
|
||||
return $user;
|
||||
}
|
||||
|
||||
/*用户权限获取判断
|
||||
@user 用户信息(model原型)
|
||||
@auth 要授权的行为动作
|
||||
@data 要操作的数据
|
||||
*/
|
||||
public function userPrivilege($user,$auth,$data)
|
||||
{
|
||||
//TD:待明确更多用户权限角色的配置、获取
|
||||
switch ($auth) {
|
||||
case 'feeEdit':
|
||||
case 'feeOrderEdit':
|
||||
case 'feeDriverEdit':
|
||||
//允许本人操作该员工创建或被关联的运单、数据
|
||||
if($user->id == $data->create_by) return true;
|
||||
//允许超管操作
|
||||
if($user->id == 1) return true;
|
||||
return false;
|
||||
break;
|
||||
case 'orderPreEdit':
|
||||
case 'orderEdit':
|
||||
case 'orderPreDelete':
|
||||
default:
|
||||
//允许员工本人操作该员工创建或被关联的运单、数据
|
||||
if($user->id == $data->from_mid) return true;
|
||||
if($data->employee_id == $this->employee_id) return true;
|
||||
|
||||
//允许超管操作
|
||||
if($user->id == 1) return true;
|
||||
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SN格式化处理(ID转SN)
|
||||
* */
|
||||
public function idToSn($id,$type){
|
||||
switch ($type) {
|
||||
case 'order':
|
||||
$pre = 'YD';
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
break;
|
||||
}
|
||||
return $pre.$sn;
|
||||
}
|
||||
|
||||
//校验财务验证码
|
||||
public function vcodeCwCheck($vcode){
|
||||
$plat = AcPlat::findOne($this->pid);
|
||||
$platExt = json_decode($plat->remark, TRUE);
|
||||
if(!isset($platExt['cw_phone'])) return ['res'=>false,'err'=>'平台尚未配置财务手机号','code'=>1];
|
||||
|
||||
$vcodeModel = new CVcode();
|
||||
$_time = time();
|
||||
//查询上次发送记录
|
||||
$where = [];
|
||||
$where['mobile'] = $platExt['cw_phone'];
|
||||
$where['deleted'] = 0;
|
||||
$where['type'] = 'caiwu';
|
||||
$res = $vcodeModel->find()->where($where)->orderby('id DESC')->one();
|
||||
if(!$res) return ['res'=>false,'err'=>'没有验证码发送记录','code'=>2];
|
||||
if ($vcode != $res->code) {
|
||||
return ['res'=>false,'err'=>'财务操作验证码校验失败,请检查并重新输入验证码!','code'=>3];
|
||||
}
|
||||
if (($_time - $res->create_at) > 7200) {
|
||||
return ['res'=>false,'err'=>'验证码已超时,请重新获取后再填写提交!','code'=>4];
|
||||
}
|
||||
return ['res'=>true,'err'=>'','code'=>0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,278 +1,263 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:33+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:44+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcContact;
|
||||
use common\models\Member as User;
|
||||
use common\models\UserExt;
|
||||
|
||||
class ContactController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
$apis = [
|
||||
'list'=>'联系人列表',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统联系人管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//通讯录列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcContact();
|
||||
$where = $where2 = [];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'contact::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'contactors' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '联系人查询成功!';
|
||||
$return['data']= [
|
||||
'total'=>$s['query']->count(),
|
||||
'contactors' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcContact();
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'contact::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'contactor';
|
||||
return $this->render('select', [
|
||||
'contactors' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$res = $model->findOne($id)->toArray();
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
$this->result('车主信息查询完成', $res, 200);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
public function actionAdd()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcContact();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑通讯录资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcContact();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
//保存通讯录资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['company' => 'company', 'name' => 'name', 'mobile' => 'mobile', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询通讯录手机号是否在库
|
||||
$hasContactor = AcContact::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($hasContactor) {
|
||||
if ($id && $id == $hasContactor->id) {
|
||||
} else {
|
||||
$id = $hasContactor->id;
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该手机号对应的通讯录已在库,系统自动现在为您调出该通讯录资料!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存通讯录资料
|
||||
$AcContact = new AcContact();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcContact->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcContact->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcContact->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcContact->save();
|
||||
$id = $AcContact->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '通讯录信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '通讯录信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
$model = new AcContact();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '通讯录数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('contact/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '通讯录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$msg = '通讯录数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcContact();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '通讯录数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
case 'hide':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
$msg = '通讯录隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '通讯录隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '通讯录隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
case 'show':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
$msg = '通讯录显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '通讯录显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '通讯录显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcContact();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
|
||||
$search['company'] = isset($search['company']) ? trim(htmlspecialchars_decode($search['company'])) : '';
|
||||
if(!empty($search['company'])){
|
||||
$where2[] = 'and';
|
||||
$where2[] = ['like', 'company', $search['company']];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($where2) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$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 AcContact();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$name = trim($post['name']) ?? '';
|
||||
if(!$name) $this->result('请传入客户名称');
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['company' => 'company', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$model = new AcContact();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$mobile = trim($post['mobile']) ?? '';
|
||||
if(!$mobile) $this->result('请传入手机号');
|
||||
//查询通讯录手机号是否在库(如果在库,则取出相应资料,剩余逻辑由前端完成)
|
||||
$hasOne = AcContact::find()->where(['mobile' => $mobile])->one();
|
||||
if($hasOne){
|
||||
$detail = $hasOne->toArray();
|
||||
$this->result('保存失败,该手机号对应的通讯录已在库,系统自动现在为您调出该通讯录资料!',$detail,100);
|
||||
}
|
||||
$data['mobile'] = $mobile;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复通讯录
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,268 +1,279 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:09+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:49+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcDriver;
|
||||
use common\models\Member as User;
|
||||
use common\models\UserExt;
|
||||
|
||||
class DriverController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
$apis = [
|
||||
'list'=>'司机列表',
|
||||
'detail'=>'详情',
|
||||
'get-status'=>'状态字典',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统司机管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//司机列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcDriver();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['DriverStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'drivers' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'drivers' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('驾驶员查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcDriver();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['DriverStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'driver';
|
||||
return $this->render('select', [
|
||||
'drivers' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$res = $model->findOne($id)->toArray();
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
$this->result('驾驶员信息查询完成', $res, 200);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
public function actionGetStatus()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
$status = Yii::$app->params['DriverStatus'];
|
||||
$this->result('司机状态字典获取成功', $status, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcDriver();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
//驾驶员资料注册系统用户(驾驶员需要可以登陆指定客户端以进行业务操作)
|
||||
$this->driverToUser($data);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑司机资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcDriver();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
//保存司机资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['name' => 'name', 'mobile' => 'mobile', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询司机手机号是否在库
|
||||
$hasDriver = AcDriver::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($hasDriver) {
|
||||
if ($id && $id == $hasDriver->id) {
|
||||
} else {
|
||||
$id = $hasDriver->id;
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该手机号对应的司机已在库,系统自动现在为您调出该司机资料!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存司机资料
|
||||
$AcDriver = new AcDriver();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcDriver->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcDriver->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcDriver->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcDriver->save();
|
||||
$id = $AcDriver->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
//查询司机对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = $userModel->find()->where(['mobile' => $data['mobile']])->one();
|
||||
if (empty($user)) {
|
||||
$userModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
$user_id = $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('info', '已成功注册该用户!');
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '司机信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '司机信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
//驾驶员资料注册系统用户(驾驶员需要可以登陆指定客户端以进行业务操作)
|
||||
$this->driverToUser($data);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
$model = new AcDriver();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '驾驶员数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('driver/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '司机删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '司机删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$msg = '驾驶员数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcDriver();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '司机数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '司机离职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
$msg = '司机离职标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '司机离职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '司机离职标记失败';
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$return['msg'] = '司机在职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
$msg = '司机在职标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$return['msg'] = '司机在职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
$msg = '司机在职标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcDriver();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy('order_by DESC')->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$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 AcDriver();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$name = trim($post['name']) ?? '';
|
||||
if(!$name) $this->result('请传入司机姓名');
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
|
||||
$model = new AcDriver();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$mobile = trim($post['mobile']) ?? '';
|
||||
if(!$mobile) $this->result('请传入手机号');
|
||||
//查询通讯录手机号是否在库(如果在库,则取出相应资料,剩余逻辑由前端完成)
|
||||
$hasOne = AcDriver::find()->where(['mobile' => $mobile])->one();
|
||||
if($hasOne){
|
||||
$detail = $hasOne->toArray();
|
||||
$this->result('保存失败,该手机号对应的驾驶员已在库,系统自动现在为您调出该司机资料!',$detail,100);
|
||||
}
|
||||
$data['mobile'] = $mobile;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//驾驶员资料注册系统会员
|
||||
private function driverToUser($data){
|
||||
//查询司机对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = $userModel->find()->where(['mobile' => $data['mobile']])->one();
|
||||
if($user) return $user->id;
|
||||
$userModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
return $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,147 +1,277 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:34:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:55+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcStore;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
use function addons\functions\isMobile;
|
||||
|
||||
class EmployeeController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
$apis = [
|
||||
'list' => '员工清单',
|
||||
'detail' => '员工详情',
|
||||
'get-status'=>'状态字典',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统员工管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionGetStatus()
|
||||
{
|
||||
$status = Yii::$app->params['EmployeeStatus'];
|
||||
$this->result('员工状态字典获取成功', $status, 200);
|
||||
}
|
||||
|
||||
//用户列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['EmployeeStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
return $this->render('list', [
|
||||
'employees' => $res,
|
||||
'pager' => $pages,
|
||||
'stores' => $stores,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search
|
||||
]);
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'employees' => $res,
|
||||
'stores' => $s['stores'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('员工查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['EmployeeStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'employee';
|
||||
return $this->render('select', [
|
||||
'employees' => $res,
|
||||
'pager' => $pages,
|
||||
'stores' => $stores,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$model = new AcEmployee();
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
public function actionAdd()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcEmployee();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
//员工资料注册系统用户
|
||||
$this->EmployeeToUser($data);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑员工资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
|
||||
if ($store) {
|
||||
$res['store_title'] = $store->title;
|
||||
}
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
//员工资料注册系统用户
|
||||
$this->EmployeeToUser($data);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//保存员工资料
|
||||
public function actionSave()
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '员工数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '员工数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '员工离职标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '员工离职标记失败';
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '员工在职标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '员工在职标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcEmployee();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
$where2[] = ['LIKE', 'adminer', $search['title']];
|
||||
}
|
||||
$store_id = isset($search['store_id']) ? (int)$search['store_id'] : 0;
|
||||
if ($store_id) $where['store_id'] = $store_id;
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$_orderby = 'orderby DESC,update_at DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy($_orderby)->all();
|
||||
$AcStore = new AcStore();
|
||||
$sids = [];
|
||||
if($res){
|
||||
foreach ($res as $k=>$v){
|
||||
$sids[] = $v->store_id;
|
||||
}
|
||||
}
|
||||
$stores = [];
|
||||
if($sids){
|
||||
$stores = $AcStore->find()->where(['IN','id',$sids])->asArray()->indexBy('id')->all();
|
||||
}
|
||||
|
||||
return ['res'=>$res,'query'=>$data,'stores'=>$stores];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保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 AcEmployee();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$name = trim($post['name']) ?? '';
|
||||
if(!$name) $this->result('请传入员工姓名');
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['name' => 'name', 'mobile' => 'mobile'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
|
||||
$model = new AcEmployee();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$mobile = trim($post['mobile']) ?? '';
|
||||
if(!isMobile($mobile)) $this->result('请传入正确的手机号');
|
||||
//查询通讯录手机号是否在库(如果在库,则取出相应资料,剩余逻辑由前端完成)
|
||||
$hasOne = AcEmployee::find()->where(['mobile' => $mobile])->one();
|
||||
if($hasOne) $this->result('保存失败,该手机号对应的数据已在库!',$hasOne,100);
|
||||
$data['mobile'] = $mobile;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
$cols = ['gender' => 'gender', 'status' => 'status', 'store_id' => 'store', 'deleted' => 'deleted'];
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['status_code' => 'status_code', 'gender'=>'gender','status' => 'status', 'store_id' => 'store_id','deleted' => 'deleted','order_by'=>'order_by'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
@@ -149,147 +279,25 @@
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存员工资料
|
||||
$AcEmployee = new AcEmployee();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcEmployee->$key = $val;
|
||||
}
|
||||
|
||||
//查询员工手机号是否在库
|
||||
$employee = AcEmployee::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($employee) {
|
||||
$id = $employee->id;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcEmployee->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcEmployee->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcEmployee->save();
|
||||
$id = $AcEmployee->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
//查询员工对应的系统用户
|
||||
return $data;
|
||||
}
|
||||
|
||||
//员工资料注册系统会员
|
||||
private function EmployeeToUser($data){
|
||||
//查询对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if (empty($user)) {
|
||||
$userModel->username = $data['mobile'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
$user_id = $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('info', '已成功注册该用户!');
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '员工信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '员工信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcEmployee();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('employee/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '员工删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '员工删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcEmployee();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '员工数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '员工离职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '员工离职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '员工在职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '员工在职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$user = $userModel->find()->where(['mobile' => $data['mobile']])->one();
|
||||
if($user) return $user->id;
|
||||
$userModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
return $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,12 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-10T01:13:34+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:41+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
use yii\data\Pagination;
|
||||
use yii\web\UploadedFile;
|
||||
use common\models\CAttachment;
|
||||
use backend\controllers\Common;
|
||||
|
||||
class ImageController extends Common
|
||||
{
|
||||
@@ -30,29 +23,47 @@
|
||||
$apis = [
|
||||
'list' => '图片列表',
|
||||
];
|
||||
$this->result('您正使用CMTS系统订单管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统图库管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$siteId = Yii::$app->params['siteId'];
|
||||
$session = Yii::$app->session;
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
//附件网址前缀
|
||||
$src = Url::base(TRUE) . "/../../upload"; //在网站根目录下使用upload/pics目录;适合使用yii框架主目录入口而非绑定子域名的情形
|
||||
if ($_SERVER['DOCUMENT_ROOT'] . '/upload' != Yii::getAlias("@upload")) {
|
||||
// $src = Url::toRoute(['attach/index','img'=>'']); //换用网络加载转换的方式-反应慢
|
||||
$src = Yii::$app->params['attachSrc'] . Yii::$app->params['attachDir'];
|
||||
}
|
||||
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'images' => $res,
|
||||
'src' => $src,
|
||||
'page'=>$this->page
|
||||
];
|
||||
|
||||
$this->result('图片查询成功', $data, 200);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$siteId = Yii::$app->params['siteId'];
|
||||
$return = [];
|
||||
$model = new CAttachment();
|
||||
$search = $where = [];
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'status_code', 1];
|
||||
$where[] = ['=', 'type', 0];
|
||||
$where[] = ['=', 'siteid', $siteId];
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$post = $this->postdata;
|
||||
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set('images::search', $search);
|
||||
} else if ($session->get('images::search')) {
|
||||
$search = $session->get('images::search');
|
||||
}
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
if ($search) {
|
||||
if ($search['create_m']) {
|
||||
$start = strtotime($search['create_m']);
|
||||
@@ -76,26 +87,12 @@
|
||||
$where[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
}
|
||||
//分页
|
||||
$orderby = ['id' => SORT_DESC];
|
||||
$Attachment = new Attachment();
|
||||
$list = $Attachment->getData($model, $where, $orderby);
|
||||
$pager = $Attachment->getPagination();
|
||||
|
||||
//附件网址前缀
|
||||
$src = Url::base(TRUE) . "/../../upload"; //在网站根目录下使用upload/pics目录;适合使用yii框架主目录入口而非绑定子域名的情形
|
||||
if ($_SERVER['DOCUMENT_ROOT'] . '/upload' != Yii::getAlias("@upload")) {
|
||||
// $src = Url::toRoute(['attach/index','img'=>'']); //换用网络加载转换的方式-反应慢
|
||||
$src = Yii::$app->params['attachSrc'] . Yii::$app->params['attachDir'];
|
||||
}
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'thumb';
|
||||
$data = [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'src' => $src,
|
||||
'callback' => $callback
|
||||
];
|
||||
$this->result('', $data, 200);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$_orderby = 'id DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy($_orderby)->all();
|
||||
return ['res'=>$res,'query'=>$data];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-13T09:20:03+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:46+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
|
||||
//主入口页
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
@@ -46,7 +38,7 @@
|
||||
$apis = [
|
||||
'h5data' => '拉取APP首页数据',
|
||||
];
|
||||
$this->result('您正使用CMTS系统接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionH5data()
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:53+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:58+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
//前端管理员入口
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
@@ -30,7 +24,7 @@
|
||||
$apis = [
|
||||
'login' => '登陆'
|
||||
];
|
||||
$this->result('您正使用CMTS系统用户管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统用户管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//用户登陆
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,13 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-24T20:28:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:00:19+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcOrderPre;
|
||||
use addons\models\AcStore;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
|
||||
class OrderpreController extends Common
|
||||
{
|
||||
@@ -30,9 +24,17 @@
|
||||
$apis = [
|
||||
'list' => '搜索询单',
|
||||
'detail' => '询单详情',
|
||||
'create' => '创建询单'
|
||||
'get-status'=>'获取询价单状态字典',
|
||||
'add' => '创建询单',
|
||||
'edit'=>'编辑',
|
||||
'cancel'=>'取消',
|
||||
'delete'=>'删除',
|
||||
'ajax'=>[
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏'
|
||||
]
|
||||
];
|
||||
$this->result('您正使用CMTS系统询价单管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统询价单管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//订单列表
|
||||
@@ -43,56 +45,201 @@
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$_res = $this->showOrders($res);
|
||||
$data = $s['data'];
|
||||
$this->showOrder($res, $data);
|
||||
$return = [
|
||||
'total' => $data->count(),
|
||||
'orders' => $_res['orders'],
|
||||
'employees' => $_res['employees'],
|
||||
'stores' => $_res['stores'],
|
||||
'page' => $this->page
|
||||
];
|
||||
$this->result('订单查询成功',$return,200);
|
||||
}
|
||||
|
||||
private function search()
|
||||
public function actionDetail()
|
||||
{
|
||||
$order = $this->preUpdate();
|
||||
$detail = $this->showOrder($order);
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionGetStatus()
|
||||
{
|
||||
$status = Yii::$app->params['OrderPreStatus'];
|
||||
$this->result('查询成功!', $status, 200);
|
||||
}
|
||||
|
||||
public function actionCancel()
|
||||
{
|
||||
$order = $this->preUpdate();
|
||||
$res = $this->userPrivilege($this->user_info,'orderPreEdit',$order);
|
||||
if(!$res) $this->result('您没有操作权限!',[],403);
|
||||
|
||||
if ($order->status_code <= 0 || $order->status_code >= 99) {
|
||||
$this->result('订单已取消或已经完成,不允许操作!',[],403);
|
||||
}
|
||||
$order->status_code = -1;
|
||||
$order->save();
|
||||
$this->result('已取消!', $order, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
public function actionAdd()
|
||||
{
|
||||
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcOrderPre();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$res = $this->userPrivilege($this->user_info,'orderPreEdit',$detail);
|
||||
if(!$res) $this->result('您没有操作权限!',[],403);
|
||||
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除记录
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$res = $this->userPrivilege($this->user_info,'orderPreDelete',$detail);
|
||||
if(!$res) $this->result('您没有操作权限!',[],403);
|
||||
|
||||
if ($detail->deleted != 0) {
|
||||
$this->result('数据已被删除过,操作无效', [], 400);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '询单记录删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '询单记录删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$_time = time();
|
||||
$detail->update_at = $_time;
|
||||
$res = true;
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
if ($detail->status_code != 0) {
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
}
|
||||
if ($res) {
|
||||
$msg = '记录隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '记录隐藏标记失败';
|
||||
$errorCode = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg, [], $errorCode);
|
||||
}
|
||||
|
||||
/*onlyMe,预置搜索条件,仅查看本人运单*/
|
||||
private function search($onlyMe=false)
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcOrderPre();
|
||||
$where = $orwhere = [];
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
|
||||
$post = $this->postdata;
|
||||
$get = yii::$app->request->get();
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
//预置搜索条件,只允许查询与自己完全相关的订单
|
||||
$where[] = ['=', 'from_uid', $this->user_id];
|
||||
$search['phone'] = $this->user_info->mobile;
|
||||
$where[] = ['=', 'from_mobile', $search['phone']];
|
||||
|
||||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||||
$search['carno'] = trim($search['carno']);
|
||||
$where[] = ['LIKE', 'car_no', $search['carno']];
|
||||
if($onlyMe){
|
||||
//预置搜索条件,只允许查询与自己完全相关的订单
|
||||
$where[] = ['=', 'from_uid', $this->user_id];
|
||||
$search['phone'] = $this->user_info->mobile;
|
||||
}
|
||||
if (isset($search['phone']) && !empty($search['phone'])) {
|
||||
$search['phone'] = trim($search['phone']);
|
||||
$where[] = ['=', 'from_mobile', $search['phone']];
|
||||
}
|
||||
|
||||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||||
$search['carno'] = trim($search['carno']);
|
||||
$where[] = ['LIKE', 'car_no', $search['carno']];
|
||||
}
|
||||
|
||||
if (isset($search['city']) && !empty($search['city'])) {
|
||||
$search['city'] = trim($search['city']);
|
||||
$where[] = ['LIKE', 'aim_city', $search['city']];
|
||||
}
|
||||
|
||||
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : '';
|
||||
$EmployeeModel = new AcEmployee();
|
||||
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : 0;
|
||||
if (!empty($search['employee'])) {
|
||||
$where[] = ['=', 'employee_id', $search['employee']];
|
||||
$employee = $EmployeeModel->findOne($search['employee']);
|
||||
$search['employee_title'] = isset($employee->name) ? $employee->name : '';
|
||||
}
|
||||
$search['store_id'] = isset($search['store_id']) ? (int)$search['store_id'] : '';
|
||||
if (empty($search['sotre_id'])) {
|
||||
$search['store_id'] = isset($search['store_id']) ? (int)$search['store_id'] : 0;
|
||||
if (empty($search['store_id'])) {
|
||||
$search['store_id'] = isset($get['store_id']) ? (int)$get['store_id'] : 0;
|
||||
}
|
||||
$StoreModel = new AcStore();
|
||||
|
||||
if (!empty($search['store_id'])) {
|
||||
$where[] = ['=', 'store_id', $search['store_id']];
|
||||
$store = $StoreModel->findOne($search['store_id']);
|
||||
$search['store_title'] = isset($store->title) ? $store->title : '';
|
||||
}
|
||||
|
||||
$search['start_province'] = isset($search['start_province']) ? trim($search['start_province']) : '';
|
||||
@@ -119,28 +266,107 @@
|
||||
if (isset($search['status_code']) && $search['status_code'] != 'all') {
|
||||
$search['status_code'] = (int)$search['status_code'];
|
||||
$where[] = ['=', 'status_code', $search['status_code']];
|
||||
} else {
|
||||
unset($search['status_code']);
|
||||
}
|
||||
|
||||
$deleted = 0;
|
||||
$where[] = ['=', 'deleted', $deleted];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$data = $model->find()->where($where)->andwhere($orwhere);
|
||||
$data = $model->find()->where($where);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$_orderby = 'update_at DESC,id DESC';
|
||||
$_orderby = 'update_at DESC,date ASC,id DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||||
return ['res' => $res, 'data' => $data];
|
||||
}
|
||||
|
||||
private function showOrder($orderRes, $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 AcOrderPre();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
if($res->pid != $this->pid) $this->result('非本平台数据,不允许操作',[],401);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
$_time = time();
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['from_uid'] = $this->user_id;
|
||||
$data['status_code'] = 1; //订单处于创建待审核状态
|
||||
$data['create_at'] = $_time;
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = $_time;
|
||||
break;
|
||||
}
|
||||
$data['pid'] = $this->pid;
|
||||
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city',
|
||||
'car_title' => 'car_title', 'car_no' => 'car_no', 'price' => 'price',
|
||||
'bind' => 'bind', 'receptionist' => "receptionist",
|
||||
'from_name' => 'from_name', 'from_mobile' => 'from_mobile',
|
||||
];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['car_value' => 'car_value', 'from_gender' => 'from_gender','from_mid'=>'from_mid','status_code'=>'status_code'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
$data['employee_id'] = isset($post['employee_id']) ? (int)$post['employee_id'] : 0;
|
||||
$data['store_id'] = isset($post['store_id']) ? (int)$post['store_id'] : 0;
|
||||
|
||||
$cols = ['remark' => 'remark', 'car' => 'car'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/*@date: 1649952000000*/
|
||||
$data['date'] = isset($post['plan_date']) ? $post['plan_date'] / 1000 : strtotime('+7 day');
|
||||
// 计划时间,默认7天后
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
订单数据显示
|
||||
*/
|
||||
private function showOrders($orderRes)
|
||||
{
|
||||
$status = Yii::$app->params['OrderPreStatus'];
|
||||
|
||||
$cids = $sids = $eids = $mids = [];
|
||||
$sids = $eids = [];
|
||||
if ($orderRes) {
|
||||
foreach ($orderRes as $r) {
|
||||
$sids[$r->store_id] = $r->store_id;
|
||||
@@ -148,9 +374,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
|
||||
$model = new AcStore();
|
||||
$_stores = $model->find()->where(['in', 'id', $sids])->all();
|
||||
$stores = [];
|
||||
@@ -189,33 +412,13 @@
|
||||
}
|
||||
unset($s);
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '订单查询成功!';
|
||||
$return['data'] = [
|
||||
'total' => $data->count(),
|
||||
'orders' => $orders,
|
||||
'employees' => $employees,
|
||||
'stores' => $stores,
|
||||
'page' => $this->page
|
||||
];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
$data = ['orders'=>$orders,'employees'=>$employees,'stores'=>$stores];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
private function showOrder($order)
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
$order = $AcOrderPre->findOne($id);
|
||||
$detail = $order->toArray();
|
||||
|
||||
if ($detail['store_id']) {
|
||||
$model = new AcStore();
|
||||
$store = $model->findOne($detail['store_id']);
|
||||
@@ -233,8 +436,8 @@
|
||||
}
|
||||
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
$sn = substr($sn, 0, 11 - strlen($order->id));
|
||||
$sn .= $order->id;
|
||||
$detail['sn'] = $detail['sn'] ? $detail['sn'] : $sn;
|
||||
|
||||
$weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六'];
|
||||
@@ -247,172 +450,6 @@
|
||||
foreach ($unsets as $us) {
|
||||
unset($detail[$us]);
|
||||
}
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionCancel()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('未指定订单!');
|
||||
}
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
$order = $AcOrderPre->findOne($id);
|
||||
if ($order->from_uid != $this->user_id) {
|
||||
$this->result('非本人订单,不允许操作!');
|
||||
}
|
||||
if ($order->status_code <= 0 || $order->status_code >= 99) {
|
||||
$this->result('订单已取消或已经完成,不允许操作!');
|
||||
}
|
||||
$order->status_code = -1;
|
||||
$order->save();
|
||||
$this->result('已取消!', $order->toArray(), 200);
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
/**
|
||||
* 创建咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
$get = Yii::$app->request->get();
|
||||
$post = $this->postdata;
|
||||
$pid = $this->pid;
|
||||
|
||||
//格式化数据 为空的项则不修改
|
||||
$data['from_uid'] = $this->user_id;
|
||||
//目标键=》POST键
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city',
|
||||
'car_title' => 'car_title', 'car_no' => 'car_no', 'price' => 'price',
|
||||
'bind' => 'bind', 'receptionist' => "receptionist",
|
||||
'from_name' => 'from_name', 'from_mobile' => 'from_mobile',
|
||||
];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = trim($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['car_value' => 'car_value', 'from_gender' => 'from_gender'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = 0;
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['remark' => 'remark', 'car' => 'car'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/*@date: 1649952000000*/
|
||||
$data['date'] = isset($post['plan_date']) ? $post['plan_date'] / 1000 : strtotime('+7 day');
|
||||
// 计划时间,默认7天后
|
||||
|
||||
$mid = isset($post['mid']) ? (int)$post['mid'] : 0;
|
||||
$data['from_mid'] = $mid;
|
||||
|
||||
$data['status_code'] = 1; //订单处于创建待审核状态
|
||||
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
$data['employee_id'] = isset($post['employee_id']) ? (int)$post['employee_id'] : 0;
|
||||
$data['store_id'] = isset($post['store_id']) ? (int)$post['store_id'] : 0;
|
||||
|
||||
//保存资料
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcOrderPre->$key = $val;
|
||||
}
|
||||
|
||||
$res = $AcOrderPre->save();
|
||||
$id = $AcOrderPre->attributes['id']; //获取插入后id
|
||||
|
||||
if ($res) {
|
||||
$this->result('询单保存成功!', ['id' => $id], 200);
|
||||
} else {
|
||||
$this->result('询单保存失败!', [], 100);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
订单数据显示格式化
|
||||
*/
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
/**
|
||||
* 更新咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
$get = Yii::$app->request->get();
|
||||
$post = $this->postdata;
|
||||
$id = isset($post['id']) ? (int)$post['id'] : 0;
|
||||
if (!$id) {
|
||||
$this->result('未指定询价单!');
|
||||
}
|
||||
$model = new AcOrderPre();
|
||||
$detail = $model->findOne($id);
|
||||
if (!$detail) {
|
||||
$this->result('询价单信息不存在!');
|
||||
}
|
||||
if ($detail->pid != $this->pid) {
|
||||
$this->result('非法操作!');
|
||||
}
|
||||
if ($detail->from_uid != $this->user_id) {
|
||||
$this->result('非法操作,请检查订单归属!');
|
||||
}
|
||||
|
||||
//格式化数据 为空的项则不修改
|
||||
|
||||
//目标键=》POST键
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city',
|
||||
'car_title' => 'car_title', 'car_no' => 'car_no',
|
||||
'from_name' => 'from_name', 'from_mobile' => 'from_mobile',
|
||||
];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = trim($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['car_value' => 'car_value', 'from_gender' => 'from_gender'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['remark' => 'remark'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$detail->date = isset($post['plan_date']) ? $post['plan_date'] / 1000 : $detail->date;
|
||||
|
||||
$detail->status_code = 1; //标记订单处于创建待审核状态
|
||||
$detail->update_at = time();
|
||||
|
||||
//保存资料
|
||||
$res = $detail->save();
|
||||
|
||||
if ($res) {
|
||||
$this->result('询单保存成功!', ['id' => $id], 200);
|
||||
} else {
|
||||
$this->result('询单保存失败!', [], 100);
|
||||
}
|
||||
return $detail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:39:14+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:19:45+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
@@ -19,230 +12,277 @@
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list' => '平台清单',
|
||||
'detail' => '平台详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'exts'=>'扩展参数',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统平台管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'plats' => $res,
|
||||
'stores' => $s['stores'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('平台查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcPlat();
|
||||
$search = $where = [];
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$exts = $this->showExt($detail);
|
||||
foreach ($exts as $k => $v) {
|
||||
$detail[$k] = $v;
|
||||
}
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcPlat();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑平台参数
|
||||
public function actionExts()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
if(!$pid) $this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
if($this->user_id !=1) $this->result('修改失败,平台配置仅支持超级管理员修改!');
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
$exts = $this->saveExt();
|
||||
if(!$exts) $this->result('参数为空,保存失败', [], 100);
|
||||
$detail->remark = $exts;
|
||||
$res = $detail->save();
|
||||
$msg = '参数编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '参数编辑成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '平台删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '平台删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '平台隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '平台隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '平台显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '平台显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$return = [];
|
||||
$model = new AcPlat();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
if (isset($_POST['title']) && $_POST['title'] != '') {
|
||||
$search['title'] = $_POST['title'];
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!$search['title']) {
|
||||
$where[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '5']);
|
||||
$res = $data->orderby('orderby DESC')->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$plats = [];
|
||||
foreach ($res as $r) {
|
||||
$plats[$r->id] = $r->toArray();
|
||||
}
|
||||
return $this->render('list', [
|
||||
'plats' => $plats,
|
||||
'pager' => $pages,
|
||||
'search' => $search,
|
||||
'status' => $status
|
||||
]);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$_orderby = 'orderby DESC,update_at DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy($_orderby)->indexBy('id')->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$data];
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保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 AcPlat();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->findOne($id);
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$title = trim($post['title']) ?? '';
|
||||
if(!$title) $this->result('请传入平台名称');
|
||||
|
||||
$data = [];
|
||||
$id = $post['id'];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['title' => 'title', 'thumb' => 'thumb'];
|
||||
|
||||
$model = new AcPlat();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
$cols = ['thumb' => 'thumb'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
$cols = ['orderby' => 'orderby', 'deleted' => 'deleted'];
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted','order_by'=>'order_by'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['update_at'] = time();
|
||||
$data['create_at'] = $data['update_at'];
|
||||
|
||||
$model = new AcPlat();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
if ($id) {
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $model->save();
|
||||
$id = $model->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '平台保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '平台保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
$exts = $this->saveExt();
|
||||
if($exts) $data['remark'] = $exts;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
* 格式化显示扩展字段
|
||||
* @data 平台数据[]
|
||||
* 返回[]
|
||||
* */
|
||||
private function showExt($data){
|
||||
$json = $data['remark'];
|
||||
$res = json_decode($json,true);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function actionExt()
|
||||
private function saveExt()
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
if (isset($_GET['pid']) && (int)$_GET['pid'] > 0) {
|
||||
$session->set('pid', (int)$_GET['pid']);
|
||||
}
|
||||
$pid = $session->get('pid');
|
||||
if (!$pid) {
|
||||
$url = Url::toRoute(['index/index', 'pid' => 0]);
|
||||
header('location:' . $url);
|
||||
exit;
|
||||
}
|
||||
|
||||
$model = new AcPlat();
|
||||
$res = $model->findOne($pid);
|
||||
$detail = [];
|
||||
if ($res) {
|
||||
$detail = json_decode($res->remark, TRUE);
|
||||
}
|
||||
return $this->render('ext', ['detail' => $detail]);
|
||||
}
|
||||
|
||||
public function actionExtsave()
|
||||
{
|
||||
$user_id = Yii::$app->user->identity->getId();
|
||||
if ($user_id != 1) {
|
||||
\Yii::$app->getSession()->setFlash('warning', '修改失败,平台配置仅支持超级管理员修改!');
|
||||
return $this->redirect(['plat/ext']);
|
||||
}
|
||||
$post = Yii::$app->request->post();
|
||||
$session = Yii::$app->session;
|
||||
$pid = $session->get('pid');
|
||||
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//目标键=》POST键
|
||||
$cols = ['cw_phone' => 'cw_phone'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
$remark = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$model = new AcPlat();
|
||||
$model->remark = $remark;
|
||||
$res = $model->updateAll(['remark' => $remark], ['id' => $pid]);
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '参数保存成功!');
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '参数保存失败!');
|
||||
}
|
||||
return $this->redirect(['plat/ext']);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcPlat();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('plat/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '平台删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '平台删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcPlat();
|
||||
$res = $model->findOne($id);
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '平台数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '平台隐藏成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '平台隐藏失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '平台显示成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '平台显示失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return));
|
||||
if(!$data) return false;
|
||||
return json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
# @Author: fm453
|
||||
# @Date: 2025/3/10
|
||||
# @updated: 上午11:27
|
||||
# @Email: 1280880631@qq.com
|
||||
@@ -1,13 +1,6 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:52+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:13:59+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
@@ -28,9 +21,11 @@
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'vcode' => '获取短信验证码'
|
||||
'vcode' => '获取短信验证码',
|
||||
'send' => '批量发送营销短信(50条)',
|
||||
'caiwu' => '给财务发送短信'
|
||||
];
|
||||
$this->result('您正使用CMTS-CLIENT系统短信管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统短信管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionSend()
|
||||
@@ -57,21 +52,21 @@
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
|
||||
$address = isset($dataPost['address']) ? $dataPost['address'] : '';
|
||||
$address = $dataPost['address'] ?? '';
|
||||
if ($address) {
|
||||
$session->set('sms::address', $address);
|
||||
} else {
|
||||
$address = $session->get('sms::address');
|
||||
}
|
||||
|
||||
$tmpl = isset($dataPost['tmpl']) ? $dataPost['tmpl'] : '';
|
||||
$tmpl = $dataPost['tmpl'] ?? '';
|
||||
if ($tmpl) {
|
||||
$session->set('sms::tmpl', $tmpl);
|
||||
} else {
|
||||
$tmpl = $session->get('sms::tmpl');
|
||||
}
|
||||
|
||||
$_guests = isset($dataPost['guests']) ? $dataPost['guests'] : '';
|
||||
$_guests = $dataPost['guests'] ?? '';
|
||||
if (!$_guests) {
|
||||
$guests = $session->get('sms::guests');
|
||||
} else {
|
||||
@@ -108,7 +103,7 @@
|
||||
|
||||
foreach ($guests as $p => $username) {
|
||||
$j--;
|
||||
$content['name'] = !empty($username) ? $username . '安诚托车' : '安诚捷顺运车';
|
||||
$content['name'] = !empty($username) ? $username . '安邮车联' : '安邮运车';
|
||||
$result = $sms->send($p, $tmpl, $content);
|
||||
$results[$p] = $result;
|
||||
|
||||
|
||||
@@ -1,95 +1,254 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-16T16:31:49+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:19:58+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcStore;
|
||||
|
||||
class StoreController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '网点清单',
|
||||
'detail' => '网点详情'
|
||||
'detail' => '网点详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS系统网点管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统网点管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$where['status_code'] = 1;
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
if (!$res) {
|
||||
$this->result('没有符合条件的结果');
|
||||
}
|
||||
$stores = [];
|
||||
foreach ($res as $k => $v) {
|
||||
$stores[$v->id] = $v->toArray();
|
||||
}
|
||||
$return = [];
|
||||
$return['data'] = [
|
||||
'stores' => $stores,
|
||||
'citys' => $citys,
|
||||
];
|
||||
$return['total'] = $data->count();
|
||||
$return['page'] = $this->page;
|
||||
$this->result('网点列表', $return, 200);
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'stores' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('网点列表查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$post = Yii::$app->request->post();
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$where['status_code'] = 1;
|
||||
$data = $model->find()->where($where);
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcStore();
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcStore();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '网点数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '网点数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '网点移除标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '网点移除标记失败';
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '网点加入标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '网点加入标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcStore();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2 = ['LIKE', 'title', $search['title']];
|
||||
$data = $data->andwhere($where2);
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = ['0' => '隐藏', '1' => '正常'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'store';
|
||||
return $this->render('select', [
|
||||
'stores' => $res,
|
||||
'pager' => $pages,
|
||||
'citys' => $citys,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$_orderby = 'order_by DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy($_orderby)->all();
|
||||
return ['res'=>$res,'query'=>$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 AcStore();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$title = trim($post['title']) ?? '';
|
||||
if(!$title) $this->result('请传入网点名称');
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
|
||||
$model = new AcStore();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$mobile = trim($post['mobile']) ?? '';
|
||||
if(!isMobile($mobile)) $this->result('请传入正确的手机号');
|
||||
//查询通讯录手机号是否在库(如果在库,则取出相应资料,剩余逻辑由前端完成)
|
||||
$hasOne = AcEmployee::find()->where(['mobile' => $mobile])->one();
|
||||
if($hasOne) $this->result('保存失败,该手机号对应的数据已在库!',$hasOne,100);
|
||||
$data['mobile'] = $mobile;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['status_code' => 'status_code', 'gender'=>'gender','status' => 'status', 'store_id' => 'store_id','deleted' => 'deleted','order_by'=>'order_by'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$cols = ['remark' => 'editor'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,161 +1,366 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:08+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:07+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
|
||||
class TruckController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list' => '板车清单',
|
||||
'detail' => '详情',
|
||||
'get-status'=>'状态字典',
|
||||
'fache'=>'发车',
|
||||
'list-online'=>'装车中',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统板车管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionGetStatus(){
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$this->result('板车状态字典', $status, 200);
|
||||
}
|
||||
|
||||
//板车列表
|
||||
public function actionList()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcTruck->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'trucks' => $res,
|
||||
'drivers' => $s['drivers'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('板车列表查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
public function actionDetail()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcTruck->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truck';
|
||||
return $this->render('select', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
$model = new AcTruck();
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$data = $this->showTruck($detail);
|
||||
$this->result('查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
public function actionAdd()
|
||||
{
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcTruck = new AcTruck();
|
||||
$AcTruck->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcTruck]);
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcTruck();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑板车资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcTruck();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $res['driver_id']])->one();
|
||||
if ($driver) {
|
||||
$res['driver_title'] = $driver->name;
|
||||
}
|
||||
$driver2 = $AcDriver->find()->where(['id' => $res['driver2_id']])->one();
|
||||
if ($driver2) {
|
||||
$res['driver2_title'] = $driver2->name;
|
||||
}
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//保存板车资料
|
||||
public function actionSave()
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '板车删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '板车删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车停用标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车停用标记失败';
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车启用标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车启用标记失败';
|
||||
}
|
||||
break;
|
||||
case 'lock':
|
||||
$detail->status_code = 99;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车锁定标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车锁定标记失败';
|
||||
}
|
||||
break;
|
||||
case 'repair':
|
||||
$detail->status_code = 2;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车检修标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车检修标记失败';
|
||||
}
|
||||
break;
|
||||
case 'reset':
|
||||
$detail->status_code = 3;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车保养标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车保养标记失败';
|
||||
}
|
||||
break;
|
||||
case 'working':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '板车恢复标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '板车恢复标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//查询车牌号是否在库
|
||||
$hasTruck = AcTruck::find()->where(['num_p' => $data['num_p'], 'num_area' => $data['num_area'], 'num_left' => $data['num_left']])->one();
|
||||
if ($hasTruck) {
|
||||
if ($id && $id != $hasTruck->id) {
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该车牌号已在库!');
|
||||
return $this->goBack();
|
||||
} else {
|
||||
$id = $hasTruck->id;
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
//发车
|
||||
public function actionFache()
|
||||
{
|
||||
$truck = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
if ($truck->status_code == 1) {
|
||||
$truck->update_at = time();
|
||||
$res = $truck->update();
|
||||
if ($res) {
|
||||
$msg = '发车成功,请进行下一步操作';
|
||||
$errorCode = 200;
|
||||
}else{
|
||||
$msg = '发车标记保存失败';
|
||||
$errorCode = 0;
|
||||
}
|
||||
}elseif ($truck->status_code == 4) {
|
||||
$msg = '当前板车已在装车中,发车操作无效';
|
||||
$errorCode = 400;
|
||||
} else if ($truck->status_code == 5) {
|
||||
$msg = '当前板车已在运输中,发车操作无效';
|
||||
$errorCode = 400;
|
||||
}else if ($truck->status_code != 1) {
|
||||
$msg = '当前板车状态不允许发车,请先确认板车已归为正常状态';
|
||||
$errorCode = 400;
|
||||
}
|
||||
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
//装车中的板车(即在线板车列表,标记了发车状态为装车中的)
|
||||
public function actionListOnline(){
|
||||
$this->postdata['status'] = 4;
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有在装车中的板车!', [], 0);
|
||||
}
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'trucks' => $res,
|
||||
'drivers' => $s['drivers'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('在线板车列表获取成功!', $data, 200);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcTruck();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$where2[] = 'and';
|
||||
$post = $this->postdata;
|
||||
if(isset($post['status'])){
|
||||
$where['status_code'] = (int)$post['status'];
|
||||
}
|
||||
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$dids = [];
|
||||
if ($res) {
|
||||
foreach ($res as $k => $v) {
|
||||
if($v->driver_id) $dids[] = $v->driver_id;
|
||||
if($v->driver2_id) $dids[] = $v->driver2_id;
|
||||
}
|
||||
}
|
||||
$drivers = [];
|
||||
if($dids){
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where[] = ['=','pid',$this->pid];
|
||||
$where[] = ['IN','id',$dids];
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
}
|
||||
return ['res'=>$res,'query'=>$data,'drivers'=>$drivers];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保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 AcTruck();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$model = new AcTruck();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$cols = ['num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
if(!$data[$col]) $this->result('请传入板车车牌号');
|
||||
}
|
||||
//查询车牌号是否在库
|
||||
$hasOne = AcTruck::find()->where(['num_p' => $data['num_p'], 'num_area' => $data['num_area'], 'num_left' => $data['num_left']])->one();
|
||||
if($hasOne) $this->result('保存失败,该车牌号已在库!',$hasOne,100);
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改车牌号,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['driver_id' => 'driver', 'driver2_id' => 'driver2', 'status_code' => 'status_code', 'max_cars' => 'max_cars', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
@@ -164,259 +369,23 @@
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
// $data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存板车资料
|
||||
$AcTruck = new AcTruck();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruck->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcTruck->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcTruck->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruck->save();
|
||||
$id = $AcTruck->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '板车资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '板车资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcTruck();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('truck/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '板车删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '板车删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcTruck();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '板车数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车停用标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '板车停用标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车入库记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '板车入库标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'lock':
|
||||
$data['status_code'] = 99;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车锁定标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'danger'];
|
||||
} else {
|
||||
$return['msg'] = '板车锁定标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'repair':
|
||||
$data['status_code'] = 2;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车检修标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'warning'];
|
||||
} else {
|
||||
$return['msg'] = '板车检修标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'reset':
|
||||
$data['status_code'] = 2;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车保养标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '板车保养标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'working':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车恢复正常,标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '板车恢复标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//发车
|
||||
public function actionFache()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($id);
|
||||
if (!$truck) {
|
||||
$return['msg'] = '板车数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($truck->status_code == 4) {
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['msg'] = '当前板车已在装车中,发车操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
} else if ($truck->status_code == 5) {
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['msg'] = '当前板车已在运输途中,发车操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
} else if ($truck->status_code != 1) {
|
||||
$return['msg'] = '当前板车状态不允许发车,请先确认板车已归为正常状态';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['status_code'] = 4;
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruck->$key = $val;
|
||||
}
|
||||
$res = $AcTruck->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '发车成功,请进行下一步操作';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '发车操作失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//浏览板车资料
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcTruck();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
private function showTruck($detail){
|
||||
$data = $detail->toArray();
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $res['driver_id']])->one();
|
||||
$driver = $AcDriver->findOne($detail->driver_id);
|
||||
if ($driver) {
|
||||
$res['driver_title'] = $driver->name;
|
||||
$res['driver_mobile'] = $driver->mobile;
|
||||
$data['driver_title'] = $driver->name;
|
||||
$data['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$driver2 = $AcDriver->find()->where(['id' => $res['driver2_id']])->one();
|
||||
$driver2 = $AcDriver->findOne($detail->driver2_id);
|
||||
if ($driver2) {
|
||||
$res['driver2_title'] = $driver2->name;
|
||||
$res['driver2_mobile'] = $driver2->mobile;
|
||||
$data['driver2_title'] = $driver2->name;
|
||||
$data['driver2_mobile'] = $driver2->mobile;
|
||||
}
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
return $this->render('detail', ['status' => $status, 'detail' => $res]);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,235 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:28+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:02+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
|
||||
class TruckcarController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list' => '承运清单',
|
||||
'detail' => '承运详情',
|
||||
'get-status'=>'获取运输状态字典',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统板车承运管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionGetStatus(){
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$this->result('板车装载状态字典', $status, 200);
|
||||
}
|
||||
//所有装车记录列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'truck_cars' => $res,
|
||||
'cars' => $s['cars'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('板车列表查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcTruckCars();
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$data = $this->showTruck($detail);
|
||||
$this->result('查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcTruckCars();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑客车上板信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
if ($detail->deleted != 0) {
|
||||
$this->result('数据已被删除过,操作无效', [], 400);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '上板记录删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '上板记录删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$_time = time();
|
||||
$detail->update_at = $_time;
|
||||
|
||||
$online_id = $detail->online_id;
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
$order_id = $detail->order_id;
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'intruck':
|
||||
//上板
|
||||
if ($detail->status_code != 0) {
|
||||
$this->result('当前运单并非待承运状态,操作无效',[], 400);
|
||||
}
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
//增加板车一辆装车统计
|
||||
$truckol->update_at = $_time;
|
||||
$truckol->updateCounters(['cars' => 1]);
|
||||
$truckol->save();
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 2;
|
||||
$order->save();
|
||||
$msg = '客车上板标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '客车上板标记失败';
|
||||
$errorCode = 100;
|
||||
}
|
||||
break;
|
||||
case 'arrive':
|
||||
//运达
|
||||
if ($detail->status_code == 0) {
|
||||
$this->result('当前运单尚待承运,操作无效',[], 400);
|
||||
}
|
||||
$detail->status_code = 99;
|
||||
$detail->to_time = $_time;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 3;
|
||||
$order->save();
|
||||
$msg = '客车运达标记记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$this->result('客车运达标记失败',[], 100);
|
||||
}
|
||||
break;
|
||||
case 'fix':
|
||||
//处理质损
|
||||
$data['status_code'] = 80;
|
||||
if ($detail->status_code != 1) {
|
||||
$this->result('当前运单并非运输中状态,操作无效',[], 400);
|
||||
}
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '客车运达标记记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$this->result('客车运损标记失败',[], 100);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$return = [];
|
||||
$model = new AcTruckCars();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
$search['start_city'] = isset($search['start_city']) ? trim(htmlspecialchars_decode($search['start_city'])) : '';
|
||||
if (!empty($search['start_city'])) {
|
||||
$where[] = ['LIKE', 'from_city', $search['start_city']];
|
||||
@@ -54,15 +239,12 @@
|
||||
$where[] = ['LIKE', 'to_city', $search['aim_city']];
|
||||
}
|
||||
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : 0;
|
||||
$CarModel = new AcCar();
|
||||
if (!empty($search['car_id'])) {
|
||||
if (!$search['car_id']) {
|
||||
$where[] = ['=', 'car_id', $search['car_id']];
|
||||
$car = $CarModel->findOne($search['car_id']);
|
||||
$search['car_title'] = isset($car->title) ? $car->title : '';
|
||||
}
|
||||
$search['status_code'] = isset($search['status_code']) ? $search['status_code'] : 'all';
|
||||
if ($search['status_code'] != 'all') {
|
||||
$where[] = ['=', 'status_code', (int)$search['status_code']];
|
||||
$search['status_code'] = isset($search['status_code']) ? (int)$search['status_code'] : 0;
|
||||
if ($search['status_code']) {
|
||||
$where[] = ['=', 'status_code', $search['status_code']];
|
||||
}
|
||||
//按月份筛选
|
||||
$search['start_m'] = isset($search['start_m']) ? $search['start_m'] : '';
|
||||
@@ -76,8 +258,10 @@
|
||||
}
|
||||
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckCars->find()->where($where);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('status_code ASC,id DESC')->all();
|
||||
|
||||
$car_ids = [];
|
||||
@@ -93,470 +277,84 @@
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$cars = $AcCar->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'cars' => $cars,
|
||||
'search' => $search
|
||||
]);
|
||||
return ['res'=>$res,'query'=>$data,'cars'=>$cars];
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保get与post数据中均包含需更新的数据id且一致
|
||||
* */
|
||||
private function preUpdate()
|
||||
{
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$AcTruckCars = [];
|
||||
$AcTruckCars['status_code'] = 0;
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
$AcTruckCars['online_id'] = $online_id;
|
||||
$order_id = Yii::$app->request->get('order_id'); //待承运订单ID
|
||||
$AcTruckCars['order_id'] = $order_id;
|
||||
$car_id = Yii::$app->request->get('car_id'); //待装客车ID
|
||||
$AcTruckCars['car_id'] = $car_id;
|
||||
return $this->render('create', ['status' => $status, 'detail' => $AcTruckCars]);
|
||||
$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 AcTruckCars();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
if($res->pid != $this->pid) $this->result('非本平台数据,不允许操作',[],401);
|
||||
return $res;
|
||||
}
|
||||
|
||||
//编辑客车上板信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //承运单ID
|
||||
$truck_id = $online_id = $store_id = $store2_id = 0;
|
||||
$truckCar = $truckol = [];
|
||||
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$res = $AcTruckCars->findOne($id);
|
||||
if ($res) {
|
||||
$truckCar = $res->toArray();
|
||||
$online_id = $res->online_id;
|
||||
$store2_id = $res->to_store;
|
||||
$store_id = $res->from_store;
|
||||
$order_id = $res->order_id;
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
/*出车计划判断*/
|
||||
$online_id = $post['online_id'] ?? 0;
|
||||
if (!(int)$online_id) {
|
||||
$this->result('未关联板车出车计划信息,保存失败',[],400);
|
||||
}
|
||||
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$truckol = $res->toArray();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
if (!$truckol) {
|
||||
$this->result('未找到指定板车出车计划,保存失败',[],404);
|
||||
}
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '关联板车数据获取异常,发车任务编辑失败';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truck/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');
|
||||
}
|
||||
$truckCar['truck_id'] = $truck_id;
|
||||
$truckCar['truck_title'] = $truck->num_p . $truck->num_area . $truck->num_left;
|
||||
$truckCar['truck_num'] = $truckCar['truck_title'] ? $truckCar['truck_title'] : $truckol['truck_num'];
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckCar['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckCar['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
|
||||
$truckCar['driver_title'] = $truckCar['driver_mobile'] = '';
|
||||
if ($driver) {
|
||||
$truckCar['driver_title'] = $driver->name;
|
||||
$truckCar['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$truckCar['from_time'] = !empty($truckCar['from_time']) ? $truckCar['from_time'] : $truckol['from_date'];
|
||||
$truckCar['to_time'] = !empty($truckCar['to_time']) ? $truckCar['to_time'] : $truckol['end_date'];
|
||||
$from_city = $order->start_city;
|
||||
$truckCar['from_city'] = !empty($truckCar['from_city']) ? $truckCar['from_city'] : $from_city;
|
||||
$truckCar['from_city'] = $truckCar['from_city'] ? $truckCar['from_city'] : $truckol['from_city'];
|
||||
$end_city = $order->aim_city;
|
||||
$truckCar['to_city'] = !empty($truckCar['to_city']) ? $truckCar['to_city'] : $end_city;
|
||||
$truckCar['to_city'] = $truckCar['to_city'] ? $truckCar['to_city'] : $truckol['end_city'];
|
||||
$truckCar['driver_name'] = isset($truckCar['driver_name']) ? $truckCar['driver_name'] : $truckol['driver_name'];
|
||||
$truckCar['driver_mobiles'] = isset($truckCar['driver_mobiles']) ? $truckCar['driver_mobiles'] : $truckol['driver_mobiles'];
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $truckCar]);
|
||||
}
|
||||
|
||||
//保存客车上板信息(直接指派方式)
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$model = new AcTruckCars();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改车牌号,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
$data['pid'] = $this->pid;
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$cols = ['from_city' => 'from_city', 'to_city' => 'to_city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['online_id' => 'online_id', 'from_store' => 'from_store', 'to_store' => 'to_store'];
|
||||
if (isset($_GET['debug']) && ($_GET['debug'] == 1)) {
|
||||
$cols['status_code'] = 'status_code';
|
||||
$cols = ['to_time' => 'to_time', 'from_time' => 'from_time'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != "") $data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
$cols = ['from_store' => 'from_store', 'to_store' => 'to_store', 'order_id' => 'order_id', 'car_id' => 'car_id','status_code'=>'status_code'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
/*出车计划判断*/
|
||||
$online_id = $data['online_id'];
|
||||
if (!$online_id) {
|
||||
$return['msg'] = '未关联板车出车计划信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
if (!$truckol) {
|
||||
$return['msg'] = '未找到指定板车出车计划,保存失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$_time = time();
|
||||
$key = 'to_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
$key = 'from_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['update_at'] = $_time;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存上板信息
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckCars->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckCars->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckCars->save();
|
||||
$id = $AcTruckCars->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
//修改对应运单状态
|
||||
$_code = 0;
|
||||
if (isset($data['status_code'])) {
|
||||
if ($data['status_code'] == 1) {
|
||||
$_code = 2;
|
||||
} else if ($data['status_code'] == 99) {
|
||||
$_code = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_code) {
|
||||
$order_id = isset($post['order_id']) ? (int)$post['order_id'] : 0;
|
||||
if (!$order_id) {
|
||||
$car = $AcTruckCars->findOne($id);
|
||||
$order_id = $car->order_id;
|
||||
}
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
$order->update_at = $_time;
|
||||
|
||||
$order->status_code = $_code;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//保存客车上板信息(板车出车界面车辆管理方式)
|
||||
public function actionSave2()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['from_city' => 'from_city', 'to_city' => 'to_city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['online_id' => 'online_id', 'from_store' => 'from_store', 'to_store' => 'to_store', 'order_id' => 'order_id', 'car_id' => 'car_id'];
|
||||
if (isset($_GET['debug']) && ($_GET['debug'] == 1)) {
|
||||
$cols['status_code'] = 'status_code';
|
||||
}
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
/*出车计划判断*/
|
||||
$online_id = $data['online_id'];
|
||||
if (!$online_id) {
|
||||
$return['msg'] = '未关联板车出车计划信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
if (!$truckol) {
|
||||
$return['msg'] = '未找到指定板车出车计划,保存失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$_time = time();
|
||||
$key = 'to_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
$key = 'from_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['update_at'] = $_time;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存上板信息
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckCars->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckCars->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckCars->save();
|
||||
$id = $AcTruckCars->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
//修改对应运单状态
|
||||
$_code = 0;
|
||||
if (isset($data['status_code'])) {
|
||||
if ($data['status_code'] == 1) {
|
||||
$_code = 2;
|
||||
} else if ($data['status_code'] == 99) {
|
||||
$_code = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_code) {
|
||||
$order_id = isset($post['order_id']) ? (int)$post['order_id'] : 0;
|
||||
if (!$order_id) {
|
||||
$car = $AcTruckCars->findOne($id);
|
||||
$order_id = $car->order_id;
|
||||
}
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
$order->update_at = $_time;
|
||||
|
||||
$order->status_code = $_code;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$data = $return = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcTruckCars();
|
||||
$car = $model->findOne($id);
|
||||
if (!$car) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除过,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, ['id' => $id]);
|
||||
|
||||
|
||||
$return['url'] = Url::toRoute('truckcar/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '上板记录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '上板记录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$data = $return = [];
|
||||
$_time = time();
|
||||
$data['update_at'] = $_time;
|
||||
|
||||
$model = new AcTruckCars();
|
||||
$car = $model->findOne($id);
|
||||
if (!$car) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$online_id = $car->online_id;
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
$order_id = $car->order_id;
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
|
||||
$where = ['id' => $id];
|
||||
switch ($get['do']) {
|
||||
case 'intruck':
|
||||
if ($car->status_code != 0) {
|
||||
$return['msg'] = '当前运单并非待承运状态,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = 1;
|
||||
$data['from_time'] = $_time;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
//增加板车一辆装车统计
|
||||
$truckol->update_at = $_time;
|
||||
$truckol->updateCounters(['cars' => 1]);
|
||||
$truckol->save();
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 2;
|
||||
$order->save();
|
||||
$return['msg'] = '客车上板标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'arrive':
|
||||
if ($car->status_code == 0) {
|
||||
$return['msg'] = '当前任务尚待承运,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = 99;
|
||||
$data['to_time'] = $_time;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 3;
|
||||
$order->save();
|
||||
$return['msg'] = '客车运达标记记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '客车运达标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'fix':
|
||||
$data['status_code'] = 80;
|
||||
if ($car->status_code != 1) {
|
||||
$return['msg'] = '当前运单并非运输中状态,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '客车运达标记记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '客车运达标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,233 +1,306 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:37:26+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:16+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
use addons\models\AcTruckRoute;
|
||||
|
||||
class TruckrouteController extends Common
|
||||
{
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
public function init()
|
||||
public $online_id = 0;
|
||||
public $truckOl;
|
||||
public function beforeAction($action)
|
||||
{
|
||||
$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']);
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
if (!$online_id) {
|
||||
$online_id = $session->get('online_id');
|
||||
} else {
|
||||
$session->set('online_id', $online_id);
|
||||
}
|
||||
if (!$online_id) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/index', $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');
|
||||
}
|
||||
$truckol = $session->get('truckOnline');
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$res = TRUE;
|
||||
if (!$truckol) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if ($online_id != $truckol['id']) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/index', $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');
|
||||
if($online_id > 0){
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckOl = $AcTruckOnline->findOne($online_id);
|
||||
if(!$truckOl) $this->result('未找到的关联板车任务!',[],404);
|
||||
$this->truckOl = $truckOl;
|
||||
$this->online_id = $online_id;
|
||||
}
|
||||
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
$apis = [
|
||||
'list' => '板车路线记录列表',
|
||||
'detail' => '路线记录详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统在途板车路线管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//所有板车位置记录列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
if ($online_id) {
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckRoute->find()->where($where)->orderby('orderby ASC,id DESC');
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
|
||||
$truck_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$truck_ids[] = $r->truck_id;
|
||||
}
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $truck_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$trucks = $AcTruck->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'trucks' => $trucks,
|
||||
'online_id' => $online_id,
|
||||
'truckol' => $truckol
|
||||
]);
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'routes' => $res,
|
||||
'truckOls' => $s['truckOls'],
|
||||
'trucks' => $s['trucks'],
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('板车路线记录查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
public function actionDetail()
|
||||
{
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcTruckRoute = [];
|
||||
$AcTruckRoute['status_code'] = 0;
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$AcTruckRoute['truck_id'] = $truckol['truck_id'];
|
||||
$AcTruckRoute['truck_num'] = $truckol['truck_num'];
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcTruckRoute();
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcTruckRoute, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
//保存资料
|
||||
$model = new AcTruckRoute();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑板车位置信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //记录ID
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$route = $AcTruckRoute->findOne($id);
|
||||
if (!$route) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '位置记录数据获取异常,请重新选择获取';
|
||||
$return['errorcode'] = 0;
|
||||
$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');
|
||||
}
|
||||
$route = $route->toArray();
|
||||
$route['truck_id'] = $truckol['truck_id'];
|
||||
$route['online_id'] = $online_id;
|
||||
$route['truck_num'] = $truckol['truck_num'];
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $route, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//保存位置记录信息
|
||||
public function actionSave()
|
||||
//删除记录
|
||||
public function actionDelete()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$online_id = Yii::$app->session->get('online_id');
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
$detail = $this->preUpdate();
|
||||
if ($detail->deleted != 0) {
|
||||
$this->result('数据已被删除过,操作无效', [], 400);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['truck_id'] = $truckol['truck_id'];
|
||||
$data['online_id'] = $online_id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '板车路线记录删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '板车路线记录删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$_time = time();
|
||||
$detail->update_at = $_time;
|
||||
$res = true;
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'show':
|
||||
if ($detail->status_code != 1) {
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
}
|
||||
if ($res) {
|
||||
$msg = '记录显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '记录显示标记失败';
|
||||
$errorCode = 0;
|
||||
}
|
||||
break;
|
||||
case 'hide':
|
||||
if ($detail->status_code != 0) {
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
}
|
||||
if ($res) {
|
||||
$msg = '记录隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '记录隐藏标记失败';
|
||||
$errorCode = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg, [], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$model = new AcTruckRoute();
|
||||
$where = [];
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
if($this->online_id){
|
||||
$where[] = ['=', 'online_id', $this->online_id];
|
||||
}
|
||||
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
|
||||
//板车
|
||||
$search['truck_id'] = isset($search['truck_id']) ? (int)$search['turck_id'] : 0;
|
||||
if ($search['truck_id']) {
|
||||
$where[] = ['=', 'truck_id', $search['truck_id']];
|
||||
}
|
||||
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('orderby ASC')->all();
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
if ($search['truck_id']) {
|
||||
$trucks[$search['truck_id']] = $AcTruck->findOne($search['truck_id']);
|
||||
}else{
|
||||
$truck_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$truck_ids[] = $r->truck_id;
|
||||
}
|
||||
$truck_ids = array_unique($truck_ids);
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $truck_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$trucks = $AcTruck->find()->where($where)->indexby('id')->all();
|
||||
}
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
if ($this->online_id) {
|
||||
$truckOls[$this->online_id] = $this->truckOl;
|
||||
}else{
|
||||
$truckOl_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$truckOl_ids[] = $r->online_id;
|
||||
}
|
||||
$truckOl_ids = array_unique($truckOl_ids);
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $truckOl_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$truckOls = $AcTruckOnline->find()->where($where)->indexby('id')->all();
|
||||
}
|
||||
|
||||
return ['res'=>$res,'query'=>$data,'trucks'=>$trucks,'truckOls'=>$truckOls];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保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 AcTruckRoute();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
if($res->pid != $this->pid) $this->result('非本平台数据,不允许操作',[],401);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
$_time = time();
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['longt' => 'lng', 'lat' => 'lat', 'addr' => 'addr'];
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
if(!$this->online_id) $this->result('未关联板车装载任务,保存失败',[],403);
|
||||
$data['online_id'] = $this->online_id;
|
||||
$data['truck_id'] = $this->truckOl->truck_id;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = $_time;
|
||||
break;
|
||||
}
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['longt' => 'lng', 'lat' => 'lat', 'addr' => 'addr','province'=>'province','city'=>'city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
@@ -237,142 +310,6 @@
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
$_time = time();
|
||||
$key = 'update_at';
|
||||
$data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time;
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存位置资料
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckRoute->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckRoute->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckRoute->save();
|
||||
$id = $AcTruckRoute->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除记录
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除过,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$route->deleted = 1;
|
||||
$res = $route->save();
|
||||
|
||||
$return['url'] = '';
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '位置记录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '位置记录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$res = TRUE;
|
||||
switch ($get['do']) {
|
||||
case 'show':
|
||||
if ($route->status_code != 1) {
|
||||
$route->status_code = 1;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'hide':
|
||||
if ($route->status_code != 0) {
|
||||
$route->status_code = 0;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
use yii\data\Pagination;
|
||||
use yii\web\UploadedFile;
|
||||
use common\models\CAttachment;
|
||||
use backend\controllers\Common;
|
||||
|
||||
class UploadController extends Common
|
||||
{
|
||||
@@ -30,7 +29,7 @@
|
||||
$apis = [
|
||||
'image' => '上传图片(单传)',
|
||||
];
|
||||
$this->result('您正使用CMTS系统文件上传接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统文件上传接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionImage()
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:37:06+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:36+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
@@ -21,7 +14,7 @@
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
// $this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
@@ -29,55 +22,33 @@
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '搜索委托单位清单',
|
||||
'detail' => '委托单位详情'
|
||||
'list' => '委托单位清单',
|
||||
'detail' => '委托单位详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS系统委托单位管理接口!', $apis, 200);
|
||||
$this->result('您正使用CMTS-GM系统委托单位管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcWeituoren();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = isset($post['search']) ? $post['search'] : NULL;
|
||||
if (!$search) {
|
||||
$search = [];
|
||||
}
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'company', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->asArray()->where($where); //asArray() 放在find后,可让查询结果以数组形式呈现
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$_orderby = 'orderby DESC,id ASC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||||
if (!$res) {
|
||||
$this->result('没有符合条件的结果');
|
||||
}
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '委托单位查询成功!';
|
||||
$return['data'] = ['total' => $data->count(),
|
||||
'data' => [
|
||||
'weituoren' => $res
|
||||
],
|
||||
'page' => $this->page];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
$data= [
|
||||
'total'=>$s['query']->count(),
|
||||
'weituoren' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('合作单位查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
@@ -90,9 +61,202 @@
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcWeituoren();
|
||||
$weituo = $model->findOne($id);
|
||||
$detail = $weituo->toArray();
|
||||
|
||||
$detail = $model->findOne($id)->toArray();
|
||||
if(!$detail) $this->result('未查询到相应数据');
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcWeituoren();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//编辑司机资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '驾驶员数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '驾驶员数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->status_code = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '合作单位隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '合作单位隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->status_code = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '合作单位显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '合作单位显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcWeituoren();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
$where2[] = ['LIKE', 'company', $search['title']];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$_orderby = 'orderby DESC,update_at DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy($_orderby)->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$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 AcWeituoren();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$company = trim($post['company']) ?? '';
|
||||
if(!$company) $this->result('请传入单位名称');
|
||||
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
|
||||
$model = new AcWeituoren();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$mobile = trim($post['mobile']) ?? '';
|
||||
if(!$mobile) $this->result('请传入手机号');
|
||||
//查询通讯录手机号是否在库(如果在库,则取出相应资料,剩余逻辑由前端完成)
|
||||
$hasOne = AcWeituoren::find()->where(['mobile' => $mobile])->one();
|
||||
if($hasOne){
|
||||
$detail = $hasOne->toArray();
|
||||
$this->result('保存失败,该手机号对应的数据已在库,系统自动现在为您调出该资料!',$detail,100);
|
||||
}
|
||||
$data['mobile'] = $mobile;
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
break;
|
||||
case 'edit':
|
||||
//编辑模式下,没有改mobile,避免校验重复性
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = time();
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted','orderby'=>'orderby'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user