StoreCate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\allwin\model;
  9. use think\Model;
  10. use category\Tree;
  11. class StoreCate extends Model{
  12. protected $pk = 'id';
  13. protected $table = 'ai_allwin_store_cate';
  14. protected $autoWriteTimestamp = true;
  15. protected $updateTime = false;
  16. //添加或编辑
  17. public function edit($param){
  18. $data['parent_id'] = $param['parent_id'];
  19. $data['title'] = trim($param['title']);
  20. $data['name'] = trim($param['name']);
  21. $data['sort'] = trim($param['sort']);
  22. $data['picture'] = trim($param['picture']);
  23. $data['update_time'] = time();
  24. if(isset($param['id'])){
  25. return self::update($data,['id'=>(int)$param['id']]);
  26. }else{
  27. if($param['parent_id']){
  28. $info = self::get($param['parent_id']);
  29. if($info['root_id']){
  30. $data['root_id'] = $info['root_id'];
  31. }else{
  32. $data['root_id'] = $info['id'];
  33. }
  34. }else{
  35. $data['root_id'] = 0;
  36. }
  37. $data['create_time'] = time();
  38. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  39. return self::insert($data);
  40. }
  41. }
  42. /**
  43. * 获取访问路径
  44. * @param int $parent_id
  45. */
  46. public function selectPath($parent_id) {
  47. $pathMaps[] = ['name'=>'行业分类','url'=>url('storecate/index')];
  48. $getPath = self::getPath($parent_id);
  49. foreach ($getPath as $value) {
  50. $pathMaps[] = ['name' => $value['title'],'url' => url('storecate/index',['parent_id'=>$value['id']])];
  51. }
  52. return $pathMaps;
  53. }
  54. /**
  55. * 获取当前路径
  56. * @param type $parent_id
  57. * @return type
  58. */
  59. public function getPath($parent_id){
  60. $result = self::field('id,title,parent_id')->select();
  61. $tree = new Tree(array('id','parent_id','title','name'));
  62. return $tree->getPath($result,$parent_id);
  63. }
  64. }