FeedbackController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: li
  5. * Date: 2018/11/6
  6. * Time: 下午 15:29
  7. */
  8. class FeedbackController extends Controller
  9. {
  10. public function actionIndex(){
  11. //$alikeName=Req::post('keyword');
  12. $priority=Req::get('priority'); //优先级
  13. $type=Req::get('type'); //类型
  14. $readStatus=Req::get('readStatus'); //读状态
  15. $origin=Req::get('origin');
  16. $pageNum=Req::get('page');
  17. $pageType=Req::get('pagetype');
  18. $chargeMan=Req::get('chargeMan');
  19. if(!$pageType) $pageType=1;
  20. $param=array();
  21. if(in_array($priority,array(-1,0,1,2))){
  22. $param['priority']=$priority;
  23. }
  24. if(in_array($readStatus,array(-0,1))){
  25. $param['readStatus']=$readStatus;
  26. }
  27. if(in_array($type,array(-1,0,1,2))){
  28. $param['type']=$type;
  29. }
  30. if($origin){
  31. $param['origin']=$origin;
  32. }
  33. if($chargeMan){
  34. $param['chargeMan']=$chargeMan;
  35. }
  36. $param['pageNum']=1;
  37. if($pageNum){
  38. $param['pageNum']=$pageNum;
  39. }
  40. $views='index';
  41. $uid=$this->coachId;
  42. if($pageType==1){
  43. $res = json_decode(http('api/feedback/coach/demand-new/list/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  44. $views='index';
  45. }elseif($pageType==2){
  46. $res = json_decode(http('api/feedback/coach/demand-running/list/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  47. $views='runnin';
  48. }elseif($pageType==3){
  49. $res = json_decode(http('api/feedback/coach/demand-queued/list/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  50. $views='queued';
  51. }elseif($pageType==4){
  52. $res = json_decode(http('api/feedback/coach/demand-rejected/list/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  53. $views='rejected';
  54. }elseif($pageType==5){
  55. $res = json_decode(http('api/feedback/coach/demand-completed/list/', 'post', $this->authUsername,$param,'armor'),true);
  56. $views='completed';
  57. }else{
  58. $res = json_decode(http('api/feedback/coach/demand-new/list/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  59. }
  60. //debug($res);
  61. $data=array();
  62. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data']) && $res['data']){
  63. $data['list']=$res['data']['list'];
  64. $data['pageTotal']=$res['data']['totalPage'];
  65. $data['page']=$res['data']['current'];
  66. }
  67. $param['pagetype']=$pageType;
  68. $data['param']=$param;
  69. $pageQuery=$param;
  70. unset($pageQuery['page']);
  71. $data['query_page']=http_build_query($pageQuery);
  72. $navQuery=$param;
  73. unset($navQuery['pagetype']);
  74. $data['query_nav']=http_build_query($navQuery);
  75. $data['pageType']=$pageType;
  76. if(isset($data['list'] )){
  77. foreach ($data['list'] as $key=>$val){
  78. $data['list'][$key]['id']=number_format($val['id'],0,'','');
  79. $data['list'][$key]['projectId']=number_format($val['projectId'],0,'','');
  80. }
  81. }
  82. $url = Yii::app()->params['armor']['url'].'api/upload/file';
  83. $data['uploadUrl'] = $url;
  84. $data['basic'] = $this->setToken();
  85. $this->render($views, $data);
  86. }
  87. public function actionReply(){
  88. $id=Req::get('id'); //优先级
  89. $status=Req::get('status');
  90. if(!$id){
  91. Yii::app()->jump->error('需求Id不正确!');
  92. }
  93. $uid=$this->coachId;
  94. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  95. $authUsername=Yii::app()->session['coachInfo']['real_name'];
  96. }else{
  97. $authUsername=Yii::app()->session['coachInfo']['coach_name'];
  98. }
  99. $param['demandId']=$id;
  100. $param['status']=$status;
  101. $param['coachId']=$uid;
  102. $param['readPeople']=$authUsername;
  103. //读取基本信息
  104. $res = json_decode(http('api/feedback/coach/demand/detail', 'post', $this->authUsername,$param,'armor'),true);
  105. // debug($res);
  106. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data']) && $res['data']){
  107. $data['data']=$res['data'];
  108. $data['data']['id']=number_format($data['data']['id'],0,'','');
  109. }else{
  110. Yii::app()->jump->error('接口错误!');
  111. }
  112. //是否点过赞
  113. $data['is_like']=0;
  114. $uid=$this->coachId;
  115. $res_like = json_decode(http('api/feedback/coach/demand/is-like/'.$id.'/'.$uid, 'get', $this->authUsername,array(),'armor'),true);
  116. if(isset($res_like['errCode']) && $res_like['errCode']=='00' && isset($res_like['data']) && $res_like['data']){
  117. if($res_like['data']['count']>0){
  118. $data['is_like']=1;
  119. }
  120. }
  121. $res_r = json_decode(http('api/feedback/coach/demand/reply/'.$id, 'get', $this->authUsername,array(),'armor'),true);
  122. if(isset($res_r['errCode']) && $res_r['errCode']=='00' && isset($res_r['data']) && $res_r['data']){
  123. $data['reply']=$res_r['data'];
  124. }
  125. $this->render('reply', $data);
  126. }
  127. //发送回复
  128. public function actionSendReply(){
  129. $id=Req::post('id');
  130. $msg=Req::post('msg');
  131. $result['status']=0;
  132. if(!$id || !$msg){
  133. exit(json_encode($result));
  134. }
  135. $uid=$this->coachId;
  136. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  137. $authUsername=Yii::app()->session['coachInfo']['real_name'];
  138. }else{
  139. $authUsername=Yii::app()->session['coachInfo']['coach_name'];
  140. }
  141. $param['demandId']=$id;
  142. $param['content']=$msg;
  143. $param['replyPeople']=$authUsername;
  144. $res = json_decode(http('api/feedback/coach/demand/reply/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  145. if(isset($res['errCode']) && $res['errCode']=='00'){
  146. $result['status']=1;
  147. $result['data']=array(
  148. 'msg'=>$msg,
  149. 'username'=>$authUsername,
  150. 'time'=>date('Y-m-d',time())
  151. );
  152. }
  153. exit(json_encode($result));
  154. }
  155. //点赞
  156. public function actionPraise(){
  157. $id=Req::post('id');
  158. $result['status']=0;
  159. if(!$id ){
  160. exit(json_encode($result));
  161. }
  162. $uid=$this->coachId;
  163. $param=array();
  164. $param['coachId']=$uid;
  165. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  166. $param['likePeople']=Yii::app()->session['coachInfo']['real_name'];
  167. }else{
  168. $param['likePeople']=Yii::app()->session['coachInfo']['coach_name'];
  169. }
  170. $res = json_decode(http('api/feedback/coach/demand/like/'.$id, 'post', $this->authUsername,$param,'armor'),true);
  171. if(isset($res['errCode']) && $res['errCode']=='00'){
  172. $result['status']=1;
  173. $result['likePeople']=$param['likePeople'];
  174. }
  175. exit(json_encode($result));
  176. }
  177. //取消点赞
  178. public function actionCancelPraise(){
  179. $id=Req::post('id');
  180. $result['status']=0;
  181. if(!$id ){
  182. exit(json_encode($result));
  183. }
  184. $uid=$this->coachId;
  185. $param=array();
  186. $param['coachId']=$uid;
  187. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  188. $param['likePeople']=Yii::app()->session['coachInfo']['real_name'];
  189. }else{
  190. $param['likePeople']=Yii::app()->session['coachInfo']['coach_name'];
  191. }
  192. $res = json_decode(http('api/feedback/coach/demand/dislike/'.$id.'/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  193. if(isset($res['errCode']) && $res['errCode']=='00'){
  194. $result['status']=1;
  195. }
  196. exit(json_encode($result));
  197. }
  198. //下载附件
  199. public function actionDownload(){
  200. $id=Req::post('id');
  201. $result['status']=0;
  202. if(!$id ){
  203. exit(json_encode($result));
  204. }
  205. $param=array();
  206. $res = json_decode(http('api/feedback/coach/demand/accessory/'.$id, 'get', $this->authUsername,$param,'armor'),true);
  207. if(isset($res['errCode']) && $res['errCode']=='00'){
  208. $result['status']=1;
  209. }
  210. exit(json_encode($result));
  211. }
  212. public function actionAdd(){
  213. $param['title']=Req::post('title');
  214. $param['type']=Req::post('type');
  215. $param['priority']=Req::post('priority');
  216. $param['question']=Req::post('question');
  217. $param['target']=Req::post('target');
  218. $param['releaseTime']=date('Y-m-d H:i:s',strtotime(Req::post('releaseTime')));
  219. $param['urlList'][]=Req::post('urlList');
  220. $uid=$this->coachId;
  221. $result['status']=0;
  222. if(isset(Yii::app()->session['coachInfo']['real_name']) && Yii::app()->session['coachInfo']['real_name']){
  223. $param['origin']=Yii::app()->session['coachInfo']['real_name'];
  224. }else{
  225. $param['origin']=Yii::app()->session['coachInfo']['coach_name'];
  226. }
  227. if(!$param['title'] || !$param['question'] || !$param['target'] || !$param['releaseTime']){
  228. exit(json_encode($result));
  229. }
  230. $res = json_decode(http('api/feedback/coach/demand/add/'.$uid, 'post', $this->authUsername,$param,'armor'),true);
  231. if(isset($res['errCode']) && $res['errCode']=='00'){
  232. $result['status']=1;
  233. }else{
  234. $result['msg']=$res['errMsg'];
  235. }
  236. exit(json_encode($result));
  237. }
  238. public function setToken(){
  239. $sign = $this->authUsername.Yii::app()->params['armor']['sign_url'].Yii::app()->params['armor']['sign'];
  240. $authPassword = md5($sign);
  241. $basic = "Basic ". base64_encode($this->authUsername.":".$authPassword);
  242. return $basic;
  243. }
  244. public function actionPlan(){
  245. $Year=Req::get('year');
  246. $Week=Req::get('week');
  247. $Stage=Req::get('stage');
  248. $Sort=Req::get('sort');
  249. $Origin=Req::get('origin');
  250. $Month=Req::get('month');
  251. $param=array();
  252. $urlArr=array();
  253. if($Year && $Week){
  254. $urlArr['year']=$Year;
  255. $urlArr['week']=$Week;
  256. $urlArr['month']=$Month;
  257. $times=$this->weekday($Year,$Week);
  258. $param['startTime']=date('Y-m-d H:i:s',$times['start']);
  259. $param['endTime']=date('Y-m-d H:i:s',$times['end']);
  260. }else{
  261. $urlArr['year']=date('Y');
  262. $urlArr['month']=date('m');
  263. $urlArr['week']=date('W');
  264. $times=$this->weekday($urlArr['year'],$urlArr['week']);
  265. $param['startTime']=date('Y-m-d H:i:s',$times['start']);
  266. $param['endTime']=date('Y-m-d H:i:s',$times['end']);
  267. }
  268. if($Stage){
  269. $urlArr['stage']=$Stage;
  270. if($Stage==7){
  271. $param['status']=0;
  272. }else{
  273. $param['stage']=(string)$Stage;
  274. }
  275. }
  276. if($Sort){
  277. $urlArr['sort']=$Sort;
  278. $param['sort']=$Sort;
  279. }
  280. if($Origin){
  281. $urlArr['origin']=$Origin;
  282. $param['origin']=$Origin;
  283. }
  284. $res = json_decode(http('api/feedback/coach/demand-plan/list', 'post', $this->authUsername,$param,'armor'),true);
  285. // debug($res);
  286. $data=array();
  287. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data']) && $res['data']){
  288. $data['data']=$res['data'];
  289. }else{
  290. // Yii::app()->jump->error('接口错误!');
  291. }
  292. $data['urlArr']=$urlArr;
  293. $data['Year']=$urlArr['year'];
  294. $data['Month']=$urlArr['month'];
  295. $data['Week']=$urlArr['week'];
  296. if(isset($urlArr['origin'])) $data['origin']=$urlArr['origin'];
  297. $this->render('plan', $data);
  298. }
  299. public function actionGetWeek(){
  300. $Y=Req::post('year');
  301. $M=Req::post('month');
  302. $today = date("Y-m-d",strtotime("$Y-$M"));
  303. $firstday = date('Y-m-01', strtotime($today));//本月第一天
  304. $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));//本月最后一天
  305. $firstWeek=intval(date('W',strtotime($firstday)));
  306. $lastWeek=intval(date('W',strtotime($lastday)));
  307. $result['status']=1;
  308. $week=array();
  309. if($lastWeek>$firstWeek){
  310. for($i=$firstWeek;$i<=$lastWeek;$i++){
  311. $week[]=$i;
  312. }
  313. }else{
  314. if($lastWeek==1 && $M==12){
  315. $lastWeek=date('W',strtotime($lastday)-86400*7);
  316. for($i=$firstWeek;$i<=$lastWeek;$i++){
  317. $week[]=$i;
  318. }
  319. }else{
  320. $week[]=$firstWeek;
  321. for($i=1;$i<=$lastWeek;$i++){
  322. $week[]=$i;
  323. }
  324. }
  325. }
  326. $result['week']=$week;
  327. exit(json_encode($result));
  328. }
  329. private function weekday($year,$week=1){
  330. $year_start = mktime(0,0,0,1,1,$year);
  331. $year_end = mktime(0,0,0,12,31,$year);
  332. // 判断第一天是否为第一周的开始
  333. if (intval(date('W',$year_start))===1){
  334. $start = $year_start;//把第一天做为第一周的开始
  335. }else{
  336. $week++;
  337. $start = strtotime('+1 monday',$year_start);//把第一个周一作为开始
  338. }
  339. // 第几周的开始时间
  340. if ($week===1){
  341. $weekday['start'] = $start;
  342. }else{
  343. $weekday['start'] = strtotime('+'.($week-0).' monday',$start);
  344. }
  345. // 第几周的结束时间
  346. $weekday['end'] = strtotime('+1 sunday',$weekday['start']);
  347. if (date('Y',$weekday['end'])!=$year){
  348. $weekday['end'] = $year_end;
  349. }
  350. return $weekday;
  351. }
  352. }