Subsidiary.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class Subsidiary extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'org_id' => input('orgId/d',0),
  13. 'count' => input('count'),
  14. ];
  15. $result = validate('Subsidiary')->check($data,[],'');
  16. if(true !== $result){
  17. HelpHander::error(validate('Subsidiary')->getError());
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. if($id > 0){
  22. $data['update_time'] = date('Y-m-d H:i:s');
  23. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  24. }else{
  25. $data['create_time'] = date('Y-m-d H:i:s');
  26. $ret = $this->allowField(true)->save($data);
  27. }
  28. if(!$ret){
  29. HelpHander::error('操作失败');
  30. }
  31. return true;
  32. }
  33. public function del($id){
  34. $ret = $this->where('id',$id)->delete();
  35. if(!$ret){
  36. HelpHander::error('删除失败');
  37. }
  38. return true;
  39. }
  40. public function lists($orgId){
  41. $lists = $this
  42. ->where('org_id',$orgId)
  43. ->order('id asc')
  44. ->select();
  45. $data = $lists?$lists->toArray():[];
  46. return $data;
  47. }
  48. }