You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

4 years ago
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. class ItemVariableController extends BaseController {
  5. //保存
  6. public function save(){
  7. $item_id = I("item_id/d");
  8. $var_name = I("var_name");
  9. $var_value = I("var_value");
  10. $login_user = $this->checkLogin();
  11. $uid = $login_user['uid'] ;
  12. if(!$this->checkItemPermn($uid , $item_id)){
  13. $this->sendError(10303);
  14. return ;
  15. }
  16. $data = array() ;
  17. $data['var_name'] = $var_name ;
  18. $data['uid'] = $uid ;
  19. $data['var_value'] = $var_value ;
  20. $data['item_id'] = $item_id ;
  21. $data['addtime'] = time() ;
  22. $id = D("ItemVariable")->add($data);
  23. if (!$id) {
  24. $this->sendError(10101);
  25. }else{
  26. $this->sendResult($id);
  27. }
  28. }
  29. //获取列表
  30. public function getList(){
  31. $item_id = I("item_id/d");
  32. $login_user = $this->checkLogin();
  33. $uid = $login_user['uid'] ;
  34. if(!$this->checkItemPermn($uid , $item_id)){
  35. $this->sendError(10303);
  36. return ;
  37. }
  38. if ($item_id > 0 ) {
  39. $ret = D("ItemVariable")->where(" item_id = '$item_id' ")->order(" addtime asc ")->select();
  40. }
  41. if ($ret) {
  42. foreach ($ret as $key => &$value) {
  43. $value['addtime'] = date("Y-m-d H:i:s",$value['addtime']);
  44. }
  45. }
  46. $this->sendResult($ret);
  47. }
  48. //删除
  49. public function delete(){
  50. $item_id = I("item_id/d");
  51. $id = I("id/d");
  52. $login_user = $this->checkLogin();
  53. $uid = $login_user['uid'] ;
  54. if(!$this->checkItemPermn($uid , $item_id)){
  55. $this->sendError(10303);
  56. return ;
  57. }
  58. $ret = D("ItemVariable")->where(" item_id = '%d' and id = '%d' ",array($item_id,$id))->delete();
  59. if ($ret) {
  60. $this->sendResult($ret);
  61. }else{
  62. $this->sendError(10101);
  63. }
  64. }
  65. }