AllwinShopCate.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 AllwinShopCate 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['update_time'] = time();
  20. if(isset($param['id'])){
  21. return self::update($data,['id'=>(int)$param['id']]);
  22. }else{
  23. $data['create_time'] = time();
  24. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  25. return self::insert($data);
  26. }
  27. }
  28. /**
  29. * 获取访问路径
  30. * @param int $parent_id
  31. */
  32. public static function selectPath(int $miniapp_id,$parent_id) {
  33. $pathMaps[] = ['name'=>'根目录','url'=>url('allwin/shopCate/index')];
  34. $getPath = self::getPath($miniapp_id,$parent_id);
  35. foreach ($getPath as $value) {
  36. $pathMaps[] = ['name' => $value['title'],'url' => url('allwin/shopCate/index',['parent_id'=>$value['id']])];
  37. }
  38. return $pathMaps;
  39. }
  40. /**
  41. * 获取当前路径
  42. * @param type $parent_id
  43. * @return type
  44. */
  45. public static function getPath($miniapp_id,$parent_id){
  46. $result = self::field('id,title,parent_id')->where(['member_miniapp_id' => $miniapp_id])->select();
  47. $tree = new Tree(array('id','parent_id','title','name'));
  48. return $tree->getPath($result,$parent_id);
  49. }
  50. }