123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- namespace api\modules\v1\controllers;
- use common\models\Designer;
- use common\models\ImageSource;
- use common\models\Manager;
- use common\models\MaterType;
- use yii\data\Pagination;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class DesignerController 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);
- $deginers = Designer::find()->select('{{%designer}}.id,realname,introduction,pic,thumbnail')
- ->where(array('{{%designer}}.status'=>Designer::STATUS_YES))
- ->leftJoin('{{%image}}','{{%image}}.topid=bd_designer.id')
- ->andWhere('{{%image}}.type=:type and {{%designer}}.company=:company',[':type'=>ImageSource::TYPE_DESIGNER,':company'=>Yii::$app->user->id]);
- $deginers=$deginers->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
- return Apireturn::sent(0,'我的设计师获取成功',200,$deginers);
- }
- /**
- * 项目经理列表
- * @return array
- */
- public function actionManagerlist()
- {
- $page = Yii::$app->request->POST('page', 1);
- $deginers = Manager::find()->select('{{%manager}}.id,realname,introduction,pic,thumbnail')
- ->where(array('{{%manager}}.status'=>Manager::STATUS_YES))
- ->leftJoin('{{%image}}','{{%image}}.topid={{%manager}}.id')
- ->andWhere('{{%image}}.type=:type and {{%manager}}.company=:company',[':type'=>ImageSource::TYPE_MANAGER,':company'=>Yii::$app->user->id]);
- $deginers=$deginers->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
- return Apireturn::sent(0,'我的项目经理获取成功',200,$deginers);
- }
- /**
- * 设计师删除
- * @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,'添加失败',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 = Manager::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);
- }
- }
|