Note.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\NoteLog;
  4. use app\BaseController;
  5. use think\console\command\Make;
  6. use think\facade\Db;
  7. use think\App;
  8. class Note extends BaseController
  9. {
  10. public $post="";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post = $this->request->post();
  15. }
  16. public function create(){
  17. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  18. if($token==""){
  19. return error_show(101,'token不能为空');
  20. }
  21. $title = isset($this->post['title']) && $this->post['title']!==""? trim($this->post['title']):"";
  22. if($title==""){
  23. return error_show(1002,"参数title不能为空");
  24. }
  25. $remark = isset($this->post['remark']) && $this->post['remark']!==""? trim($this->post['remark']):"";
  26. if($remark==""){
  27. return error_show(1002,"参数remark不能为空");
  28. }
  29. $company_type= isset($this->post['company_type']) && $this->post['company_type']!==""? trim($this->post['company_type']):"";
  30. if($company_type==""){
  31. return error_show(1002,"参数company_type不能为空");
  32. }
  33. $model_id= isset($this->post['model_id']) && $this->post['model_id']!==""? $this->post['model_id']:[];
  34. $noteNo= isset($this->post['noteNo']) && $this->post['noteNo'] !==""? $this->post['noteNo']:"";
  35. $bugNo= makeNo("BG");
  36. $apply_id =VerifyTokens($token);
  37. if(empty($apply_id)||$apply_id['code']!=0){
  38. return error_show($apply_id['code'],$apply_id['message']);
  39. }
  40. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  41. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  42. $tem=[];
  43. $tem['bugNo']=$bugNo;
  44. $tem['title']="";
  45. $tem['level']="";
  46. $tem['status']="";
  47. $tem['remark']="";
  48. $tem['noteNo']="";
  49. //$tem['company_type']="";
  50. $tem['deal_name']="";
  51. $tem['type']="";
  52. //array_column($in,"id");
  53. $tem['model_id']="";
  54. $level= isset($this->post['level']) && $this->post['level']!==""? intval($this->post['level']):"2";
  55. $type= isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']):"2";
  56. $weight= isset($this->post['weight']) && $this->post['weight']!==""? trim($this->post['weight']):"";
  57. $status= isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"0";
  58. $submit = isset($this->post['submit']) && $this->post['submit']!==""? intval($this->post['submit']):"1";
  59. $data=[
  60. "model_id"=>!empty($model_id) ? array_pop($model_id):"0",
  61. "bugNo"=>$bugNo,
  62. "noteNo"=>$noteNo,
  63. "title"=>$title,
  64. "remark"=>$remark,
  65. "company_type"=>$company_type,
  66. "apply_name"=>$ri,
  67. "apply_id"=>$rm,
  68. "level"=>$level,
  69. "type"=>$type,
  70. "submit"=>$submit,
  71. "weight"=>$weight,
  72. "status"=>$status,
  73. "is_del"=>0,
  74. "addtime"=>date("Y-m-d H:i:s"),
  75. "updatetime"=>date("Y-m-d H:i:s")
  76. ];
  77. $datainfo= Db::name('note')->insert($data);
  78. if($datainfo){
  79. NoteLog::log($tem,$this->post,1);
  80. return error_show(0,"新建成功");
  81. }else{
  82. return error_show(1002,"新建失败");
  83. }
  84. }
  85. public function list(){
  86. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  87. if($token==""){
  88. return error_show(101,'token不能为空');
  89. }
  90. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  91. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  92. $where =[['is_del','=',0]];
  93. $bugNo =isset($this->post['bugNo']) &&$this->post['bugNo'] !=="" ? trim($this->post['bugNo']):"";
  94. if($bugNo!=""){
  95. $where[]=['bugNo',"like","%$bugNo%"];
  96. }
  97. $model_id =isset($this->post['model_id']) &&$this->post['model_id'] !=="" ? trim($this->post['model_id']):"";
  98. if($model_id!=""){
  99. $where[]=['model_id',"=",$model_id];
  100. }
  101. $noteNo =isset($this->post['noteNo']) &&$this->post['noteNo'] !=="" ? trim($this->post['noteNo']):"";
  102. if($noteNo!=""){
  103. $where[]=['noteNo',"like","%$noteNo%"];
  104. }
  105. $company_type =isset($this->post['company_type']) &&$this->post['company_type'] !=="" ? trim($this->post['company_type']):"";
  106. if($company_type!=""){
  107. $where[]=['company_type',"=",$company_type];
  108. }
  109. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? trim($this->post['apply_name']):"";
  110. if($apply_name!==""){
  111. $where[]=['apply_name',"like","%$apply_name%"];
  112. }
  113. $apply_id =VerifyTokens($token);
  114. if(empty($apply_id)||$apply_id['code']!=0){
  115. return error_show($apply_id['code'],$apply_id['message']);
  116. }
  117. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  118. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  119. $is_created = isset($this->post['is_created']) && $this->post['is_created'] !==""? intval($this->post['is_created']):"0";
  120. if($status!==""){
  121. if($status<8){
  122. $where[]=['status',"=",$status];
  123. }elseif ($status==8){
  124. $where[]=['status',"<=",$status];
  125. $where[]=['status',"<>",5];
  126. }elseif ($status===9){
  127. // $where[]=['apply_id',"=",$rm];
  128. }elseif ($status===10){
  129. $str = Db::name('deal')->where(['action_id'=>$rm,'is_del'=>0])->select()->toArray();
  130. $data =array_unique(array_column($str,'bugNo')) ;
  131. $where[]=['bugNo',"in",$data];
  132. }elseif ($status===11){
  133. $var = Db::name('deal')->where(['deal_id'=>$rm,'is_del'=>0,'status'=>0])->select()->toArray();
  134. $da =array_unique(array_column($var,'bugNo')) ;
  135. $where[]=['bugNo',"in",$da];
  136. }
  137. }
  138. if($is_created==1){
  139. $where[]=['apply_id',"=",$rm];
  140. }
  141. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  142. if($start!==""){
  143. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  144. }
  145. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  146. if($end!==""){
  147. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  148. }
  149. $title = isset($this->post['title']) && $this->post['title'] !==""? intval($this->post['title']):"";
  150. if($title!==""){
  151. $where[]=['title',"like","%$title%"];
  152. }
  153. $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
  154. if($level!==""){
  155. $where[]=['level','=',$level];
  156. }
  157. $type = isset($this->post['type']) && $this->post['type'] !==""? intval($this->post['type']):"";
  158. if($type!==""){
  159. $where[]=['type','=',$type];
  160. }
  161. $deal_name= isset($this->post['deal_name']) && $this->post['deal_name'] !==""? trim($this->post['deal_name']):"";
  162. if ($deal_name!==""){
  163. $item = Db::name('deal')->where([["deal_name","like","%$deal_name%"],["is_del","=",0],['status',"=",0]])->select()->toArray();
  164. $cn =array_unique(array_column($item,'bugNo'));
  165. $where[]=["bugNo","in",$cn];
  166. }
  167. $count = Db::name('note')->where($where)->count();
  168. $total = ceil($count/$size);
  169. $page = $page>$total ? $total:$page;
  170. $list = Db::name('note')->where($where)->page($page,$size)->order("addtime desc")->select();
  171. $data=[];
  172. foreach ($list as $value){
  173. $var = Db::name('depart_user')->alias('a')->join("company_item b","a.itemid = b.id","left")
  174. ->where(['a.uid'=>$value['apply_id'],'a.is_del'=>0])->column('b.name,b.id');
  175. $dn=[];
  176. foreach ($var as $vmp){
  177. $dn[]=isset($vmp['id']) && $vmp['id'] !=0 ? make($vmp['id']):[];
  178. }
  179. //$value['rename'] =$var;
  180. $str = Db::name("deal")->where(['bugNo'=>$value['bugNo'],'status'=>0,'is_del'=>0])->find();
  181. $value['deal_id']=isset($str['deal_id']) ?$str['deal_id']:"";
  182. $value['deal_name']=isset($str['deal_name']) ?$str['deal_name']:"";
  183. $value['can']= isset($value['model_id']) && $value['model_id'] !=0 ? made($value['model_id']):[];
  184. $value['company_name']=$dn;
  185. $data[]=$value;
  186. }
  187. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  188. }
  189. public function edit(){
  190. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  191. if($token==""){
  192. return error_show(101,'token不能为空');
  193. }
  194. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  195. if($id==""){
  196. return error_show(1002,"参数id不能为空");
  197. }
  198. $info=Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
  199. if(empty($info)){
  200. return error_show(1004,"未找到数据");
  201. }
  202. $title = isset($this->post['title']) && $this->post['title']!==""? trim($this->post['title']):"";
  203. if($title==""){
  204. return error_show(1002,"参数title不能为空");
  205. }
  206. $model_id= isset($this->post['model_id']) && $this->post['model_id']!==""? $this->post['model_id']:[];
  207. // if(empty($model_id)){
  208. // return error_show(1002,"参数model_id不能为空");
  209. // }
  210. $remark = isset($this->post['remark']) && $this->post['remark']!==""? trim($this->post['remark']):"";
  211. if($remark==""){
  212. return error_show(1002,"参数remark不能为空");
  213. }
  214. $company_type= isset($this->post['company_type']) && $this->post['company_type']!==""? trim($this->post['company_type']):"";
  215. if($company_type==""){
  216. return error_show(1002,"参数company_type不能为空");
  217. }
  218. $level= isset($this->post['level']) && $this->post['level']!==""? intval($this->post['level']):"1";
  219. if($level==""){
  220. return error_show(1002,"参数level不能为空");
  221. }
  222. $status= isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):$info['status'];
  223. $noteNo= isset($this->post['noteNo']) && $this->post['noteNo'] !==""? $this->post['noteNo']:"";
  224. $type= isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']):"0";
  225. if($type===""){
  226. return error_show(1002,"参数type不能为空");
  227. }
  228. $weight= isset($this->post['weight']) && $this->post['weight']!==""? trim($this->post['weight']):"0";
  229. $inf=Db::name('deal')->where(['bugNo'=>$info['bugNo'],'status'=>0,"is_del"=>0])->find();
  230. // $deal_name = isset($this->post['deal_name']) && $this->post['deal_name']!=="" ? trim($this->post['deal_name']):"";
  231. // if($deal_name==""){
  232. // return error_show(1004,"参数deal_name不能为空");
  233. // }
  234. $tem=[];
  235. $tem['noteNo']=$info['noteNo'];
  236. $tem['bugNo']=$info['bugNo'];
  237. $tem['title']=$info['title'];
  238. $tem['level']=$info['level'];
  239. $tem['status']=$info['status'];
  240. $tem['remark']=$info['remark'];
  241. // $tem['company_type']=$info['company_type'];
  242. $tem['deal_name']=isset($inf['deal_name']) ? $inf['deal_name']:"";
  243. $tem['type']=$info['type'];
  244. //array_column($in,"id");
  245. $tem['model_id']=$info['model_id'];
  246. $apply_id =VerifyTokens($token);
  247. if(empty($apply_id)||$apply_id['code']!=0){
  248. return error_show($apply_id['code'],$apply_id['message']);
  249. }
  250. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  251. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  252. // $dom = Db::name('manange')->where(['manange_id'=>$rm,'company_id'=>$company_type,'is_del'=>0])->find();
  253. // if ($info['status']!=$status){
  254. // if($dom==false){
  255. // return error_show(1002,"无权限修改");
  256. // }
  257. // }
  258. $deal_id = isset($this->post['deal_id']) && $this->post['deal_id']!=="" ? intval($this->post['deal_id']):"";
  259. $this->post['deal_name']='';
  260. $datai=[];
  261. if($deal_id!==""){
  262. // if($dom==false){
  263. // return error_show(1002,"无权限修改");
  264. // }
  265. // $stn = Db::name('manange')->where(['manange_id'=>$deal_id,'company_id'=>$company_type,'is_del'=>0])->find();
  266. // if($stn==false){
  267. // return error_show(1002,"处理人不存在");
  268. // }
  269. $to= GetInfoById($token,['id'=>$deal_id]);
  270. if((!empty($to) && $to['code']!=0) ||empty($to) ){
  271. return error_show($to['code'],"未找到处理人信息");
  272. }
  273. $in = $to['data'];
  274. $this->post['deal_name']=$in['nickname'];
  275. if(empty($inf)||$info['status']!=$status){
  276. $datai['deal_id'] = $in['id'];
  277. $datai['deal_name'] = $in['nickname'];
  278. $datai['action_id'] =$rm;
  279. $datai['action_name'] = $ri;
  280. $datai['bugNo'] = $info['bugNo'];
  281. $datai['level'] = 1;
  282. $datai['type'] = 1;
  283. $datai['status'] =0;
  284. $datai['is_del'] = 0;
  285. $datai['addtime'] = date("Y-m-d H:i:s");
  286. $datai['updatetime'] = date("Y-m-d H:i:s");
  287. }else{
  288. $datai['action_id'] =$rm;
  289. $datai['action_name'] = $ri;
  290. $datai['id']= $inf['id'];
  291. $datai['deal_name'] = $in['nickname'];
  292. $datai['deal_id'] = $in['id'];
  293. $datai['updatetime'] = date("Y-m-d H:i:s");
  294. }
  295. }
  296. Db::startTrans();
  297. try{
  298. $data=[
  299. "id"=>$id,
  300. "title"=>$title,
  301. "noteNo"=>$noteNo,
  302. "remark"=>$remark,
  303. //"model_id"=>is_null(array_pop($model_id)) ? array_pop($model_id):"0",
  304. "model_id"=>!empty($model_id) ? array_pop($model_id):"0",
  305. "company_type"=>$company_type,
  306. // "apply_name"=>$ri,
  307. // "apply_id"=>$rm,
  308. "level"=>$level,
  309. "type"=>$type,
  310. "weight"=>$weight,
  311. "status"=>$status,
  312. "is_del"=>0,
  313. "updatetime"=>date("Y-m-d H:i:s")
  314. ];
  315. $datainfo = Db::name('note')->where($info)->save($data);
  316. if($datainfo){
  317. if ($info['status']!=$status && $inf!=false){
  318. $inf['action_id']=$rm;
  319. $inf['action_name']=$ri;
  320. $inf['status']=1;
  321. $inf['updatetime']=date("Y-m-d H:i:s");
  322. $dc = Db::name('deal')->where(['id'=>$inf['id'],'status'=>0,'is_del'=>0])->save($inf);
  323. if($dc==false){
  324. Db::rollback();
  325. return error_show(1002,"更新失败");
  326. }
  327. }
  328. if(!empty($datai)){
  329. $dai= Db::name('deal')->save($datai);
  330. if($dai==false){
  331. Db::rollback();
  332. return error_show(1002,"更新失败");
  333. }
  334. }
  335. NoteLog::log($tem,$this->post,2);
  336. Db::commit();
  337. return error_show(0,"更新成功");
  338. }else{
  339. Db::rollback();
  340. return error_show(1002,"更新失败");
  341. }
  342. }catch (\Exception $e){
  343. Db::rollback();
  344. return error_show(1004,$e->getMessage());
  345. }
  346. // $item['deal_id']
  347. }
  348. public function info(){
  349. $id=isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  350. if($id=="") {
  351. return error_show(1002, "参数id不能为空");
  352. }
  353. $info = Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
  354. $var = Db::name('depart_user')->alias('a')->join("company_item b","a.itemid = b.id","left")
  355. ->where(['a.uid'=>$info['apply_id'],'a.is_del'=>0])->column('b.name,b.id');
  356. // $dn=[];
  357. // foreach ($var as $vmp){
  358. // $dn[]=isset($vmp['id']) && $vmp['id'] !=0 ? make($vmp['id']):[];
  359. // }
  360. $item = Db::name('deal')->where(['bugNo'=>$info['bugNo'],'is_del'=>0,'status'=>0])->find();
  361. $info['deal_id']=isset($item['deal_id']) ? $item['deal_id']:"";
  362. $info['deal_name']=isset($item['deal_name']) ? $item['deal_name']:"";
  363. $in= isset($info['model_id']) && $info['model_id'] !=0 ? made($info['model_id']):[];
  364. $info['can']=$in;
  365. $info['company_name']=$var;
  366. $info['model_id']=array_column($in,"id");
  367. if(empty($info)){
  368. return error_show(1002,"未找到数据");
  369. }else{
  370. return app_show(0,"获取成功",$info);
  371. }
  372. }
  373. public function del(){
  374. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  375. if($id==""){
  376. return error_show(1002,"参数id不能为空");
  377. }
  378. $info=Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
  379. if(empty($info)){
  380. return error_show(1002,"未找到数据");
  381. }
  382. $str['is_del']=1;
  383. $str['updatetime']=date("Y-m-d H:i:s");
  384. $info=Db::name('note')->where(['is_del'=>0])->save($str);
  385. return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
  386. }
  387. }