12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Db;
- use ocr\AipImageSearch;
- use org\Qiniu;
- class AipImageSearchModel extends Model{
- protected $name = 'ocrimage';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- //显示
- public function index($map, $Nowpage, $limits,$od)
- {
- return $this->alias ('o')
- //field('r.id,r.title,r.cate_id,r.photo,r.remark,r.keyword,r.content,r.views,r.type,r.is_tui,r.from,r.writer,r.ip,r.create_time,r.update_time,r.status,rc.name,r.music')
- //->join('article_cate rc', 'r.cate_id = rc.id')
- ->where($map)
- ->page($Nowpage, $limits)
- ->order($od)
- ->select();
- }
- //图片添加
- public function add($data)
- {
- $add=$this->allowField(true)->save($data);
- //$add=1;
- $oid=$this->oid;
- //halt($data);
- if($add){
- $APP_ID = "19011542";
- $API_KEY = "8IhdHiBUdLRgKzxbt4Lh5FTq";
- $SRCRET_KEY = "Ku1lOeQjNYmG5nabOjq3t1xu5yaLINv8";
- $client = new AipImageSearch($APP_ID, $API_KEY, $SRCRET_KEY);
- //$image=$data["product_image"];
- $image = file_get_contents(ROOT_PATH . 'public' . DS . $data["product_image"]);
- //$image = ROOT_PATH . 'public' . DS . $data["product_image"];
- //echo $dir;die;
- // 如果有可选参数
- $options = array();
- $arr=array("name"=>$data["pruduct_name"],"id"=>$oid);
- $options["brief"] =json_encode($arr);
- $options["class_id1"] = 1;
- $options["class_id2"] = 1;
- //halt($options);
- // 带参数调用商品图检索—入库, 图片参数为本地图片
- $res=$client->sameHqAdd($image, $options);
- //halt($res);
- //halt($res);
- if(isset($res["error_code"])){
- $del = Db::name('ocrimage')->where('oid',$oid)->delete();
- return json(["code"=>100,"msg"=>"上传失败"]);
- }
- if($res){
- return json(["code"=>200,"msg"=>"上传成功"]);
- }else{
- $del = Db::name('ocrimage')->where('oid',$oid)->delete();
- return json(["code"=>100,"msg"=>"上传失败"]);
- }
- }
- else{
- return json(["code"=>100,"msg"=>"添加失败"]);
- }
- }
- //图库信息修改
- public function edit($data){
- $data['type'] = 1;
- $edit=$this->allowField(true)->save($data,["oid"=>$data['oid']]);
- if($edit){
- return json(["code"=>200,"msg"=>"修改成功"]);
- }else{
- return json(["code"=>100,"msg"=>"修改失败"]);
- }
- }
- //图库删除
- public function del($oid)
- {
- $data=$this->where("oid",$oid)->find();
- $del=$this->where("oid",$oid)->delete();
- $APP_ID = "17529719";
- $API_KEY = "xSNZEGbH8BmG84b4UBcOjIm5";
- $SRCRET_KEY = "0PEGcgmGQnTPWb7mqWSAZvBRqHcDEz9Z";
- $client = new AipImageSearch($APP_ID, $API_KEY, $SRCRET_KEY);
- $image = file_get_contents(ROOT_PATH . 'public' . DS . $data["product_image"]);
- // 调用删除商品,传入参数为图片
- $res=$client->sameHqDeleteByImage($image);
- if($del&&$res){
- return json(["code"=>200,"data"=>"删除成功"]);
- }else{
- return json(["code"=>100,"data"=>"删除失败"]);
- }
- }
- }
|