pageList($condition, $field, $order, $page, $list_rows, $alias, $join); return $this->success($data); } /** * 获取类目通过上级类目ID * @param $level * @param int $pid * @return array */ public function getCategoryByParent($site_id,$level,$pid = 0,$cat_type=1,$type='allcategory') { $condition=[ ['site_id','=',$site_id], ['cat_level','=',$level], ['api_type','=',$type] ]; if($pid){ $condition[]=['cat_pid','=',$pid]; } if($cat_type){ $condition[]=['cat_type','=',$cat_type]; } $list = model('shopalilife_category')->getList($condition, '*', '', '', null, 'cat_id'); $data = $this->success($list); Cache::tag('aliCategory')->set("aliCategory_{$level}_{$pid}", $data); return $data; } public function getCategory($site_id,$type='allcategory',$cat_type=1){ $condition=[ ['site_id','=',$site_id], ['api_type','=',$type], ['cat_type','=',$cat_type], ]; $items = model('shopalilife_category')->getColumn($condition, '*', 'cat_id', '', null, 'cat_id'); $config=[ 'id' => 'cat_id', // id名称 'pid' => 'cat_pid', // pid名称 'title' => 'cat_name', // 标题名称 'child' => 'children', // 子元素键名 'step' => 3, ]; $tree =new Tree($config); $lists=$tree::toLayer($items); $temp=[]; foreach ($lists as $item) { if ($item['cat_level'] == 1) { $temp[] = $item; } } return $temp; } /** * 同步商品类目 */ public function syncCategory($site_id,$item_type=1,$type='allcategory') { if($type=='allcategory'){ $api='alipay.open.app.item.allcategory.query'; $key='alipay_open_app_item_allcategory_query_response'; }else{ $api='alipay.open.app.localitem.allcategory.query'; $key='alipay_open_app_localitem_allcategory_query_response'; } $res = ( new MinCode($site_id) )->requestApi($api,['item_type'=>$item_type]); $res=$res[$key]; if ($res[ 'code' ] != 10000) return $res; if (!empty($res[ 'cats' ])) { model('shopalilife_category')->delete([['site_id','=',$site_id],['api_type','=',$type],['cat_type','=',$item_type]]); $data = []; foreach ($res[ 'cats' ] as $item) { foreach ($item['cat_and_parent'] as $value){ $data[$value['cat_id']]=[ 'site_id' => $site_id, 'cat_id' => $value['cat_id'], 'cat_pid' => $value['f_cat_id']??'', 'cat_name' => $value['cat_name'], 'cat_level' => $value['cat_level'], 'qualification_status' => $value['qualification_status']??'', 'cat_type' => $item_type, 'api_type' => $type, 'create_time' => time(), ]; } } model('shopalilife_category')->addList(array_values($data)); return $this->success(1); }else{ return $this->error(-1,'未发现有可用分类信息'); } } /*** * 获取模版信息 * @param $site_id * @param $cat_id * @param $type * @return void */ public function getCatTemplate($site_id,$cat_id,$type='allcategory',$item_type=''){ $data=['category_id'=>$cat_id]; if($type=='allcategory'){ $api='alipay.open.app.item.template.query'; $key='alipay_open_app_item_template_query_response'; }else{ $api='alipay.open.app.localitem.template.query'; $key='alipay_open_app_localitem_template_query_response'; $data['item_type']=$item_type; } $res = ( new MinCode($site_id) )->requestApi($api,$data); $res=$res[$key]; return $res; } /** * 获取分类信息 * @param $third_cat_id * @param $site_id */ public function getCategoryInfo($third_cat_id, $site_id=0) { $info = model('shopalilife_category')->getInfo([['site_id','=',$site_id],[ 'cat_id', '=', $third_cat_id ] ]); if (empty($info)) return $info; return $info; } }