From 7244023619d67a5203270b616513e6e4ef346315 Mon Sep 17 00:00:00 2001 From: fm453 <393213759@qq.com> Date: Sun, 13 Jul 2025 18:48:29 +0800 Subject: [PATCH] =?UTF-8?q?ADD=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=96=87=E7=AB=A0=E3=80=81=E9=80=9A=E7=9F=A5=E7=AD=89?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=AB=AF=E6=8E=A5=E5=8F=A3=EF=BC=9B=20FIX?= =?UTF-8?q?=EF=BC=9A=E4=BF=AE=E6=AD=A3=E8=8B=A5=E5=B9=B2=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + ctms-admin/controllers/NewsController.php | 2 +- ctms-api/controllers/client/v1/Common.php | 2 +- .../controllers/client/v1/FansController.php | 14 +- .../controllers/client/v1/IndexController.php | 44 +- .../controllers/client/v1/NewsController.php | 3 +- .../client/v1/OrderpreController.php | 2 + .../controllers/client/v1/SmsController.php | 10 +- ctms-api/controllers/gm/v1/Common.php | 86 +- .../controllers/gm/v1/FeeorderController.php | 4 +- .../controllers/gm/v1/IndexController.php | 24 +- .../controllers/gm/v1/JiaocheController.php | 1110 ++++++++++------- .../controllers/gm/v1/NewsCatController.php | 271 ++++ ctms-api/controllers/gm/v1/NewsController.php | 277 ++++ .../controllers/gm/v1/NoticeController.php | 269 ++++ 15 files changed, 1616 insertions(+), 503 deletions(-) create mode 100644 ctms-api/controllers/gm/v1/NewsCatController.php create mode 100644 ctms-api/controllers/gm/v1/NewsController.php create mode 100644 ctms-api/controllers/gm/v1/NoticeController.php diff --git a/.gitignore b/.gitignore index ca6c7a7..46df50f 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ private.html /assets/ /admins/web/assets/ /logs/ +/admins/runtime/ diff --git a/ctms-admin/controllers/NewsController.php b/ctms-admin/controllers/NewsController.php index 3851070..66a4c69 100644 --- a/ctms-admin/controllers/NewsController.php +++ b/ctms-admin/controllers/NewsController.php @@ -133,7 +133,7 @@ class NewsController extends Common{ } } - $cols = ['orderby'=>'orderby','deleted'=>'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed']; + $cols = ['order_by'=>'order_by','deleted'=>'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed']; foreach($cols as $col=>$key){ if(isset($post[$key])){ $data[$col] = (int)$post[$key]; diff --git a/ctms-api/controllers/client/v1/Common.php b/ctms-api/controllers/client/v1/Common.php index 05f3772..57b5381 100755 --- a/ctms-api/controllers/client/v1/Common.php +++ b/ctms-api/controllers/client/v1/Common.php @@ -89,7 +89,7 @@ class Common extends Controller public function fansToken($user = [], $refresh = FALSE, $expire = NULL) { - //生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化 + //生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化;Token应该入库,有核对流程 $expire = $expire ? $expire : '+1 day'; $token = Yii::$app->session->get('fansToken'); $tokenExpired = Yii::$app->session->get('fansTokenExpired'); diff --git a/ctms-api/controllers/client/v1/FansController.php b/ctms-api/controllers/client/v1/FansController.php index 0ed87f6..e6c7731 100644 --- a/ctms-api/controllers/client/v1/FansController.php +++ b/ctms-api/controllers/client/v1/FansController.php @@ -119,8 +119,8 @@ class FansController extends Common if (!$res) { $this->result('验证码校验失败'); } - if (($this->timetamp - $res->create_at) > 300) { - // 超时5分钟 + if (($this->timestamp - $res->create_at) > 300) { + //超时5分钟 $this->result('验证码已失效,请重新获取'); } @@ -283,8 +283,8 @@ class FansController extends Common } /** - * 添加一个新用户 - * @param $data 用户数据 + * 添加一个新用户 用户数据 + * @param $data * @return void */ private function fansAdd($data, $userModel) @@ -301,9 +301,9 @@ class FansController extends Common return $userModel; } - /** - * @param $user 用户实例 - * @param $hasExt 有否扩展 + /** 用户实例、有否扩展 + * @param $user + * @param $hasExt * @return void */ private function fansLogin($user, $hasExt = FALSE) diff --git a/ctms-api/controllers/client/v1/IndexController.php b/ctms-api/controllers/client/v1/IndexController.php index 214c8b4..3784948 100755 --- a/ctms-api/controllers/client/v1/IndexController.php +++ b/ctms-api/controllers/client/v1/IndexController.php @@ -44,7 +44,7 @@ class IndexController extends Common public function actionAdsSplash() { $ads = [ - // "http://public.hiluker.com/ctms/client/app-kp/kp01.jpg", + "http://public.hiluker.com/ctms/client/app-kp/kp01.jpg", "http://public.hiluker.com/ctms/client/app-kp/kp03.jpg", ]; $this->result('开屏广告!', $ads, 200); @@ -55,7 +55,7 @@ class IndexController extends Common $ads = [ '0'=>[ "image"=>'http://public.hiluker.com/ctms/client/app-banner/banner01.jpg', - "link"=>'/pages/uni-starter/ucenter/ucenter' + "link"=>'/pages/ctms/news/list/list' ], '1'=>[ "image"=>'http://public.hiluker.com/ctms/client/app-banner/banner03.jpg', @@ -96,18 +96,18 @@ class IndexController extends Common $_where[]=['=','is_turnover',0]; //排除交车单 $_where[] = ['between','sign_date',$start,$end]; $data = $model->find()->where($_where); - $order_today_count = $data->count(); + $order_today_count = (int)$data->count(); //今日交车 $_where = $where; $_where[]=['=','is_turnover',1]; //交车单 $_where[] = ['between','sign_date',$start,$end]; $data = $model->find()->where($_where); - $jiaoche_today_count = $data->count(); + $jiaoche_today_count = (int)$data->count(); //今日录单 $_where = $where; $_where[] = ['between','create_at',$start,$end]; $data = $model->find()->where($_where); - $order_today_create = $data->count(); + $order_today_create = (int)$data->count(); //昨日 $_end = $start; @@ -118,18 +118,18 @@ class IndexController extends Common $_where[]=['=','is_turnover',0]; //排除交车单 $_where[] = ['between','sign_date',$_start,$_end]; $data = $model->find()->where($_where); - $order_yesterday_count = $data->count(); + $order_yesterday_count = (int)$data->count(); //昨日交车 $_where = $where; $_where[]=['=','is_turnover',1]; //交车单 $_where[] = ['between','sign_date',$_start,$_end]; $data = $model->find()->where($_where); - $jiaoche_yesterday_count = $data->count(); + $jiaoche_yesterday_count = (int)$data->count(); //昨日录单 $_where = $where; $_where[] = ['between','create_at',$_start,$_end]; $data = $model->find()->where($_where); - $order_yesterday_create = $data->count(); + $order_yesterday_create = (int)$data->count(); //本月起始时间点 $_start = date('Y-m-01 00:00:00'); @@ -142,38 +142,40 @@ class IndexController extends Common $_where[]=['=','is_turnover',0]; //排除交车单 $_where[] = ['between','sign_date',$_start,$_end]; $data = $model->find()->where($_where); - $order_month_count = $data->count(); + $order_month_count = (int)$data->count(); //本月交车 $_where = $where; $_where[]=['=','is_turnover',1]; $_where[] = ['between','sign_date',$_start,$_end]; $data = $model->find()->where($_where); - $jiaoche_month_count = $data->count(); + $jiaoche_month_count = (int)$data->count(); //累计运单 $_where = $where; $_where[]=['=','is_turnover',0]; //排除交车单 $data = $model->find()->where($_where); - $order_all_count = $data->count(); + $order_all_count = (int)$data->count(); //累计交车 $_where = $where; $_where[]=['=','is_turnover',1]; $data = $model->find()->where($_where); - $jiaoche_all_count = $data->count(); + $jiaoche_all_count = (int)$data->count(); $return = []; $return['code'] = 200; $return['msg'] = '首页数据下载!'; $return['data']= [ - 'orderToday'=>$order_today_count, - 'orderYesterday'=>$order_yesterday_count, - 'orderMonth'=>$order_month_count, - 'orderTotal'=>$order_all_count, - 'jiaocheToday'=>$jiaoche_today_count, - 'jiaocheYesterday'=>$jiaoche_yesterday_count, - 'jiaocheMonth'=>$jiaoche_month_count, - 'jiaocheTotal'=>$jiaoche_all_count, - 'notice'=>0 + 'orderToday'=>$order_today_count, + 'orderTodayCreate'=>$order_today_create, + 'orderYesterday'=>$order_yesterday_count, + 'orderYesterdayCreate'=>$order_yesterday_create, + 'orderMonth'=>$order_month_count, + 'orderTotal'=>$order_all_count, + 'jiaocheToday'=>$jiaoche_today_count, + 'jiaocheYesterday'=>$jiaoche_yesterday_count, + 'jiaocheMonth'=>$jiaoche_month_count, + 'jiaocheTotal'=>$jiaoche_all_count, + 'notice'=>0 ]; exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); } diff --git a/ctms-api/controllers/client/v1/NewsController.php b/ctms-api/controllers/client/v1/NewsController.php index 3bed466..fb26922 100755 --- a/ctms-api/controllers/client/v1/NewsController.php +++ b/ctms-api/controllers/client/v1/NewsController.php @@ -57,6 +57,7 @@ class NewsController extends Common } $model = new AcNews(); $detail = $model->findOne($id); + if(!$detail) $this->result('查询失败,未找到指定内容!'); $s = $this->formatDetail($detail->toArray()); $this->result('查询成功!', $s, 200); } @@ -188,7 +189,7 @@ class NewsController extends Common // 'src="/upload/pics/' $upload_url = 'https://dacms.hiluker.cn'; - $s['content'] = str_replace('src="/upload/pics/', 'src="' . $upload_url . '/upload/pics/', $s['content']); + $s['content'] = str_replace('src="/upload/pics/', 'src="' . $upload_url . '/upload-ctms/pics/', $s['content']); return $s; } } diff --git a/ctms-api/controllers/client/v1/OrderpreController.php b/ctms-api/controllers/client/v1/OrderpreController.php index 8cd84c0..c660086 100755 --- a/ctms-api/controllers/client/v1/OrderpreController.php +++ b/ctms-api/controllers/client/v1/OrderpreController.php @@ -52,8 +52,10 @@ class OrderpreController extends Common $post = $this->postdata; $search = isset($post['search']) ? $post['search'] : []; //预置搜索条件,只允许查询与自己完全相关的订单 + if(!$this->user_id) $this->result('用户未登陆,拒绝查询!', [], 0); $where[] = ['=', 'from_uid', $this->user_id]; $search['phone'] = $this->user_info->mobile; + if(!$search['phone']) $this->result('没有用户手机号,查询失败!', [], 0); $where[] = ['=', 'from_mobile', $search['phone']]; if (isset($search['carno']) && !empty($search['carno'])) { diff --git a/ctms-api/controllers/client/v1/SmsController.php b/ctms-api/controllers/client/v1/SmsController.php index a80cd21..a079bcf 100755 --- a/ctms-api/controllers/client/v1/SmsController.php +++ b/ctms-api/controllers/client/v1/SmsController.php @@ -3,7 +3,7 @@ namespace api\controllers\client\v1; use Yii; -use vendor\aliyun\dysms\Sms; +use vendor\aliyun\dysms\Sms as DysmsClient; use common\models\CSms; use common\models\CVcode; use addons\models\AcPlat; @@ -21,7 +21,9 @@ class SmsController extends Common public function actionIndex() { $apis = [ - 'vcode'=>'获取短信验证码' + 'vcode'=>'获取短信验证码', + 'send'=>'群发', + 'caiwu'=>'财务获取验证码' ]; $this->result('您正使用CMTS-CLIENT系统短信管理接口!', $apis, 200); } @@ -157,7 +159,7 @@ class SmsController extends Common $config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign']; $option = array(); - $sms = new Sms($option, $config); + $sms = new DysmsClient($option, $config); $_time = time(); $vcodeModel = new CVcode(); //查询上次发送记录 @@ -215,7 +217,7 @@ class SmsController extends Common break; } - // 发送前控制 + //发送前控制 $host = yii::$app->request->hostName; $debug = $params['aliDySms']['debug'] ?? FALSE; $domains = $params['aliDySms']['domains'] ?? []; diff --git a/ctms-api/controllers/gm/v1/Common.php b/ctms-api/controllers/gm/v1/Common.php index 8aefb35..aa312ab 100755 --- a/ctms-api/controllers/gm/v1/Common.php +++ b/ctms-api/controllers/gm/v1/Common.php @@ -16,6 +16,7 @@ class Common extends Controller { protected int $pid = 0; + protected object $plat; protected int $user_id = 0; protected int $site_id = 0; protected int $store_id = 0; @@ -151,17 +152,91 @@ /* * SN格式化处理(ID转SN) + * 除平台SN(强制4位)外,其他一律32位 + * 基础格式:平台前缀PSN-应用场景标识-时间戳-随机码后缀 * */ public function idToSn($id,$type){ + $plat = AcPlat::findOne($this->pid); + $psn = $plat->sn; //"AYCL",强制4位 + $_sn = $psn.'-'; //4+1=5 + $_id = intval($id); + if($_id != $id) return false; + $res = false; + switch ($type) { + //常规运单 case 'order': - $pre = 'YD'; - $sn = '00000000000'; //11位 - $sn = substr($sn, 0, 11 - strlen($id)); - $sn .= $id; + $pre = 'YD'; //2位 + if($id>=0){ + $str = date('YmdHis'); //20250701120102,14位 + $_sn .= $pre.$str; //5+2+14 = 21; + $sn = '00000000000'; //11位 + $sn = substr($sn, 0, 11 - strlen($id)); + $sn .= $id; + $_sn .= $sn; //21+11 = 32 + }else{ + $str = date('YmdHis'); //20250701120102,14位 + $str2 = date('ymdH'); //25070112, 8位 + $sn = md5($str,true); //转换为二进制16个字符串的md5 + $_sn .= $pre.$str2.'-'.$sn; //5+2+8+1+16 = 32; + } + $res = true; + break; + //预制运单 + case 'orderPre': + $pre = 'PREYD'; //5位 + if($id>=0){ + $str = date('ymdHi'); //2507011201,10位 + $_sn .= $pre.$str.'-'; //5+5+10+1 = 21; + $sn = '00000000000'; //11位 + $sn = substr($sn, 0, 11 - strlen($id)); + $sn .= $id; + $_sn .= $sn; //21+11 = 32 + }else{ + $str = date('YmdHis'); //20250701120102,14位 + $str2 = date('ymd'); //250701, 6位 + $sn = md5($str,true); //转换为二进制16个字符串的md5 + $_sn .= $pre.$str2.$sn; //5+5+6+16 = 32; + } + $res = true; + break; + //新闻内容 + case 'news': + $pre = 'NEWS'; //4位 + if($id>=0){ + $str = date('YmdHis'); //20250701120102,14位 + $_sn .= $pre.$str; //5+4+14 = 23; + $sn = '000000000'; //9位 + $sn = substr($sn, 0, 9 - strlen($id)); + $sn .= $id; + $_sn .= $sn; //23+9 = 32 + }else{ + $str = date('YmdHis'); //20250701120102,14位 + $str2 = date('ymd'); //250701, 6位 + $sn = md5($str,true); //转换为二进制16个字符串的md5 + $_sn .= $pre.$str2.'-'.$sn; //5+4+6+1+16 = 32; + } + $res = true; + break; + default: + //默认方式,无须前缀、后缀 + $_str = date('YmdHis'); //20250701120102 + $md5_hash = md5($_str.$type,true); //转换为二进制16个字符串的md5 + $_sn .= $md5_hash; //5+16 = 21; + if($id>=0){ + $sn = '00000000000'; //11位 + $sn = substr($sn, 0, 11 - strlen($id)); + $sn .= $id; + $_sn .= $sn; //21+11 = 32 + }else{ + $_str = date('ymdHi'); //2507011201, 10位 + $_sn .= $_str.mt_rand(0,9); //21+10+1=32; + } + $res = true; break; } - return $pre.$sn; + if(!$res) return false; + return $_sn; } //校验财务验证码 @@ -187,4 +262,5 @@ } return ['res'=>true,'err'=>'','code'=>0]; } + } diff --git a/ctms-api/controllers/gm/v1/FeeorderController.php b/ctms-api/controllers/gm/v1/FeeorderController.php index ced298a..9338024 100755 --- a/ctms-api/controllers/gm/v1/FeeorderController.php +++ b/ctms-api/controllers/gm/v1/FeeorderController.php @@ -160,9 +160,11 @@ $this->preChonghong($detail); //操作日志处理 + $statusCode = $detail->status_code; + $_status = $status[$statusCode] ?? '未知'; $key = 'cwlogs'; $logs = $detail->cwlogs ? json_decode($detail->cwlogs, TRUE) : []; - $log = $this->user_info->username . '于' . date('Y-m-d H:i') . '申请冲红;冲红前状态码[' . $status . ']'; + $log = $this->user_info->username . '于' . date('Y-m-d H:i') . '申请冲红;冲红前状态码[' . $_status . ']'; array_unshift($logs, $log); /*修改票据状态,状态代码:2 */ diff --git a/ctms-api/controllers/gm/v1/IndexController.php b/ctms-api/controllers/gm/v1/IndexController.php index d246503..81d38c3 100755 --- a/ctms-api/controllers/gm/v1/IndexController.php +++ b/ctms-api/controllers/gm/v1/IndexController.php @@ -67,18 +67,18 @@ $_where[] = ['=', 'is_turnover', 0]; //排除交车单 $_where[] = ['between', 'sign_date', $start, $end]; $data = $model->find()->where($_where); - $order_today_count = $data->count(); + $order_today_count = (int)$data->count(); //今日交车 $_where = $where; $_where[] = ['=', 'is_turnover', 1]; //交车单 $_where[] = ['between', 'sign_date', $start, $end]; $data = $model->find()->where($_where); - $jiaoche_today_count = $data->count(); + $jiaoche_today_count = (int)$data->count(); //今日录单 $_where = $where; $_where[] = ['between', 'create_at', $start, $end]; $data = $model->find()->where($_where); - $order_today_create = $data->count(); + $order_today_create = (int)$data->count(); //昨日 $_end = $start; @@ -89,18 +89,18 @@ $_where[] = ['=', 'is_turnover', 0]; //排除交车单 $_where[] = ['between', 'sign_date', $_start, $_end]; $data = $model->find()->where($_where); - $order_yesterday_count = $data->count(); + $order_yesterday_count = (int)$data->count(); //昨日交车 $_where = $where; $_where[] = ['=', 'is_turnover', 1]; //交车单 $_where[] = ['between', 'sign_date', $_start, $_end]; $data = $model->find()->where($_where); - $jiaoche_yesterday_count = $data->count(); + $jiaoche_yesterday_count = (int)$data->count(); //昨日录单 $_where = $where; $_where[] = ['between', 'create_at', $_start, $_end]; $data = $model->find()->where($_where); - $order_yesterday_create = $data->count(); + $order_yesterday_create = (int)$data->count(); //本月起始时间点 $_start = date('Y-m-01 00:00:00'); @@ -113,31 +113,33 @@ $_where[] = ['=', 'is_turnover', 0]; //排除交车单 $_where[] = ['between', 'sign_date', $_start, $_end]; $data = $model->find()->where($_where); - $order_month_count = $data->count(); + $order_month_count = (int)$data->count(); //本月交车 $_where = $where; $_where[] = ['=', 'is_turnover', 1]; $_where[] = ['between', 'sign_date', $_start, $_end]; $data = $model->find()->where($_where); - $jiaoche_month_count = $data->count(); + $jiaoche_month_count = (int)$data->count(); //累计运单 $_where = $where; $_where[] = ['=', 'is_turnover', 0]; //排除交车单 $data = $model->find()->where($_where); - $order_all_count = $data->count(); + $order_all_count = (int)$data->count(); //累计交车 $_where = $where; $_where[] = ['=', 'is_turnover', 1]; $data = $model->find()->where($_where); - $jiaoche_all_count = $data->count(); + $jiaoche_all_count = (int)$data->count(); $return = []; $return['code'] = 200; $return['msg'] = '首页数据下载!'; $return['data'] = [ 'orderToday' => $order_today_count, - 'orderYesterday' => $order_yesterday_count, + 'orderTodayCreate'=>$order_today_create, + 'orderYesterday'=>$order_yesterday_count, + 'orderYesterdayCreate'=>$order_yesterday_create, 'orderMonth' => $order_month_count, 'orderTotal' => $order_all_count, 'jiaocheToday' => $jiaoche_today_count, diff --git a/ctms-api/controllers/gm/v1/JiaocheController.php b/ctms-api/controllers/gm/v1/JiaocheController.php index d271ebe..9d2dddd 100755 --- a/ctms-api/controllers/gm/v1/JiaocheController.php +++ b/ctms-api/controllers/gm/v1/JiaocheController.php @@ -32,85 +32,348 @@ class JiaocheController extends Common { public function beforeAction($action) - { - $session = Yii::$app->session; - $pid = $session->get('pid'); - $pid = 1; - if (!$pid) { - $return = []; - $return['code'] = 0; - $return['msg'] = '您正使用本系统内部接口,禁止非法链接使用!'; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - return parent::beforeAction($action); - } + { + if (!$this->pid) { + $this->result('您正使用本系统内部接口,禁止非法链接使用!'); + } + return parent::beforeAction($action); + } public function actionIndex() { - $return = []; - $return['code'] = 200; - $return['msg'] = '您正使用CMTS系统,本接口为内部系统接口,禁止非法链接使用!'; - $return['data'] = ['total' => 0, 'data' => [], 'page' => 1]; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); + $apis = [ + 'list'=>'列表', + 'detail'=>'详情', + 'get-status'=>'状态字典', + 'add'=>'添加', + 'edit'=>'编辑', + 'delete'=>'删除', + 'show'=>'显示', + 'hide'=>'隐藏', + 'ajax'=>'ajax操作' + ]; + $this->result('您正使用CMTS-GM系统运单交车管理接口!', $apis, 200); } //订单列表 public function actionList() { - $pid = Yii::$app->session->get('pid'); - $pid = 1; - $session = Yii::$app->session; + $s = $this->search(); + $res = $s['res']; + if (!$res) { + $this->result('没有查询到相应的数据!', [], 0); + } + $data = $s['data']; + $this->showOrders($res, $data); + } + + public function actionGetStatus() + { + $status = Yii::$app->params['OrderPreStatus']; + $this->result('查询成功!', $status, 200); + } + + public function actionGetPayments() + { + $payments = $this->getPayments(); + $this->result('查询成功!', $payments, 200); + } + + public function actionDetail() + { + $order = $this->preUpdate(); + $this->showOrder($order); + } + + public function actionAdd() + { + //数据预检查、编排 + $pre = $this->preSave('add'); + if(!$pre['data']) $this->result('数据预检查未通过,保存失败', $pre['data'], 100); + + //保存资料 + $model = new AcOrder(); + foreach ($pre['data'] as $key => $val) { + $model->$key = $val; + } + $res = $model->save(); + $msg = '数据保存失败!'; + if(!$res) $this->result($msg, [], 100); + + $msg = '数据保存成功!'; + if($pre['err']) $msg .= $pre['err_msg']; + + $return = []; + $return['id']= $model->attributes['id']; //获取插入后id; + $this->result($msg,$return, 200); + } + + public function actionEdit() + { + $detail = $this->preUpdate(); + $res = $this->userPrivilege($this->user_info,'orderEdit',$detail); + if(!$res) $this->result('您没有操作权限!',[],403); + + //数据预检查、编排 + $pre = $this->preSave('edit'); + if(!$pre['data']) $this->result('数据预检查未通过,保存失败', $pre['data'], 100); + + //保存资料 + $data = $pre['data']; + foreach ($data as $key=>$val) { + $detail->$key = $val; + } + $res = $detail->save(); + $msg = '数据编辑失败!'; + if(!$res) $this->result($msg, [], 100); + + $msg = '数据编辑成功!'; + if($pre['err']) $msg .= $pre['err_msg']; + + $return = []; + $return['data']= $detail; + $this->result($msg,$return, 200); + } + + public function actionDelete() + { + $detail = $this->preUpdate(); + $res = $this->userPrivilege($this->user_info,'orderDelete',$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']) { + default: + break; + } + $this->result($msg, [], $errorCode); + } + + /** + * 订单搜索 + * @param $search [] 预置搜索条件 + * @param $sql string 直接使用SQL语句,需要配合$args一同使用,传入后search一切条件无效 + * @param array $args sql的参数 + * @return array + */ + private function search($search = [], $sql = '', $args = []) + { + $pid = $this->pid; $return = []; $model = new AcOrder(); - $where = $orwhere = []; - $where[] = 'and'; - $where[] = ['=', 'pid', $pid]; - $post = Yii::$app->request->post(); - $search = isset($post['search']) ? $post['search'] : []; - - $CarModel = new AcCar(); - if (isset($search['carno']) && !empty($search['carno'])) { - $search['carno'] = trim($search['carno']); - $cars = $CarModel->find()->where(['LIKE', 'num_left', $search['carno']])->limit(5)->offset(0)->all(); //最多仅显示可匹配车牌号的前5个 - if (empty($cars)) { - $return['code'] = 400; - $return['msg'] = '未查询到相关车辆'; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); + $page = $this->page; + $pageSize = $this->pageSize; + if ($sql && $args) { + $data = $model->find()->where($sql, $args); + } else { + $where = $orWhere = []; + $where[] = 'and'; + $where[] = ['=', 'pid', $pid]; + $deleted = 0; + $where[] = ['=', 'deleted', $deleted]; + $where[] = ['=', 'is_turnover', 1]; //交车单 + + $post = $this->postdata; + $search = $search ?? $post['search']; + + //车牌号使用完整精准搜索(皖A88888) + $CarModel = new AcCar(); + if (!empty($search['carno'])) { + $search['carno'] = trim($search['carno']); + $sql = 'CONCAT(num_p,num_area,num_left) = :carno or num_frame LIKE :carno'; + $cars = $CarModel->find()->where($sql, [':carno' => $search['carno']])->limit(5)->offset(0)->all(); + + //最多仅显示可匹配车牌号的前5个 + if (empty($cars)) { + $return['code'] = 400; + $return['msg'] = '未查询到相关车辆'; + return ['res' => FALSE, 'data' => $return]; + } else { + $car_ids = []; + foreach ($cars as $car) { + $car_ids[] = $car->id; + } + $where[] = ['IN', 'car_id', $car_ids]; + } + } + + if (!empty($search['city'])) { + $search['city'] = trim($search['city']); + $where[] = ['LIKE', 'aim_city', $search['city']]; + } + + if (!empty($search['phone'])) { + $search['phone'] = trim($search['phone']); + $orwhere = ['or', ['LIKE', 'sender_mobiles', $search['phone']], ['LIKE', 'receiver_mobiles', $search['phone']]]; + } + + $search['employee'] = isset($search['employee']) ? (int)$search['employee'] : ''; + $EmployeeModel = new AcEmployee(); + 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['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['from_mid'] = isset($search['from_mid']) ? (int)$search['from_mid'] : ''; + $UserModel = new User(); + if (!empty($search['from_mid'])) { + $where[] = ['=', 'from_mid', $search['from_mid']]; + $user = $UserModel->findById(['id' => $search['from_mid']]); + $search['from_mtitle'] = isset($user->username) ? $user->username : ''; + } + + $citys = $search['citys'] ?? []; + if ($citys) { + $_orwhere = [ + 'or', + ['OR LIKE', 'aim_city', $citys], + ['OR LIKE', 'start_city', $citys] + ]; + $orWhere[] = $_orwhere; } else { - $car_ids = []; - foreach ($cars as $car) { - $car_ids[] = $car->id; + $search['aim_city'] = isset($search['aim_city']) ? trim($search['aim_city']) : ''; + if (!empty($search['aim_city'])) { + $where[] = ['LIKE', 'aim_city', $search['aim_city']]; + } + $search['start_city'] = isset($search['start_city']) ? trim($search['start_city']) : ''; + if (!empty($search['start_city'])) { + $where[] = ['LIKE', 'start_city', $search['start_city']]; + } + } + + 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']); + } + + if (isset($search['is_holdon'])) { + $search['is_holdon'] = (int)$search['is_holdon']; + $where[] = ['=', 'is_holdon', $search['is_holdon']]; + } + if (isset($search['is_over'])) { + $search['is_over'] = (int)$search['is_over']; + $where[] = ['=', 'is_over', $search['is_over']]; + } + if (isset($search['is_commission'])) { + $search['is_commission'] = (int)$search['is_commission']; + $where[] = ['=', 'is_commission', $search['is_commission']]; + } + //运单是否通过了财务确认 + $search['is_cwqr'] = $search['is_cwqr'] ?? ($get['is_cwqr'] ?? ''); + if ($search['is_cwqr'] != '') { + $search['is_cwqr'] = (int)$search['is_cwqr']; + $where[] = ['=', 'is_cwqr', $search['is_cwqr']]; + } + + //签约时间筛选 + $search['sign_m'] = isset($search['sign_m']) ? $search['sign_m'] : ''; + $search['sign_after'] = isset($search['sign_after']) ? $search['sign_after'] : ''; + $search['sign_before'] = isset($search['sign_before']) ? $search['sign_before'] : ''; + //按月份筛选 + if (!empty($search['sign_m'])) { + $start = strtotime($search['sign_m']); + $s = date("Y-m-d H:i:s", $start); + $ldm = strtotime("last day of " . $s); + $m = date("Y-m-d", $ldm) . " 23:59:59"; + $end = strtotime($m); + $where[] = ['between', 'sign_date', $start, $end]; + } //按指定时段筛选 + else if (!empty($search['sign_after']) && !empty($search['sign_before'])) { + $start = strtotime($search['sign_after']); + $end = strtotime($search['sign_before']); + $where[] = ['between', 'sign_date', $start, $end]; + } //按指定时间临界点筛选(以不早于为优先筛选条件) + else if (!empty($search['sign_after'])) { + $start = strtotime($search['sign_after']); + $where[] = ['>=', 'sign_date', $start]; + } else if (!empty($search['sign_before'])) { + $end = strtotime($search['sign_before']); + $where[] = ['<=', 'sign_date', $end]; + } + + //仅查看我自己的 + if (isset($search['onlyme']) && $search['onlyme'] == 1) { + $where[] = ['=', 'create_by', $this->user_id]; + } + + //带序列号搜索(TBD:后期考虑改为精准唯一搜索) + if (isset($search['sn']) && $search['sn'] != 'undefined' && $search['sn']) { + $where[] = ['LIKE', 'sn', $search['sn']]; + } + + //引用设定特别约定的查询条件(不允许从客户端直接传入) + if ($this->addtionWhere) { + $orWhere[] = $this->addtionWhere; + } + + $data = $model->find()->where($where); + //要确保$orWhere的每一个子键都是['or',['=',字段,值],['=',字段,值]]的方式,or,=等符号是约定俗成的 + if ($orWhere) { + foreach ($orWhere as $v) { + $data = $data->andWhere($v); } - $where[] = ['IN', 'car_id', $car_ids]; } } - if (isset($search['city']) && !empty($search['city'])) { - $search['city'] = trim($search['city']); - $where[] = ['LIKE', 'start_city', $search['city']]; - } - - if (isset($search['phone']) && !empty($search['phone'])) { - $search['phone'] = trim($search['phone']); - $orwhere = ['or', ['LIKE', 'sender_mobiles', $search['phone']], ['LIKE', 'receiver_mobiles', $search['phone']]]; - } - - $deleted = 0; - $where[] = ['=', 'deleted', $deleted]; - $where[] = ['=', 'is_turnover', 1]; //交车单 - - $data = $model->find()->where($where)->andwhere($orwhere); - - $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']); - + $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)->all(); + + return ['res' => $res, 'data' => $data]; + } + + /* + 订单数据显示格式化 + */ + private function showOrders($orderRes, $data) + { $status = Yii::$app->params['OrderStatus']; $cids = $sids = $eids = $mids = []; - if ($res) { - foreach ($res as $r) { + if ($orderRes) { + foreach ($orderRes as $r) { $cids[$r->car_id] = $r->car_id; $sids[$r->store_id] = $r->store_id; $eids[$r->employee_id] = $r->employee_id; @@ -119,9 +382,7 @@ } $model = new AcStore(); - $where = []; - $where['pid'] = Yii::$app->session->get('pid'); - $_stores = $model->find()->where(['in', 'id', $sids])->all(); + $_stores = $model->find()->where(['in', 'id', $sids])->indexBy('id')->all(); $stores = []; foreach ($_stores as $s) { $stores[$s->id] = $s->toArray(); @@ -134,7 +395,7 @@ $employees[$s->id] = $s->toArray(); } - $model = new User(); + $model = new Fans(); $users = []; $_users = $model->find()->where(['in', 'id', $mids])->all(); foreach ($_users as $s) { @@ -151,6 +412,12 @@ $sids[] = $s->series_id; $cars[$s->id] = $s->toArray(); } + unset($s); + + $model = new AcCarBrand(); + $brands = $model->find()->where(['in', 'id', $bids])->indexBy('id')->all(); + $model = new AcCarSeries(); + $series = $model->find()->where(['in', 'id', $sids])->indexBy('id')->all(); if ($cars) { foreach ($cars as &$car) { @@ -173,74 +440,315 @@ } } } + unset($car); $orders = []; - $unsets = ['pid', 'commission', 'commission_left', 'fee_truck', 'create_at', 'create_by', 'deleted', 'income', 'expense', 'fee_deliver', 'fee_extra', 'fee_insurance', 'fee_pickup', 'fee_urgent', 'from_bid', 'from_mid', 'is_commission', 'is_cwqr', 'is_holdon', 'is_over', 'pay_receive_pids', 'pay_send_pids', 'pre_id', 'remark', 'car_extra', 'thumb_b', 'thumb_f', 'thumb_l', 'thumb_r', 'thumbs', 'driving_lisence', 'videos']; - foreach ($res as $s) { - $car = $cars[$s->car_id]; + foreach ($orderRes as $s) { + $car = []; + if ($s->car_id) { + $car = $cars[$s->car_id]; + } $s = $s->toArray(); - if (isset($exts[$s['from_mid']])) { - foreach ($exts[$s['from_mid']] as $col => $val) { - $s[$col] = $val; - } - } - foreach ($unsets as $us) { - unset($s[$us]); - } + $weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六']; $wk = date('w', $s['sign_date']); $s['signdate'] = date('Y-m-d ', $s['sign_date']) . '星期' . $weekdays[$wk]; - $s['from_province'] = Yii::$app->params['regionAreas'][$s['start_province']]; - $s['to_province'] = Yii::$app->params['regionAreas'][$s['aim_province']]; - $s['car_number'] = $car['number2']; - $s['car_title'] = $car['title']; + $s['from_province'] = $s['start_province'] ? Yii::$app->params['regionAreas'][$s['start_province']] : ''; + $s['to_province'] = $s['aim_province'] ? Yii::$app->params['regionAreas'][$s['aim_province']] : ''; + $s['car_number'] = $car['number2'] ?? ''; + $s['car_title'] = $car['title'] ?? ''; + $s['car_title'] = $s['car_title'] ? $s['car_title'] : ($car['title2'] ?? ''); $s['status'] = $status[$s['status_code']]; $orders[] = $s; } + unset($s); $return = []; $return['code'] = 200; $return['msg'] = '订单查询成功!'; - $return['data'] = ['total' => $data->count(), - 'data' => [ - 'orders' => $orders, - 'employees' => $employees, - 'stores' => $stores, - 'users' => $users - ], - 'page' => 1]; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); + $return['data'] = [ + 'total' => $data->count(), + 'orders' => $orders, + 'employees' => $employees, + 'stores' => $stores, + 'users' => $users, + 'page' => $this->page + ]; + $this->result($return['msg'], $return['data'], $return['code']); } - public function actionDetail() + /* + * 数据更新前的预检查,返回对应关联数据 + * 必须确保get与post数据中均包含需更新的数据id且一致 + * */ + private function preUpdate() { - $pid = Yii::$app->session->get('pid'); - $status = Yii::$app->params['OrderStatus']; - $post = Yii::$app->request->post(); - $return = []; - - $id = isset($post['oid']) ? $post['oid'] : 0; - if ($id <= 0) { - $return['code'] = 200; - $return['msg'] = '查询参数错误!'; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); + $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 AcOrder(); + $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['create_by'] = $this->user_id; + $data['status_code'] = 1; //订单处于创建待审核状态 + $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参数不匹配,请检查'); + $data['update_at'] = $_time; + break; } - $AcOrder = new AcOrder(); - $order = $AcOrder->findOne($id); + $data['pid'] = $this->pid; + + $cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city', 'aim_address' => 'aim_address', + 'signer' => 'signer', 'bind' => 'bind', 'wtdw' => "wtdw", + 'sender_name' => 'sender_name', 'sender_idcard' => 'sender_idcard', 'sender_mobiles' => 'sender_mobiles', + 'receiver_name' => 'receiver_name', 'receiver_idcard' => 'receiver_idcard', 'receiver_mobiles' => 'receiver_mobiles', + 'car_extra' => 'car_extra']; + foreach ($cols as $col=>$key) { + if (isset($post[$key]) && $post[$key] !='') { + $data[$col] = trim($post[$key]); + } + } + + $cols = ['car_id'=>'car_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', 'not_insurance' => 'not_insurance', 'weituo' => 'weituo']; + foreach ($cols as $col => $key) { + $data[$col] = isset($post[$key]) ? (int)$post[$key] : 0; + } + + //图片组处理 + $col = $key = 'thumbs'; + if (isset($post[$key]) && !empty($post[$key])) { + $imgs = $post[$key]; //数组格式 + $imgs = array_unique($imgs); + $imgs = json_encode($imgs); + $data[$col] = $imgs; + } + + $col = $key = 'remark'; + if (isset($post[$key]) && $post[$key] != '') { + $data[$col] = htmlspecialchars($post[$key]); + } + + $sign_date = isset($post['sign_date']) ? strtotime($post['sign_date']) : ''; + $data['sign_date'] = $sign_date ? $sign_date : $_time; + + //部分规则校验 + $has_err = false; + $_err = []; + $data['is_cwqr'] = 0; //修改财务确认状态为待确认 + $DefaultCarInsuranceValueMax =Yii::$app->params['DefaultCarInsuranceValueMax']; + /*不投保的,保额不超过20W,保费为0*/ + if ($data['not_insurance']) { + if ($data['fee_insurance']) { + $data['fee_insurance']=0; + $has_err = true; + $_err[] = '勾选了不投保,已强制修改保费为0!'; + } + if ($data['car_value']>$DefaultCarInsuranceValueMax) { + $data['car_value'] = $DefaultCarInsuranceValueMax; + $has_err = true; + $_err[] = '勾选了不投保,默认最高赠送的运输险保额不超过'.$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; + $_err[] = '请注意,运费未正确填写!'; + } + if (!$data['pay_send']&&!$data['pay_receive']) { + $has_err = true; + $_err[] = '请注意,到收运费及起运地预收运费均未填写!'; + } + if ($fee_total !=$data['fee_total']) { + $has_err = true; + $_err[] = '请注意,所填运费、保费、提车费、送车费、额外费用、加急费等各项费用汇总的值与所填写的总费用不一致,请检查并更新'; + } + if ($fee_pay !=$data['fee_total']) { + $has_err = true; + $_err[] = '请注意,所填起运地预付运费、到收运费的汇总值与所填写的总费用不一致,请检查并更新'; + } + + /*门店归属*/ + if($data['employee_id']){ + $employeeModel = new AcEmployee(); + $employee = $employeeModel->findOne($this->employee_id); + if(!$employee){ + $has_err = true; + $_err[] = '指定的员工信息并不存在,已自动清除关联'; + $data['employee_id'] = 0; + } + if ($employee && !$data['store_id']) { + $data['store_id'] = $employee->store_id; + } + } + + //查询联系人信息是否在库 + $sender_mobiles = isset($data['sender_mobiles']) ? $data['sender_mobiles'] : null; + $receiver_mobiles = isset($data['receiver_mobiles']) ? $data['receiver_mobiles'] : null; + if (isMobile($sender_mobiles)) { + $this->contactorToFans($sender_mobiles,$data); + } + if ($receiver_mobiles && $receiver_mobiles != $sender_mobiles) { + if (isMobile($receiver_mobiles)) { + $this->contactorToFans($receiver_mobiles,$data); + } + } + + //生成现付说明 + $payments = $this->getPayments(); + if ($post['pay_send']) { + $txt = $post['payto'] . '收款' . $post['pay_send'] . '元(' . $payments[$post['payment']] . ')'; + if ($data['remark']) { + $data['remark'] .= ' ; ' . $txt; + } else { + $data['remark'] = $txt; + } + } + + //没有指定车辆ID时,生成车辆信息(确保前端传入了必须的参数:isTempCarno,carno_left,carno_frame,carno_p,carno_area,carno_left,carno_title + if(!$data['car_id']){ + $carModel = new AcCar(); + $where = []; + if ($post['isTempCarno']) { + $post['carno_left'] .= '临'; + } + if (empty($post['carno_frame'])) { + $where['num_p'] = $post['carno_p']; + $where['num_area'] = $post['carno_area']; + $where['num_left'] = $post['carno_left']; + } + $post['carno_frame'] = $post['carno_frame'] ?? ''; + if (!empty($post['carno_frame'])) { + $where['num_frame'] = $post['carno_frame']; + } + $car = $carModel->find()->where($where)->one(); + if (empty($car)) { + $carModel->pid = $this->pid; + $carModel->num_frame = $post['carno_frame']; + $carModel->num_p = $post['carno_p']; + $carModel->num_area = $post['carno_area']; + $carModel->num_left = $post['carno_left']; + $carModel->title = $post['carno_title']; + $carModel->status_code = 1; + $carModel->create_at = $_time; + $carModel->update_at = $_time; + $carModel->save(); + $car_id = $carModel->attributes['id']; + } else { + $car_id = $car->id; + } + $data['car_id'] = $car_id; + } + + $return = ['data'=>$data,'err'=>$has_err,'err_msg'=>$_err]; + return $data; + } + + /* + * 将联系人信息转存入表,同时存入主数据库的fans表 + * */ + private function contactorToFans($mobile,$data) + { + $_time = time(); + $res = false; + //查询联系人信息是否在库 + $contactModel = new AcContact(); + $contactor = $contactModel->find()->where(['mobile'=>$mobile,'pid'=>$this->pid])->one(); + if($contactor){ + $name = $data['sender_name'] ?? $contactor->name; + $idcard = $data['idcard'] ?? $contactor->idcard; + if($name != $contactor->name || $idcard != $contactor->idcard){ + $contactor->update_at = $_time; + $contactor->name = $name; + $contactor->idcard = $idcard; + $res = $contactor->save(); + } + }else{ + $contactModel->name = $data['sender_name'] ?? ''; + $contactModel->mobile = $data['sender_mobiles']; + $contactModel->pid = $this->pid; + $contactModel->idcard = $data['sender_idcard'] ?? ''; + $contactModel->create_at = $_time; + $contactModel->status_code = 1; + $res = $contactModel->save(); + } + + //框架核心数据表Fans + $userModel = new Fans(); + $user = $userModel->findByUsername($mobile); + if (!$user) { + $userModel->mobile = $mobile; + $userModel->email = $mobile.'@hiluker.com'; + $userModel->setPassword(Yii::$app->params['defaultFansPassword']); + $userModel->generateAuthKey(); + $userModel->created_at = $_time; + $userModel->from = 'ctms'; + $userModel->save(); + } + return $res; + } + + private function showOrder($order) + { $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 Fans(); + $fans = $model->findOne($detail['from_mid']); + $user = $fans->toArray(); + $model = new AcFansExt(); + $_exts = $model->find()->where(['mid' => $detail['from_mid'],'mobile'=>$fans->mobile, 'pid' => $this->pid, 'deleted' => 0])->indexBy('id')->all(); + foreach ($_exts as $ext) { + $ext = $ext->toArray(); + $user[$ext['key']] = $ext['value']; + } + $detail['_user'] = $user; + + if ($detail['store_id']) { + $model = new AcStore(); + $store = $model->findOne($detail['store_id']); + if ($store) { + $detail['store_title'] = $store->title; + $detail['_store'] = $store->toArray(); + } } - $model = new AcEmployee(); - $employee = $model->findOne($detail['employee_id']); - if ($employee) { - $detail['employee_title'] = $employee->name; + if ($detail['employee_id']) { + $model = new AcEmployee(); + $employee = $model->findOne($detail['employee_id']); + if ($employee) { + $detail['employee_title'] = $employee->name; + $detail['_employee'] = $employee->toArray(); + } } $detail['car_owner_id'] = $detail['car_brand_id'] = $detail['car_series_id'] = 0; @@ -251,22 +759,8 @@ $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']; - } - } + $detail['car_number'] = $detail['car_number'] ?: $car->num_frame; + $detail['_car'] = $car->toArray(); } $AcCarOwner = new AcCarOwner(); @@ -274,6 +768,7 @@ if ($owner) { $_owner = User::findOne($detail['car_owner_id']); $detail['car_owner'] = $_owner->username . '【' . $_owner->mobile . '】'; + $detail['_car_owner'] = $_owner->toArray(); } $AcCarBrand = new AcCarBrand(); @@ -283,123 +778,57 @@ } $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; + $sn = substr($sn, 0, 11 - strlen($order->id)); + $sn .= $order->id; + $detail['sn'] = $detail['sn'] ? $detail['sn'] : $sn; - $detail['signdate'] = date('Y-m-d 星期w', $detail['sign_date']); - $detail['from_province'] = Yii::$app->params['regionAreas'][$detail['start_province']]; - $detail['to_province'] = Yii::$app->params['regionAreas'][$detail['aim_province']]; - $detail['remark'] = htmlspecialchars_decode($detail['remark']); + $weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六']; + $wk = date('w', $detail['date']); + $detail['signdate'] = date('Y-m-d 星期' . $weekdays[$wk], $detail['sign_date']); + $detail['from_province'] = isset($detail['start_province']) ? Yii::$app->params['regionAreas'][$detail['start_province']] : ''; + $detail['to_province'] = isset($detail['aim_province']) ? Yii::$app->params['regionAreas'][$detail['aim_province']] : ''; + $detail['remark'] = $detail['remark'] || ''; + $detail['remark'] = trim($detail['remark']) ? htmlspecialchars_decode(trim($detail['remark'])) : ''; - // $src = 'http://'.$_SERVER["HTTP_HOST"].'/upload'; - // $detail['thumb_b'] = $src.$detail['thumb_b']; - - $unsets = ['commission', 'commission_left', 'fee_truck', 'create_at', 'create_by', 'deleted', 'income', 'expense', 'fee_deliver', 'fee_extra', 'fee_insurance', 'fee_pickup', 'fee_urgent', 'from_bid', 'from_mid', 'is_commission', 'is_cwqr', 'is_holdon', 'is_over', 'pay_receive_pids', 'pay_send_pids', 'pre_id']; - foreach ($unsets as $us) { - unset($detail[$us]); + $imgDir = Yii::getAlias('@upload'); + $imgKeys = ['driving_lisence', 'thumb_f', 'thumb_b', 'thumb_l', 'thumb_r']; + foreach ($imgKeys as $k) { + $detail[$k] = $detail[$k] ? $detail[$k] : '/pics/nopic.jpg'; + $url_pre = substr($detail[$k], 0, 4); + if ($url_pre == '/pic') { + $detail[$k . '_url'] = Url::to('@upload' . $detail[$k], $this->imgHttp); + } else if ($url_pre == 'http') { + $detail[$k . '_url'] = $detail[$k]; + } } - $return['code'] = 200; - $return['msg'] = '订单查询成功!'; - $return['data'] = $detail; + $detail['thumbs'] = $detail['thumbs'] ? json_decode($detail['thumbs']) : []; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); + if ($detail['thumbs']) { + $thumbs = $detail['thumbs']; + $thumbs_url = []; + foreach ($thumbs as $k => $v) { + $url_pre = substr($v, 0, 4); + if ($url_pre == '/pic') { + $v_url = Url::to('@upload' . $v, $this->imgHttp); + } else if ($url_pre == 'http') { + $v_url = $v; + } + $thumbs_url[] = ['src' => $v, 'url' => $v_url]; + } + $detail['thumbs_url'] = $thumbs_url; + } + + $this->result('订单查询成功!', $detail, 200); } - public function actionCreate() - { - $get = Yii::$app->request->get(); - $post = Yii::$app->request->post(); - $pid = (int)$post['pid']; - - //格式化数据 为空的项则不修改 - //目标键=》POST键 - $cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city', 'aim_address' => 'aim_address', - 'signer' => 'signer', 'bind' => 'bind', 'wtdw' => "wtdw", - 'sender_name' => 'sender_name', 'sender_idcard' => 'sender_idcard', 'sender_mobiles' => 'sender_mobiles', - 'receiver_name' => 'receiver_name', 'receiver_idcard' => 'receiver_idcard', 'receiver_mobiles' => 'receiver_mobiles', - 'car_extra' => 'car_extra']; - foreach ($cols as $col => $key) { - if (isset($post[$key]) && $post[$key] != '') { - $data[$col] = trim($post[$key]); - } - } - //'car_id'=>'car_id','employee_id'=>'employee_id', - //'weituo'=>'weituo' - $cols = ['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', 'not_insurance' => 'not_insurance',]; - foreach ($cols as $col => $key) { - $data[$col] = 0; - if (isset($post[$key]) && $post[$key] != '') { - $data[$col] = (int)$post[$key]; - } - } - - $cols = ['remark' => 'remark']; - foreach ($cols as $col => $key) { - if (isset($post[$key]) && $post[$key] != '') { - $data[$col] = htmlspecialchars($post[$key]); - } - } - $data['remark'] = isset($data['remark']) ? isset($data['remark']) : ''; - - /*@sign_date: 1649952000000*/ - $sign_date = isset($post['sign_date']) ? strtotime($post['sign_date'] / 1000) : ''; - $data['sign_date'] = $sign_date ? $sign_date : time(); - - $mid = isset($post['mid']) ? (int)$post['mid'] : 11; //11是方孟 - $data['create_by'] = $mid; - $data['is_cwqr'] = 0; //修改财务确认状态为待确认 - $data['is_turnover'] = 1; //交车补单 - $data['status_code'] = 1; //订单处于创建待审核状态 - - //部分规则校验 - $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']) { - $return = []; - $return['code'] = 100; - $return['msg'] = '请注意,运费未正确填写!'; - $return['data'] = []; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); - } - - if ($fee_total != $data['fee_total']) { - $return = []; - $return['code'] = 100; - $return['msg'] = '所填各项费用汇总的值与所填写的总费用不一致!'; - $return['data'] = []; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); - } - if ($fee_pay != $data['fee_total']) { - $return = []; - $return['code'] = 100; - $return['msg'] = '所填现付与到收费用汇总的值与所填写的总费用不一致!'; - $return['data'] = []; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); - } - - $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'] = 0; - $model = new AcEmployee(); - $employee = $model->findOne($data['employee_id']); - if ($employee) { - $data['store_id'] = $employee->store_id; - } - - //校验生成部分补充数据 - //生成现付说明 + private function getPayments(){ $payments = [ 'wechat' => '微信', 'alipay' => '支付宝', @@ -408,227 +837,6 @@ 'bankunion' => '银联', 'others' => '其他' ]; - if ($post['pay_send']) { - $txt = $post['payto'] . '收款' . $post['pay_send'] . '元(' . $payments[$post['payment']] . ')'; - $data['remark'] .= ' ; ' . $txt; - } - //生成车辆信息 - $carModel = new AcCar(); - $where = []; - if ($post['isTempCarno']) { - $post['carno_left'] .= '临'; - } - if (empty($post['carno_frame'])) { - $where['num_p'] = $post['carno_p']; - $where['num_area'] = $post['carno_area']; - $where['num_left'] = $post['carno_left']; - } - if (!empty($post['carno_frame'])) { - $where['num_frame'] = $post['carno_frame']; - } - $car = $carModel->find()->where($where)->one(); - if (empty($car)) { - $carModel->pid = $pid; - $carModel->num_frame = $post['carno_frame']; - $carModel->num_p = $post['carno_p']; - $carModel->num_area = $post['carno_area']; - $carModel->num_left = $post['carno_left']; - $carModel->title = $post['carno_title']; - $carModel->status_code = 1; - $carModel->create_at = time(); - $carModel->update_at = time(); - $carModel->save(); - $car_id = $carModel->attributes['id']; - } else { - $car_id = $car->id; - } - $data['car_id'] = $car_id; - - //查询联系人信息是否在库 - $sender_mobiles = isset($data['sender_mobiles']) ? $data['sender_mobiles'] : NULL; - $receiver_mobiles = isset($data['receiver_mobiles']) ? $data['receiver_mobiles'] : NULL; - if ($sender_mobiles) { - //项目分支自有数据表 - $contactModel = new AcContact(); - $contactor = $contactModel->find()->where(['mobile' => $data['sender_mobiles'], 'pid' => $pid])->one(); - if (empty($contactor)) { - $contactModel->name = isset($data['sender_name']) ? $data['sender_name'] : '客户'; - $contactModel->mobile = $data['sender_mobiles']; - $contactModel->pid = $pid; - $contactModel->idcard = isset($data['sender_idcard']) ? $data['sender_idcard'] : ''; - $contactModel->create_at = time(); - $contactModel->status_code = 1; - $contactModel->save(); - } else { - $_contactDatas = []; - $_contactDatas['name'] = isset($data['sender_name']) ? $data['sender_name'] : $contactModel->name; - $_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel->idcard; - if ($_contactDatas['name'] == $contactModel->name && $_contactDatas['idcard'] == $contactModel->idcard) { - //无须做任何变化 - } else { - $_contactDatas['update_at'] = time(); - $contactModel->updateAll($_contactDatas, ['id' => $contactModel->id]); - } - } - - //框架核心数据表Fans - $userModel = new Fans(); - $user = $userModel->findByUsername($sender_mobiles); - if (empty($user)) { - $userModel->mobile = $sender_mobiles; - $userModel->email = $sender_mobiles . '@hiluker.com'; - $userModel->setPassword(Yii::$app->params['defaultFansPassword']); - $userModel->generateAuthKey(); - $userModel->created_at = time(); - $userModel->from = 'ctms'; - $userModel->save(); - } - } - if ($receiver_mobiles && $receiver_mobiles != $sender_mobiles) { - //项目分支自有数据表 - $contactModel2 = new AcContact(); - $contactor2 = $contactModel2->find()->where(['mobile' => $data['receiver_mobiles'], 'pid' => $pid])->one(); - if (empty($contactor2)) { - $contactModel2->name = isset($data['receiver_name']) ? $data['receiver_name'] : '客户'; - $contactModel2->mobile = $data['receiver_mobiles']; - $contactModel2->pid = $pid; - $contactModel2->idcard = isset($data['receiver_idcard']) ? $data['receiver_idcard'] : ''; - $contactModel2->create_at = time(); - $contactModel2->status_code = 1; - $contactModel2->save(); - } else { - $_contactDatas = []; - $_contactDatas['name'] = isset($data['receiver_name']) ? $data['receiver_name'] : $contactModel2->name; - $_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel2->idcard; - if ($_contactDatas['name'] == $contactModel2->name && $_contactDatas['idcard'] == $contactModel2->idcard) { - //无须做任何变化 - } else { - $_contactDatas['update_at'] = time(); - $contactModel2->updateAll($_contactDatas, ['id' => $contactModel2->id]); - } - } - //框架核心数据表Fans - $userModel = new Fans(); - $user = $userModel->findByUsername($receiver_mobiles); - if (empty($user)) { - $userModel->mobile = $receiver_mobiles; - $userModel->email = $receiver_mobiles . '@hiluker.com'; - $userModel->setPassword(Yii::$app->params['defaultFansPassword']); - $userModel->generateAuthKey(); - $userModel->created_at = time(); - $userModel->from = 'ctms'; - $userModel->save(); - } - } - - //保存资料 - $AcOrder = new AcOrder(); - foreach ($data as $key => $val) { - $AcOrder->$key = $val; - } - - $res = $AcOrder->save(); - $id = $AcOrder->attributes['id']; //获取插入后id - - if ($res) { - $return = []; - $return['code'] = 200; - $return['msg'] = '订单保存成功!'; - $return['data'] = ['id' => $id]; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); - } else { - $return = []; - $return['code'] = 100; - $return['msg'] = '订单保存失败!'; - $return['data'] = []; - exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT)); - } - } - - 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 AcOrder(); - $res = $model->findOne($id); - $return = []; - $return['timeout'] = 1; //几秒后自动跳转 - $return['status'] = 0; - $return['ajax'] = 1; - - if (!$res) { - $return['msg'] = '订单数据不存在'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } else { - $order = $res; - if ($order->deleted > 0) { - $return['msg'] = '订单已被删除了,无法操作'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - } - - switch ($get['do']) { - case 'cancel': - if ($order->is_cwqr > 0) { - $return['msg'] = '订单已入账,请先联系财务销账后再取消'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - if ($order->status_code > 1) { - $return['msg'] = '订单已进入运输后流程,无法操作取消'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - if ($order->status_code == -1) { - $return['msg'] = '订单已经是被取消状态'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - $data['status_code'] = -1; - $model->id = $id; - $res = $model->updateAll($data, $where); - if ($res) { - $return['msg'] = '订单取消成功'; - $return['errorcode'] = 200; - $return['data'] = ['css' => 'btn-info']; - } else { - $return['msg'] = '订单取消失败'; - $return['errorcode'] = 0; - } - break; - case 'truckcar': - if ($order->status_code == -1) { - $return['msg'] = '订单已被取消,不能承运'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - if ($order->status_code != 1) { - $return['msg'] = '订单当前非初始状态(协议签订),不可作承运处理'; - $return['errorcode'] = 404; - exit(json_encode($return, JSON_UNESCAPED_UNICODE)); - } - $data['status_code'] = 5; - $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)); + return $payments; } } diff --git a/ctms-api/controllers/gm/v1/NewsCatController.php b/ctms-api/controllers/gm/v1/NewsCatController.php new file mode 100644 index 0000000..d3f3b21 --- /dev/null +++ b/ctms-api/controllers/gm/v1/NewsCatController.php @@ -0,0 +1,271 @@ +pid) { + $this->result('您正使用本系统内部接口,禁止非法链接使用!'); + } + return parent::beforeAction($action); + } + + public function actionIndex() + { + $apis = [ + 'list'=>'清单', + 'detail'=>'详情', + 'add'=>'添加', + 'edit'=>'编辑', + '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'=>intval($s['query']->count()), + 'cats' => $res, + 'page'=>$this->page + ]; + $this->result('文章分类查询成功!', $data, 200); + } + + public function actionDetail() + { + $id = (int)Yii::$app->request->get('id'); + if(!$id) $this->result('请求错误,未携带ID参数'); + $model = new AcNewsCat(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据'); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'NewsCat'); + if($sn) $res->sn = $sn; + $res->save(); + } + $this->result('文章分类查询完成', $res->toArray(), 200); + } + + public function actionAdd() + { + //数据预检查、编排 + $data = $this->preSave('add'); + if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100); + + //保存资料 + $model = new AcNewsCat(); + 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->is_show = 0; + $res = $detail->save(); + if ($res) { + $msg = '文章隐藏标记成功'; + $errorCode = 200; + } else { + $msg = '文章隐藏标记失败'; + } + break; + case 'show': + $detail->is_show = 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 AcNewsCat(); + $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', 'title', $search['title']]; + $where2[] = ['LIKE', 'des', $search['title']]; + } + + $search['pcat'] = isset($search['cat']) ? trim(htmlspecialchars_decode($search['pcat_sn'])) : ''; + $search['pcid'] = isset($search['cid']) ? intval($search['pcid']) : 0; + if (!empty($search['pcat'])) { + $where['pcat_sn'] = $search['pcat']; + }elseif ($search['pcid']) { + $where['pcid'] = $search['pcid']; + } + + $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 AcNewsCat(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据',[],404); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'NewsCat'); + if($sn) $res->sn = $sn; + $res->save(); + } + return $res; + } + + /* + * 数据保存前的预检查(查重、参数校验等) + * 要保存的数据[],直接从post中取出 + * @op,操作类型(add,edit……) + * 校验机制: + * 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续; + * 查重:禁止录入重复数据 + * 返回:校验重组后的数据 + * */ + private function preSave($op) + { + $post = $this->postdata; + $data = []; + //格式化数据 + //目标键=》POST键 + $_time = time(); + $id = 0; + $model = new AcNewsCat(); + switch ($op) { + case 'add': + $data['is_show'] = 1; + $data['create_at'] = $_time; + $data['update_at'] = $data['create_at']; + $sn = $this->idToSn($id,'NewsCat'); + if($sn) $data['sn'] = $sn; + break; + case 'edit': + $id = (int)Yii::$app->request->get('id'); + $_id = (int)$post['id']; + if(!$id != $_id) $this->result('id参数不匹配,请检查'); + $data['update_at'] = $_time; + $data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0; + break; + } + + $data['pid'] = $this->pid; + + //目标键=》POST键 + $cols = ['title'=>'title','des'=>'des']; + foreach($cols as $col=>$key){ + if(isset($post[$key])){ + $data[$col] = trim($post[$key]); + }elseif(!$id){ + $data[$col] = ''; + } + } + + $cols = ['order_by' => 'order_by', 'deleted'=>'deleted','pcat_id'=>'pcat_id']; + foreach ($cols as $col => $key) { + if(isset($post[$key])){ + $data[$col] = (int)$post[$key]; + } + } + + return $data; + } +} \ No newline at end of file diff --git a/ctms-api/controllers/gm/v1/NewsController.php b/ctms-api/controllers/gm/v1/NewsController.php new file mode 100644 index 0000000..8ff0d16 --- /dev/null +++ b/ctms-api/controllers/gm/v1/NewsController.php @@ -0,0 +1,277 @@ +pid) { + $this->result('您正使用本系统内部接口,禁止非法链接使用!'); + } + return parent::beforeAction($action); + } + + public function actionIndex() + { + $apis = [ + 'list'=>'清单', + 'detail'=>'详情', + 'add'=>'添加', + 'edit'=>'编辑', + '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'=>intval($s['query']->count()), + 'news' => $res, + 'page'=>$this->page + ]; + $this->result('文章查询成功!', $data, 200); + } + + public function actionDetail() + { + $id = (int)Yii::$app->request->get('id'); + if(!$id) $this->result('请求错误,未携带ID参数'); + $model = new AcNews(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据'); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'News'); + if($sn) $res->sn = $sn; + $res->save(); + } + $this->result('文章信息查询完成', $res->toArray(), 200); + } + + public function actionAdd() + { + //数据预检查、编排 + $data = $this->preSave('add'); + if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100); + + //保存资料 + $model = new AcNews(); + 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->is_show = 0; + $res = $detail->save(); + if ($res) { + $msg = '文章隐藏标记成功'; + $errorCode = 200; + } else { + $msg = '文章隐藏标记失败'; + } + break; + case 'show': + $detail->is_show = 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 AcNews(); + $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', 'title', $search['title']]; + $where2[] = ['LIKE', 'des', $search['title']]; + } + + $search['cat'] = isset($search['cat']) ? trim(htmlspecialchars_decode($search['cat_sn'])) : ''; + $search['cid'] = isset($search['cid']) ? intval($search['cid']) : 0; + if (!empty($search['cat'])) { + $where['cat_sn'] = $search['cat']; + }elseif ($search['cid']) { + $where['cid'] = $search['cid']; + } + + $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 AcNews(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据',[],404); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'News'); + if($sn) $res->sn = $sn; + $res->save(); + } + return $res; + } + + /* + * 数据保存前的预检查(查重、参数校验等) + * 要保存的数据[],直接从post中取出 + * @op,操作类型(add,edit……) + * 校验机制: + * 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续; + * 查重:禁止录入重复数据 + * 返回:校验重组后的数据 + * */ + private function preSave($op) + { + $post = $this->postdata; + $data = []; + //格式化数据 + //目标键=》POST键 + $_time = time(); + $id = 0; + $model = new AcNews(); + switch ($op) { + case 'add': + $data['is_show'] = 1; + $data['create_at'] = $_time; + $data['update_at'] = $data['create_at']; + $sn = $this->idToSn($id,'News'); + if($sn) $data['sn'] = $sn; + break; + case 'edit': + $id = (int)Yii::$app->request->get('id'); + $_id = (int)$post['id']; + if(!$id != $_id) $this->result('id参数不匹配,请检查'); + $data['update_at'] = $_time; + $data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0; + break; + } + + $data['pid'] = $this->pid; + + //目标键=》POST键 + $cols = ['title'=>'title','des'=>'des']; + foreach($cols as $col=>$key){ + if(isset($post[$key])){ + $data[$col] = trim($post[$key]); + }elseif(!$id){ + $data[$col] = ''; + } + } + + $cols = ['content'=>'editor']; + foreach($cols as $col=>$key){ + if(isset($post[$key])){ + $data[$col] = htmlspecialchars($post[$key]); + } + } + + $cols = ['order_by' => 'order_by', 'deleted' => 'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed']; + foreach ($cols as $col => $key) { + if(isset($post[$key])){ + $data[$col] = (int)$post[$key]; + } + } + + return $data; + } +} \ No newline at end of file diff --git a/ctms-api/controllers/gm/v1/NoticeController.php b/ctms-api/controllers/gm/v1/NoticeController.php new file mode 100644 index 0000000..8503241 --- /dev/null +++ b/ctms-api/controllers/gm/v1/NoticeController.php @@ -0,0 +1,269 @@ +pid) { + $this->result('您正使用本系统内部接口,禁止非法链接使用!'); + } + return parent::beforeAction($action); + } + + public function actionIndex() + { + $apis = [ + 'list'=>'清单', + 'detail'=>'详情', + 'add'=>'添加', + 'edit'=>'编辑', + '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'=>intval($s['query']->count()), + 'news' => $res, + 'page'=>$this->page + ]; + $this->result('通知查询成功!', $data, 200); + } + + public function actionDetail() + { + $id = (int)Yii::$app->request->get('id'); + if(!$id) $this->result('请求错误,未携带ID参数'); + $model = new AcNotice(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据'); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'Notice'); + if($sn) $res->sn = $sn; + $res->save(); + } + $this->result('文章信息查询完成', $res->toArray(), 200); + } + + public function actionAdd() + { + //数据预检查、编排 + $data = $this->preSave('add'); + if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100); + + //保存资料 + $model = new AcNotice(); + 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->is_show = 0; + $res = $detail->save(); + if ($res) { + $msg = '文章隐藏标记成功'; + $errorCode = 200; + } else { + $msg = '文章隐藏标记失败'; + } + break; + case 'show': + $detail->is_show = 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 AcNotice(); + $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', 'title', $search['title']]; + $where2[] = ['LIKE', 'content', $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 AcNotice(); + $res = $model->findOne($id); + if(!$res) $this->result('未查询到相应数据',[],404); + //SN处理 + if(!$res->sn){ + $sn = $this->idToSn($id,'Notice'); + if($sn) $res->sn = $sn; + $res->save(); + } + return $res; + } + + /* + * 数据保存前的预检查(查重、参数校验等) + * 要保存的数据[],直接从post中取出 + * @op,操作类型(add,edit……) + * 校验机制: + * 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续; + * 查重:禁止录入重复数据 + * 返回:校验重组后的数据 + * */ + private function preSave($op) + { + $post = $this->postdata; + $data = []; + //格式化数据 + //目标键=》POST键 + $_time = time(); + $id = 0; + $model = new AcNotice(); + switch ($op) { + case 'add': + $data['is_show'] = 1; + $data['create_at'] = $_time; + $data['update_at'] = $data['create_at']; + $sn = $this->idToSn($id,'Notice'); + if($sn) $data['sn'] = $sn; + break; + case 'edit': + $id = (int)Yii::$app->request->get('id'); + $_id = (int)$post['id']; + if(!$id != $_id) $this->result('id参数不匹配,请检查'); + $data['update_at'] = $_time; + $data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0; + break; + } + + $data['pid'] = $this->pid; + + //目标键=》POST键 + $cols = ['title'=>'title','des'=>'des']; + foreach($cols as $col=>$key){ + if(isset($post[$key])){ + $data[$col] = trim($post[$key]); + }elseif(!$id){ + $data[$col] = ''; + } + } + + $cols = ['content'=>'editor']; + foreach($cols as $col=>$key){ + if(isset($post[$key])){ + $data[$col] = htmlspecialchars($post[$key]); + } + } + + $cols = ['order_by' => 'order_by', 'deleted' => 'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed']; + foreach ($cols as $col => $key) { + if(isset($post[$key])){ + $data[$col] = (int)$post[$key]; + } + } + + return $data; + } +} \ No newline at end of file