ProductClassService.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\service;
  3. use app\model\ProductClass;
  4. use think\db\exception\DataNotFoundException;
  5. use think\db\exception\DbException;
  6. use think\db\exception\ModelNotFoundException;
  7. use think\Model;
  8. class ProductClassService{
  9. /**
  10. * @throws ModelNotFoundException
  11. * @throws DataNotFoundException
  12. * @throws DbException
  13. */
  14. public static function getProductClassById($id){
  15. $del_flag = "N";
  16. return (new \app\model\ProductClass)
  17. //->field('')
  18. ->where("type_id",$id)
  19. ->where("del_flag",'=', "N")
  20. ->select();
  21. }
  22. public static function getProductClass(){
  23. $type_data = (new ProductClass)->field("type_id")->group("type_id")->select();
  24. for ($i=0;$i<count($type_data);$i++){
  25. $type_data[$i]["data"]=(new ProductClass)
  26. ->field('id, parent_name, parent_id, name')
  27. ->where('type_id', $type_data[$i]['type_id'])
  28. ->select();
  29. for ($j=0;$j<count($type_data[$i]["data"]);$j++){
  30. //$type_data[$i]["data"][$j]["data"] = [];
  31. $type_data[$i]["data"][$j]["data"]=(new ProductClass)
  32. ->field('parent_name, parent_id, name')
  33. ->where('parent_id', $type_data[$i]['data'][$j]['parent_id'])
  34. ->select();
  35. }
  36. }
  37. return $type_data;
  38. }
  39. }