123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\service;
- use app\model\ProductClass;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Model;
- class ProductClassService{
- /**
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- */
- public static function getProductClassById($id){
- $del_flag = "N";
- return (new \app\model\ProductClass)
- //->field('')
- ->where("type_id",$id)
- ->where("del_flag",'=', "N")
- ->select();
- }
- public static function getProductClass(){
- $type_data = (new ProductClass)->field("type_id")->group("type_id")->select();
- for ($i=0;$i<count($type_data);$i++){
- $type_data[$i]["data"]=(new ProductClass)
- ->field('id, parent_name, parent_id, name')
- ->where('type_id', $type_data[$i]['type_id'])
- ->select();
- for ($j=0;$j<count($type_data[$i]["data"]);$j++){
- //$type_data[$i]["data"][$j]["data"] = [];
- $type_data[$i]["data"][$j]["data"]=(new ProductClass)
- ->field('parent_name, parent_id, name')
- ->where('parent_id', $type_data[$i]['data'][$j]['parent_id'])
- ->select();
- }
- }
- return $type_data;
- }
- }
|