0
0

AssetCate.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use tools\Phptree;
  5. class AssetCate extends Base
  6. {
  7. public function addSave(){
  8. $data = request()->post();
  9. $data['org_id'] = cur_org_id();
  10. $result = validate('AssetCate')->check($data,[],'add');
  11. if(true !== $result){
  12. $this->error = validate('AssetCate')->getError();
  13. return false;
  14. }
  15. $data['create_time'] = date('Y-m-d H:i:s');
  16. $ret = $this->allowField(true)->save($data);
  17. if(!$ret){
  18. $this->error = '操作失败';
  19. return false;
  20. }
  21. return true;
  22. }
  23. public function editSave(){
  24. $data = request()->post();
  25. $result = validate('AssetCate')->check($data,[],'edit');
  26. if(true !== $result){
  27. $this->error = validate('AssetCate')->getError();
  28. return false;
  29. }
  30. $data['update_time'] = date('Y-m-d H:i:s');
  31. $id = $data['id'];
  32. unset($data['id']);
  33. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  34. if(!$ret){
  35. $this->error = '操作失败';
  36. return false;
  37. }
  38. return true;
  39. }
  40. public function showAllTree(){
  41. $lists = Db::name('asset_cate')->field('id,title,parent_id')->where('org_id',cur_org_id())->order('id asc')->select();
  42. if (empty($lists)) {
  43. return array();
  44. }
  45. $tree = Phptree::makeTree(($lists), array(
  46. 'primary_key'=>'id',
  47. 'parent_key'=>'parent_id',
  48. 'expanded' => true
  49. ));
  50. return $tree;
  51. }
  52. public function formatAllTree(){
  53. $lists = Db::name('asset_cate')->field('id as value,title as label,parent_id')->where('org_id',cur_org_id())->order('id asc')->select();
  54. if (empty($lists)) {
  55. return array();
  56. }
  57. $tree = Phptree::makeTree(($lists), array(
  58. 'primary_key'=>'value',
  59. 'parent_key'=>'parent_id',
  60. 'expanded' => true
  61. ));
  62. return $tree;
  63. }
  64. }