ItemGroupController.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. /*
  5. 项目分组管理
  6. */
  7. class ItemGroupController extends BaseController {
  8. //添加和编辑
  9. public function save(){
  10. $login_user = $this->checkLogin();
  11. $group_name = I("group_name");
  12. $item_ids = I("item_ids");
  13. $id = I("id/d");
  14. if ($id) {
  15. D("ItemGroup")->where(" id = '$id' ")->save(array("group_name"=>$group_name,"item_ids"=>$item_ids));
  16. }else{
  17. $data = array() ;
  18. $data['uid'] = $login_user['uid'] ;
  19. $data['group_name'] = $group_name ;
  20. $data['item_ids'] = $item_ids ;
  21. $data['created_at'] = date("Y-m-d H:i:s") ;
  22. $data['updated_at'] = date("Y-m-d H:i:s") ;
  23. $id = D("ItemGroup")->add($data);
  24. }
  25. usleep(200000);
  26. $return = D("ItemGroup")->where(" id = '$id' ")->find();
  27. if (!$return && !$id ) {
  28. $return = array() ;
  29. $return['error_code'] = 10103 ;
  30. $return['error_message'] = 'request fail' ;
  31. }
  32. $this->sendResult($return);
  33. }
  34. //获取列表
  35. public function getList(){
  36. $login_user = $this->checkLogin();
  37. if ($login_user['uid'] > 0 ) {
  38. $ret = D("ItemGroup")->where(" uid = '$login_user[uid]' ")->order(" s_number asc,id asc ")->select();
  39. }
  40. if ($ret) {
  41. $this->sendResult($ret);
  42. }else{
  43. $this->sendResult(array());
  44. }
  45. }
  46. //删除
  47. public function delete(){
  48. $id = I("id/d")? I("id/d") : 0;
  49. $login_user = $this->checkLogin();
  50. if ($id && $login_user['uid']) {
  51. $ret = D("ItemGroup")->where(" id = '$id' and uid = '$login_user[uid]'")->delete();
  52. }
  53. if ($ret) {
  54. D("ItemGroup")->where(" id = '$id' ")->delete();
  55. D("ItemSort")->where(" item_group_id = '$id' ")->delete();
  56. $this->sendResult($ret);
  57. }else{
  58. $this->sendError(10101);
  59. }
  60. }
  61. // 给我的项目组们保存顺序
  62. public function saveSort(){
  63. $login_user = $this->checkLogin();
  64. $groups = I("groups") ;
  65. $data_array = json_decode(htmlspecialchars_decode($groups) , true) ;
  66. $uid = $login_user['uid'] ;
  67. if($data_array){
  68. foreach ($data_array as $key => $value) {
  69. $id = intval($value['id']);
  70. $ret = D("ItemGroup")->where(" id = '$id' and uid = '{$uid}'")->save(array('s_number'=>$value['s_number']));
  71. }
  72. }
  73. $this->sendResult(array());
  74. }
  75. }