AisStoreCate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 行业分类
  7. */
  8. namespace app\ais\model;
  9. use think\Model;
  10. use category\Tree;
  11. class AisStoreCate extends Model{
  12. //添加或编辑
  13. public function edit($param){
  14. $data['parent_id'] = $param['parent_id'];
  15. $data['title'] = trim($param['title']);
  16. $data['name'] = trim($param['name']);
  17. $data['sort'] = trim($param['sort']);
  18. $data['picture'] = trim($param['picture']);
  19. $data['update_time'] = time();
  20. if(isset($param['id'])){
  21. return self::update($data,['id'=>(int)$param['id']]);
  22. }else{
  23. if($param['parent_id']){
  24. $info = self::get($param['parent_id']);
  25. if($info['root_id']){
  26. $data['root_id'] = $info['root_id'];
  27. }else{
  28. $data['root_id'] = $info['id'];
  29. }
  30. }else{
  31. $data['root_id'] = 0;
  32. }
  33. $data['create_time'] = time();
  34. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  35. return self::insert($data);
  36. }
  37. }
  38. /**
  39. * 获取访问路径
  40. * @param int $parent_id
  41. */
  42. public function selectPath($parent_id) {
  43. $pathMaps[] = ['name'=>'行业分类','url'=>url('storeCate/index')];
  44. $getPath = self::getPath($parent_id);
  45. foreach ($getPath as $value) {
  46. $pathMaps[] = ['name' => $value['title'],'url' => url('storeCate/index',['parent_id'=>$value['id']])];
  47. }
  48. return $pathMaps;
  49. }
  50. /**
  51. * 获取当前路径
  52. * @param type $parent_id
  53. * @return type
  54. */
  55. public function getPath($parent_id){
  56. $result = self::field('id,title,parent_id')->select();
  57. $tree = new Tree(array('id','parent_id','title','name'));
  58. return $tree->getPath($result,$parent_id);
  59. }
  60. }