AisShopCate.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 AisShopCate extends Model{
  12. protected $pk = 'id';
  13. //添加或编辑
  14. public static function edit($param){
  15. $data['title'] = $param['title'];
  16. $data['content'] = $param['content'];
  17. $data['picture'] = $param['picture'];
  18. $data['types'] = $param['types'];
  19. $data['show_type'] = $param['show_type'];
  20. $data['update_time'] = time();
  21. if(empty($param['id'])){
  22. $data['create_time'] = time();
  23. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  24. return self::insert($data);
  25. }else{
  26. return self::update($data,['id'=>(int)$param['id']]);
  27. }
  28. }
  29. /**
  30. * 获取访问路径
  31. * @param int $parent_id
  32. */
  33. public static function selectPath(int $miniapp_id,$parent_id) {
  34. $pathMaps[] = ['name'=>'根目录','url'=>url('ais/shopCate/index')];
  35. $getPath = self::getPath($miniapp_id,$parent_id);
  36. foreach ($getPath as $value) {
  37. $pathMaps[] = ['name' => $value['title'],'url' => url('ais/shopCate/index',['parent_id'=>$value['id']])];
  38. }
  39. return $pathMaps;
  40. }
  41. /**
  42. * 获取当前路径
  43. * @param type $parent_id
  44. * @return type
  45. */
  46. public static function getPath($miniapp_id,$parent_id){
  47. $result = self::field('id,title,parent_id')->where(['member_miniapp_id' => $miniapp_id])->select();
  48. $tree = new Tree(array('id','parent_id','title','name'));
  49. return $tree->getPath($result,$parent_id);
  50. }
  51. }