DesignerController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use common\models\Designer;
  4. use common\models\ImageSource;
  5. use common\models\Manager;
  6. use common\models\MaterType;
  7. use yii\data\Pagination;
  8. use yii\rest\ActiveController;
  9. use common\library\Apireturn;
  10. use yii\helpers\ArrayHelper;
  11. use yii\filters\auth\QueryParamAuth;
  12. use yii;
  13. class DesignerController extends ActiveController
  14. {
  15. const DISPLAY = 15;//显示条数
  16. public $modelClass = 'common\models';
  17. public function behaviors()
  18. {
  19. return ArrayHelper::merge(parent::behaviors(), [
  20. 'authenticator' => [
  21. 'class' => QueryParamAuth::className(),
  22. 'tokenParam' => "token",//access-token修改为token
  23. 'optional' => [//不需要认证方法名 array
  24. ],
  25. ]
  26. ]);
  27. }
  28. /**
  29. * 设计师列表
  30. * @return array
  31. */
  32. public function actionList()
  33. {
  34. $page = Yii::$app->request->POST('page', 1);
  35. $deginers = Designer::find()->select('{{%designer}}.id,realname,introduction,pic,thumbnail')
  36. ->where(array('{{%designer}}.status'=>Designer::STATUS_YES))
  37. ->leftJoin('{{%image}}','{{%image}}.topid=bd_designer.id')
  38. ->andWhere('{{%image}}.type=:type and {{%designer}}.company=:company',[':type'=>ImageSource::TYPE_DESIGNER,':company'=>Yii::$app->user->id]);
  39. $deginers=$deginers->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
  40. return Apireturn::sent(0,'我的设计师获取成功',200,$deginers);
  41. }
  42. /**
  43. * 项目经理列表
  44. * @return array
  45. */
  46. public function actionManagerlist()
  47. {
  48. $page = Yii::$app->request->POST('page', 1);
  49. $deginers = Manager::find()->select('{{%manager}}.id,realname,introduction,pic,thumbnail')
  50. ->where(array('{{%manager}}.status'=>Manager::STATUS_YES))
  51. ->leftJoin('{{%image}}','{{%image}}.topid={{%manager}}.id')
  52. ->andWhere('{{%image}}.type=:type and {{%manager}}.company=:company',[':type'=>ImageSource::TYPE_MANAGER,':company'=>Yii::$app->user->id]);
  53. $deginers=$deginers->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all();
  54. return Apireturn::sent(0,'我的项目经理获取成功',200,$deginers);
  55. }
  56. /**
  57. * 设计师删除
  58. * @return array
  59. */
  60. public function actionDeldesigner()
  61. {
  62. $id = Yii::$app->request->post('id');
  63. $deginers = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
  64. if(!isset($deginers)){
  65. return Apireturn::sent(1,'找不到设计师',200);
  66. }
  67. $deginers->status=Designer::STATUS_NO;
  68. if($deginers->save()){
  69. return Apireturn::sent(0,'删除成功',200);
  70. }
  71. return Apireturn::sent(1,'删除失败',200);
  72. }
  73. /**
  74. * 项目经理删除
  75. * @return array
  76. */
  77. public function actionDelmanager()
  78. {
  79. $id = Yii::$app->request->post('id');
  80. $deginers = Manager::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
  81. if(!isset($deginers)){
  82. return Apireturn::sent(1,'找不到经理',200);
  83. }
  84. $deginers->status=Manager::STATUS_NO;
  85. if($deginers->save()){
  86. return Apireturn::sent(0,'删除成功',200);
  87. }
  88. return Apireturn::sent(1,'删除失败',200);
  89. }
  90. /**
  91. * 设计师和管理人缘添加
  92. * @return array
  93. */
  94. public function actionAdddesign()
  95. {
  96. $type = Yii::$app->request->post('type');
  97. $avatar = Yii::$app->request->post('avatar');
  98. $realname = Yii::$app->request->post('realname');
  99. $intro = Yii::$app->request->post('intro');
  100. if(empty($type)||empty($avatar)||empty($realname)||empty($intro)){
  101. return Apireturn::sent(1,'参数错误',200);
  102. }
  103. //10 设计师 11:经理
  104. if($type==10){
  105. $newperson = new Designer();
  106. }
  107. else if($type==11){
  108. $newperson = new Manager();
  109. }
  110. else{
  111. return Apireturn::sent(1,'参数错误',200);
  112. }
  113. $newperson->company=Yii::$app->user->id;
  114. $newperson->realname=$realname;
  115. $newperson->introduction=$intro;
  116. $transaction = Yii::$app->db->beginTransaction();
  117. if($newperson->save()){
  118. $ava = new ImageSource;
  119. $ava->type=$type;
  120. $ava->topid=$newperson->id;
  121. $ava->pic=$avatar;
  122. $ava->thumbnail=$avatar;
  123. $ava->created_at=time();
  124. $ava->updated_at=time();
  125. if($ava->save()){
  126. $transaction->commit();
  127. return Apireturn::sent(0,'添加人员成功',200);
  128. }
  129. else{
  130. $transaction->rollBack();
  131. return Apireturn::sent(1,'添加人员失败',200);
  132. }
  133. }
  134. return Apireturn::sent(1,'添加失败',200,$newperson->getErrors());
  135. }
  136. /**
  137. * 设计师和管理人员编辑
  138. * @return array
  139. */
  140. public function actionEdit()
  141. {
  142. $id = Yii::$app->request->post('id');
  143. $type = Yii::$app->request->post('type');
  144. $avatar = Yii::$app->request->post('avatar');
  145. $realname = Yii::$app->request->post('realname');
  146. $intro = Yii::$app->request->post('intro');
  147. if(empty($id)||empty($type)||empty($avatar)||empty($realname)||empty($intro)){
  148. return Apireturn::sent(1,'参数错误',200);
  149. }
  150. //10 设计师 11:经理
  151. if($type==10){
  152. $newperson = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
  153. }
  154. else if($type==11){
  155. $newperson = Manager::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]);
  156. }
  157. else{
  158. return Apireturn::sent(1,'参数错误',200);
  159. }
  160. if(empty($newperson)){
  161. return Apireturn::sent(1,'找不到该名人缘',200);
  162. }
  163. $newperson->company=Yii::$app->user->id;
  164. $newperson->realname=$realname;
  165. $newperson->introduction=$intro;
  166. $transaction = Yii::$app->db->beginTransaction();
  167. if($newperson->save()){
  168. $ava = ImageSource::findOne(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>$type]);;
  169. $ava->topid=$id;
  170. $ava->pic=$avatar;
  171. $ava->thumbnail=$avatar;
  172. $ava->updated_at=time();
  173. if($ava->save()){
  174. $transaction->commit();
  175. return Apireturn::sent(0,'修改人员成功',200);
  176. }
  177. else{
  178. $transaction->rollBack();
  179. return Apireturn::sent(1,'修改人员失败',200);
  180. }
  181. }
  182. return Apireturn::sent(1,'修改失败',200);
  183. }
  184. }