Initial commit,修正

This commit is contained in:
2025-07-13 19:37:38 +08:00
parent 38ce288e27
commit 65bbd06981
12384 changed files with 3985464 additions and 8 deletions
+425
View File
@@ -0,0 +1,425 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:33:45
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCar;
use addons\models\AcAlbums;
use addons\models\AcAlbumPics;
use addons\models\AcAlbumVersion;
class AlbumsController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return $this->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev',[]);
}
//相册列表
public function actionList()
{
return $this->render('../layouts/dev');
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);
}elseif($session->get($searchSession)){
$search = $session->get($searchSession);
}
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : '';
$CarModel = new AcCar();
if(empty($search['car_id'])){
$search['car_id'] = isset($get['car_id']) ? (int)$get['car_id'] : 0;
}
if(!empty($search['car_id'])){
$where[] = ['=','car_id',$search['car_id']];
$car = $CarModel->findOne($search['car_id']);
$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];
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
$status = Yii::$app->params['AlbumStatus'];
$orders = [];
foreach($res as $s){
$s = $s->toArray();
$orders[$s['id']] = $s;
}
return $this->render('list',[
'orders' => $orders,
'pager' => $pages,
'status'=>$status,
'search'=>$search
]);
}
//验新车
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');
$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();
}
}
}
+538
View File
@@ -0,0 +1,538 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-14T11:44:34+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCar;
use addons\models\AcCarOwner;
use addons\models\AcCarBrand;
use addons\models\AcCarSeries;
use common\models\Fans;
class CarController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
//车辆列表
public function actionList()
{
$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 Fans();
$where = [];
$_users = $User->find()->where(['in','id',$mids])->all();
$users = [];
foreach($_users as $s){
$users[$s->id] = $s->toArray();
}
$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;
}
}
return $this->render('list',[
'cars'=>$cars,
'pager' => $pages,
'owners'=>$owners,
'users'=>$users,
'status'=>$status,
'search'=>$search
]);
}
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 Fans();
$where = [];
$_users = $User->find()->where(['in','id',$mids])->all();
$users = [];
foreach($_users as $s){
$users[$s->id] = $s->toArray();
}
$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()
{
$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 = Fans::findIdentity($mid);
if($user){
$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]);
}
//复制客车资料后新建
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 = Fans::findIdentity($mid);
if($user){
$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键
$cols = ['title'=>'title','num_frame'=>'num_frame','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]) : '';
}
//查询车牌号是否在库
$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;
}
}
$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;
}
$cols = ['remark'=>'editor'];
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参数
$AcCarOwner = new AcCarOwner();
$owner = $AcCarOwner->findOne($data['owner_id']);
if($owner){
$data['mid'] = $owner->mid;
}
//保存车辆资料
$AcCar = new AcCar();
foreach($data as $key=>$val){
$AcCar->$key = $val;
}
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($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 AcCar();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
}
+285
View File
@@ -0,0 +1,285 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 03:40:46
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:34:13
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCarBrand;
class CarbrandController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev',[]);
}
//车品牌列表
public function actionList()
{
global $_HI,$_FM;
$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;
}
$status = Yii::$app->params['CommonStatus'];
return $this->render('list',[
'brands' => $brands,
'pager' => $pages,
'status'=>$status,
'search'=>$search
]);
}
//车品牌列表
public function actionSelect()
{
global $_HI,$_FM;
$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;
}
$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
]);
}
//新增车品牌
public function actionNew()
{
global $_HI,$_FM;
$status = Yii::$app->params['CommonStatus'];
$AcCarBrand = new AcCarBrand();
$AcCarBrand->status_code = 0;
return $this->render('modify',['status'=>$status,'detail'=>$AcCarBrand->toArray()]);
}
//更新车品牌
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');
//格式化数据
$data = [];
$data['title'] = trim($post['title']);
//目标键=》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();
}
}
//删除用户
public function actionDelete($id)
{
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;
$data['update_at'] = time();
$data['deleted'] = 1;
$model = new AcCarBrand();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
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 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));
}
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,JSON_UNESCAPED_UNICODE));
}
}
+675
View File
@@ -0,0 +1,675 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 03:40:46
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 10:10:32
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCar;
use addons\models\AcCarOwner;
use addons\models\AcStore;
use addons\models\AcEmployee;
use addons\models\AcFansExt;
use common\models\Fans;
use common\models\CSms;
use common\models\CVcode;
use vendor\aliyun\dysms\Sms;
class CarownerController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev',[]);
}
//车主用户列表
public function actionList()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$model = new AcCarOwner();
$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','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)->indexBy('mid')->all();
$status = Yii::$app->params['CommonStatus'];
$gender = Yii::$app->params['gender'];
$model = new AcStore();
$where = [];
$where['pid'] = $pid;
$_stores = $model->find()->where($where)->all();
$stores = [];
foreach($_stores as $s){
$stores[$s->id] = $s->toArray();
}
$eids = $mids = [];
foreach($res as $r){
$eids[$r['employee_id']] = $r['employee_id'];
$mids[$r['mid']] = $r['mid'];
}
$model = new AcEmployee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach($_employees as $s){
$employees[$s->id] = $s->toArray();
}
$model = new Fans();
$users = [];
$_users = $model->find()->where(['in','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
$model = new AcFansExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
if(isset($users[$s['id']])){
if($ext['mobile']==$users[$s['id']]['mobile']){
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$owners = [];
foreach($res as $s){
$s = $s->toArray();
$owners[$s['id']] = $s;
}
return $this->render('list',[
'owners' => $owners,
'pager' => $pages,
'employees'=>$employees,
'stores'=>$stores,
'users'=>$users,
'exts'=>$exts,
'status'=>$status,
'gender'=>$gender,
'search'=>$search
]);
}
//车主用户选择
public function actionSelect()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$model = new AcCarOwner();
$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','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)->indexBy('mid')->all();
$status = Yii::$app->params['CommonStatus'];
$gender = Yii::$app->params['gender'];
$model = new AcStore();
$where = [];
$where['pid'] = $pid;
$_stores = $model->find()->where($where)->all();
$stores = [];
foreach($_stores as $s){
$stores[$s->id] = $s->toArray();
}
$eids = $mids = [];
foreach($res as $r){
$eids[$r['employee_id']] = $r['employee_id'];
$mids[$r['mid']] = $r['mid'];
}
$model = new AcEmployee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach($_employees as $s){
$employees[$s->id] = $s->toArray();
}
$model = new Fans();
$users = [];
$_users = $model->find()->where(['in','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
$model = new AcFansExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
if(isset($users[$s['id']])){
if($ext['mobile']==$users[$s['id']]['mobile']){
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$owners = [];
foreach($res as $s){
$s = $s->toArray();
if(isset($exts[$s['mid']])){
foreach($exts[$s['mid']] as $col=>$val){
$s[$col] = $val;
}
}
$owners[$s['id']] = $s;
}
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'carowner';
return $this->render('select',[
'owners' => $owners,
'pager' => $pages,
'employees'=>$employees,
'stores'=>$stores,
'users'=>$users,
'exts'=>$exts,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'callback'=>$callback
]);
}
//新增车主
public function actionNew()
{
global $_HI,$_FM;
$levels = Yii::$app->params['customerLevels'];
return $this->render('modify',['levels'=>$levels]);
}
//更新车主
public function actionEdit()
{
global $_HI,$_FM;
$levels = Yii::$app->params['customerLevels'];
$model = new AcCarOwner();
$id = Yii::$app->request->get('id');
$pid = Yii::$app->session->get('pid');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
$res['last_send'] = $res['last_send'] ? date('Y-m-d',$res['last_send']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
}else{
$res = [];
}
//查询对应的系统用户
$user = Fans::findIdentity($res['mid']);
$res['mobile'] = '';
if($user){
$res['mobile'] = $user->mobile;
}
$exts = AcFansExt::find()->where(['mid' => $res['mid'],'mobile' => $res['mobile'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
if($store){
$res['store_title'] = $store->title;
}
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
if($employee){
$res['employee_title'] = $employee->name;
}
// memory_get_usage();//查看当前内存,字节
return $this->render('modify',[
'detail'=>$res,
'levels'=>$levels,
'id'=>$id,
]);
}
//保存车主资料
public function actionSave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
if(!$post['mobile']){
\Yii::$app->getSession()->setFlash('warning', '请输入主手机号码!');
$url = Url::toRoute(['carowner/edit','id'=>$id]);
return $this->redirect(['modify','id'=>$id]);
}
$mobile = $post['mobile'];
//查询对应的系统用户
$userModel = new Fans();
$user = $userModel->findByUsername($mobile);
if(empty($user)){
$pwd = isset($post['password']) ? trim($post['password']) : Yii::$app->params['defaultFansPassword'];
$userModel->mobile = $mobile;
$userModel->email = $mobile.'@hiluker.com';
$userModel->setPassword($pwd);
$userModel->generateAuthKey();
$userModel->created_at = time();
$userModel->from = 'ctms';
$userModel->save();
$user_id = $userModel->attributes['id']; //获取插入后id
}else{
$user_id = $user->id;
}
/*保存扩展资料 S*/
$AcFansExt = new AcFansExt();
//批量硬删及软删
$AcFansExt->deleteAll(['deleted'=>2,'pid'=>$pid,'mid'=>$user_id]); //硬删,变更历史3次的
$AcFansExt->updateAllCounters(['deleted'=>1],['pid'=>$pid,'mid'=>$user_id]); //更新已有数据
//开始写入新传入的数据
$datas = [];
$data = [];
$cols = ['realname'=>'realname','nickname'=>'nickname','title'=>'title','password'=>'password','mobiles'=>'mobiles','thumb'=>'thumb','province'=>'province','idcard'=>'idcard'];
foreach($cols as $col=>$key){
$data['pid'] = $pid;
$data['mid'] = $user_id;
$data['key'] = $col;
$data['mobile'] = $mobile;
$data['value'] = isset($post[$key]) ? trim($post[$key]) : '';
$datas[] = $data;
}
//批量插入
$model = clone $AcFansExt;
foreach($datas as $attributes)
{
$model->isNewRecord = true;
$model->setAttributes($attributes,false);
$model->save() && $model->id=0;
}
/*保存扩展资料 E*/
//格式化数据
$data = [];
//目标键=》POST键
$cols = ['gender'=>'gender','total_fee'=>'total_fee','level'=>'level','score'=>'score','store_id'=>'store','employee_id'=>'employee','status_code'=>'status_code','deleted'=>'deleted'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$cols = ['last_send'=>'last_send','last_contact'=>'last_contact'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? strtotime($post[$key]) : 0;
}
$cols = ['remark'=>'editor'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$data['mid'] = $user_id;
//格式化车主资料
$AcCarOwner = new AcCarOwner();
foreach($data as $key=>$val){
$AcCarOwner->$key = $val;
}
//查询该车主是否在库
$carOwner = AcCarOwner::find()->where(['pid'=>$data['pid'],'mid'=>$data['mid']])->one();
if($carOwner){
$id = $carOwner->id;
}
//车主资料入库
if($id){
$AcCarOwner->id = $id;
unset($data['create_at']);
$res = $AcCarOwner->updateAll($data,['id'=>$id]);
}else{
$res = $AcCarOwner->save();
$id = $AcCarOwner->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 = [];
// if($res){
// $return['msg'] = '车主信息保存成功';
// $return['errorcode'] = 200;
// $return['url'] = Url::toRoute(['carowner/edit','id'=>$id]);
// $return['buttons'] = [
// ['title'=>'好的,我知道了','class'=>'primary','url'=>$return['url']]
// ];
// }else{
// $return['msg'] = '车主信息保存失败';
// $return['errorcode'] = 0;
// $return['url'] = Url::toRoute(['carowner/new',$post]);
// $return['buttons'] = [
// ['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
// ];
// }
// $classes = ['0'=>'warning','200'=>'success'];
// $return['content'] = $return['msg'];
// $return['class'] = $classes[$return['errorcode']];
// Yii::$app->request->setBodyParams($return);
// return Yii::$app->runAction('index/msg');
}
//删除用户
public function actionDelete($id)
{
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;
$data['update_at'] = time();
$data['deleted'] = 1;
$model = new AcCarOwner();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
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 AcCarOwner();
$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'=>'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,JSON_UNESCAPED_UNICODE));
}
//短信营销
public function actionMsg()
{
global $_HI,$_FM;
$levels = Yii::$app->params['customerLevels'];
$model = new AcCarOwner();
$id = Yii::$app->request->get('id');
$pid = Yii::$app->session->get('pid');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
$res['last_send'] = $res['last_send'] ? date('Y-m-d',$res['last_send']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new Fans();
$user = Fans::find()->where(['id'=>$res['mid']])->one();
$res['mobile'] = '';
if($user){
$res['mobile'] = $user->mobile;
}
$exts = AcFansExt::find()->where(['mid' => $res['mid'],'mobile' => $res['mobile'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
if($store){
$res['store_title'] = $store->title;
}
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
if($store){
$res['employee_title'] = $employee->name;
}
$op = Yii::$app->request->get('op');
$opp = Yii::$app->request->get('opp');
if(!$op){
return $this->render('msg',[
'detail'=>$res,
'levels'=>$levels,
'id'=>$id,
]);
}elseif($op=='send'){
$option = [];
$config = [];
$config['accessKeyId'] = Yii::$app->params['aliDySms']['accessKeyId'];
$config['accessKeySecret'] = Yii::$app->params['aliDySms']['accessKeySecret'];
$config['sign'] = Yii::$app->params['aliDySms']['sign'];
$sms = new Sms($option,$config);
$phone = $res['mobile'];
$content=[];
switch($opp){
case 'vcode': //发送验证码
$code = mt_rand(1000,9999);
$content['code'] = $code;
$tmpl = Yii::$app->params['aliDySms']['tmpl']['vcode'];
//验证码入库
$vcodeModel = new CVcode();
$vcode = [];
$vcode['code'] = $code;
$vcode['mobile'] = $phone;
$vcode['create_at'] = time();
foreach($vcode as $key=>$val){
$vcodeModel->$key = $val;
}
$vcodeModel->save();
break;
case 'birthday': //发送生日祝福
$realname = isset($res['realname'])?$res['realname']:'VIP';
$content['name'] = $realname;
$content['company'] = Yii::$app->request->post('company');
$content['company'] = $content['company'] ? $content['company'] : '安诚托车';
$tmpl = Yii::$app->params['aliDySms']['tmpl']['acBirthday'];
break;
}
$result = $sms->send($phone,$tmpl,$content);
//保存发送记录
$smsModel = new CSms();
$smsdata = [];
$sid = Yii::$app->session->get('sid');
$smsdata['sid'] = (int)$sid;
$smsdata['pid'] = $pid;
$smsdata['uid'] = Yii::$app->user->identity->id;
$smsdata['mobile'] = $phone;
$smsdata['content'] = json_encode($content,JSON_UNESCAPED_UNICODE);
$smsdata['create_at'] = time();
foreach($smsdata as $key=>$val){
$smsModel->$key = $val;
}
$smsModel->save();
$return = [];
$msg = '';
if(!$result){
$msg .= "【".$phone."】发送失败,接口提示:".$sms->errors."\r\n";
$return['errorcode'] = 0;
}elseif(is_array($result) && $result['Code'] !='OK'){
$msg .= "【".$phone."】发送失败,接口提示:".$result['Message']."\r\n";
$return['errorcode'] = 0;
}else{
$msg .= "【".$phone."】发送成功"."\r\n";
$return['errorcode'] = 0;
}
$return['msg'] = $msg;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
//信息摘要
public function actionInfo()
{
global $_HI,$_FM;
$levels = Yii::$app->params['customerLevels'];
$model = new AcCarOwner();
$id = Yii::$app->request->get('id');
$pid = Yii::$app->session->get('pid');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
$res['last_send'] = $res['last_send'] ? date('Y-m-d',$res['last_send']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new Fans();
$user = Fans::find()->where(['id'=>$res['mid']])->one();
$res['mobile'] = '';
if($user){
$res['mobile'] = $user->mobile;
}
$exts = AcFansExt::find()->where(['mid' => $res['mid'],'mobile' => $res['mobile'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
if($store){
$res['store_title'] = $store->title;
}
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
if($store){
$res['employee_title'] = $employee->name;
}
return $this->render('info',[
'detail'=>$res,
'levels'=>$levels,
'id'=>$id,
]);
}
}
+357
View File
@@ -0,0 +1,357 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 03:40:46
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:37:06
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCarBrand;
use addons\models\AcCarSeries;
class CarseriesController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev',[]);
}
//车型列表
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);
}elseif($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_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
]);
}
//车型列表
public function actionSelect()
{
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);
}elseif($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
]);
}
//新增车型
public function actionNew()
{
global $_HI,$_FM;
$status = Yii::$app->params['CommonStatus'];
$AcCarSeries = new AcCarSeries();
$AcCarSeries->status_code = 0;
return $this->render('modify',['status'=>$status,'detail'=>$AcCarSeries->toArray()]);
}
//更新车型
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 = [];
}
//查询对应的品牌
$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;
//格式化车型资料
$AcCarSeries = new AcCarSeries();
foreach($data as $key=>$val){
$AcCarSeries->$key = $val;
}
//车型资料入库
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();
}
}
//删除车型
public function actionDelete($id)
{
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;
$data['update_at'] = time();
$data['deleted'] = 1;
$model = new AcCarSeries();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
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 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));
}
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,JSON_UNESCAPED_UNICODE));
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:37:17
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
// use addons\models\Citys;
class CityController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionSelect()
{
$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
]);
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
#
# @Author: fm453
# @Date: 2024/7/16
# @updated: 上午8:48
# @Email: 1280880631@qq.com
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use yii\web\Controller;
class Common extends Controller
{
protected $pid = 0;
public $postdata = [];
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$get = Yii::$app->request->get();
$session = Yii::$app->session;
$this->pid = $session->get('pid');
if (!$this->pid) {
return Yii::$app->response->redirect(['index/index']);
}
//判断请求内容类型 content-type,支持 json请求
$postdata = Yii::$app->request->post();
$headers = Yii::$app->request->headers;
$contentType = $headers->get('content-type');
if ($contentType=="application/json") {
$postdata = json_decode(file_get_contents('php://input'), true);
}
$this->postdata = $postdata;
}
public function result($msg, $data=null, $code=0)
{
$return = [];
$return['code'] = $code;
$return['msg'] = $msg;
if ($data) {
$return['data'] = $data;
}
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
+308
View File
@@ -0,0 +1,308 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-14T19:14:12+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcContact;
use common\models\Fans;
class ContactController extends \yii\web\Controller
{
// 替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
public function actionIndex()
{
return $this->render('index');
}
//通讯录列表
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);
}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','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
]);
}
public function actionSelect()
{
$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);
}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','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
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑通讯录资料
public function actionEdit()
{
$model = new AcContact();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
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]);
}
}
//查询对应的系统用户
$userModel = new Fans();
$user = $userModel->findByUsername($data['mobile']);
if(empty($user)){
$pwd = Yii::$app->params['defaultFansPassword'];
$userModel->mobile = $data['mobile'];
$userModel->email = $data['mobile'].'@hiluker.com';
$userModel->setPassword($pwd);
$userModel->generateAuthKey();
$userModel->created_at = time();
$userModel->from = 'ctms';
$userModel->save();
}
$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();
}
}
//删除
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 AcContact();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
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 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));
}
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));
}
}
+287
View File
@@ -0,0 +1,287 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-15T10:22:53+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcDriver;
use common\models\Member;
class DriverController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
public function actionIndex()
{
return $this->render('index');
}
//司机列表
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);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('order_by DESC,id DESC')->all();
$status = Yii::$app->params['DriverStatus'];
return $this->render('list',[
'drivers'=>$res,
'pager' => $pages,
'status'=>$status,
'search'=>$search
]);
}
public function actionSelect()
{
$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)->orderby('order_by DESC,id DESC')->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
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑司机资料
public function actionEdit()
{
$model = new AcDriver();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
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','order_by'=>'order_by','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
}
//查询司机对应的系统用户
$MemberModel = new Member();
$user = $MemberModel->find()->where(['mobile'=>$data['mobile']])->one();
if(empty($user)){
$MemberModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
$MemberModel->mobile = $data['mobile'];
$MemberModel->email = $data['mobile'].'@hiluker.com';
$MemberModel->setPassword(Yii::$app->params['defaultUserPassword']);
$MemberModel->generateAuthKey();
$MemberModel->avatar = Yii::$app->params['defaultUserAvatar'];
$MemberModel->created_at = time();
$MemberModel->status = 1;
$MemberModel->save();
$user_id = $MemberModel->attributes['id']; //获取插入后id
if($user_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 AcDriver();
foreach($data as $key=>$val){
$model->$key = $val;
}
$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));
}
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 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));
}
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));
}
}
+315
View File
@@ -0,0 +1,315 @@
<?php
/**
* @Author: fm453
* @Date: 2018-12-02 11:40:44
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 08:19:06
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcEmployee;
use addons\models\AcStore;
use common\models\Member;
use addons\models\AcUserExt;
class EmployeeController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
public function actionIndex()
{
return $this->render('index');
}
//用户列表
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);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('status DESC,order_by DESC,id ASC')->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
]);
}
public function actionSelect()
{
$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);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('status DESC,order_by DESC,id ASC')->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();
}
$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
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑员工资料
public function actionEdit()
{
$model = new AcEmployee();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
if($store){
$res['store_title'] = $store->title;
}
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'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['gender'=>'gender','status'=>'status','store_id'=>'store','order_by'=>'order_by','deleted'=>'deleted'];
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]) : '';
}
$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
}
//查询员工对应的系统用户
$MemberModel = new Member();
$user = $MemberModel->find()->where(['mobile'=>$data['mobile']])->one();
if(empty($user)){
$MemberModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
$MemberModel->mobile = $data['mobile'];
$MemberModel->email = $data['mobile'].'@hiluker.com';
$MemberModel->setPassword(Yii::$app->params['defaultUserPassword']);
$MemberModel->generateAuthKey();
$MemberModel->avatar = Yii::$app->params['defaultUserAvatar'];
$MemberModel->created_at = time();
$MemberModel->status = 1;
$MemberModel->save();
$user_id = $MemberModel->attributes['id']; //获取插入后id
if($user_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));
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2018-10-09 04:42:25
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class ErrorController extends \yii\web\Controller
{
public $enableCsrfValidation = false; //取消csrf令牌验证;
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionReport()
{
$request = Yii::$app->request;
$get = $request->get();
$url = Urldecode($get['url']);
$code = 0;
if($request->isPost){
$code = getMillisecond().'_'.rand(0,999);
$filename = $code.'.php';
$post = $request->post();
$code = $post['code']!=0 ? $post['code'] : $code;
$post['time'] = time();
fm_load()->fm_func('error');
fmFunc_error_write($filename,$post);
$msg = [];
$msg['title'] = '报错提交通知';
$msg['content'] = '感谢反馈,工程师将尽快处理!您本次的反馈工单号为<code>'.$code.'</code>';
$msg['class'] = 'success';
$btn = [];
$btn['title'] = '返回';
// $btn['url'] = Url::current();
$btn['url'] = $url;
$btn['class'] = 'primary';
$msg['buttons'][] = $btn;
$btn = [];
$btn['title'] = '查看工单';
$btn['url'] = Url::toRoute(['error/order','code'=>$code]);
$btn['class'] = 'warning';
$msg['buttons'][] = $btn;
$btn = [];
$btn['title'] = '回到首页';
$btn['url'] = Url::home();
$btn['class'] = 'info';
$msg['buttons'][] = $btn;
return $this->render('../layouts/msg',$msg);
}
return $this->render('report',['url'=>$url]);
}
public function actionOrder()
{
$request = Yii::$app->request;
$get = $request->get();
$code = Urldecode($get['code']);
$filename = $code.'.php';
fm_load()->fm_func('error');
$data = [];
$file = fmFunc_error_get($code);
include $file;
return $this->render('report',['code'=>$code,'data'=>$data,'url'=>$data['url']]);
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:02:21+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcFeeOrder;
use addons\models\AcFeeDriver;
use addons\models\AcOrder;
use addons\models\AcOrderPre;
use addons\models\AcOrderStatus;
use addons\models\AcStore;
use addons\models\AcEmployee;
use addons\models\AcPlat;
use common\models\CVcode;
class FeeController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('@app/views/layouts/dev',[]);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+381
View File
@@ -0,0 +1,381 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:41:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
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 GpsController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
$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');
}
}
//主界面
public function actionIndex()
{
return $this->render('index',[]);
}
//所有板车位置记录列表
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
]);
}
public function actionNew()
{
$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'); //发车任务
$AcTruckRoute['truck_id'] = $truckol['truck_id'];
$AcTruckRoute['truck_num'] = $truckol['truck_num'];
return $this->render('modify',['status'=>$status,'detail'=>$AcTruckRoute,'online_id'=>$online_id,'truckol'=>$truckol]);
}
//编辑板车位置信息
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'); //发车任务
$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'];
$status = Yii::$app->params['CommonStatus'];
return $this->render('modify',['status'=>$status,'detail'=>$route,'online_id'=>$online_id,'truckol'=>$truckol]);
}
//保存位置记录信息
public function actionSave()
{
$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'); //发车任务
$data = [];
$data['truck_id'] = $truckol['truck_id'];
$data['online_id'] = $online_id;
//格式化数据
//目标键=》POST键
$cols = ['longt'=>'lng','lat'=>'lat','addr'=>'addr'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['orderby'=>'orderby','status_code'=>'status_code'];
foreach($cols as $col=>$key){
$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));
}
}
+205
View File
@@ -0,0 +1,205 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:25:38
# @Last modified by: fm453
# @Last modified time: 2022-03-11T10:17:21+08:00
* @Email: fm453@lukegzs.com
*/
//主入口页
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcPlat;
use common\models\CLog;
class IndexController extends \yii\web\Controller
{
public $enableCsrfValidation = false;
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
}
public function beforeAction($action){
$session = Yii::$app->session;
$pid = $session->get('pid');
if(!$pid){
$action->actionMethod='actionIndex';
$action->id='index';
}
return parent::beforeAction($action);
}
public function actionIndex()
{
$session = Yii::$app->session;
$platModel = new AcPlat();
$_plats = $platModel->find()->where(['status_code'=>1,'deleted'=>0])->orderby('orderby DESC')->all();
$plats = [];
if($_plats){
foreach($_plats as $p){
$plats[$p->id] = $p->toArray();
}
}else{
$plats[] = ['id'=>1,'title'=>'安诚捷顺','thumb'=>'http://public.hiluker.com/qichetuoyun/logo.png'];
}
if(isset($_GET['pid'])){
$pid = (int)$_GET['pid'];
if($pid>0){
$session->set('pid',$pid);
return $this->actionWelcome();
exit;
}else{
return $this->render('index',['plats'=>$plats]);
}
}
$pid = $session->get('pid');
if(!$pid){
return $this->render('index',['plats'=>$plats]);
}else{
return $this->actionWelcome();
}
}
public function actionWelcome()
{
//登录系统欢迎界面,显示入口集
global $_HI,$_FM;
$user_id=Yii::$app->user->identity->getId();
//登录记录
$query = CLog::find();
$nowTable = CLog::tablename();
$count = $query->count();
$pages = new Pagination(['totalCount' => $count,'pageSize' => '10']);
$log = $query->offset($pages->offset)
->limit($pages->limit)
->orderBy('id desc')
->all();
$sql = "SELECT *,FROM_UNIXTIME(create_time,'%Y-%m') as period,COUNT(*) as times FROM ".$nowTable." GROUP BY period LIMIT 12";
$History = Yii::$app->db->createCommand($sql)->queryAll();
$HistoryMonthStr = '';
$HistoryMonthNum = '';
foreach($History as $val){
$HistoryMonthStr .= "'".$val['period']."',";
$HistoryMonthNum .= $val['times'].",";
}
$HistoryMonthStr = substr($HistoryMonthStr,0,-1);
$HistoryMonthNum = substr($HistoryMonthNum,0,-1);
$keywords = '';
$description = '';
return $this->render('welcome',[
'log' => $log,
'pages' => $pages,
'HistoryMonthStr' => $HistoryMonthStr,
'HistoryMonthNum' => $HistoryMonthNum,
'keywords' => $keywords,
'description' => $description,
]);
}
public function actionMenus()
{
//登录系统欢迎界面,显示入口集
global $_HI,$_FM;
$user_id=Yii::$app->user->identity->getId();
$navs = array();
$entries = array();
$entries[] = array('name'=>'车主列表','title'=>'对所运车辆的车主用户信息进行管理','url'=>Url::toRoute('carowner/list'),'icon'=>'fa fa-user','class'=>'primary');
$entries[] = array('name'=>'新增车主','title'=>'新增加一个托车车主','url'=>Url::toRoute('carowner/new'),'icon'=>'fa fa-user-plus','class'=>'primary');
$entries[] = array('name'=>'客车列表','title'=>'全部客户车辆记录','url'=>Url::toRoute('car/list'),'icon'=>'fa fa-car','class'=>'primary');
$entries[] = array('name'=>'新增客车','title'=>'新增一条客户车辆记录','url'=>Url::toRoute('car/new'),'icon'=>'fa fa-edit','class'=>'primary');
$navs[] = array('name'=>'客户管理','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'合同列表','title'=>'点击查看全部已签合同单','url'=>Url::toRoute('order/list'),'icon'=>'fa fa-list','class'=>'primary');
$entries[] = array('name'=>'新签合同','title'=>'新签一份托车合同单','url'=>Url::toRoute('order/new'),'icon'=>'fa fa-pencil','class'=>'primary');
$entries[] = array('name'=>'装车安排','title'=>'板车装车任务管理','url'=>Url::toRoute('truckol/list'),'icon'=>'fa fa-hourglass-half fa-spin','class'=>'primary');
$entries[] = array('name'=>'出车单','title'=>'查看在途板车的出车清单','url'=>Url::toRoute('truckol/index'),'icon'=>'fa fa-list','class'=>'primary');
$entries[] = array('name'=>'咨询列表','title'=>'所有已记录咨询过的客户','url'=>Url::toRoute('orderpre/list'),'icon'=>'fa fa-calendar','class'=>'primary');
$entries[] = array('name'=>'记录咨询','title'=>'新记录一个客户咨询','url'=>Url::toRoute('orderpre/new'),'icon'=>'fa fa-calendar-plus-o','class'=>'primary');
$navs[] = array('name'=>'运单管理','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'相册列表','title'=>'全部验车相册记录','url'=>Url::toRoute('albums/list'),'icon'=>'fa fa-film','class'=>'primary');
$entries[] = array('name'=>'验商品车','title'=>'商品车提车验车','url'=>Url::toRoute('albums/newcar'),'icon'=>'fa fa-camera-retro','class'=>'primary');
$entries[] = array('name'=>'首发验车','title'=>'运单首发网点的验车记录','url'=>Url::toRoute(['albums/order','v'=>0]),'icon'=>'fa fa-camera','class'=>'primary');
$entries[] = array('name'=>'到站验车','title'=>'运单中转或到达网点的验车记录','url'=>Url::toRoute(['albums/order','v'=>1]),'icon'=>'fa fa-image','class'=>'primary');
$navs[] = array('name'=>'验车相册','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'运单费用','title'=>'所有运单相关的费用单据管理','url'=>Url::toRoute('feeorder/index'),'icon'=>'fa fa-book','class'=>'primary');
$entries[] = array('name'=>'待审运单','title'=>'所有等待财务确认的运单','url'=>Url::toRoute(['order/list','is_cwqr'=>0]),'icon'=>'fa fa-gavel','class'=>'primary');
$navs[] = array('name'=>'财务管理','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'网点列表','title'=>'对公司全部网点门店进行管理','url'=>Url::toRoute('store/list'),'icon'=>'fa fa-cubes','class'=>'primary');
$entries[] = array('name'=>'新增网点','title'=>'新增加一个网点','url'=>Url::toRoute('store/new'),'icon'=>'fa fa-cube','class'=>'primary');
$entries[] = array('name'=>'员工列表','title'=>'对公司各网点员工进行管理','url'=>Url::toRoute('employee/list'),'icon'=>'fa fa-venus-mars','class'=>'primary');
$entries[] = array('name'=>'新增员工','title'=>'新增员工','url'=>Url::toRoute('employee/new'),'icon'=>'fa fa-venus-double','class'=>'primary');
$entries[] = array('name'=>'板车管理','title'=>'公司板车列表','url'=>Url::toRoute('truck/list'),'icon'=>'fa fa-truck','class'=>'primary');
$entries[] = array('name'=>'司机管理','title'=>'公司板车司机列表','url'=>Url::toRoute('driver/list'),'icon'=>'fa fa-group','class'=>'primary');
$navs[] = array('name'=>'公司管理','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'H5端','title'=>'H5版管理端','url'=>Yii::$app->params['H5Links'].'index.html','icon'=>'fa fa-cubes','class'=>'primary');
$navs[] = array('name'=>'手机端','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'切换平台','title'=>'选择要管理的平台','url'=>Url::toRoute(['index/index','pid'=>0]),'icon'=>'fa fa-random','class'=>'primary');
if($user_id==1){
$entries[] = array('name'=>'平台列表','title'=>'选择管理平台或新增平台','url'=>Url::toRoute(['plat/list']),'icon'=>'fa fa-desktop','class'=>'primary');
}
$entries[] = array('name'=>'客车品牌','title'=>'新增或编辑小车的品牌','url'=>Url::toRoute('carbrand/list'),'icon'=>'fa fa-registered','class'=>'primary');
$entries[] = array('name'=>'车型参数','title'=>'新增或编辑小车各车系车型的基础参数','url'=>Url::toRoute('carseries/list'),'icon'=>'fa fa-pie-chart','class'=>'primary');
$navs[] = array('name'=>'平台管理','entries'=>$entries);
unset($entries);
$keywords = '';
$description = '';
return $this->render('menus',[
'navs' => $navs,
'keywords' => $keywords,
'description' => $description,
]);
}
public function actionMap()
{
$lat = (float) Yii::$app->request->get('lat');
$lng = (float) Yii::$app->request->get('lng');
if (empty($lat) || empty($lng)) {
$lat = 0;
$lng = 0;
}
$search = [];
$search['keyword'] = Yii::$app->request->get('title');
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'showLatLng';
return $this->render('map',[
'lat'=>$lat,
'lng'=>$lng,
'search'=>$search,
'callback'=>$callback,
]);
}
public function actionMsg()
{
$params = Yii::$app->request->bodyParams;
return $this->render('../layouts/msg',$params);
}
}
+456
View File
@@ -0,0 +1,456 @@
<?php
#
# @Author: fm453
# @Date: 2024/7/16
# @updated: 下午3:55
# @Email: 1280880631@qq.com
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcNewsCat;
use addons\models\AcNews;
class NewsController extends Common{
public $enableCsrfValidation = false;
public function actionIndex(){
}
public function actionList(){
$options = $this->_tableOptions();
$columns = $options['columns'];
$operator = $options['operator'];
$tpl = 'list';
return $this->render($tpl, [
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE)
]);
}
public function actionSelect()
{
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'news';
if($id) $callback .= '-'.$id;
$options = $this->_tableOptions();
$columns = $options['columns'];
$operator = $options['operator'];
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'select';
return $this->render($tpl, [
'id' => $id,
'callback'=>$callback,
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE)
]);
}
public function actionNew()
{
$pid = $this->pid;
$tpl = 'modify';
return $this->render(
$tpl,
[
'detail'=>[],
'id'=>0
]
);
}
public function actionEdit()
{
$pid = $this->pid;
$post = $this->postdata;
$id = Yii::$app->request->get('id');
$AcNews = new AcNews();
$news = $AcNews->findOne($id);
$detail = $news->toArray();
if($detail['cid']){
$AcNewsCat = new AcNewsCat();
$cat = $AcNewsCat->findOne($detail['cid']);
if($cat){
$detail['cat_title'] = $cat->title;
}
}
$tpl = 'modify';
return $this->render(
$tpl,
[
'detail'=>$detail,
'id'=>$id
]
);
}
/*复制文章*/
public function actionCopy()
{
$pid = $this->pid;
$post = $this->postdata;
$id = Yii::$app->request->get('id');
$AcNews = new AcNews();
$news = $AcNews->findOne($id);
$detail = $news->toArray();
$detail['id'] = 0;
$tpl = 'modify';
return $this->render(
$tpl,
[
'detail'=>$detail
]
);
}
public function actionSave(){
$post = $this->postdata;
$id = isset($post['id']) ? (int)$post['id'] : 0;
$pid = Yii::$app->session->get('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 = ['orderby'=>'orderby','deleted'=>'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed'];
foreach($cols as $col=>$key){
if(isset($post[$key])){
$data[$col] = (int)$post[$key];
}
}
$cols = ['is_show'=>'is_show'];
foreach($cols as $col=>$key){
if(!$id){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 1;
}else{
if(isset($post[$col])){
$data[$col] = (int)$post[$key];
}
}
}
if(!$id){
$data['create_at'] = time();
}
$data['update_at'] = time();
$data['pid'] = $pid;
//保存
$msg = '数据保存失败';
$res = false;
$cpde = 0;
$model = new AcNews();
if($id){
$_rec = $model::findOne($id);
if($_rec){
foreach($data as $key=>$val){
$_rec->$key = $val;
}
$res = $_rec->save();
if($res){
$msg = '数据保存成功';
$code = 200;
}
}
}else{
foreach($data as $key=>$val){
$model->$key = $val;
}
$res = $model->save();
if($res){
$msg = '数据新增成功';
$id = $model->attributes['id']; //获取插入后id
$code = 200;
}
}
$data['id'] = $id;
$op = Yii::$app->request->get('op');
if($op){
return $this->redirect(['edit','id'=>$id]);
}
$this->result($msg,$data,200);
}
public function actionAjax(){
$op = $_GET['op']; //操作标识,只允许客户端GET传入
$post = $this->postdata;
$msg = '删除失败';
if(!isset($post['id'])){
$this->result($msg,$post,200);
}
$id = $post['id'];
$model = new AcNews();
$data = $model->findOne($id);
if(!$data){
$msg = '数据不存在,操作失败';
$this->result($msg,$post,200);
}
if($data->pid != $this->pid){
$msg = '归属平台不匹配,禁止操作';
$this->result($msg,$post,200);
}
switch($op){
case 'del':
if($data->deleted >0){
$msg = '数据已被删除过,操作无效';
$this->result($msg,$post,200);
}
$data->deleted += 1;
$_res = $data->save();
$msg = $_res ? '删除成功' : '操作失败,数据更新没有成功!';
$res = $data;
break;
default:
break;
}
$this->result($msg,$res,200);
}
public function actionJson()
{
$res = $this->search();
$list = $res['list'];
$ids = $res['ids'];
$pcats = $res['pcats'];
$cats = $res['cats'];
$newList = [];
foreach($ids as $id){
$row = $list[$id];
$row['cat_title'] = '';
if($row['cid']>0){
if(isset($cats[$row['cid']])){
$row['cat_title'] = $cats[$row['cid']]['title'];
}
}
$newList[] = $row;
}
$data = [];
$data['total'] = $res['total'];
$data['totalNotFiltered'] = $res['total'];
$data['rows'] = $newList;
header('Content-Type:application/json');
exit(json_encode($data,JSON_UNESCAPED_UNICODE)); //注意不要加强制object参数
}
private function search(){
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcNews();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = $this->postdata;
$get = Yii::$app->request->get();
$searchSession = 'news::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($search['title']) : '';
if (!empty($search['title'])) {
$where[] = ['LIKE','title',$search['title']];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$totalCount = $data->count();
$_orderby = 'orderby DESC';
$res = $data->orderby($_orderby)->all();
$list = $ids = $cids = $pcids = [];
$cats = $pcats = [];
if ($res) {
foreach ($res as $r) {
if($r->cid){
$cids[] = $r->cid;
}
$ids[] = $r->id;
$list[$r->id] = $r->toArray(); //内容按ID列出,以便后用
}
}
$CatModel = new AcNewsCat();
if($cids){
$res = $CatModel->find()->where(['IN','id',$cids])->all();
foreach ($res as $r) {
if($r->pcat_id){
$pcids[]= $r->pcat_id;
}
$cats[$r->id] = $r;
}
if($pcids){
$res = $CatModel->find()->where(['IN','id',$pcids])->all();
foreach ($res as $r) {
$pcats[$r->id] = $r;
}
}
}
$data = [];
$data['total'] = $totalCount;
$data['totalNotFiltered'] = $totalCount;
$data['cats'] = $cats;
$data['pcats'] = $pcats;
$data['list'] = $list;
$data['ids'] = $ids;
return $data;
}
private function _tableOptions(){
$columns = [];
$columns['id'] = [
'field'=>'id',
'title'=>'ID',
'footerFormatter'=>'CountTotalFooter',
'searchable'=>false
];
$columns['cat'] = [
'field'=>'cid',
'title'=>'分类',
'class'=>"resize_able",
'formatter'=>'catFormatter',
'filterControl'=>"select",
'sortable'=>true,
'searchable'=>true
];
$columns['title'] = [
'field'=>'title',
'title'=>'标题',
'class'=>"resize_able",
'editable'=>'textEditor',
'formatter'=>'textFormatter',
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'filterControl'=>"input",
'searchable'=>true
];
$columns['des'] = [
'field'=>'des',
'title'=>'简述',
'editable'=>'textEditor',
'formatter'=>'textFormatter',
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'searchable'=>true
];
$columns['orderby'] = [
'field'=>'orderby',
'title'=>'排序',
'editable'=>'textEditor',
'formatter'=>'numFormatter',
'sortable'=>true,
'searchable'=>true
];
$columns['viewCount'] = [
'field'=>'viewed',
'title'=>'浏览量',
'formatter'=>'numFormatter',
'footerFormatter'=>'NumCountFooter',
'sortable'=>true,
'searchable'=>false
];
$columns['likeCount'] = [
'field'=>'liked',
'title'=>'收藏量',
'formatter'=>'numFormatter',
'footerFormatter'=>'NumCountFooter',
'sortable'=>true,
'searchable'=>false
];
$columns['readingCount'] = [
'field'=>'reading',
'title'=>'在看',
'formatter'=>'numFormatter',
'footerFormatter'=>'NumCountFooter',
'sortable'=>true,
'searchable'=>false
];
$columns['isShow'] = [
'field'=>'is_show',
'title'=>'显示',
'editable'=>'textEditor',
'formatter'=>'yesnoFormatter',
'filterControl'=>"select",
'sortable'=>true,
'searchable'=>false
];
$columns['create_at'] = [
'field'=>'create_at',
'title'=>'创建日期',
'formatter'=>'dateFormatter',
'sortable'=>true,
'searchable'=>false
];
$columns['update_at'] = [
'field'=>'update_at',
'title'=>'更新时间',
'formatter'=>'timeFormatter',
'sortable'=>true,
'searchable'=>false
];
$operator = [];
$operator['showDetail'] = [
'class'=>'view',
'title'=>'概览',
'icon'=>'eye',
'func'=>false
];
$operator['save'] = [
'class'=>'save',
'title'=>'保存',
'icon'=>'save',
'func'=>false
];
$operator['remove'] = [
'class'=>'remove',
'title'=>'移除',
'icon'=>'trash',
'func'=>false
];
$operator['edit'] = [
'class'=>'href',
'title'=>'编辑',
'icon'=>'pencil',
'func'=>false
];
return [
'columns' => $columns,
'operator' => $operator
];
}
}
@@ -0,0 +1,447 @@
<?php
# @Author: fm453
# @Date: 2024/7/16
# @updated: 下午3:55
# @Email: 1280880631@qq.com
namespace backend\controllers;
use addons\models\AcNewsCat;use Yii;
class NewscatController extends Common{
public $enableCsrfValidation = false;
public function actionIndex(){}
public function actionList()
{
$options = $this->_tableOptions();
$columns = $options['columns'];
$operator = $options['operator'];
$tpl = 'list';
return $this->render($tpl, [
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE)
]);
}
private function _tableOptions(){
$columns = [];
$columns['id'] = [
'field'=>'id',
'title'=>'ID',
'align'=>'center',
'vlign'=>'middle',
'halign'=>'center',
'width'=>30,
'widthUnit'=>'px',
'footerFormatter'=>'CountTotalFooter',
'sortable'=>true,
'searchable'=>false
];
$columns['pcat_id'] = [
'field'=>'pcat_id',
'title'=>'上级分类',
'align'=>'center',
'vlign'=>'middle',
'halign'=>'center',
'width'=>120,
'widthUnit'=>'px',
'class'=>"resize_able",
'formatter'=>'catFormatter',
'filterControl'=>"select",
'sortable'=>true,
'searchable'=>false
];
$columns['pcat_title'] = [
'field'=>'pcat_title',
'title'=>'上级分类',
'align'=>'center',
'vlign'=>'middle',
'halign'=>'center',
'width'=>150,
'widthUnit'=>'px',
'class'=>"resize_able",
'filterControl'=>"select",
'visible'=>false,
'sortable'=>true,
'searchable'=>false
];
$columns['title'] = [
'field'=>'title',
'title'=>'标题',
'align'=>'center',
'vlign'=>'middle',
'halign'=>'center',
// 'width'=>120,
// 'widthUnit'=>'px',
'class'=>"resize_able",
'cellStyle'=>'cellStyle',
'editable'=>'textEditor',
//该列可编辑
'formatter'=>'textFormatter',
// 'filterControl'=>"input",
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'searchable'=>true
];
$columns['des'] = [
'field'=>'des',
'title'=>'简述',
'align'=>'center',
'vlign'=>'middle',
'halign'=>'center',
// 'width'=>120,
// 'widthUnit'=>'px',
'titleTooltip'=>'英文简写的代码,后期用于权限判断等场景',
'class'=>"resize_able",
'cellStyle'=>'cellStyle',
'editable'=>'textEditor',
'formatter'=>'textFormatter',
// 'filterControl'=>"select",
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'searchable'=>true
];
$columns['orderby'] = [
'field'=>'orderby',
'title'=>'排序',
'width'=>40,
'widthUnit'=>'px',
'editable'=>'textEditor',
'formatter'=>'numFormatter',
'sortable'=>true,
'searchable'=>false
];
$columns['create_at'] = [
'field'=>'create_at',
'title'=>'创建日期',
'formatter'=>'dateFormatter',
'sortable'=>true,
'searchable'=>false
];
$columns['update_at'] = [
'field'=>'update_at',
'title'=>'更新时间',
'formatter'=>'timeFormatter',
'sortable'=>true,
'searchable'=>false
];
$operator = [];
$operator['showDetail'] = [
'class'=>'view',
'title'=>'概览',
'icon'=>'eye',
'func'=>false
];
$operator['save'] = [
'class'=>'save',
'title'=>'保存',
'icon'=>'save',
'func'=>false
];
$operator['remove'] = [
'class'=>'remove',
'title'=>'移除',
'icon'=>'trash',
'func'=>false
];
return [
'columns' => $columns,
'operator' => $operator
];
}
public function actionSelect()
{
/**
* 选择分类
* @id [int] 来源页的元素数据唯一标识ID
* @cid [int] 来源页的传入的已迁选中的分类ID
* @callback [string] 来源页的元素标签标识
*/
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'newsCat';
if($id) $callback .= '-'.$id;
$cid = Yii::$app->request->get('cid');
$options = $this->_tableOptions();
$columns = $options['columns'];
unset($columns['pcat_title']);
$operator = $options['operator'];
$operator['select'] = [
'class'=>'select',
'title'=>'选择',
'icon'=>'check-square-o',
'func'=>false
];
unset($operator['remove']);
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'select';
return $this->render($tpl, [
'id' => $id,
'selected_id'=>$cid,
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE),
'callback'=>$callback
]);
}
public function actionPcat(){
/**
* 选择上级分类
* @id [int] 当前来源子类ID
*/
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$model = new AcNewsCat();
$cat = $model->findOne($id);
$pcat_id = 0;
if($cat->pcat_id) $pcat_id = $cat->pcat_id;
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'newsCat';
if($id) $callback .= '-'.$id;
$options = $this->_tableOptions();
$columns = $options['columns'];
unset($columns['pcat_title']);
$operator = $options['operator'];
$operator['select'] = [
'class'=>'select',
'title'=>'选择',
'icon'=>'check-square-o',
'func'=>false
];
unset($operator['remove']);
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'pcat';
return $this->render($tpl, [
'id' => $id,
'selected_id'=>$pcat_id,
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE),
'callback'=>$callback
]);
}
public function actionJson(){
$res = $this->Search();
$list = $res['list'];
$ids = $res['ids'];
$totalCount = $res['total'];
$pcats = $res['pcats'];
$cats = $res['cats'];
$newList = [];
foreach($ids as $id){
$row = $list[$id];
if($row['pcat_id']){
$row['pcat_title'] = $list[$row['pcat_id']]['title'];
}
$newList[] = $row;
}
//客户端表格类型 bootstrapTable 或 dataTable;
// $table_type = "dataTable";
$table_type = "bootstrapTable";
$data = [];
if($table_type=="dataTable"){
$data['draw'] = 1; //客户端表是否需要重绘
$data['recordsTotal'] = $totalCount;
$data['recordsFiltered'] = $totalCount;
$data['pcats'] = $pcats;
$data['cats'] = $cats;
$data['data'] = $newList;
} elseif($table_type=="bootstrapTable"){
$data['total'] = $totalCount;
$data['totalNotFiltered'] = $totalCount;
$data['pcats'] = $pcats;
$data['cats'] = $cats;
$data['rows'] = $newList;
}
header('Content-Type:application/json');
exit(json_encode($data,JSON_UNESCAPED_UNICODE)); //注意不要加强制object参数
}
private function search(){
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcNewsCat();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = $this->postdata;
$get = Yii::$app->request->get();
$searchSession = 'newscat::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($search['title']) : '';
if (!empty($search['title'])) {
$where[] = ['LIKE','title',$search['title']];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$totalCount = $data->count();
$_orderby = 'orderby DESC';
$res = $data->orderby($_orderby)->all();
$list = $cids = $pcids = [];
$cats = $pcats = [];
if ($res) {
foreach ($res as $r) {
if($r->pcat_id){
//重排数组,保留查询结果的排序
$pcids[] = $r->pcat_id; //父类
$cids[$r->pcat_id][] = $r->id; //子分类,按父类分组
}else{
$cids['0'][] = $r->id; //无父类的
}
$ids[] = $r->id;
$list[$r->id] = $r->toArray(); //内容按ID列出,以便后用
}
}
if($pcids){
foreach ($pcids as $pcid) {
$pcats[] = $list[$pcid];
foreach($cids[$pcid] as $k=>$id){
$cats[$pcid][] = $list[$id];
}
}
foreach($cids as $pcid=>$ccids){
foreach($ccids as $k=>$id){
$cats[$pcid][] = $list[$id];
}
}
}
return ['ids'=>$ids,'list'=>$list,'total'=>$totalCount,'pcats'=>$pcats,'cats'=>$cats];
}
public function actionSave(){
$post = $this->postdata;
$id = isset($post['id']) ? (int)$post['id'] : 0;
$pid = Yii::$app->session->get('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 = ['orderby'=>'orderby','deleted'=>'deleted','pcat_id'=>'pcat_id'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$cols = ['is_show'=>'is_show'];
foreach($cols as $col=>$key){
if(!$id){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 1;
}elseif(isset($post[$col])){
$data[$col] = (int)$post[$key];
}
}
if(!$id){
$data['create_at'] = time();
}
$data['update_at'] = time();
$data['pid'] = $pid;
//保存
$msg = '数据保存失败';
$res = false;
$cpde = 0;
$model = new AcNewsCat();
if($id){
$_rec = $model::findOne($id);
if($_rec){
foreach($data as $key=>$val){
$_rec->$key = $val;
}
$_rec->id = $id;
$res = $_rec->save();
if($res){
$msg = '数据保存成功';
$code = 200;
}
}
}else{
foreach($data as $key=>$val){
$model->$key = $val;
}
$res = $model->save();
if($res){
$msg = '数据新增成功';
$id = $model->attributes['id']; //获取插入后id
$code = 200;
}
}
$data['id'] = $id;
$this->result($msg,$data,200);
}
public function actionAjax(){
$op = $_GET['op']; //操作标识,只允许客户端GET传入
$post = $this->postdata;
$msg = '删除失败';
if(!isset($post['id'])){
$this->result($msg,$post,200);
}
$id = $post['id'];
$model = new AcNewsCat();
$data = $model->findOne($id);
if(!$data){
$msg = '数据不存在,操作失败';
$this->result($msg,$post,200);
}
if($data->pid != $this->pid){
$msg = '归属平台不匹配,禁止操作';
$this->result($msg,$post,200);
}
switch($op){
case 'del':
if($data->deleted >0){
$msg = '数据已被删除过,操作无效';
$this->result($msg,$post,200);
}
$data->deleted += 1;
$_res = $data->save();
$msg = $_res ? '删除成功' : '操作失败,数据更新没有成功!';
$res = $data;
break;
default:
break;
}
$this->result($msg,$res,200);
}
}
@@ -0,0 +1,308 @@
<?php
# @Author: fm453
# @Date: 2024/7/16
# @updated: 下午3:55
# @Email: 1280880631@qq.com
namespace backend\controllers;
use addons\models\AcNewsCat;use Yii;
class NewscatController extends Common{
public $enableCsrfValidation = false;
public function actionIndex(){}
public function actionList()
{
global $_HI,$_FM;
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcNewsCat();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'newscat::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($search['title']) : '';
if (!empty($search['title'])) {
$where[] = ['LIKE','title',$search['title']];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$_orderby = 'orderby DESC';
$res = $data->orderby($_orderby)->all();
$list = $cids = $pcids = [];
$cats = $pcats = [];
if ($res) {
foreach ($res as $r) {
if($r->pcat_id){
//重排数组,保留查询结果的排序
$pcids[] = $r->pcat_id; //父类
$cids[$r->pcat_id][] = $r->id; //子分类
}
$list[$r->id] = $r->toArray(); //内容按ID列出,以便后用
}
}
if($pcids){
foreach ($pcids as $pcid) {
$pcats[] = $list[$pcid];
}
foreach($cids as $pcid=>$ids){
foreach($ids as $id){
$cats[$pcid][] = $list[$id];
}
}
}
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'datatable';
$tpl = 'table';
return $this->render($tpl, [
'cats' => $cats,
'pcats' => $pcats,
'search'=>$search
]);
}
public function actionSelect()
{
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'newsCat';
if($id) $callback .= '-'.$id;
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'select';
return $this->render($tpl, [
'id' => $id,
'callback'=>$callback
]);
}
public function actionPcat(){
/**
* 选择上级分类
* @id [int] 当前来源子类ID
*/
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'newsCat';
if($id) $callback .= '-'.$id;
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'select';
return $this->render($tpl, [
'id' => $id,
'callback'=>$callback
]);
}
public function actionJson(){
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcNewsCat();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = $this->postdata;
$get = Yii::$app->request->get();
$searchSession = 'newscat::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($search['title']) : '';
if (!empty($search['title'])) {
$where[] = ['LIKE','title',$search['title']];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$totalCount = $data->count();
$_orderby = 'orderby DESC';
$res = $data->orderby($_orderby)->all();
$list = $ids = $cids = $pcids = [];
$cats = $pcats = $newList = [];
if ($res) {
foreach ($res as $r) {
if($r->pcat_id){
//重排数组,保留查询结果的排序
$pcids[] = $r->pcat_id; //父类
$cids[$r->pcat_id][] = $r->id; //子分类,按父类分组
}else{
$cids['0'][] = $r->id; //无父类的
}
$ids[] = $r->id;
$list[$r->id] = $r->toArray(); //内容按ID列出,以便后用
}
}
if($pcids){
foreach ($pcids as $pcid) {
$pcats[] = $list[$pcid];
foreach($cids[$pcid] as $k=>$id){
$cats[$pcid][] = $list[$id];
}
}
foreach($cids as $pcid=>$ccids){
foreach($ccids as $k=>$id){
$cats[$pcid][] = $list[$id];
}
}
}
if(isset($post['id']) && (int)$post['id']){
$id = (int)$post['id'];
if($list[$id]){
$list[$id]['no_edit'] = $list[$id]['_isUnselectable'] = 1;
if($list[$id]['pcat_id']){
$list[$id]['_isSelected'] = 1;
}
}
}
foreach($ids as $id){
$row = $list[$id];
if($row['pcat_id']){
$row['pcat_title'] = $list[$row['pcat_id']]['title'];
}
$newList[] = $row;
}
//客户端表格类型 bootstrapTable 或 dataTable;
// $table_type = "dataTable";
$table_type = "bootstrapTable";
$data = [];
if($table_type=="dataTable"){
$data['draw'] = 1; //客户端表是否需要重绘
$data['recordsTotal'] = $totalCount;
$data['recordsFiltered'] = $totalCount;
$data['pcats'] = $pcats;
$data['cats'] = $cats;
$data['data'] = $newList;
} elseif($table_type=="bootstrapTable"){
$data['total'] = $totalCount;
$data['totalNotFiltered'] = $totalCount;
$data['pcats'] = $pcats;
$data['cats'] = $cats;
$data['rows'] = $newList;
}
header('Content-Type:application/json');
exit(json_encode($data,JSON_UNESCAPED_UNICODE)); //注意不要加强制object参数
}
public function actionSave(){
$post = $this->postdata;
$id = isset($post['id']) ? (int)$post['id'] : 0;
$pid = Yii::$app->session->get('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 = ['orderby'=>'orderby','deleted'=>'deleted','pcat_id'=>'pcat_id'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$cols = ['is_show'=>'is_show'];
foreach($cols as $col=>$key){
if(!$id){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 1;
}elseif(isset($post[$col])){
$data[$col] = (int)$post[$key];
}
}
if(!$id){
$data['create_at'] = time();
}
$data['update_at'] = time();
$data['pid'] = $pid;
//保存
$msg = '数据保存失败';
$res = false;
$cpde = 0;
$model = new AcNewsCat();
if($id){
$_rec = $model::findOne($id);
if($_rec){
foreach($data as $key=>$val){
$_rec->$key = $val;
}
$_rec->id = $id;
$res = $_rec->save();
if($res){
$msg = '数据保存成功';
$code = 200;
}
}
}else{
foreach($data as $key=>$val){
$model->$key = $val;
}
$res = $model->save();
if($res){
$msg = '数据新增成功';
$id = $model->attributes['id']; //获取插入后id
$code = 200;
}
}
$data['id'] = $id;
$this->result($msg,$data,200);
}
public function actionAjax(){
$op = $_GET['op']; //操作标识,只允许客户端GET传入
$post = $this->postdata;
$res = [];
switch($op){
case 'del':
$msg = '软删除,假定成功';
$res = $post;
break;
default:
break;
}
$this->result($msg,$res,200);
}
}
+346
View File
@@ -0,0 +1,346 @@
<?php
#
# @Author: fm453
# @Date: 2024/7/16
# @updated: 下午3:55
# @Email: 1280880631@qq.com
namespace backend\controllers;
use addons\models\AcNotice;use Yii;
class NoticeController extends Common{
public $enableCsrfValidation = false;
public function actionIndex(){
}
public function actionList(){
$options = $this->_tableOptions();
$columns = $options['columns'];
$operator = $options['operator'];
$tpl = 'list';
return $this->render($tpl, [
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE)
]);
}
private function _tableOptions(){
$columns = [];
$columns['id'] = [
'field'=>'id',
'title'=>'ID',
'footerFormatter'=>'CountTotalFooter',
'searchable'=>false
];
$columns['title'] = [
'field'=>'title',
'title'=>'标题',
'class'=>"resize_able",
'editable'=>'textEditor',
'formatter'=>'textFormatter',
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'filterControl'=>"input",
'searchable'=>true
];
$columns['content'] = [
'field'=>'content',
'title'=>'内容',
'editable'=>'textEditor',
'formatter'=>'textFormatter',
'searchFormatter'=>true,
'searchHighlightFormatter'=>'customSearchFmt',
'searchable'=>true
];
$columns['isShow'] = [
'field'=>'is_show',
'title'=>'显示',
'editable'=>'textEditor',
'formatter'=>'yesnoFormatter',
'filterControl'=>"select",
'sortable'=>true,
'searchable'=>false
];
$columns['create_at'] = [
'field'=>'create_at',
'title'=>'创建日期',
'formatter'=>'dateFormatter',
'sortable'=>true,
'searchable'=>false
];
$columns['update_at'] = [
'field'=>'update_at',
'title'=>'更新时间',
'formatter'=>'timeFormatter',
'sortable'=>true,
'searchable'=>false
];
$operator = [];
$operator['showDetail'] = [
'class'=>'view',
'title'=>'概览',
'icon'=>'eye',
'func'=>false
];
$operator['save'] = [
'class'=>'save',
'title'=>'保存',
'icon'=>'save',
'func'=>false
];
$operator['remove'] = [
'class'=>'remove',
'title'=>'移除',
'icon'=>'trash',
'func'=>false
];
return [
'columns' => $columns,
'operator' => $operator
];
}
public function actionSelect()
{
$pid = $this->pid;
$id = Yii::$app->request->get('id');
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'news';
if($id) $callback .= '-'.$id;
$options = $this->_tableOptions();
$columns = $options['columns'];
$operator = $options['operator'];
//不使用模板框架
// $this->layout = '@app/views/layouts/table';
$tpl = 'select';
return $this->render($tpl, [
'id' => $id,
'callback'=>$callback,
'columns' => json_encode($columns,JSON_UNESCAPED_UNICODE),
'operator' => json_encode($operator,JSON_UNESCAPED_UNICODE)
]);
}
public function actionNew()
{
$pid = $this->pid;
$tpl = 'modify';
return $this->render(
$tpl,
[
'detail'=>[],
'id'=>0
]
);
}
public function actionEdit()
{
$pid = $this->pid;
$post = $this->postdata;
$id = Yii::$app->request->get('id');
$AcNotice = new AcNotice();
$notice = $AcNotice->findOne($id);
$detail = $notice->toArray();
$tpl = 'modify';
return $this->render(
$tpl,
[
'detail'=>$detail,
'id'=>$id
]
);
}
public function actionSave(){
$post = $this->postdata;
$id = isset($post['id']) ? (int)$post['id'] : 0;
$pid = Yii::$app->session->get('pid');
//格式化数据
//目标键=》POST键
$cols = ['title'=>'title','content'=>'content'];
foreach($cols as $col=>$key){
if(isset($post[$key])){
$data[$col] = trim($post[$key]);
}elseif(!$id){
$data[$col] = '';
}
}
$cols = ['deleted'=>'deleted'];
foreach($cols as $col=>$key){
if(isset($post[$key])){
$data[$col] = (int)$post[$key];
}elseif(!$id){
$data[$col] = 0;
}
}
$cols = ['is_show'=>'is_show'];
foreach($cols as $col=>$key){
if(!$id){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 1;
}else{
if(isset($post[$col])){
$data[$col] = (int)$post[$key];
}
}
}
if(!$id){
$data['create_at'] = time();
}
$data['update_at'] = time();
$data['pid'] = $pid;
//保存
$msg = '数据保存失败';
$res = false;
$cpde = 0;
$model = new AcNotice();
if($id){
$_rec = $model::findOne($id);
if($_rec){
foreach($data as $key=>$val){
$_rec->$key = $val;
}
$res = $_rec->save();
if($res){
$msg = '数据保存成功';
$code = 200;
}
}
}else{
foreach($data as $key=>$val){
$model->$key = $val;
}
$res = $model->save();
if($res){
$msg = '数据新增成功';
$id = $model->attributes['id']; //获取插入后id
$code = 200;
}
}
$data['id'] = $id;
$op = Yii::$app->request->get('op');
if($op){
return $this->redirect(['edit','id'=>$id]);
}
$this->result($msg,$data,200);
}
public function actionAjax(){
$op = $_GET['op']; //操作标识,只允许客户端GET传入
$post = $this->postdata;
$res = [];
$msg = '删除失败';
if(!isset($post['id'])){
$this->result($msg,$post,200);
}
$id = $post['id'];
$model = new AcNotice();
$data = $model->findOne($id);
if(!$data){
$msg = '数据不存在,操作失败';
$this->result($msg,$post,200);
}
if($data->pid != $this->pid){
$msg = '归属平台不匹配,禁止操作';
$this->result($msg,$post,200);
}
switch($op){
case 'del':
if($data->deleted >0){
$msg = '数据已被删除过,操作无效';
$this->result($msg,$post,200);
}
$data->deleted += 1;
$_res = $data->save();
$msg = $_res ? '删除成功' : '操作失败,数据更新没有成功!';
$res = $data;
break;
default:
break;
}
$this->result($msg,$res,200);
}
public function actionJson()
{
$res = $this->search();
$list = $res['list'];
$ids = $res['ids'];
$newList = [];
foreach($ids as $id){
$row = $list[$id];
$newList[] = $row;
}
$data = [];
$data['total'] = $res['total'];
$data['totalNotFiltered'] = $res['total'];
$data['rows'] = $newList;
header('Content-Type:application/json');
exit(json_encode($data,JSON_UNESCAPED_UNICODE)); //注意不要加强制object参数
}
private function search(){
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcNotice();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = $this->postdata;
$get = Yii::$app->request->get();
$searchSession = 'notice::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($search['title']) : '';
if (!empty($search['title'])) {
$where[] = ['LIKE','title',$search['title']];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$totalCount = $data->count();
$_orderby = 'id ASC';
$res = $data->orderby($_orderby)->all();
$list = $ids = [];
if ($res) {
foreach ($res as $r) {
$ids[] = $r->id;
$list[$r->id] = $r->toArray(); //内容按ID列出,以便后用
}
}
$data = [];
$data['total'] = $totalCount;
$data['totalNotFiltered'] = $totalCount;
$data['list'] = $list;
$data['ids'] = $ids;
return $data;
}
}
File diff suppressed because it is too large Load Diff
+862
View File
@@ -0,0 +1,862 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcCar;
use addons\models\AcCarOwner;
use addons\models\AcCarBrand;
use addons\models\AcCarSeries;
use addons\models\AcStore;
use addons\models\AcEmployee;
use addons\models\AcOrder;
use addons\models\AcOrderPre;
use addons\models\AcOrderStatus;
use addons\models\AcPlat;
use common\models\CVcode;
use addons\models\AcContact;
use common\models\Member as User;
use addons\models\AcUserExt;
use common\models\Fans;
use addons\models\AcFansExt;
class OrderpreController extends Common
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
}
//主界面
public function actionIndex()
{
global $_HI,$_FM;
return $this->render('../layouts/dev', []);
}
//订单列表
public function actionList()
{
global $_HI,$_FM;
$pid = $this->pid;
$session = Yii::$app->session;
$model = new AcOrderPre();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'orderPre::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['car_no'] = isset($search['car_no']) ? trim($search['car_no']) : '';
if (!empty($search['car_no'])) {
$where[] = ['=','car_no',$search['car_no']];
}
$search['car_title'] = isset($search['car_title']) ? trim($search['car_title']) : '';
if (!empty($search['car_title'])) {
$where[] = ['LIKE','car_no',$search['car_no']];
}
$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 : '';
}
$search['start_province'] = isset($search['start_province']) ? trim($search['start_province']) : '';
if (!empty($search['start_province'])) {
$where[] = ['=','start_province',$search['start_province']];
}
$search['start_city'] = isset($search['start_city']) ? trim($search['start_city']) : '';
if (!empty($search['start_city'])) {
$where[] = ['LIKE','start_city',$search['start_city']];
}
$search['aim_province'] = isset($search['aim_province']) ? trim($search['aim_province']) : '';
if (!empty($search['aim_province'])) {
$where[] = ['=','aim_province',$search['aim_province']];
}
$search['aim_city'] = isset($search['aim_city']) ? trim($search['aim_city']) : '';
if (!empty($search['aim_city'])) {
$where[] = ['LIKE','aim_city',$search['aim_city']];
}
$search['from_name'] = isset($search['from_name']) ? trim($search['from_name']) : '';
if (!empty($search['from_name'])) {
$where[] = ['LIKE','from_name',$search['from_name']];
}
$search['from_phone'] = isset($search['from_phone']) ? trim($search['from_phone']) : '';
if (!empty($search['from_phone'])) {
$where[] = ['LIKE','from_phone',$search['from_phone']];
}
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']);
}
//计划日期筛选
$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','date',$start,$end];
}
//按指定时段筛选
elseif (!empty($search['sign_after']) && !empty($search['sign_before'])) {
$start = strtotime($search['sign_after']);
$end = strtotime($search['sign_before']);
$where[] = ['between','date',$start,$end];
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif (!empty($search['sign_after'])) {
$start = strtotime($search['sign_after']);
$where[] = ['>=','date',$start];
} elseif (!empty($search['sign_before'])) {
$end = strtotime($search['sign_before']);
$where[] = ['<=','date',$end];
}
if (isset($search['onlyme']) && $search['onlyme']==1) {
$where[] = ['=','create_by',Yii::$app->user->identity->id];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$_orderby = 'id DESC';
if (isset($search['orderby']) && $search['orderby']=='date') {
$_orderby = 'date DESC,id DESC';
}
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
$status = Yii::$app->params['OrderPreStatus'];
$sids = $eids = $uids = $mids = [];
if ($res) {
foreach ($res as $r) {
$sids[$r->store_id] = $r->store_id;
$mids[$r->from_mid] = $r->from_mid;
$uids[$r->from_uid] = $r->from_uid;
$eids[$r->employee_id] = $r->employee_id;
}
}
$model = new AcStore();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_stores = $model->find()->where(['in','id',$sids])->all();
$stores = [];
foreach ($_stores as $s) {
$stores[$s->id] = $s->toArray();
}
$model = new AcEmployee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach ($_employees as $s) {
$employees[$s->id] = $s->toArray();
}
// $model = new User();
// $users = [];
// $_users = $model->find()->where(['in','id',$mids])->all();
// foreach($_users as $s){
// $s = $s->toArray();
// $users[$s['id']] = $s;
// }
//
// $model = new AcUserExt();
// $exts = [];
// $_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
// foreach($_exts as $ext){
// $ext = $ext->toArray();
// if(isset($users[$s['id']])){
// if($ext['mobile']==$users[$s['id']]['mobile']){
// $exts[$ext['mid']][$ext['key']] = $ext['value'];
// }
// }
// }
$model = new Fans();
$users = [];
$_users = $model->find()->where(['in','id',$uids])->all();
foreach ($_users as $s) {
$s = $s->toArray();
$users[$s['id']] = $s;
}
$model = new AcFansExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach ($_exts as $ext) {
$ext = $ext->toArray();
if (isset($users[$s['id']])) {
if ($ext['mobile']==$users[$s['id']]['mobile']) {
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$orders = [];
foreach ($res as $s) {
$s = $s->toArray();
if (isset($exts[$s['from_mid']])) {
foreach ($exts[$s['from_mid']] as $col=>$val) {
$s[$col] = $val;
}
}
$orders[$s['id']] = $s;
}
if (isset($get['export']) && $get['export']=='all') {
$this->export($orders, $stores, $users, $exts, $status);
die;
}
return $this->render('list', [
'orders' => $orders,
'pager' => $pages,
'stores'=>$stores,
'employees'=>$employees,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'search'=>$search,
'totalCount'=>$data->count()
]);
}
//导出数据
public function export($orders, $stores, $users, $exts, $status)
{
/* 输入到CSV文件 */
$html = "\xEF\xBB\xBF";//UTF8标记
$html .= "\n";
/* 输出表头 */
$filter = array(
'id' => '序号',
'car_no' => '车牌/架号',
'car_title' => '品牌车型',
'from_name' => '联系人',
'from_mobile' => '联系电话',
'date' => '计划时间',
'start_where' => '始发地',
'end_where' => '目的地',
'store' => '网点',
'employee' => '经办人',
'receptionist' => '接待员',
'bind' => '介绍人',
'car_value' => '车辆保价',
'price' => '报价',
'car' => '客户备注'
);
foreach ($filter as $key => $title) {
$html .= $title . ",\t";
}
$html .= "\n";//换行
$htmldata = "";
foreach ($orders as $vo) {
foreach ($filter as $key => $title) {
switch ($key) {
case 'date':
$htmldata .= date('Y年m月d日', $vo['date']).",\t";
break;
case 'start_where':
$htmldata .= isset(Yii::$app->params['regionAreas'][$vo['start_province']]) ? Yii::$app->params['regionAreas'][$vo['start_province']] : '';
$htmldata .= '-';
$htmldata .= isset($vo['start_city']) ? $vo['start_city'] : '';
$htmldata .= ",\t";
break;
case 'end_where':
$htmldata .= isset(Yii::$app->params['regionAreas'][$vo['aim_province']]) ? Yii::$app->params['regionAreas'][$vo['aim_province']] : '';
$htmldata .= '-';
$htmldata .= isset($vo['aim_city']) ? $vo['aim_city'] : '';
$htmldata .= ",\t";
break;
case 'store':
$htmldata .= isset($stores[$vo['store_id']]['title']) ? $stores[$vo['store_id']]['title'] : '';
$htmldata .= ",\t";
break;
case 'employee':
$htmldata .= isset($employees[$vo['employee_id']]['name']) ? $employees[$vo['employee_id']]['name'] : '';
$htmldata .= ",\t";
break;
case 'car':
$htmldata .= strip_tags(htmlspecialchars_decode($vo['car'])).",\t";
break;
case 'status':
$htmldata .= $status[$vo['status_code']].",\t";
break;
case 'price':
case 'car_value':
$htmldata .= isset($vo[$key]) ? (int)$vo[$key] : 0;
$htmldata .= ",\t";
break;
default:
$htmldata .= isset($vo[$key]) ? $vo[$key] : '';
$htmldata .= ",\t";
break;
}
}
$htmldata .= "\n";
}
$html .=$htmldata;
/* 输出XLS文件 */
header("Content-type:text/xls");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:text/comma-separated-values;charset=UTF-8");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Transfer-Encoding:binary");
header("Content-Disposition:attachment; filename=预约列表".date('ymd').".xls");
echo $html;
}
//选择匹配
public function actionSelect()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$session = Yii::$app->session;
$model = new AcOrderPre();
$where = [];
$where[]='and';
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
$get = Yii::$app->request->get();
$searchSession = 'orderPre::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['car_no'] = isset($search['car_no']) ? trim($search['car_no']) : '';
if (!empty($search['car_no'])) {
$where[] = ['=','car_no',$search['car_no']];
}
$search['car_title'] = isset($search['car_title']) ? trim($search['car_title']) : '';
if (!empty($search['car_title'])) {
$where[] = ['LIKE','car_no',$search['car_no']];
}
$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 : '';
}
$search['start_province'] = isset($search['start_province']) ? trim($search['start_province']) : '';
if (!empty($search['start_province'])) {
$where[] = ['=','start_province',$search['start_province']];
}
$search['start_city'] = isset($search['start_city']) ? trim($search['start_city']) : '';
if (!empty($search['start_city'])) {
$where[] = ['LIKE','start_city',$search['start_city']];
}
$search['aim_province'] = isset($search['aim_province']) ? trim($search['aim_province']) : '';
if (!empty($search['aim_province'])) {
$where[] = ['=','aim_province',$search['aim_province']];
}
$search['aim_city'] = isset($search['aim_city']) ? trim($search['aim_city']) : '';
if (!empty($search['aim_city'])) {
$where[] = ['LIKE','aim_city',$search['aim_city']];
}
$search['from_name'] = isset($search['from_name']) ? trim($search['from_name']) : '';
if (!empty($search['from_name'])) {
$where[] = ['LIKE','from_name',$search['from_name']];
}
$search['from_phone'] = isset($search['from_phone']) ? trim($search['from_phone']) : '';
if (!empty($search['from_phone'])) {
$where[] = ['LIKE','from_phone',$search['from_phone']];
}
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']);
}
//计划日期筛选
$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','date',$start,$end];
}
//按指定时段筛选
elseif (!empty($search['sign_after']) && !empty($search['sign_before'])) {
$start = strtotime($search['sign_after']);
$end = strtotime($search['sign_before']);
$where[] = ['between','date',$start,$end];
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif (!empty($search['sign_after'])) {
$start = strtotime($search['sign_after']);
$where[] = ['>=','date',$start];
} elseif (!empty($search['sign_before'])) {
$end = strtotime($search['sign_before']);
$where[] = ['<=','date',$end];
}
if (isset($search['onlyme']) && $search['onlyme']==1) {
$where[] = ['=','create_by',Yii::$app->user->identity->id];
}
$deleted = 0;
if (isset($_GET['deleted'])) {
$deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0;
}
$where[]=['=','deleted',$deleted];
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$_orderby = 'id DESC';
if (isset($search['orderby']) && $search['orderby']=='date') {
$_orderby = 'date DESC,id DESC';
}
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
$status = Yii::$app->params['OrderPreStatus'];
$sids = $eids = $uids = $mids = [];
if ($res) {
foreach ($res as $r) {
$sids[$r->store_id] = $r->store_id;
$mids[$r->from_mid] = $r->from_mid;
$uids[$r->from_uid] = $r->from_uid;
$eids[$r->employee_id] = $r->employee_id;
}
}
$model = new AcStore();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_stores = $model->find()->where(['in','id',$sids])->all();
$stores = [];
foreach ($_stores as $s) {
$stores[$s->id] = $s->toArray();
}
$model = new AcEmployee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach ($_employees as $s) {
$employees[$s->id] = $s->toArray();
}
$model = new Fans();
$users = [];
$_users = $model->find()->where(['in','id',$uids])->all();
foreach ($_users as $s) {
$s = $s->toArray();
$users[$s['id']] = $s;
}
$model = new AcFansExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach ($_exts as $ext) {
$ext = $ext->toArray();
if (isset($users[$s['id']])) {
if ($ext['mobile']==$users[$s['id']]['mobile']) {
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
}
}
$orders = [];
foreach ($res as $s) {
$s = $s->toArray();
if (isset($exts[$s['from_mid']])) {
foreach ($exts[$s['from_mid']] as $col=>$val) {
$s[$col] = $val;
}
}
$orders[$s['id']] = $s;
}
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'order';
return $this->render('select', [
'orders' => $orders,
'pager' => $pages,
'employees'=>$employees,
'stores'=>$stores,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
$status = Yii::$app->params['OrderPreStatus'];
$AcOrder = new AcOrderPre();
$AcOrder->status_code = 0;
$detail = $AcOrder->toArray();
return $this->render('modify', ['status'=>$status,'detail'=>$detail]);
}
public function actionEdit()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderPreStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrderPre = new AcOrderPre();
$order = $AcOrderPre->findOne($id);
$detail = $order->toArray();
$model = new AcStorePre();
$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;
}
$model = new Fans();
$user = $model->findOne($detail['from_uid']);
$model = new AcFansExt();
$exts = [];
$_exts = $model->find()->where(['mid'=>$detail['from_uid'],'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'];
}
}
}
$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 actionCopy()
{
$pid = Yii::$app->session->get('pid');
$status = Yii::$app->params['OrderStatus'];
$post = Yii::$app->request->post();
$id = Yii::$app->request->get('id');
$AcOrder = new AcOrderPre();
$order = $AcOrder->findOne($id);
$detail = $order->toArray();
$detail['remark'] = '';
$detail['car'] = '';
unset($detail['id']);
$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;
}
$tpl = 'modify';
return $this->render(
$tpl,
[
'status'=>$status,
'detail'=>$detail,
'store'=>$store,
'employee'=>$employee,
'id'=>0
]
);
}
//保存运单信息
public function actionSave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
$AcOrderPre = new AcOrderPre();
if ($id) {
$order = $AcOrderPre->findOne($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','bind'=>'bind','from_mobile'=>'from_mobile','from_name'=>'from_name','receptionist'=>'receptionist'];
foreach ($cols as $col=>$key) {
if (isset($post[$key]) && $post[$key] !='') {
$data[$col] = trim($post[$key]);
}
}
$cols = ['store_id'=>'store_id','employee_id'=>'employee_id','from_mid'=>'from_mid','car_value'=>'car_value','from_uid'=>'from_uid','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]);
}
}
$sign_date = isset($post['date']) ? strtotime($post['date']) : '';
$data['date'] = !$sign_date ? time() : $sign_date;
//部分规则校验
$has_err = true;
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$model = new AcEmployee();
$data['employee_id'] = $data['employee_id'] ?? 0;
$employee = $model->findOne($data['employee_id']);
if ($employee) {
$data['store_id'] = $employee->store_id;
$data['status_code'] = 1; //员工跟进中
$data['receptionist'] = $data['receptionist'] ?? $employee->name;
}
//保存资料
if ($id) {
unset($data['create_at']);
$res = $AcOrderPre->updateAll($data, ['id'=>$id]);
} else {
foreach ($data as $key=>$val) {
$AcOrderPre->$key = $val;
}
$res = $AcOrderPre->save();
$id = $AcOrderPre->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();
}
}
public function actionDelete()
{
$get = Yii::$app->request->get();
$post = Yii::$app->request->post();
$id = (int)$get['id'];
$return = [];
$model = new AcOrderPre();
$order = $model->findOne($id);
if (!$order) {
$return['msg'] = '订单数据不存在';
$return['errorcode'] = 404;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
} else {
if ($order->deleted>0) {
$return['msg'] = '订单已被删除了';
$return['errorcode'] = 101;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->status_code!=0) {
$return['msg'] = '订单非初始状态,不可删除;如果该订单不正确,可取消操作';
$return['errorcode'] = 102;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
// $data = $where = [];
// $where['pid'] = Yii::$app->session->get('pid');
// $where['id'] = $id;
// $data['update_at'] = time();
// $data['deleted'] = 1;
//
// $model->id = $id;
// $res = $model->updateAll($data, $where);
$order->deleted = 1;
$order->update_at = time();
$res = $order->save();
$return = [];
$return['url'] = Url::toRoute('order/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['id'] = $id;
$data['update_at'] = time();
$model = new AcOrderPre();
$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->status_code>1) {
$return['msg'] = '订单已进入处理流程,无法操作取消';
$return['errorcode'] = 403;
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
if ($order->status_code==-1) {
$return['msg'] = '订单已经是被取消状态';
$return['errorcode'] = 100;
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;
default:
break;
}
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
}
}
+260
View File
@@ -0,0 +1,260 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:41:49
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcPlat;
class PlatController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
$model = new AcPlat();
$search = $where = [];
$where[] = 'and';
if(isset($_POST['title']) && $_POST['title']!=''){
$search['title'] = $_POST['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
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
public function actionEdit()
{
$model = new AcPlat();
$id = Yii::$app->request->get('id');
$res = $model->findOne($id);
if($res){
$res = $res->toArray();
}
return $this->render('modify',['detail'=>$res]);
}
public function actionSave()
{
$post = Yii::$app->request->post();
$data = [];
$id = $post['id'];
//目标键=》POST键
$cols = ['title'=>'title','thumb'=>'thumb'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['orderby'=>'orderby','deleted'=>'deleted'];
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();
}
}
public function actionExt()
{
$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');
$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));
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:29:56
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:52:06
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use backend\models\LoginForm;
use backend\models\Menu;
use backend\components\Helper;
/**
* Site controller
*/
class SiteController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['get'],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionIndex()
{
$user_id=Yii::$app->user->identity->getId();
$user_info = Yii::$app->authManager->getRolesByUser($user_id);
$roleType = key($user_info);
$menu = array();
// $menu2 = new Menu();
// $menu2 = $menu2->getLeftMenuList();
// print_r($menu2['2']);die;
if(isset($_GET['debug']) && $_GET['debug']){
if(in_array($roleType,['站长','超级管理员'])){ //只有在以站长或超级管理员身份手动开启调试模式,才可以使用管理权限菜单
$menu = yii\helpers\ArrayHelper::merge(
require(Yii::getAlias('@backend').'/menus/'.'0.php'),
require(Yii::getAlias('@backend').'/menus/'.'admin.php')
);
}else{
$menu = require(Yii::getAlias('@backend').'/menus/'.'0.php');
}
}else{
$menu = require(Yii::getAlias('@backend').'/menus/'.'0.php');
}
return $this->render('index',[
'menu' => $menu,
'user_info' => $roleType
]);
}
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$model->loginLog();
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
public function actionError($e){
echo $e;
}
}
+284
View File
@@ -0,0 +1,284 @@
<?php
/**
* @Author: fm453
* @Date: 2018-06-04 11:06:07
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:02
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\helpers\Url;
use vendor\aliyun\dysms\Sms;
use common\models\CSms;
use common\models\CVcode;
use addons\models\AcPlat;
class SmsController extends \yii\web\Controller
{
public $enableCsrfValidation = false;//取消对POST数据的csrf令牌验证
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
public function actionIndex()
{
global $_HI;
global $_FM;
$_HI['action'] = 'index';
/*自定义常量*/
/*默认配置*/
$_HI['accessKeyId'] = 'LTAIQrJFtHfqsyOt'; // AccessKeyId
$_HI['accessKeySecret'] = 'tvGieI3vNI7Si3imauCB4rJ3OX4AR8'; // AccessKeySecret
$_HI['sign'] = '嗨路客';
$_HI['tmpl'] = 'SMS_116695055';
$_HI['reportQueueName'] = 'Alicom-Queue-31737903-SmsReport'; //状态报告接收
$_HI['UpQueueName'] = 'Alicom-Queue-31737903-SmsUp'; //上行消息接收
return $this->render('index');
}
public function actionGsend()
{
global $_HI;
global $_FM;
$session = Yii::$app->session;
$session->set('sms::success',0);
$session->set('sms::msg','');
$session->set('sms::guests',[]);
/*自定义常量*/
/*默认配置*/
$_HI['accessKeyId'] = Yii::$app->params['aliDySms']['accessKeyId']; // AccessKeyId
$_HI['accessKeySecret'] = Yii::$app->params['aliDySms']['accessKeySecret']; // AccessKeySecret
$_HI['sign'] = Yii::$app->params['aliDySms']['sign'];
$_HI['tmpl'] = Yii::$app->params['aliDySms']['tmpl']['acGongxue'];
$_HI['reportQueueName'] = Yii::$app->params['aliDySms']['reportQueueName']; //状态报告接收
$_HI['UpQueueName'] = Yii::$app->params['aliDySms']['UpQueueName']; //上行消息接收
return $this->render('gsend');
}
public function actionSend()
{
global $_HI;
global $_FM;
global $START_TIME;
$session = Yii::$app->session;
//数据取出方法
$dataPost = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
$dataGet = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
$params = Yii::$app->params;
$config = array();
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
if($config){
$session->set('sms::config',$config);
}else{
$config = $session->get('sms::config');
}
$option = array();
$sms = new Sms($option,$config);
$address = isset($dataPost['address']) ? $dataPost['address'] : '';
if($address){
$session->set('sms::address',$address);
}else{
$address = $session->get('sms::address');
}
$tmpl = isset($dataPost['tmpl']) ? $dataPost['tmpl'] : '';
if($tmpl){
$session->set('sms::tmpl',$tmpl);
}else{
$tmpl = $session->get('sms::tmpl');
}
$_guests = isset($dataPost['guests']) ? $dataPost['guests'] : '';
if(!$_guests){
$guests = $session->get('sms::guests');
}else{
$_guests = explode("\r\n",$_guests);
$guests = array();
foreach($_guests as $c){
$_c = explode(',', $c);
if(count($_c)>1){
$k = trim($_c[1]);
$v = trim($_c[0]);
$guests[$k] = $v;
}
}
unset($_c);unset($k);unset($v);
$guests = array_unique($guests);
}
if(!$guests){
$i = (int)$session->get('sms::success');
$session->set('sms::success',0);
$msg = $session->get('sms::msg');
$session->set('sms::msg','');
\Yii::$app->getSession()->setFlash('info', '群发完成,共成功发送'.$i.'条;详情:'.$msg);
return $this->render('gsend');
}
$results = array();
$msg = "";
$content = [];
$content['address'] = $address;
$i = 0;
$j = 50;
foreach($guests as $p=>$username){
$j--;
$content['name'] = !empty($username) ? $username.'安诚托车' : '安诚捷顺运车';
$result = $sms->send($p,$tmpl,$content);
$results[$p] = $result;
if(!$result){
$msg .= "【".$p."】发送失败,接口提示:".$sms->errors."\r\n";
}elseif($result->Code !='OK'){
$msg .= "【".$p."】发送失败,接口提示:".$result->Message."\r\n";
}else{
$i++;
$msg .= "【".$p."】发送成功"."\r\n";
}
unset($guests[$p]);
if($j==0){
break;
}
}
$session->set('sms::guests',$guests);
$i += (int)$session->get('sms::success');
$session->set('sms::success',$i);
$msg .= $session->get('sms::msg');
$session->set('sms::msg',$msg);
\Yii::$app->getSession()->setFlash('info', '群发完成,共成功发送'.$i.'条;详情:'.$msg);
return $this->render('ajax');
}
//发送验证码
public function actionVcode()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$plat = AcPlat::findOne($pid);
$platExt = json_decode($plat->remark,true);
//数据取出方法
$dataPost = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
$dataGet = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
$params = Yii::$app->params;
$config = array();
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
$option = array();
$sms = new Sms($option,$config);
$op = Yii::$app->request->get('op');
$content=[];
switch($op){
case 'caiwu':
$phone = $platExt['cw_phone'];
$codetype = 'caiwu';
if(!$phone){
$return = [];
$return['errorcode'] = 1;
$return['msg'] = '还没有配置财务手机号,请联系站长管理员进行设置';
exit(json_encode($return));
}
$vcodeModel = new CVcode();
//查询上次发送记录
$_time = time();
$where=[];
$where['mobile'] = $phone;
$where['deleted'] = 0;
$where['type'] = $codetype;
$res = $vcodeModel->find()->where($where)->one();
if($res){
if(($_time-$res->create_at)<7200){
$code = $res->code;
$return = [];
$return['errorcode'] = 2;
$return['msg'] = '上次发送的验证码仍然可用;请注意查看财务手机';
exit(json_encode($return));
}else{
$res->deleted = 1;
$res->save();
}
}
$code = mt_rand(1000,9999);
$content['code'] = $code;
$tmpl = Yii::$app->params['aliDySms']['tmpl']['cwVcode'];
//验证码入库
$vcode = [];
$vcode['code'] = $code;
$vcode['type'] = $codetype;
$vcode['mobile'] = $phone;
$vcode['create_at'] = time();
foreach($vcode as $key=>$val){
$vcodeModel->$key = $val;
}
break;
default:
$mobile = Yii::$app->request->post('mobile');
break;
}
$result = $sms->send($phone,$tmpl,$content);
//保存发送记录
$smsModel = new CSms();
$smsdata = [];
$sid = Yii::$app->params['siteId'];
$smsdata['sid'] = (int)$sid;
$smsdata['pid'] = $pid;
$smsdata['uid'] = Yii::$app->user->identity->id;
$smsdata['mobile'] = $phone;
$smsdata['content'] = json_encode($content,JSON_UNESCAPED_UNICODE);
$smsdata['create_at'] = time();
foreach($smsdata as $key=>$val){
$smsModel->$key = $val;
}
$smsModel->save();
$return = [];
$msg = '';
if(!$result){
$msg .= "发送失败,接口提示:".$sms->errors."\r\n";
$return['errorcode'] = 3;
}elseif(is_array($result) && $result['Code'] !='OK'){
$msg .= "发送失败,接口提示:".$result['Message']."\r\n";
$return['errorcode'] = 4;
}else{
$vcodeModel->save();
$msg .= "发送成功"."\r\n";
$return['errorcode'] = 0;
}
$return['msg'] = $msg;
exit(json_encode($return));
}
}
+251
View File
@@ -0,0 +1,251 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:08
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcStore;
class StoreController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
$model = new AcStore();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$post = Yii::$app->request->post();
$where['deleted'] = 0;
$data = $model->find()->where($where);
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2 = ['LIKE','title',$search['title']];
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('order_by DESC,id ASC')->all();
$status = Yii::$app->params['CommonStatus'];
return $this->render('list',[
'stores'=>$res,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status,
'search'=>$search
]);
}
public function actionSelect()
{
$model = new AcStore();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$post = Yii::$app->request->post();
$where['deleted'] = 0;
$where['status_code'] = 1;
$data = $model->find()->where($where);
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2 = ['LIKE','title',$search['title']];
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('order_by DESC,id ASC')->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
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
public function actionEdit()
{
$model = new AcStore();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
$citys = Yii::$app->params['citys'];
$res['city_title'] = isset($citys[$res['city']]['name']) ? $citys[$res['city']]['name'] : '';
return $this->render('modify',['detail'=>$res]);
}
public function actionSave()
{
$post = Yii::$app->request->post();
$data = [];
$data['pid'] = Yii::$app->session->get('pid');
$id = $post['id'];
//目标键=》POST键
$cols = ['title'=>'title','longt'=>'lng','lat'=>'lat','addr'=>'addr'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['city'=>'city','order_by'=>'order_by','deleted'=>'deleted'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$data['update_at'] = time();
$data['create_at'] = time();
$data['status_code'] = 1;
$model = new AcStore();
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();
}
}
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 AcStore();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('store/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 AcStore();
$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 '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,JSON_UNESCAPED_UNICODE));
}
}
+438
View File
@@ -0,0 +1,438 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:17
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcTruck;
use addons\models\AcDriver;
class TruckController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
//板车列表
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)->orderby('order_by DESC,id DESC')->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
]);
}
public function actionSelect()
{
$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)->orderby('order_by DESC,id DESC')->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();
}
$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
]);
}
public function actionNew()
{
$status = Yii::$app->params['TruckStatus'];
$AcTruck = new AcTruck();
$AcTruck->status_code = 0;
return $this->render('modify',['status'=>$status,'detail'=>$AcTruck]);
}
//编辑板车资料
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]);
}
//保存板车资料
public function actionSave()
{
$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]) : '';
}
//查询车牌号是否在库
$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;
}
}
$cols = ['driver_id'=>'driver','driver2_id'=>'driver2','max_cars'=>'max_cars','order_by'=>'order_by','deleted'=>'deleted'];
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]) : '';
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$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();
}
}
//删除板车
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));
}elseif($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));
}elseif($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();
}
$AcDriver = new AcDriver();
$driver = $AcDriver->find()->where(['id' => $res['driver_id']])->one();
if($driver){
$res['driver_title'] = $driver->name;
$res['driver_mobile'] = $driver->mobile;
}
$driver2 = $AcDriver->find()->where(['id' => $res['driver2_id']])->one();
if($driver2){
$res['driver2_title'] = $driver2->name;
$res['driver2_mobile'] = $driver2->mobile;
}
$status = Yii::$app->params['TruckStatus'];
return $this->render('detail',['status'=>$status,'detail'=>$res]);
}
}
+577
View File
@@ -0,0 +1,577 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:13
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
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 \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
//所有装车记录列表
public function actionList()
{
$pid = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
$AcTruckCars = new AcTruckCars();
$where = [];
$where[]='and';
$where[] = ['=','pid',Yii::$app->session->get('pid')];
$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']];
}
$search['aim_city'] = isset($search['aim_city']) ? trim(htmlspecialchars_decode($search['aim_city'])) : '';
if(!empty($search['aim_city'])){
$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'])){
$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['start_m'] = isset($search['start_m']) ? $search['start_m'] : '';
if(!empty($search['start_m'])){
$start = strtotime($search['start_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','from_time',$start,$end];
}
$where[] = ['=','deleted',0];
$data = $AcTruckCars->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('status_code ASC,id DESC')->all();
$car_ids = [];
foreach($res as $r){
$car_ids[] = $r->car_id;
}
$AcCar = new AcCar();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$car_ids];
$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
]);
}
public function actionNew()
{
$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]);
}
//编辑客车上板信息
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;
}
$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();
}
$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');
//格式化数据
//目标键=》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'];
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;
}elseif($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;
}elseif($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));
}
}
+937
View File
@@ -0,0 +1,937 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:21
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
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\AcEmployee;
use addons\models\AcGps;
use addons\models\AcGpsRoute;
class TruckolController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//出车单
public function actionIndex()
{
$AcTruckOnline = new AcTruckOnline();
$where = [];
$where[]='and';
$where[] = ['=','pid',Yii::$app->session->get('pid')];
$where[] = ['>','status_code',0];
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where[] = ['LIKE','num_left',$search['title']];
}
$where[] = ['=','deleted',0];
$data = $AcTruckOnline->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '10']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
$status = Yii::$app->params['TruckOnlineStatus'];
$stores = [];
$AcStore = new AcStore();
if($res){
$store_ids = [];
foreach($res as $r){
$store_ids[$r->from_store] = $r->from_store;
$store_ids[$r->end_store] = $r->end_store;
}
array_unique($store_ids);
$_stores = $AcStore->find()->where(['IN','id',$store_ids])->all();
if($_stores){
foreach($_stores as $r){
$stores[$r->id] = $r->toArray();
}
}
}
return $this->render('index',[
'list'=>$res,
'pager' => $pages,
'status'=>$status,
'stores'=>$stores,
'search'=>$search
]);
}
//在线板车列表(标记了发车状态——装车中的)
public function actionList()
{
$AcTruck = new AcTruck();
$where = [];
$where[]='and';
$where[] = ['=','pid',Yii::$app->session->get('pid')];
$where[] = ['=','status_code',4];
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where[] = ['LIKE','num_left',$search['title']];
}
$where[] = ['=','deleted',0];
$data = $AcTruck->find()->where($where);
$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
]);
}
//选择可装车的板车
public function actionSelect()
{
$AcTruck = new AcTruck();
$where = [];
$where[]='and';
$where[] = ['=','pid',Yii::$app->session->get('pid')];
$where[] = ['=','status_code',4];
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where[] = ['LIKE','num_left',$search['title']];
}
$where[] = ['=','deleted',0];
$data = $AcTruck->find()->where($where);
$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();
}
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol';
return $this->render('select',[
'trucks'=>$res,
'pager' => $pages,
'drivers'=>$drivers,
'status'=>$status,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionSelect2()
{
$AcTruckOnline = new AcTruckOnline();
$where = [];
$where[]='and';
$where[] = ['=','pid',Yii::$app->session->get('pid')];
$where[] = ['>','status_code',0];
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where[] = ['LIKE','num_left',$search['title']];
}
$where[] = ['=','deleted',0];
$data = $AcTruckOnline->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '10']);
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
$status = Yii::$app->params['TruckOnlineStatus'];
$stores = [];
$AcStore = new AcStore();
if($res){
$store_ids = [];
foreach($res as $r){
$store_ids[$r->from_store] = $r->from_store;
$store_ids[$r->end_store] = $r->end_store;
}
array_unique($store_ids);
$_stores = $AcStore->find()->where(['IN','id',$store_ids])->all();
if($_stores){
foreach($_stores as $r){
$stores[$r->id] = $r->toArray();
}
}
}
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol';
return $this->render('select2',[
'list'=>$res,
'pager' => $pages,
'status'=>$status,
'stores'=>$stores,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
$status = Yii::$app->params['TruckOnlineStatus'];
$AcTruckOnline = [];
$AcTruckOnline['status_code'] = 0;
return $this->render('edit',['status'=>$status,'detail'=>$AcTruckOnline]);
}
//编辑板车装车计划资料
public function actionEdit()
{
// $id = Yii::$app->request->get('id'); //装车任务ID
$id = 0;
$truck_id = Yii::$app->request->get('truck_id'); //板车ID
$store_id = $store2_id = 0;
$pid = Yii::$app->session->get('pid');
$AcTruckOnline = new AcTruckOnline();
$AcTruck = new AcTruck();
$truckol = [];
$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');
}
if(!$id){
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','truck_id',$truck_id];
$where[] = ['<','status_code',99];
$where[] = ['=','deleted',0];
$res = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one();
if($res){
$id = $res->id;
$store_id = $res->from_store;
$store2_id = $res->end_store;
$truckol = $res->toArray();
}
}
$truckol['truck_id'] = $truck_id;
$truckol['truck_title'] = $truck->num_p.$truck->num_area.$truck->num_left;
$truckol['truck_num'] = $truckol['truck_title']?$truckol['truck_title']:$truckol['truck_num'];
$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;
}
$AcDriver = new AcDriver();
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
$truckol['driver_title'] = $truckol['driver_mobile'] = '';
if($driver){
$truckol['driver_title'] = $driver->name;
$truckol['driver_mobile'] = $driver->mobile;
}
$truckol['driver_name'] = isset($truckol['driver_name'])?$truckol['driver_name']:$truckol['driver_title'];
$truckol['driver_mobiles'] = isset($truckol['driver_mobiles'])?$truckol['driver_mobiles']:$truckol['driver_mobile'];
$status = Yii::$app->params['TruckOnlineStatus'];
return $this->render('edit',['status'=>$status,'detail'=>$truckol]);
}
//更新板车装车任务资料
public function actionModify()
{
$id = Yii::$app->request->get('id'); //装车任务ID
// $truck_id = Yii::$app->request->get('truck_id'); //板车ID
$truck_id = 0;
$store_id = $store2_id = 0;
$pid = Yii::$app->session->get('pid');
$AcTruckOnline = new AcTruckOnline();
$AcTruck = new AcTruck();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if($res){
$truck_id = $res->truck_id;
$store_id = $res->from_store;
$store2_id = $res->end_store;
$truckol = $res->toArray();
}
$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');
}
$truckol['truck_id'] = $truck_id;
$truckol['truck_title'] = $truck->num_p.$truck->num_area.$truck->num_left;
$truckol['truck_num'] = $truckol['truck_title']?$truckol['truck_title']:$truckol['truck_num'];
$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;
}
$AcDriver = new AcDriver();
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
$truckol['driver_title'] = $truckol['driver_mobile'] = '';
if($driver){
$truckol['driver_title'] = $driver->name;
$truckol['driver_mobile'] = $driver->mobile;
}
$truckol['driver_name'] = isset($truckol['driver_name'])?$truckol['driver_name']:$truckol['driver_title'];
$truckol['driver_mobiles'] = isset($truckol['driver_mobiles'])?$truckol['driver_mobiles']:$truckol['driver_mobile'];
$status = Yii::$app->params['TruckOnlineStatus'];
return $this->render('modify',['status'=>$status,'detail'=>$truckol]);
}
//保存装车基础资料
public function actionSave()
{
$post = Yii::$app->request->post();
$id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
//格式化数据
//目标键=》POST键
$cols = ['driver_name'=>'driver_name','driver_mobiles'=>'driver_mobiles','driver_idcard'=>'driver_idcard','truck_num'=>'truck_num','end_city'=>'end_city','from_city'=>'from_city'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['truck_id'=>'truck_id','from_store'=>'from_store','end_store'=>'end_store'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$key = 'status_code';
if(isset($post[$key])){
$data[$key] = (int)$post[$key];
}
/*板车规则判断
*一辆板车只能有一条可用装车任务表单
**/
$truck_id = $data['truck_id'];
if(!$truck_id){
$return['msg'] = '未指定板车信息,保存失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
if(!$truck){
$return['msg'] = '未找到指定板车,保存失败';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$AcTruckOnline = new AcTruckOnline();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','truck_id',$truck_id];
$where[] = ['<','status_code',99];
$where[] = ['=','deleted',0];
$truckol = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one();
if($truckol){
if($id != $truckol->id){
$return['msg'] = '该板车已有未完成的托运任务,不允许重复指派';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$key = 'remark';
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
$_time = time();
$key = 'from_date';
$data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time;
$key = 'end_date';
if(isset($post[$key])){
$data[$key] = strtotime($post[$key]);
}
if(!$id){
$data['create_at'] = $_time;
}
$data['update_at'] = $_time;;
$data['pid'] = $pid;
//保存板车资料
$AcTruckOnline = new AcTruckOnline();
foreach($data as $key=>$val){
$AcTruckOnline->$key = $val;
}
if($id){
$res = $AcTruckOnline->updateAll($data,['id'=>$id]);
}else{
$res = $AcTruckOnline->save();
$id = $AcTruckOnline->attributes['id']; //获取插入后id
}
if($res){
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
return $this->redirect(['modify','id'=>$id]);
}else{
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
return $this->goBack();
}
}
//随车车辆管理
public function actionCars()
{
$pid = Yii::$app->session->get('pid');
$id = Yii::$app->request->get('id'); //装车任务ID
$AcTruckOnline = new AcTruckOnline();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if(!$res){
$post = Yii::$app->request->post();
$return = [];
$return['msg'] = '发车任务记录获取失败,请重新获取';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['truckol/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');
}
$truck_id = $res->truck_id;
$store_id = $res->from_store;
$store2_id = $res->end_store;
$truckol = $res->toArray();
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
$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;
}
$online_id = $id;
$AcTruckCars = new AcTruckCars();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','online_id',$online_id];
$where[] = ['=','deleted',0];
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
$carids = $orderids = [];
if($truckcars){
foreach($truckcars as $t){
$carids[] = $t->car_id;
$orderids[] = $t->order_id;
}
}
$AcCar = new AcCar();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$carids];
$where[] = ['=','deleted',0];
$cars = $AcCar->find()->where($where)->indexby('id')->all();
$status = Yii::$app->params['TruckCarsStatus'];
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
return $this->render('cars',[
'status'=>$status,
'truckOnLineStatus'=>$truckOnLineStatus,
'truckol'=>$truckol,
'cars'=>$cars,
'truckcars'=>$truckcars
]);
}
//保存装车随车资料
public function actionCarssave()
{
$post = Yii::$app->request->post();
$online_id = (int)$post['id'];
$pid = Yii::$app->session->get('pid');
//格式化数据
//目标键=》POST键
$cols = ['car_id','order_id'];
foreach($cols as $key){
if(!isset($post[$key])){
$return['msg'] = '未传入的运单或车辆信息,保存失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
$car_ids = $post['car_id'];
if(!is_array($car_ids)){
$return['msg'] = '传入的车辆数据不正确,保存失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$order_ids = $post['order_id'];
if(!is_array($order_ids)){
$return['msg'] = '传入的运单数据不正确,保存失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if(count($car_ids) != count($order_ids)){
$return['msg'] = '传入的车辆数据与运单数据不匹配,保存失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*筛除已在运输中的运单及车辆数据 TBD*/
$AcTruckCars = new AcTruckCars();
$cars = [];
$_time = time();
foreach($car_ids as $k=>$car_id){
$car = [];
$car['pid'] = $pid;
$car['online_id'] = $online_id;
$car['car_id'] = $car_id;
$car['order_id'] = $order_ids[$k];
$car['create_at'] = $_time;
$car['update_at'] = $_time;
$cars[] = $car;
$model = clone $AcTruckCars;
foreach($car as $key=>$val){
$model->$key = $val;
}
$model->save();
}
$return['msg'] = '操作完成,请刷新页面并检查数据';
$return['errorcode'] = 200;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//板车出发
public function actionChufa()
{
$id = Yii::$app->request->get('id'); //装车任务ID
$return = [];
$AcTruckOnline = new AcTruckOnline();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if(!$res){
$post = Yii::$app->request->post();
$return['msg'] = '发车任务记录获取失败,请重新获取';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($res->status_code!=0){
$return['msg'] = '关联出车任务非“待出发”状态,操作失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$truck_id = $res->truck_id;
$truckol = $res->toArray();
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
if(!$truck){
$return['msg'] = '关联板车数据获取异常,操作失败';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*更新数据*/
$_time = time();
$data = [];
$data['update_at'] = $_time;
$data['status_code'] = 1;
$res = $AcTruckOnline->updateAll($data,['id'=>$id]);
$data = [];
$data['update_at'] = $_time;
$data['status_code'] = 5;
$AcTruck->updateAll($data,['id'=>$truck_id]);
if($res){
$return['msg'] = '出车任务出发标记操作成功';
$return['errorcode'] = 200;
}else{
$return['msg'] = '出发标记操作失败';
$return['errorcode'] = 100;
}
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//板车到达
public function actionArrive()
{
$id = Yii::$app->request->get('id'); //装车任务ID
$return = [];
$AcTruckOnline = new AcTruckOnline();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if(!$res){
$post = Yii::$app->request->post();
$return['msg'] = '发车任务记录获取失败,请重新获取';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
if($res->status_code!=1){
$return['msg'] = '关联出车任务非“进行中”(在途)状态,操作失败';
$return['errorcode'] = 400;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
$truck_id = $res->truck_id;
$truckol = $res->toArray();
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
if(!$truck){
$return['msg'] = '关联板车数据获取异常,操作失败';
$return['errorcode'] = 404;
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
/*更新数据*/
$_time = time();
$data = [];
$data['update_at'] = $_time;
$data['status_code'] = 99;
$res = $AcTruckOnline->updateAll($data,['id'=>$id]);
$data = [];
$data['update_at'] = $_time;
$data['status_code'] = 0;
$AcTruck->updateAll($data,['id'=>$truck_id]);
if($res){
$return['msg'] = '出车任务运达标记操作成功';
$return['errorcode'] = 200;
}else{
$return['msg'] = '运达标记操作失败';
$return['errorcode'] = 100;
}
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
}
//删除板车装车任务
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();
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('truckol/index');
$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 actionPrint()
{
$pid = Yii::$app->session->get('pid');
$id = Yii::$app->request->get('id'); //装车任务ID
$AcTruckOnline = new AcTruckOnline();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if(!$res){
$post = Yii::$app->request->post();
$return = [];
$return['msg'] = '发车任务记录获取失败,请重新获取';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['truckol/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');
}
$truck_id = $res->truck_id;
$store_id = $res->from_store;
$store2_id = $res->end_store;
$truckol = $res->toArray();
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
$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;
}
$online_id = $id;
$AcTruckCars = new AcTruckCars();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','online_id',$online_id];
$where[] = ['=','deleted',0];
$where[] = ['>','status_code',0];
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
$carids = $orderids = [];
if($truckcars){
foreach($truckcars as $t){
$carids[] = $t->car_id;
$orderids[] = $t->order_id;
}
}
$counts = [];
$AcCar = new AcCar();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$carids];
$where[] = ['=','deleted',0];
$cars = $AcCar->find()->where($where)->indexby('id')->all();
$AcOrder = new AcOrder();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$orderids];
$where[] = ['=','deleted',0];
$orders = $AcOrder->find()->where($where)->indexby('id')->all();
$employee_ids = [];
$count['fee_total'] = $count['pay_receive'] = 0;
foreach($orders as $v){
$employee_ids[] = $v->employee_id;
$count['fee_total'] += $v->fee_total;
$count['pay_receive'] += $v->pay_receive;
}
$AcEmployee = new AcEmployee();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$employee_ids];
$where[] = ['=','deleted',0];
$employees = $AcEmployee->find()->where($where)->indexby('id')->all();
$count['cars'] = count($truckcars);
$status = Yii::$app->params['TruckCarsStatus'];
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
return $this->render('print',[
'status'=>$status,
'truckOnLineStatus'=>$truckOnLineStatus,
'truckol'=>$truckol,
'cars'=>$cars,
'orders'=>$orders,
'employees'=>$employees,
'truckcars'=>$truckcars,
'count'=>$count
]);
}
//浏览详情
public function actionDetail()
{
$pid = Yii::$app->session->get('pid');
$id = Yii::$app->request->get('id'); //装车任务ID
$AcTruckOnline = new AcTruckOnline();
$truckol = [];
$res = $AcTruckOnline->findOne($id);
if(!$res){
$post = Yii::$app->request->post();
$return = [];
$return['msg'] = '发车任务记录获取失败,请重新获取';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['truckol/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');
}
$truck_id = $res->truck_id;
$store_id = $res->from_store;
$store2_id = $res->end_store;
$truckol = $res->toArray();
$AcTruck = new AcTruck();
$truck = $AcTruck->findOne($truck_id);
$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;
}
$online_id = $id;
$AcTruckCars = new AcTruckCars();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['=','online_id',$online_id];
$where[] = ['=','deleted',0];
$where[] = ['>','status_code',1];
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
$carids = $orderids = [];
if($truckcars){
foreach($truckcars as $t){
$carids[] = $t->car_id;
$orderids[] = $t->order_id;
}
}
$counts = [];
$AcCar = new AcCar();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$carids];
$where[] = ['=','deleted',0];
$cars = $AcCar->find()->where($where)->indexby('id')->all();
$AcOrder = new AcOrder();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$orderids];
$where[] = ['=','deleted',0];
$orders = $AcOrder->find()->where($where)->indexby('id')->all();
$employee_ids = [];
$count['fee_total'] = $count['pay_receive'] = 0;
foreach($orders as $v){
$employee_ids[] = $v->employee_id;
$count['fee_total'] += $v->fee_total;
$count['pay_receive'] += $v->pay_receive;
}
$AcEmployee = new AcEmployee();
$where = [];
$where[] = 'and';
$where[] = ['=','pid',$pid];
$where[] = ['IN','id',$employee_ids];
$where[] = ['=','deleted',0];
$employees = $AcEmployee->find()->where($where)->indexby('id')->all();
$count['cars'] = count($truckcars);
$status = Yii::$app->params['TruckCarsStatus'];
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
return $this->render('detail',[
'status'=>$status,
'truckOnLineStatus'=>$truckOnLineStatus,
'truckol'=>$truckol,
'cars'=>$cars,
'orders'=>$orders,
'employees'=>$employees,
'truckcars'=>$truckcars,
'count'=>$count
]);
}
}
+381
View File
@@ -0,0 +1,381 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:42:25
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
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 \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
$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');
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
//所有板车位置记录列表
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
]);
}
public function actionNew()
{
$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'); //发车任务
$AcTruckRoute['truck_id'] = $truckol['truck_id'];
$AcTruckRoute['truck_num'] = $truckol['truck_num'];
return $this->render('modify',['status'=>$status,'detail'=>$AcTruckRoute,'online_id'=>$online_id,'truckol'=>$truckol]);
}
//编辑板车位置信息
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'); //发车任务
$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'];
$status = Yii::$app->params['CommonStatus'];
return $this->render('modify',['status'=>$status,'detail'=>$route,'online_id'=>$online_id,'truckol'=>$truckol]);
}
//保存位置记录信息
public function actionSave()
{
$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'); //发车任务
$data = [];
$data['truck_id'] = $truckol['truck_id'];
$data['online_id'] = $online_id;
//格式化数据
//目标键=》POST键
$cols = ['longt'=>'lng','lat'=>'lat','addr'=>'addr'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['orderby'=>'orderby','status_code'=>'status_code'];
foreach($cols as $col=>$key){
$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));
}
}
+252
View File
@@ -0,0 +1,252 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-04-26 22:56:16
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\CAttachment;
use common\components\Attachment;
class UploadController extends \yii\web\Controller
{
public $enableCsrfValidation = false; //取消csrf令牌验证;不取消的话文件上传会失败
public function checkPid()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
return $pid;
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionImage()
{
global $_HI,$_FM;
$this->checkPid();
$siteId = Yii::$app->params['siteId'];
$session = Yii::$app->session;
$pid = (int)$session->get('pid');
$model = new CAttachment();
$search = $where = [];
$where[] = 'and';
$where[] = ['=','status_code',1];
$where[] = ['=','type',0];
$where[] = ['=','siteid',$siteId];
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
if(isset($post['search'])){
$search = $post['search'];
$session->set('images::search',$search);
}elseif($session->get('images::search')){
$search = $session->get('images::search');
}
if($search){
if($search['create_m']){
$start = strtotime($search['create_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','create_at',$start,$end];
}elseif(!empty($search['create_after']) && !empty($search['create_before'])){
$start = strtotime($search['create_after']);
$end = strtotime($search['create_before']);
$where[] = ['between','create_at',$start,$end];
}elseif(!empty($search['create_after'])){
$start = strtotime($search['create_after']);
$where[] = ['>=','create_at',$start];
}elseif(!empty($search['create_before'])){
$end = strtotime($search['create_before']);
$where[] = ['<=','create_at',$end];
}
if($search['title']){
$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'];
}
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'thumb';
return $this->render('image',[
'list'=>$list,
'pager' => $pager,
'src'=>$src,
'callback'=>$callback
]);
}
public function actionImages()
{
global $_HI,$_FM;
$this->checkPid();
$siteId = Yii::$app->params['siteId'];
$session = Yii::$app->session;
$pid = (int)$session->get('pid');
$model = new CAttachment();
$search = $where = [];
$where[] = 'and';
$where[] = ['=','status_code',1];
$where[] = ['=','type',0];
$where[] = ['=','siteid',$siteId];
$where[] = ['=','pid',$pid];
$post = Yii::$app->request->post();
if(isset($post['search'])){
$search = $post['search'];
$session->set('images::search',$search);
}elseif($session->get('images::search')){
$search = $session->get('images::search');
}
if($search){
if($search['create_m']){
$start = strtotime($search['create_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','create_at',$start,$end];
}elseif(!empty($search['create_after']) && !empty($search['create_before'])){
$start = strtotime($search['create_after']);
$end = strtotime($search['create_before']);
$where[] = ['between','create_at',$start,$end];
}elseif(!empty($search['create_after'])){
$start = strtotime($search['create_after']);
$where[] = ['>=','create_at',$start];
}elseif(!empty($search['create_before'])){
$end = strtotime($search['create_before']);
$where[] = ['<=','create_at',$end];
}
if($search['title']){
$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'];
}
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'thumb';
return $this->render('images',[
'list'=>$list,
'search'=>$search,
'pager' => $pager,
'src'=>$src,
'callback'=>$callback
]);
}
public function actionImage_save()
{
global $_HI,$_FM;
$post = Yii::$app->request->post();
if(!$post['root']){
die(json_encode('没有传入文件路径'));
}
// 文件附件目录
$attachDir = Yii::getAlias('@upload'); //附件所在目录
$targetDir = "/pics"; //开始构建目标转存目录
if (!file_exists($attachDir . $targetDir)) {
@mkdir($attachDir . $targetDir);
}
$session = Yii::$app->session;
$siteId = Yii::$app->params['siteId'];
$targetDir .= '/'.$siteId;
if (!file_exists($attachDir . $targetDir)) {
@mkdir($attachDir . $targetDir);
}
$pid = (int)$session->get('pid');
$targetDir .= '/'.$pid;
if (!file_exists($attachDir . $targetDir)) {
@mkdir($attachDir . $targetDir);
}
$timeDir = date('Ym');
$targetDir .= "/".$timeDir;
if (!file_exists($attachDir . $targetDir)) {
@mkdir($attachDir . $targetDir);
}
//处理请求的文件信息
$title = isset($post['name']) ? $post['name'] : md5(TIMESTAMP).'.jpg';
//取后缀名
if($post['ext']){
$suffix = strtolower($post['ext']);
}else{
$_names = explode('.',$title);
$suffix = tolower($_names[count($_names)-1]);
}
$newName = date('dHis',TIMESTAMP).'_'.md5($title);
$root = $post['root'];
$newFile = $attachDir . $targetDir."/".$newName.".".$suffix;
$tempfile = $post['root'];
//文件移动,【完整文件名-含路径,目标目录】
rename($tempfile,$newFile);
$options = json_encode($post['params']);
//文件入库
$model = new CAttachment();
$model->siteid = $siteId;
$model->pid = $pid;
$model->uid = $_FM['user']['uid'];
$model->mid = 0;
$model->type = 0;
$model->status_code = 1;
$model->title = $title;
$model->filesize = $post['size'];
$model->route = $targetDir."/".$newName.".".$suffix;
$model->options = $options;
$model->update_at = $model->create_at = time();
$model->save();
$id = $model->attributes['id']; //获取插入后id
$return=[];
$return['msg'] = '';
$return['code'] = 0;
$return['path'] = $model->route;
if(!$id){
$return['code'] = 453100;
$return['msg'] = $model->getErrors();
}
$return['data'] = ['id'=>$id];
die(json_encode($return,JSON_UNESCAPED_UNICODE));
}
}
+307
View File
@@ -0,0 +1,307 @@
<?php
/**
* @Author: fm453
* @Date: 2018-06-04 11:06:07
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 08:07:18
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use addons\models\AcWeituoren;
use common\models\Fans;
class WeituorenController extends \yii\web\Controller
{
//替代常规的_construct 析构函数;其他方法调用前执行
public function init()
{
parent::init();
$session = Yii::$app->session;
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$session->set('pid',(int)$_GET['pid']);
}
$pid = $session->get('pid');
if(!$pid){
return Yii::$app->response->redirect(['index/index']);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
//列表
public function actionList()
{
$model = new AcWeituoren();
$pid = Yii::$app->session->get('pid');
$session = Yii::$app->session;
$where = $where2 = [];
$where2[]='and';
$where['pid'] = $pid;
$post = Yii::$app->request->post();
$search = [];
$searchSession = 'weituoren::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[] = ['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' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = Yii::$app->params['CommonStatus'];
return $this->render('list',[
'weituorens'=>$res,
'pager' => $pages,
'status'=>$status,
'search'=>$search
]);
}
public function actionSelect()
{
$model = new AcWeituoren();
$pid = Yii::$app->session->get('pid');
$session = Yii::$app->session;
$where = $where2 = [];
$where2[]='and';
$where['pid'] = $pid;
$post = Yii::$app->request->post();
$search = [];
$searchSession = 'weituoren::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[] = ['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' => '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') : 'weituoren';
return $this->render('select',[
'weituorens'=>$res,
'pager' => $pages,
'status'=>$status,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑资料
public function actionEdit()
{
$model = new AcWeituoren();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
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'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
//查询手机号是否在库
$hasWeituoren = AcWeituoren::find()->where(['mobile'=>$data['mobile']])->one();
if($hasWeituoren){
if($id && $id==$hasWeituoren->id){
}else{
$id = $hasWeituoren->id;
\Yii::$app->getSession()->setFlash('danger', '保存失败,该手机号对应的委托单位已在库,系统自动现在为您调出其资料!');
return $this->redirect(['edit','id'=>$id]);
}
}
//查询对应的系统用户
$userModel = new Fans();
$user = $userModel->findByUsername($data['mobile']);
if(empty($user)){
$pwd = Yii::$app->params['defaultFansPassword'];
$userModel->mobile = $data['mobile'];
$userModel->email = $data['mobile'].'@hiluker.com';
$userModel->setPassword($pwd);
$userModel->generateAuthKey();
$userModel->created_at = time();
$userModel->from = 'ctms';
$userModel->save();
}
$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;
//保存通讯录资料
$AcWeituoren = new AcWeituoren();
foreach($data as $key=>$val){
$AcWeituoren->$key = $val;
}
if($id){
$AcWeituoren->id = $id;
unset($data['create_at']);
$res = $AcWeituoren->updateAll($data,['id'=>$id]);
}else{
$res = $AcWeituoren->save();
$id = $AcWeituoren->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'];
$data = $where = [];
$where['pid'] = Yii::$app->session->get('pid');
$where['id'] = $id;
$data['update_at'] = time();
$data['deleted'] = 1;
$model = new AcWeituoren();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('weituoren/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 AcWeituoren();
$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));
}
}