123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- namespace api\modules\v1\controllers;
- use common\library\ZM_Geohash;
- use common\models\Appointment;
- use common\models\Building;
- use common\models\Comment;
- use common\models\Designer;
- use common\models\ImageSource;
- use common\models\Manager;
- use common\models\UserCompany;
- use common\models\UserInfo;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class AppointController extends ActiveController
- {
- const DISPLAY = 15;//显示条数
- public $modelClass = 'common\models';
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- ],
- ]
- ]);
- }
- /**
- * 预约列表 装修端
- * @return array
- */
- public function actionList()
- {
- $page = Yii::$app->request->POST('page', 1);
- $models = Appointment::find()->select(['{{%appointment}}.uid','pid','booking_time','state','{{%appointment}}.type'])
- ->joinWith(['building'=>function($query){
- $query->select(['id','name']);}])
- ->andwhere('{{%building}}.uid=:uid',[':uid'=>Yii::$app->user->id])
- ->with(['userinfo'=>function($query){
- $query->select('nickname,portrait,uid');
- },]);
- $is_member =UserCompany::findOne(['uid'=>Yii::$app->user->id])->getAttribute('member');
- if($is_member==UserCompany::ISMEMBER){
- $models->with(['user'=>function($query){
- $query->select('id,tel');
- }]);
- }
- $models = $models->orderBy('bd_appointment.created_at desc');
- $models=$models->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
- foreach ($models as $key => $each){
- $models[$key]['booking_time']=date('Y-m-d H:i',$models[$key]['booking_time']);
- if(!empty($models[$key]['userinfo']) && !empty($models[$key]['userinfo']['portrait']))
- $models[$key]['userinfo']['portrait'] = UserInfo::imagesUrl($models[$key]['userinfo']['portrait']);
- }
- $data['list']=$models;
- $data['ismember']=$is_member;
- return Apireturn::sent(1,'订单列表获取成功',200,$data);
- }
- /**
- * 预约列表 用户端
- * @return array
- */
- public function actionAppointlist()
- {
- $page = Yii::$app->request->POST('page', 1);
- $latitude=Yii::$app->request->post('latitude','');
- $longitude=Yii::$app->request->post('longitude','');
- $models = Appointment::find()->select(['{{%appointment}}.uid','pid','booking_time'])->where(array('{{%appointment}}.uid'=>Yii::$app->user->id))
- ->with(['userinfo'=>function($query){
- $query->select('nickname,portrait,uid');
- },'building',]);
- $geohash = new ZM_Geohash();
- $models = $models->orderBy('bd_appointment.created_at desc');
- $models=$models->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
- foreach ($models as $key => $each){
- $models[$key]['booking_time']=date('Y-m-d H:i',$each['booking_time']);
- $images = ImageSource::find()->select('pic')->where('topid=:id and status=:status', [':id' => $each['pid'], ':status' => ImageSource::STATUS_YES])->andWhere(['type' => [20,30,40,50]])->one();
- $models[$key]['img']=$images;
- if(!empty($latitude)&&!empty($longitude))
- {
- $distance = $geohash->getDistance($latitude,$longitude,$each['building']['latitude'],$each['building']['longitude']);
- $models[$key]['building']['distance'] = sprintf( "%.1f ",$distance/1000);
- }
- }
- return Apireturn::sent(1,'预约列表获取成功',200,$models);
- }
- /**
- * 预约单详情
- * @return array
- */
- public function actionAppointdetail()
- {
- $page = Yii::$app->request->POST('page', 1);
- $id = Yii::$app->request->post('id');
- if(empty($id)){
- return Apireturn::sent(0,'参数错误',200);
- }
- $model = Building::find()->where('id=:id',[':id'=>$id])->one();
- $comment = Comment::find()->where('pid=:pid',[':pid'=>$id])->all();
- $img =$model->allimg;
- $data['banner']=$img;
- $data['buiding']=$model;
- $data['comment']=$comment;
- return Apireturn::sent(1,'预约单详情',200,$data);
- }
- /**
- * 设计师删除
- * @return array
- */
- public function actionDeldesigner()
- {
- $id = Yii::$app->request->post('id');
- $deginers = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
- if(!isset($deginers)){
- return Apireturn::sent(1,'找不到设计师',200);
- }
- $deginers->status=Designer::STATUS_NO;
- if($deginers->save()){
- return Apireturn::sent(0,'删除成功',200);
- }
- return Apireturn::sent(1,'删除失败',200);
- }
- /**
- * 项目经理删除
- * @return array
- */
- public function actionDelmanager()
- {
- $id = Yii::$app->request->post('id');
- $deginers = Manager::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
- if(!isset($deginers)){
- return Apireturn::sent(1,'找不到经理',200);
- }
- $deginers->status=Manager::STATUS_NO;
- if($deginers->save()){
- return Apireturn::sent(0,'删除成功',200);
- }
- return Apireturn::sent(1,'删除失败',200);
- }
- /**
- * 设计师和管理人缘添加
- * @return array
- */
- public function actionAdddesign()
- {
- $type = Yii::$app->request->post('type');
- $avatar = Yii::$app->request->post('avatar');
- $realname = Yii::$app->request->post('realname');
- $intro = Yii::$app->request->post('intro');
- if(empty($type)||empty($avatar)||empty($realname)||empty($intro)){
- return Apireturn::sent(1,'参数错误',200);
- }
- //10 设计师 11:经理
- if($type==10){
- $newperson = new Designer();
- }
- else if($type==11){
- $newperson = new Manager();
- }
- else{
- return Apireturn::sent(1,'参数错误',200);
- }
- $newperson->company=Yii::$app->user->id;
- $newperson->realname=$realname;
- $newperson->introduction=$intro;
- $transaction = Yii::$app->db->beginTransaction();
- if($newperson->save()){
- $ava = new ImageSource;
- $ava->type=$type;
- $ava->topid=$newperson->id;
- $ava->pic=$avatar;
- $ava->thumbnail=$avatar;
- $ava->created_at=time();
- $ava->updated_at=time();
- if($ava->save()){
- $transaction->commit();
- return Apireturn::sent(0,'添加人员成功',200);
- }
- else{
- $transaction->rollBack();
- return Apireturn::sent(1,'添加人员失败',200);
- }
- }
- return Apireturn::sent(1,'添加失败11',200,$newperson->getErrors());
- }
- /**
- * 设计师和管理人员编辑
- * @return array
- */
- public function actionEdit()
- {
- $id = Yii::$app->request->post('id');
- $type = Yii::$app->request->post('type');
- $avatar = Yii::$app->request->post('avatar');
- $realname = Yii::$app->request->post('realname');
- $intro = Yii::$app->request->post('intro');
- if(empty($id)||empty($type)||empty($avatar)||empty($realname)||empty($intro)){
- return Apireturn::sent(1,'参数错误',200);
- }
- //10 设计师 11:经理
- if($type==10){
- $newperson = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
- }
- else if($type==11){
- $newperson = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
- }
- else{
- return Apireturn::sent(1,'参数错误',200);
- }
- if(empty($newperson)){
- return Apireturn::sent(1,'找不到该名人缘',200);
- }
- $newperson->company=Yii::$app->user->id;
- $newperson->realname=$realname;
- $newperson->introduction=$intro;
- $transaction = Yii::$app->db->beginTransaction();
- if($newperson->save()){
- $ava = ImageSource::findOne(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>$type]);;
- $ava->topid=$id;
- $ava->pic=$avatar;
- $ava->thumbnail=$avatar;
- $ava->updated_at=time();
- if($ava->save()){
- $transaction->commit();
- return Apireturn::sent(0,'修改人员成功',200);
- }
- else{
- $transaction->rollBack();
- return Apireturn::sent(1,'修改人员失败',200);
- }
- }
- return Apireturn::sent(1,'修改失败',200);
- }
- }
|