12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Db;
- use ocr\AipImageSearch;
- use org\Qiniu;
- class SimilarimageModel 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)
- {
- $data['type'] = $data['tid'];
- $add=$this->allowField(true)->save($data);
- $oid=$this->oid;
- if($add){
- $APP_ID = config('site.appid');
- $API_KEY = config('site.appkey');
- $SRCRET_KEY = config('site.srcretkey');
- $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["tags"] = $data['tid'].','.$data['user_id'];
- // 带参数调用商品图检索—入库, 图片参数为本地图片
- $res=$client->similarAdd($image, $options);
- 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){
- $a = 500000;
- $b = 700000000;
- $c =$a/$b;
- echo $c;die;
- halt($data);
- $edit=$this->allowField(true)->save($data,["oid"=>$data['oid']]);
- if($edit){
- }else{
- return json(["code"=>100,"msg"=>"修改失败"]);
- }
- }
- //图库删除
- public function del($oid)
- {
- $data=$this->where("oid",$oid)->find();
- $del=$this->where("oid",$oid)->delete();
- $APP_ID = config('site.appid');
- $API_KEY = config('site.appkey');
- $SRCRET_KEY = config('site.srcretkey');
- $client = new AipImageSearch($APP_ID, $API_KEY, $SRCRET_KEY);
- $image = file_get_contents(ROOT_PATH . 'public' . DS . $data["product_image"]);
- // 调用删除相似图,传入参数为图片
- $res=$client->similarDeleteByImage($image);
- if($del&&$res){
- return json(["code"=>200,"msg"=>"删除成功"]);
- }else{
- return json(["code"=>100,"msg"=>"删除失败"]);
- }
- }
- }
|