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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+63
View File
@@ -0,0 +1,63 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-04-28 17:21:02
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class AssetController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
return $this->render('../layouts/dev',[]);
}
public function actionRoom()
{
return $this->render('../layouts/dev',[]);
}
public function actionIncidental()
{
return $this->render('../layouts/dev',[]);
}
public function actionSale()
{
return $this->render('../layouts/dev',[]);
}
public function actionOther()
{
return $this->render('../layouts/dev',[]);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2019-01-12 12:13:35
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class AttachController extends \yii\web\Controller
{
public $enableCsrfValidation = false; //取消csrf令牌验证;
//主界面
public function actionIndex()
{
$request = Yii::$app->request;
$get = $request->get();
$img = Urldecode($get['img']);
$file = Yii::getAlias("@upload").$img;
$img = file_get_contents($file);
$this->showImg($file);
}
/*
* php 页面直接输出图片
*/
function showImg($img){
$info = getimagesize($img);
$imgExt = image_type_to_extension($info[2], false); //获取文件后缀
$fun = "imagecreatefrom{$imgExt}";
$imgInfo = $fun($img); //1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename )
$mime = $info['mime'];
header('Content-Type:'.$mime);
$quality = 100;
if($imgExt == 'png') $quality = 9; //输出质量,JPEG格式(0-100),PNG格式(0-9)
$getImgInfo = "image{$imgExt}";
$getImgInfo($imgInfo, null, $quality); //2.将图像输出到浏览器或文件。如: imagepng ( resource $image )
//TBD: PNG图片会显示其被修改前的原始文件,与直接用SRC引用的方法有所不同
imagedestroy($imgInfo);
}
/*图片转换为 base64格式编码*/
function base64EncodeImage ($image_file) {
$base64_image = '';
$image_info = getimagesize($image_file);
$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
return $base64_image;
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-04-28 17:20:59
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
// use backend\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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionSelect()
{
$citys = Yii::$app->params['citys'];
$pager = new Pagination(['totalCount' =>count($citys), 'pageSize' => '20']);
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'city';
$search=[];
return $this->render('select',[
'citys'=>$citys,
'pager' => $pager,
'search'=>$search,
'callback'=>$callback
]);
}
}
+712
View File
@@ -0,0 +1,712 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 03:40:46
# @Last modified by: fm453
# @Last modified time: 2021-09-15T15:22:35+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\Fans;
use backend\models\FmContract as Contract;
use backend\models\FmRoomOwner as RoomOver;
use backend\models\FmUserExt as UserExt;
class ContractController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
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');
$model = new AcCustomer();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = $pid;
$post = Yii::$app->request->post();
$search = isset($post['search']) ? $post['search'] : [];
$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$session = Yii::$app->session;
if($page==0){
$session->set('Guest:List:'.$pid,$search);
}else{
$search = $search ? $search : $session->get('Guest:List:'.$pid);
}
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$selectMid = false;
$mids = [];
$search['nickname'] = isset($search['nickname']) ? trim(htmlspecialchars_decode($search['nickname'])) : '';
if(!empty($search['nickname'])){
$_mids = [];
$_exts = LvUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'nickname'])->andwhere(['OR',['LIKE','value',$search['nickname']]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
$search['phone'] = isset($search['phone']) ? trim(htmlspecialchars_decode($search['phone'])) : '';
if(!empty($search['phone'])){
$where2[] = ['LIKE','mobile',$search['phone']];
}
$search['hotel'] = isset($search['hotel']) ? (int)$search['hotel'] : 0;
if(!empty($search['hotel'])){
$where2[] = ['=','hotel_id',$search['hotel']];
$hotel = AcHotel::find()->where(['id'=>$search['hotel']])->one();
$search['hotel_title'] = $hotel['title'];
}
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : 0;
if(!empty($search['employee'])){
$where2[] = ['=','employee_id',$search['employee']];
$employee = AcEmployee::find()->where(['id'=>$search['employee']])->one();
$search['employee_title'] = $employee['name'];
}
$search['channel'] = isset($search['channel']) ? (int)$search['channel'] : 0;
$channels= Yii::$app->params['saleChannels'];
if(!empty($search['channel'])){
$where2[] = ['=','channel',$search['channel']];
}
//入住时间筛选
$search['checkin_m'] = isset($search['checkin_m']) ? $search['checkin_m'] : '';
$search['checkin_after'] = isset($search['checkin_after']) ? $search['checkin_after'] : '';
$search['checkin_before'] = isset($search['checkin_before']) ? $search['checkin_before'] : '';
//按月份筛选
if(!empty($search['checkin_m'])){
$start = strtotime($search['checkin_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);
$where2[] = ['between','last_checkin',$start,$end];
}
//按指定时段筛选
elseif(!empty($search['checkin_after']) && !empty($search['checkin_before'])){
$start = strtotime($search['checkin_after']);
$end = strtotime($search['checkin_before']);
$where2[] = ['between','last_checkin',$start,$end];
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif(!empty($search['checkin_after'])){
$start = strtotime($search['checkin_after']);
$where2[] = ['>=','last_checkin',$start];
}elseif(!empty($search['checkin_before'])){
$end = strtotime($search['checkin_before']);
$where2[] = ['<=','last_checkin',$end];
}
//生日筛选
$mids2 = [];
$search['birthday_m'] = isset($search['birthday_m']) ? $search['birthday_m'] : '';
$search['birthday_after'] = isset($search['birthday_after']) ? $search['birthday_after'] : '';
$search['birthday_before'] = isset($search['birthday_before']) ? $search['birthday_before'] : '';
//按月份筛选
if(!empty($search['birthday_m'])){
$start = strtotime($search['birthday_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);
$_mids = [];
$_exts = LvUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['between','value',$start,$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
//按指定时段筛选
elseif(!empty($search['birthday_after']) && !empty($search['birthday_before'])){
$start = strtotime($search['birthday_after']);
$end = strtotime($search['birthday_before']);
$_mids = [];
$_exts = LvUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['between','value',$start,$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif(!empty($search['birthday_after'])){
$start = strtotime($search['birthday_after']);
$_mids = [];
$_exts = LvUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['>=','value',$start]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}elseif(!empty($search['birthday_before'])){
$end = strtotime($search['birthday_before']);
$_mids = [];
$_exts = LvUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['<=','value',$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
if($selectMid){
$mids2 = $mids[0];
foreach($mids as $_mids){
if($_mids){
foreach($_mids as $mid){
if(!in_array($mid,$mids2)){
unset($_mids[$mid]);
};
$mids2 = $_mids;
}
}
}
$where2[] = ['IN','mid',$mids2];
}
$where['deleted'] = 0;
$data = $model->find()->where($where)->andwhere(['AND',$where2]);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->orderBy('id DESC')->offset($pages->offset)->limit($pages->limit)->indexBy('mid')->all();
$status = ['0'=>'隐藏','1'=>'显示'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new AcHotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
$eids = $mids = [];
foreach($res as $r){
$r = $r->toArray();
$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 LvUserExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
$guests = [];
foreach($res as $s){
$s = $s->toArray();
foreach($exts[$s['mid']] as $col=>$val){
$s[$col] = $val;
}
$guests[] = $s;
}
$model = new User();
$users = [];
$_users = $model->find()->where(['IN','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
return $this->render('list',[
'guests' => $guests,
'pager' => $pages,
'employees'=>$employees,
'hotels'=>$hotels,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'total'=>$data->count(),
]);
}
//客户列表选择
public function actionSelect()
{
return $this->render('../layouts/dev',[]);
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$model = new AcCustomer();
$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 = ['0'=>'隐藏','1'=>'显示'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new AcHotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$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 LvUserExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
$guests = [];
foreach($res as $s){
$s = $s->toArray();
foreach($exts[$s['mid']] as $col=>$val){
$s[$col] = $val;
}
$guests[$s['id']] = $s;
}
$model = new User();
$users = [];
$_users = $model->find()->where(['in','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'carowner';
return $this->render('select',[
'guests' => $guests,
'pager' => $pages,
'employees'=>$employees,
'hotels'=>$hotels,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'callback'=>$callback
]);
}
//新增车主
public function actionNew()
{
global $_HI,$_FM;
return $this->render('modify',[]);
}
//更新车主
public function actionEdit()
{
global $_HI,$_FM;
$model = new AcCustomer();
$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_checkin'] = $res['last_checkin'] ? date('Y-m-d',$res['last_checkin']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
$res['realname'] = $res['name'];
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new User();
$user = User::find()->where(['id'=>$res['mid']])->one();
if($user){
$res['mobile'] = $user->mobile;
}
$hotel = AcHotel::find()->where(['id' => $res['hotel_id']])->one();
if($hotel){
$res['hotel_title'] = $hotel->title;
}
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
if($employee){
$res['employee_title'] = $employee->name;
}
$exts = LvUserExt::find()->where(['mid' => $res['mid'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
return $this->render('modify',[
'detail'=>$res,
'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(['guest/edit','id'=>$id]);
return $this->redirect(['new','id'=>$id]);
}
$mobile = $post['mobile'];
//查询对应的系统用户
$userModel = new User();
$user = User::find()->where(['mobile'=>$mobile])->one();
if(!$user){
$pwd = isset($post['password']) ? trim($post['password']) : Yii::$app->params['defaultUserPassword'];
$userModel->mobile = $mobile;
$userModel->username = $mobile;
$userModel->email = $mobile.'@hiluker.com';
$userModel->setPassword($pwd);
$userModel->generateAuthKey();
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
$userModel->created_at = time();
$userModel->status = 1;
$res = $userModel->save();
// $res = $userModel->getErrors();
$user_id = $userModel->attributes['id']; //获取插入后id
}else{
$user_id = $user->id;
$pwd = isset($post['password']) ? trim($post['password']) : '';
if($pwd){
$user->setPassword($pwd);
$user->generateAuthKey();
$user->updated_at = time();
$res = $user->save();
}
}
//格式化数据
$data = [];
//目标键=》POST键
$cols = ['name'=>'realname','mobile'=>'mobile','idcard'=>'idcard','passport'=>'passport','country'=>'country','province'=>'province','channel'=>'channel','thumb'=>'thumb'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['gender'=>'gender','total_fee'=>'total_fee','money'=>'money','jifen'=>'jifen','score'=>'score','hotel_id'=>'hotel','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_checkin'=>'last_checkin','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]) : '';
}
$birthday = isset($post['ext']['birthday']) ? strtotime($post['ext']['birthday']) : 0;
if($birthday){
$data['birth_y'] = date('Y',$birthday);
$data['birth_m'] = date('m',$birthday);
$data['birth_d'] = date('d',$birthday);
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$data['mid'] = $user_id;
//格式化车主资料
$AcCustomer = new AcCustomer();
foreach($data as $key=>$val){
$AcCustomer->$key = $val;
}
//查询该客户是否在库
$customer = AcCustomer::find()->where(['pid'=>$data['pid'],'mid'=>$data['mid']])->one();
if($customer){
$id = $customer->id;
}
//客户资料入库
if($id){
$AcCustomer->id = $id;
unset($data['create_at']);
$res = $AcCustomer->updateAll($data,['id'=>$id]);
}else{
$res = $AcCustomer->save();
$id = $AcCustomer->attributes['id']; //获取插入后id
}
//保存扩展资料
$LvUserExt = new LvUserExt();
//批量软删
$LvUserExt->updateAll(['deleted'=>1],['deleted'=>0,'pid'=>$pid,'mid'=>$user_id]);
$datas = [];
$data = [];
$exts = $post['ext'];
foreach($exts as $col=>$val){
$data['pid'] = $pid;
$data['mid'] = $user_id;
$data['key'] = $col;
$data['mobile'] = $mobile;
$data['value'] = trim($val);
$datas[] = $data;
}
//批量插入
$model = clone $LvUserExt;
foreach($datas as $attributes)
{
$model->isNewRecord = true;
$model->setAttributes($attributes,false);
$model->save() && $model->id=0;
}
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 AcCustomer();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('guest/list');
// $return['url'] = Url::previous();
$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 actionMsg()
{
global $_HI,$_FM;
$model = new AcCustomer();
$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_checkin'] = $res['last_checkin'] ? date('Y-m-d',$res['last_checkin']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
$res['realname'] = $res['name'];
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new User();
$user = User::find()->where(['id'=>$res['mid']])->one();
if($user){
$res['mobile'] = $user->mobile;
}
return $this->render('../layouts/dev',[]);
$hotel = AcHotel::find()->where(['id' => $res['hotel_id']])->one();
if($hotel){
$res['hotel_title'] = $hotel->title;
}
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
if($employee){
$res['employee_title'] = $employee->name;
}
$exts = LvUserExt::find()->where(['mid' => $res['mid'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
return $this->render('modify',[
'detail'=>$res,
'id'=>$id,
]);
}
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 AcCustomer();
$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));
}
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;
case 'contact':
$data['last_contact'] = time();
$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:
$return['msg'] = '无效的操作';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'info'];
break;
}
exit(json_encode($return));
}
}
+334
View File
@@ -0,0 +1,334 @@
<?php
/**
* @Author: fm453
* @Date: 2018-12-02 11:40:44
# @Last modified by: fm453
# @Last modified time: 2021-09-15T15:53:42+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\Member;
use backend\models\FmUserExt as UserExt;
use backend\models\FmEmployee as Employee;
use backend\models\FmHotel as Hotel;
use backend\models\FmStore as Store;
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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
public function actionIndex()
{
return $this->render('index');
}
//用户列表
public function actionList()
{
$model = new Employee();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$where['deleted'] = 0;
$data = $model->find()->where($where);
if($search['title']){
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'离职','1'=>'在职'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
return $this->render('list',[
'employees'=>$res,
'pager' => $pages,
'hotels'=>$hotels,
'status'=>$status,
'gender'=>$gender,
'search'=>$search
]);
}
public function actionSelect()
{
$model = new Employee();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$where['deleted'] = 0;
$data = $model->find()->where($where);
if($search['title']){
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'离职','1'=>'在职'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new AcHotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'employee';
return $this->render('select',[
'employees'=>$res,
'pager' => $pages,
'hotels'=>$hotels,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑员工资料
public function actionEdit()
{
$model = new Employee();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
}
$store = Store::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','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 Employee();
foreach($data as $key=>$val){
$AcEmployee->$key = $val;
}
//查询员工手机号是否在库
$employee = Employee::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', '已成功注册该账号!');
}
}
$return = [];
if($res){
$return['msg'] = '员工信息保存成功';
$return['errorcode'] = 200;
$return['url'] = Url::toRoute(['employee/edit','id'=>$id]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'primary','url'=>$return['url']]
];
}else{
$return['msg'] = '员工信息保存失败';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['employee/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()
{
$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 Employee();
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));
}
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 Employee();
$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));
}
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));
}
}
+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']]);
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-04-28 17:28:29
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionOrder()
{
return $this->render('../layouts/dev',[]);
}
public function actionRoom()
{
return $this->render('../layouts/dev',[]);
}
public function actionIncidental()
{
return $this->render('../layouts/dev',[]);
}
public function actionSale()
{
return $this->render('../layouts/dev',[]);
}
public function actionOther()
{
return $this->render('../layouts/dev',[]);
}
}
+711
View File
@@ -0,0 +1,711 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 03:40:46
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:37:16+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\Fans;
use backend\models\FmCustomer as Customer;
use backend\models\FmUserExt as UserExt;
use backend\models\FmHotel as Hotel;
use backend\models\FmRoom as Room;
use backend\models\FmEmployee as Employee;
class GuestController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
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 Customer();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = $pid;
$post = Yii::$app->request->post();
$search = isset($post['search']) ? $post['search'] : [];
$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$session = Yii::$app->session;
if($page==0){
$session->set('Guest:List:'.$pid,$search);
}else{
$search = $search ? $search : $session->get('Guest:List:'.$pid);
}
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$selectMid = false;
$mids = [];
$search['nickname'] = isset($search['nickname']) ? trim(htmlspecialchars_decode($search['nickname'])) : '';
if(!empty($search['nickname'])){
$_mids = [];
$_exts = UserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'nickname'])->andwhere(['OR',['LIKE','value',$search['nickname']]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
$search['phone'] = isset($search['phone']) ? trim(htmlspecialchars_decode($search['phone'])) : '';
if(!empty($search['phone'])){
$where2[] = ['LIKE','mobile',$search['phone']];
}
$search['hotel'] = isset($search['hotel']) ? (int)$search['hotel'] : 0;
if(!empty($search['hotel'])){
$where2[] = ['=','hotel_id',$search['hotel']];
$hotel = AcHotel::find()->where(['id'=>$search['hotel']])->one();
$search['hotel_title'] = $hotel['title'];
}
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : 0;
if(!empty($search['employee'])){
$where2[] = ['=','employee_id',$search['employee']];
$employee = Employee::find()->where(['id'=>$search['employee']])->one();
$search['employee_title'] = $employee['name'];
}
$search['channel'] = isset($search['channel']) ? (int)$search['channel'] : 0;
$channels= Yii::$app->params['saleChannels'];
if(!empty($search['channel'])){
$where2[] = ['=','channel',$search['channel']];
}
//入住时间筛选
$search['checkin_m'] = isset($search['checkin_m']) ? $search['checkin_m'] : '';
$search['checkin_after'] = isset($search['checkin_after']) ? $search['checkin_after'] : '';
$search['checkin_before'] = isset($search['checkin_before']) ? $search['checkin_before'] : '';
//按月份筛选
if(!empty($search['checkin_m'])){
$start = strtotime($search['checkin_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);
$where2[] = ['between','last_checkin',$start,$end];
}
//按指定时段筛选
elseif(!empty($search['checkin_after']) && !empty($search['checkin_before'])){
$start = strtotime($search['checkin_after']);
$end = strtotime($search['checkin_before']);
$where2[] = ['between','last_checkin',$start,$end];
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif(!empty($search['checkin_after'])){
$start = strtotime($search['checkin_after']);
$where2[] = ['>=','last_checkin',$start];
}elseif(!empty($search['checkin_before'])){
$end = strtotime($search['checkin_before']);
$where2[] = ['<=','last_checkin',$end];
}
//生日筛选
$mids2 = [];
$search['birthday_m'] = isset($search['birthday_m']) ? $search['birthday_m'] : '';
$search['birthday_after'] = isset($search['birthday_after']) ? $search['birthday_after'] : '';
$search['birthday_before'] = isset($search['birthday_before']) ? $search['birthday_before'] : '';
//按月份筛选
if(!empty($search['birthday_m'])){
$start = strtotime($search['birthday_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);
$_mids = [];
$_exts = UserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['between','value',$start,$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
//按指定时段筛选
elseif(!empty($search['birthday_after']) && !empty($search['birthday_before'])){
$start = strtotime($search['birthday_after']);
$end = strtotime($search['birthday_before']);
$_mids = [];
$_exts = UserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['between','value',$start,$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
//按指定时间临界点筛选(以不早于为优先筛选条件)
elseif(!empty($search['birthday_after'])){
$start = strtotime($search['birthday_after']);
$_mids = [];
$_exts = AcUserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['>=','value',$start]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}elseif(!empty($search['birthday_before'])){
$end = strtotime($search['birthday_before']);
$_mids = [];
$_exts = UserExt::find()->where(['pid'=>$pid,'deleted'=>0,'key'=>'birthday'])->andwhere(['OR',['<=','value',$end]])->indexBy('id')->groupBy('mid')->all();
foreach($_exts as $mid=>$ext){
$_mids[$ext['mid']] = $ext['mid'];
}
$selectMid = true;
$mids[] = $_mids;
}
if($selectMid){
$mids2 = $mids[0];
foreach($mids as $_mids){
if($_mids){
foreach($_mids as $mid){
if(!in_array($mid,$mids2)){
unset($_mids[$mid]);
};
$mids2 = $_mids;
}
}
}
$where2[] = ['IN','mid',$mids2];
}
$where['deleted'] = 0;
$data = $model->find()->where($where)->andwhere(['AND',$where2]);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->orderBy('id DESC')->offset($pages->offset)->limit($pages->limit)->indexBy('mid')->all();
$status = ['0'=>'隐藏','1'=>'显示'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
$eids = $mids = [];
foreach($res as $r){
$r = $r->toArray();
$eids[$r['employee_id']] = $r['employee_id'];
$mids[$r['mid']] = $r['mid'];
}
$model = new Employee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach($_employees as $s){
$employees[$s->id] = $s->toArray();
}
$model = new UserExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
$guests = [];
foreach($res as $s){
$s = $s->toArray();
foreach($exts[$s['mid']] as $col=>$val){
$s[$col] = $val;
}
$guests[] = $s;
}
$model = new Fans();
$users = [];
$_users = $model->find()->where(['IN','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
return $this->render('list',[
'guests' => $guests,
'pager' => $pages,
'employees'=>$employees,
'hotels'=>$hotels,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'total'=>$data->count(),
]);
}
//客户列表选择
public function actionSelect()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$model = new Customer();
$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 = ['0'=>'隐藏','1'=>'显示'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
$eids = $mids = [];
foreach($res as $r){
$eids[$r['employee_id']] = $r['employee_id'];
$mids[$r['mid']] = $r['mid'];
}
$model = new Employee();
$employees = [];
$_employees = $model->find()->where(['in','id',$eids])->indexBy('id')->all();
foreach($_employees as $s){
$employees[$s->id] = $s->toArray();
}
$model = new UserExt();
$exts = [];
$_exts = $model->find()->where(['in','mid',$mids])->andwhere(['pid'=>$pid,'deleted'=>0])->indexBy('id')->all();
foreach($_exts as $ext){
$ext = $ext->toArray();
$exts[$ext['mid']][$ext['key']] = $ext['value'];
}
$guests = [];
foreach($res as $s){
$s = $s->toArray();
foreach($exts[$s['mid']] as $col=>$val){
$s[$col] = $val;
}
$guests[$s['id']] = $s;
}
$model = new Fans();
$users = [];
$_users = $model->find()->where(['in','id',$mids])->all();
foreach($_users as $s){
$s = $s->toArray();
$users[$s['id']] = $s;
}
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'guest';
return $this->render('select',[
'guests' => $guests,
'pager' => $pages,
'employees'=>$employees,
'hotels'=>$hotels,
'exts'=>$exts,
'users'=>$users,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'callback'=>$callback
]);
}
//新增客户
public function actionNew()
{
global $_HI,$_FM;
return $this->render('modify',[]);
}
//更新客户
public function actionEdit()
{
global $_HI,$_FM;
$model = new Customer();
$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_checkin'] = $res['last_checkin'] ? date('Y-m-d',$res['last_checkin']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
$res['realname'] = $res['name'];
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new Fans();
$user = Fans::find()->where(['id'=>$res['mid']])->one();
if($user){
$res['mobile'] = $user->mobile;
}
$hotel = Hotel::find()->where(['id' => $res['hotel_id']])->one();
if($hotel){
$res['hotel_title'] = $hotel->title;
}
$employee = Employee::find()->where(['id' => $res['employee_id']])->one();
if($employee){
$res['employee_title'] = $employee->name;
}
$exts = UserExt::find()->where(['mid' => $res['mid'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
return $this->render('modify',[
'detail'=>$res,
'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(['guest/edit','id'=>$id]);
return $this->redirect(['new','id'=>$id]);
}
$mobile = $post['mobile'];
//查询对应的系统用户
$userModel = new Fans();
$user = Fans::find()->where(['mobile'=>$mobile])->one();
if(!$user){
$pwd = isset($post['password']) ? trim($post['password']) : Yii::$app->params['defaultUserPassword'];
$userModel->mobile = $mobile;
$userModel->email = $mobile.'@hiluker.com';
$userModel->setPassword($pwd);
$userModel->generateAuthKey();
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
$userModel->created_at = time();
$userModel->from = 'pms';
$res = $userModel->save();
// $res = $userModel->getErrors();
$user_id = $userModel->attributes['id']; //获取插入后id
}else{
$user_id = $user->id;
$pwd = isset($post['password']) ? trim($post['password']) : '';
if($pwd){
$user->setPassword($pwd);
$user->generateAuthKey();
$user->updated_at = time();
$res = $user->save();
}
}
//格式化数据
$data = [];
//目标键=》POST键
$cols = ['name'=>'realname','mobile'=>'mobile','idcard'=>'idcard','passport'=>'passport','country'=>'country','province'=>'province','channel'=>'channel','thumb'=>'thumb'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['gender'=>'gender','total_fee'=>'total_fee','money'=>'money','jifen'=>'jifen','score'=>'score','hotel_id'=>'hotel','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_checkin'=>'last_checkin','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]) : '';
}
$birthday = isset($post['ext']['birthday']) ? strtotime($post['ext']['birthday']) : 0;
if($birthday){
$data['birth_y'] = date('Y',$birthday);
$data['birth_m'] = date('m',$birthday);
$data['birth_d'] = date('d',$birthday);
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['pid'] = $pid;
$data['mid'] = $user_id;
//格式化车主资料
$AcCustomer = new Customer();
foreach($data as $key=>$val){
$AcCustomer->$key = $val;
}
//查询该客户是否在库
$customer = Customer::find()->where(['pid'=>$data['pid'],'mid'=>$data['mid']])->one();
if($customer){
$id = $customer->id;
}
//客户资料入库
if($id){
$AcCustomer->id = $id;
unset($data['create_at']);
$res = $AcCustomer->updateAll($data,['id'=>$id]);
}else{
$res = $AcCustomer->save();
$id = $AcCustomer->attributes['id']; //获取插入后id
}
//保存扩展资料
$AcUserExt = new UserExt();
//批量软删
$AcUserExt->updateAll(['deleted'=>1],['deleted'=>0,'pid'=>$pid,'mid'=>$user_id]);
$datas = [];
$data = [];
$exts = $post['ext'];
foreach($exts as $col=>$val){
$data['pid'] = $pid;
$data['mid'] = $user_id;
$data['key'] = $col;
$data['mobile'] = $mobile;
$data['value'] = trim($val);
$datas[] = $data;
}
//批量插入
$model = clone $AcUserExt;
foreach($datas as $attributes)
{
$model->isNewRecord = true;
$model->setAttributes($attributes,false);
$model->save() && $model->id=0;
}
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 Customer();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('guest/list');
// $return['url'] = Url::previous();
$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 actionMsg()
{
global $_HI,$_FM;
$model = new Customer();
$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_checkin'] = $res['last_checkin'] ? date('Y-m-d',$res['last_checkin']) : '';
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d',$res['last_contact']) : '';
$res['realname'] = $res['name'];
}else{
$res = [];
}
//查询对应的系统用户
$userModel = new Fans();
$user = User::find()->where(['id'=>$res['mid']])->one();
if($user){
$res['mobile'] = $user->mobile;
}
return $this->render('../layouts/dev',[]);
$hotel = Hotel::find()->where(['id' => $res['hotel_id']])->one();
if($hotel){
$res['hotel_title'] = $hotel->title;
}
$employee = Employee::find()->where(['id' => $res['employee_id']])->one();
if($employee){
$res['employee_title'] = $employee->name;
}
$exts = UserExt::find()->where(['mid' => $res['mid'],'pid'=>$pid,'deleted'=>0])->all();
if($exts){
foreach($exts as $ext){
$res[$ext['key']] = $ext['value'];
}
}
return $this->render('modify',[
'detail'=>$res,
'id'=>$id,
]);
}
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 Customer();
$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));
}
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;
case 'contact':
$data['last_contact'] = time();
$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:
$return['msg'] = '无效的操作';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'info'];
break;
}
exit(json_encode($return));
}
}
+250
View File
@@ -0,0 +1,250 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:40:15+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use backend\models\FmHotel as Hotel;
class HotelController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$where['deleted'] = 0;
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'隐藏','1'=>'正常'];
return $this->render('list',[
'hotels'=>$res,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status
]);
}
public function actionSelect()
{
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$where['deleted'] = 0;
$where['status_code'] = 1;
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'隐藏','1'=>'正常'];
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'hotel';
return $this->render('select',[
'hotels'=>$res,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status,
'callback'=>$callback
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
public function actionEdit()
{
$model = new Hotel();
$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','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 Hotel();
foreach($data as $key=>$val){
$model->$key = $val;
}
if($id){
$model->id = $id;
$res = $model->updateAll($data,['id'=>$id]);
}else{
$res = $model->save();
}
$return = [];
if($res){
$id = $model->attributes['id']; //获取插入后id
$return['msg'] = '酒店保存成功';
$return['errorcode'] = 200;
$return['url'] = Url::toRoute(['hotel/edit','id'=>$id]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'primary','url'=>$return['url']]
];
}else{
$return['msg'] = '酒店保存失败';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['hotel/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()
{
$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 Hotel();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('hotel/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['pid'] = Yii::$app->session->get('pid');
$where['id'] = $id;
$data['update_at'] = time();
$model = new Hotel();
$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));
}
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));
}
}
+125
View File
@@ -0,0 +1,125 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:25:38
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:11:41+08:00
* @Email: fm453@lukegzs.com
*/
//主入口页
namespace backend\controllers;
use common\models\Log;
use backend\models\Menu;
use yii\data\Pagination;
use yii\helpers\Url;
use Yii;
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;
if(isset($_GET['pid'])){
$pid = (int)$_GET['pid'];
if($pid>0){
$session->set('pid',$pid);
return $this->actionWelcome();
exit;
}else{
return $this->render('index');
}
}
$pid = $session->get('pid');
if(!$pid){
return $this->render('index');
}else{
return $this->actionWelcome();
}
}
public function actionWelcome()
{
//登录系统欢迎界面,显示入口集
global $_HI,$_FM;
$navs = array();
$entries = array();
$entries[] = array('name'=>'客户列表','title'=>'对客户档案进行管理','url'=>Url::toRoute('guest/list'),'icon'=>'fa fa-users','class'=>'primary');
$entries[] = array('name'=>'新增客户','title'=>'新增加一个客户','url'=>Url::toRoute('guest/new'),'icon'=>'fa fa-user-plus','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('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('hotel/list'),'icon'=>'fa fa-th-large','class'=>'primary');
$entries[] = array('name'=>'新增酒店','title'=>'新增加一个酒店','url'=>Url::toRoute('hotel/new'),'icon'=>'fa fa-th-list','class'=>'primary');
$entries[] = array('name'=>'客房列表','title'=>'对全部酒店门店进行管理','url'=>Url::toRoute('room/list'),'icon'=>'fa fa-cubes','class'=>'primary');
$entries[] = array('name'=>'新增客房','title'=>'新增加一个客房','url'=>Url::toRoute('room/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');
$navs[] = array('name'=>'酒店管理','entries'=>$entries);
$entries = array();
$entries[] = array('name'=>'切换平台','title'=>'选择要管理的平台','url'=>Url::toRoute(['index/index','pid'=>0]),'icon'=>'fa fa-random','class'=>'primary');
$navs[] = array('name'=>'平台管理','entries'=>$entries);
unset($entries);
return $this->render('welcome',[
'navs' => $navs,
]);
}
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);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2018-08-17 20:08:49
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class OrderController extends \yii\web\Controller
{
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
return $this->render('../layouts/dev',[]);
}
public function actionDriver()
{
return $this->render('../layouts/dev',[]);
}
public function actionOrder()
{
return $this->render('../layouts/dev',[]);
}
public function actionNew()
{
return $this->render('../layouts/dev',[]);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2018-08-17 20:06:49
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
class OrderpreController extends \yii\web\Controller
{
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
return $this->render('../layouts/dev',[]);
}
public function actionDriver()
{
return $this->render('../layouts/dev',[]);
}
public function actionOrder()
{
return $this->render('../layouts/dev',[]);
}
}
+308
View File
@@ -0,0 +1,308 @@
<?php
/**
* @Author: fm453
* @Date: 2018-12-02 11:40:44
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:41:13+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use common\models\Fans;
use backend\models\FmUserExt as UserExt;
use backend\models\FmRoomOwner as RoomOwner;
class OwnerController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
public function actionIndex()
{
return $this->render('index');
}
//业主列表
public function actionList()
{
$model = new RoomOwner();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$where['deleted'] = 0;
$data = $model->find()->where($where);
if($search['title']){
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'无协议','1'=>'履约中'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
return $this->render('list',[
'owners'=>$res,
'pager' => $pages,
'status'=>$status,
'gender'=>$gender,
'search'=>$search
]);
}
public function actionSelect()
{
$model = new RoomOwner();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = Yii::$app->session->get('pid');
$post = Yii::$app->request->post();
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','name',$search['title']];
}
$where['deleted'] = 0;
$data = $model->find()->where($where);
if($search['title']){
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'无协议','1'=>'履约中'];
$gender = ['0'=>'未设置','1'=>'男','2'=>'女'];
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'owner';
return $this->render('select',[
'owners'=>$res,
'pager' => $pages,
'status'=>$status,
'gender'=>$gender,
'search'=>$search,
'callback'=>$callback
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
//编辑业主资料
public function actionEdit()
{
$model = new RoomOwner();
$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();
$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','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]) ? $post[$key] : '';
}
$data['create_at'] = time();
$data['update_at'] = $data['create_at'];
$data['status_code'] = 1;
$data['pid'] = $pid;
//保存业主资料
$AcRoomOwner = new RoomOwner();
foreach($data as $key=>$val){
$AcRoomOwner->$key = $val;
}
//查询业主手机号是否在库
$roomowner = AcRoomOwner::find()->where(['mobile'=>$data['mobile']])->one();
if($roomowner){
$id = $roomowner->id;
}
if($id){
$AcRoomOwner->id = $id;
unset($data['create_at']);
$res = $AcRoomOwner->updateAll($data,['id'=>$id]);
}else{
$res = $AcRoomOwner->save();
$id = $AcRoomOwner->attributes['id']; //获取插入后id
}
//查询业主对应的系统账号
$userModel = new User();
$user = User::find()->where(['mobile'=>$data['mobile']])->one();
if(empty($user)){
$userModel->mobile = $data['mobile'];
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
$userModel->generateAuthKey();
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
$userModel->created_at = time();
$userModel->status = 1;
$userModel->save();
$user_id = $userModel->attributes['id']; //获取插入后id
}
// \Yii::$app->getSession()->setFlash('info', '已成功注册该业主!');
// $url = Url::toRoute(['owner/edit','id'=>$id]);
// return $this->redirect($url);
$return = [];
if($res){
$return['msg'] = '业主信息保存成功';
$return['errorcode'] = 200;
$return['url'] = Url::toRoute(['owner/edit','id'=>$id]);
$return['buttons'] = [
['title'=>'好的,我知道了','class'=>'primary','url'=>$return['url']]
];
}else{
$return['msg'] = '业主信息保存失败';
$return['errorcode'] = 0;
$return['url'] = Url::toRoute(['owner/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()
{
$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 RoomOwner();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('owner/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['pid'] = Yii::$app->session->get('pid');
$where['id'] = $id;
$data['update_at'] = time();
$model = new RoomOwner();
$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));
}
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));
}
}
+452
View File
@@ -0,0 +1,452 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
# @Last modified by: fm453
# @Last modified time: 2021-09-15T16:42:59+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use backend\models\FmHotel as Hotel;
use backend\models\FmRoom as Room;
use backend\models\FmRoomOwner as RoomOwner;
class RoomController 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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionList()
{
global $_HI,$_FM;
$pid = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$model = new Room();
$where = $where2 = [];
$where2[]='and';
$where['pid'] = $pid;
$post = Yii::$app->request->post();
$search = isset($post['search']) ? $post['search'] : [];
$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$session = Yii::$app->session;
if($page==0){
$session->set('Room:List:'.$pid,$search);
}else{
$search = $search ? $search : $session->get('Room:List:'.$pid);
}
$hotel_id = Yii::$app->request->get('hotel_id');
$hotel_id = (int)$hotel_id;
if($hotel_id){
$search['hotel'] = $hotel_id;
}
$model = new Room();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
if(!empty($search['title'])){
$where2[] = ['LIKE','title',$search['title']];
}
$search['hotel'] = isset($search['hotel']) ? (int)$search['hotel'] : 0;
if(!empty($search['hotel'])){
$where2[] = ['=','hotel_id',$search['hotel']];
$hotel = Hotel::find()->where(['id'=>$search['hotel']])->one();
$search['hotel_title'] = $hotel['title'];
}
$search['f'] = isset($search['f']) ? (int)$search['f'] : 0;
if(!empty($search['f'])){
$where2[] = ['=','f',$search['f']];
}else{
unset($search['f']);
}
$search['t'] = isset($search['t']) ? (int)$search['t'] : 0;
if(!empty($search['t'])){
$where2[] = ['=','t',$search['t']];
}else{
unset($search['t']);
}
$search['c'] = isset($search['c']) ? (int)$search['c'] : 0;
if(!empty($search['c'])){
$where2[] = ['=','c',$search['c']];
}else{
unset($search['c']);
}
$search['w'] = isset($search['w']) ? (int)$search['w'] : 0;
if(!empty($search['w'])){
$where2[] = ['=','w',$search['w']];
}else{
unset($search['w']);
}
$search['b'] = isset($search['b']) ? (int)$search['b'] : 0;
if(!empty($search['b'])){
$where2[] = ['=','b',$search['b']];
}else{
unset($search['b']);
}
$search['measure'] = isset($search['measure']) ? (int)$search['measure'] : 0;
if(!empty($search['measure'])){
$where2[] = ['<=','measure',$search['measure']];
}else{
unset($search['measure']);
}
$where['deleted'] = 0;
$data = $model->find()->where($where)->andwhere(['AND',$where2]);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->orderBy('hotel_id DESC, id DESC')->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'隐藏','1'=>'正常'];
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$_hotels = $model->find()->where($where)->all();
$hotels = [];
foreach($_hotels as $s){
$hotels[$s->id] = $s->toArray();
}
$rooms = [];
foreach($res as $s){
$s = $s->toArray();
$rooms[] = $s;
}
return $this->render('list',[
'rooms'=>$rooms,
'hotels'=>$hotels,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status,
'pager' => $pages,
'search'=>$search,
'hotel_id'=>$hotel_id,
'total'=>$data->count(),
]);
}
public function actionSelect()
{
$model = new Hotel();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$where['deleted'] = 0;
$where['status_code'] = 1;
$data = $model->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'隐藏','1'=>'正常'];
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'hotel';
return $this->render('select',[
'hotels'=>$res,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status,
'callback'=>$callback
]);
}
public function actionNew()
{
return $this->render('modify',[]);
}
public function actionEdit()
{
$model = new Room();
$id = Yii::$app->request->get('id');
$res = $model->find()->where(['id' => $id])->one();
if($res){
$res = $res->toArray();
$cols = ['signtime','deadline'];
foreach($cols as $col){
$res[$col] = $res[$col] ? date('Y-m-d',$res[$col]) : '';
}
$cols = ['income','expense','surplus'];
foreach($cols as $col){
$res[$col] = round($res[$col]/100,2);
}
}
$hotel = Hotel::find()->where(['id' => $res['hotel_id']])->one();
if($hotel){
$res['hotel_title'] = $hotel->title;
}
$owner = RoomOwner::findOne($res['owner_id']);
if($owner){
$res['owner_title'] = $owner->name;
}
return $this->render('modify',[
'detail'=>$res,
'id'=>$id,
]);
}
public function actionSave()
{
$post = Yii::$app->request->post();
$data = [];
$data['pid'] = Yii::$app->session->get('pid');
$id = $post['id'];
$op = Yii::$app->request->get('op');
switch($op){
case 'basic':
//目标键=》POST键
$cols = ['title'=>'title','sn'=>'sn','thumb'=>'thumb','longt'=>'lng','lat'=>'lat','addr'=>'addr'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$cols = ['hotel_id'=>'hotel_id','f'=>'f','t'=>'t','c'=>'c','w'=>'w','b'=>'b','measure'=>'measure','deleted'=>'deleted'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$data['detail'] = $post['editor'];
$data['status_code'] = 1;
break;
case 'params':
//目标键=》POST键
$cols = ['wifi'=>'wifi','cooking'=>'cooking','gas'=>'gas','parker'=>'parker','swimmingpool'=>'swimmingpool'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
break;
case 'owner':
//目标键=》POST键
$cols = ['owner_id'=>'owner_id','signmonths'=>'signmonths'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
}
$cols = ['income'=>'income','expense'=>'expense','surplus'=>'surplus'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? (int)($post[$key]*100) : 0;
}
$cols = ['signtime'=>'signtime','deadline'=>'deadline'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? strtotime($post[$key]) : 0;
}
break;
case 'other':
//目标键=》POST键
$cols = ['landscape'=>'landscape','feature'=>'feature','tag'=>'tag','traffic'=>'traffic'];
foreach($cols as $col=>$key){
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
}
$data['remark'] = $post['remark-editor'];
break;
default:
\Yii::$app->getSession()->setFlash('success', '无效的数据保存操作!');
return $this->redirect(['edit','id'=>$id]);
break;
}
$data['update_at'] = time();
$model = new Room();
if($id){
$model = $model->findOne($id);
}
foreach($data as $key=>$val){
$model->$key = $val;
}
if($id){
$model->id = $id;
$res = $model->update();
}else{
$model->create_at = $data['update_at'];
$res = $model->save();
}
if($res){
$id = $id ? $id : $model->attributes['id']; //取插入后id
\Yii::$app->getSession()->setFlash('success', '房间资料保存成功!');
return $this->redirect(['edit','id'=>$id]);
}else{
\Yii::$app->getSession()->setFlash('warning', '房间资料保存失败!');
if($id){
return $this->redirect(['edit','id'=>$id]);
}else{
return $this->redirect(['new']);
}
}
}
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 Room();
foreach($data as $key=>$val){
$model->$key = $val;
}
$model->id = $id;
$res = $model->updateAll($data,$where);
$return = [];
$return['url'] = Url::toRoute('room/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['pid'] = Yii::$app->session->get('pid');
$where['id'] = $id;
$data['update_at'] = time();
$model = new Room();
$res = $model->findOne($id);
$return = [];
$return['timeout'] = 1; //3秒后自动跳转
$return['status'] = 0;
$return['ajax'] = 1;
if(!$res){
$return['msg'] = '房间数据不存在';
$return['errorcode'] = 404;
exit(json_encode($return));
}
$data = $res;
switch($get['do'])
{
case 'hide':
$data->status_code = 0;
$res = $data->update();
if($res !== false){
$return['msg'] = '房间隐藏成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'info'];
}else{
$return['msg'] = '房间隐藏失败';
$return['errorcode'] = 0;
}
break;
case 'show':
$data->status_code = 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '房间显示成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '房间显示失败';
$return['errorcode'] = 0;
}
break;
case 'cooking':
$data->cooking = ($data->cooking) ? 0 : 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '参数标记成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '参数标记失败';
$return['errorcode'] = 0;
}
break;
case 'parker':
$data->parker = ($data->parker) ? 0 : 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '参数标记成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '参数标记失败';
$return['errorcode'] = 0;
}
break;
case 'swimmingpool':
$data->swimmingpool = ($data->swimmingpool) ? 0 : 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '参数标记成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '参数标记失败';
$return['errorcode'] = 0;
}
break;
case 'gas':
$data->gas = ($data->gas) ? 0 : 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '参数标记成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '参数标记失败';
$return['errorcode'] = 0;
}
break;
case 'wifi':
$data->wifi = ($data->wifi) ? 0 : 1;
$res = $data->update();
if($res !== false){
$return['msg'] = '参数标记成功';
$return['errorcode'] = 200;
$return['data'] = ['css'=>'default'];
}else{
$return['msg'] = '参数标记失败';
$return['errorcode'] = 0;
}
break;
default:
break;
}
exit(json_encode($return));
}
}
+111
View File
@@ -0,0 +1,111 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:29:56
* @Last Modified by: fm453
* @Last Modified time: 2021-04-28 17:12:54
* @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);
$role = $user_info[key($user_info)];
$menu = array();
$roleType = $role->type;
require Yii::getAlias('@backend').'/menus/'.'0.php';
$menu2 = new Menu();
$menu2 = $menu2->getLeftMenuList();
if(isset($_GET['debug']) && $_GET['debug']){
$menu = array_merge($menu,$menu2);
}
return $this->render('index',[
'menu' => $menu,
'user_info' => key($user_info)
]);
}
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();
}
}
+179
View File
@@ -0,0 +1,179 @@
<?php
/**
* @Author: fm453
* @Date: 2018-08-17 19:39:41
* @Last Modified by: fm453
* @Last Modified time: 2021-04-28 17:30:36
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\data\Pagination;
use yii\helpers\Url;
use backend\models\CAttachment;
use common\components\Attachment;
class UploadController extends \yii\web\Controller
{
public $enableCsrfValidation = false; //取消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){
$url = Url::toRoute('/index/index');
return $this->redirect($url);
}
}
//主界面
public function actionIndex()
{
return $this->render('../layouts/dev',[]);
}
public function actionImage()
{
global $_HI,$_FM;
$siteId = Yii::$app->params['siteId'];
$session = Yii::$app->session;
$pid = (int)$session->get('pid');
$model = new CAttachment();
$where = [];
$where['status_code'] = 1;
$where['type'] = 0;
$where['siteid'] = $siteId;
$where['pid'] = $pid;
//分页
$orderby = ['id' => SORT_DESC];
$Attachemnt = new Attachment();
$list = $Attachemnt->getData($model,$where,$orderby);
$pager = $Attachemnt->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'=>$list,
'pager' => $pager,
'src'=>$src,
'callback'=>$callback
]);
}
public function actionImage_save()
{
global $_HI,$_FM;
// $post = [
// 'name'=> "IMG_3829.JPG",
// 'path'=>"/temp",
// 'root'=> "/Users/fm453/webdev/localhost/i/upload/temp/IMG_3829.JPG",
// 'size'=> 271389,
// 'type'=> "image/jpeg",
// 'lasttime'=> 'Mon Oct 15 2018 19:43:05 GMT+0800 (中国标准时间)',
// 'ext'=> "JPG",
// 'params'=> '{type: "image/jpeg", width: 1080, height: 1080}'
// ];
$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));
}
public function actionSimditor()
{
//针对simditor插件
global $_HI,$_FM;
// "success": true/false,
// "msg": "error message", # optional
// "file_path": "[real file path]"
//
$return=[];
$return['msg'] = '';
$return['success'] = true;
$return['file_path'] = 'http://public.hiluker.com/anchengjieshun/banner-ad-1180-300.png';
die(json_encode($return));
}
}