You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
412 lines
18 KiB
412 lines
18 KiB
<?php |
|
namespace app\api\controller; |
|
use app\api\model\Bidding; |
|
use app\common\controller\Api; |
|
use app\common\model\Banner; |
|
use app\common\model\Collect; |
|
use app\common\model\Tender; |
|
use app\common\ResponseJson; |
|
use app\common\SdException; |
|
use app\middleware\Token; |
|
use OSS\Core\OssException; |
|
use sdModule\common\helper\Excel; |
|
use sdModule\common\Sc; |
|
use Smalot\PdfParser\Parser; |
|
use think\facade\App; |
|
use think\facade\Db; |
|
use Imagick; |
|
class Index extends Api |
|
{ |
|
const APP_ID = '23542778'; |
|
const API_KEY = '0ySWTA6pHnRI7u9gXuPROH86'; |
|
const SECRET_KEY = 'SdYmL9VU0k55DaGXGSdZ8frqCgQcdPgT'; |
|
|
|
public array $middleware = [Token::class=>['except'=>['download','banner','auto']]]; |
|
|
|
|
|
/** |
|
* @param \Bidding $bidding |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DbException |
|
* @author Deng |
|
* @date 2020-12-22 11:15 |
|
* 首页获取列表 |
|
* OR LOCATE(\''.$value . '\', type) > 0 |
|
*/ |
|
public function getBidingList(Bidding $bidding){ |
|
$member = \app\api\model\Member::getMember(); |
|
if(!$member){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
$getData = $this->request->get(); |
|
$where = 'delete_time=0'; |
|
if(isset($getData['keyword']) && $getData['keyword']!=''){ |
|
/* $where.= ' AND (LOCATE(\''.$getData['keyword'] . '\',title)>0 OR LOCATE(\''.$getData['keyword'] . '\',contract_title)>0 OR LOCATE(\''.$getData['keyword'] . '\',contractNo)>0 OR LOCATE(\''.$getData['keyword'] . '\',project_title)>0)';*/ |
|
$where.= ' AND (LOCATE(\''.$getData['keyword'] . '\',title)>0)'; |
|
} |
|
if(!$getData['status'] == 3){ |
|
$where.= ' AND status='.$getData['status']; |
|
} |
|
$getData['status'] = isset($getData['status']) ? $getData['status'] : 0; |
|
if (isset($getData['is_urgent'])) $where.= ' AND is_urgent='.$getData['is_urgent']; |
|
return ResponseJson::success($bidding->getBiddingList($getData['page'],$getData['limit'],$where)); |
|
} |
|
|
|
/** |
|
* @param Bidding $bidding |
|
* @param $id |
|
* @param $member_id |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2020-12-22 11:42 |
|
* 获取详情 |
|
*/ |
|
public function getBidingDetails(Bidding $bidding,$id,$member_id=0){ |
|
$member = \app\api\model\Member::getMember(); |
|
if(!$member){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
return ResponseJson::success($bidding->getBindingDetails($id,$member['id'])); |
|
} |
|
|
|
/** |
|
* @param Collect $collect |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2020-12-22 14:44 |
|
* 关注招标 |
|
*/ |
|
public function attention(Collect $collect){ |
|
$getData = $this->request->get(); |
|
$member = \app\api\model\Member::getMember(); |
|
if(empty($member)){ |
|
return ResponseJson::fail('您暂时还未登录,请登录后关注招标项目'); |
|
} |
|
if($member['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
if(empty($getData['bidding_id'])){ |
|
return ResponseJson::fail('参数缺失'); |
|
} |
|
$data = $collect->where([ |
|
'member_id' => $member['id'], |
|
'bidding_id' => $getData['bidding_id'], |
|
'delete_time' => 0 |
|
])->find(); |
|
if(!$data){ |
|
$result = $collect->save([ |
|
'member_id' => $member['id'], |
|
'bidding_id' => $getData['bidding_id'], |
|
'create_time' => date('Y-m-d H:i:s'), |
|
'update_time' => date('Y-m-d H:i:s'), |
|
]); |
|
return $result ? ResponseJson::success('','关注成功') : ResponseJson::fail('关注成功'); |
|
}else{ |
|
return ResponseJson::fail('您已经关注该项目'); |
|
} |
|
} |
|
|
|
/** |
|
* @param Collect $collect |
|
* @return \think\response\Json |
|
* @throws \Exception |
|
* @author Deng |
|
* @date 2020-12-22 14:44 |
|
* 取消关注 |
|
*/ |
|
public function cancelAttention(Collect $collect){ |
|
$getData = $this->request->get(); |
|
$member = \app\api\model\Member::getMember(); |
|
if(!$member){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($member['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
if(empty($getData['bidding_id'])){ |
|
return ResponseJson::fail('参数缺失'); |
|
} |
|
$data = $collect->where(['member_id' => $member['id'], 'bidding_id' => $getData['bidding_id'], 'delete_time' => 0])->findOrEmpty(); |
|
if($data){ |
|
$result = $collect->where('id',$data['id'])->useSoftDelete('delete_time',time())->delete(); |
|
return $result ? ResponseJson::success('','操作成功') : ResponseJson::fail('操作失败'); |
|
}else{ |
|
return ResponseJson::fail('取消关注的招标项目不存在'); |
|
} |
|
} |
|
/** |
|
* @return \think\response\File |
|
* @author Deng |
|
* @date 2020-12-22 14:07 |
|
* 文件下载 |
|
*/ |
|
public function download(){ |
|
$getData = $this->request->get(); |
|
$str = App::getRootPath() . '/upload/' . $getData['path']; |
|
if (file_exists($str)) { |
|
return download($str, $getData['tag']); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* @return \think\response\Json |
|
* @throws SdException |
|
* 阿里云oss |
|
*/ |
|
public function ailOss(){ |
|
try { |
|
if (empty($_FILES['file'])) { |
|
return ResponseJson::fail('无上传文件'); |
|
} |
|
$result = Sc::aLiYunOSS()->uploadFile('file'); |
|
} catch (OssException $e) { |
|
throw new SdException($e->getErrorMessage()); |
|
} |
|
return ResponseJson::success($result); |
|
} |
|
|
|
/** |
|
* @param \app\api\model\Member $member |
|
* @return \think\response\Json |
|
* @author Deng |
|
* @date 2021-01-04 11:25 |
|
* 投标 |
|
*/ |
|
public function tender(\app\api\model\Member $member){ |
|
$getPost = $this->request->post(); |
|
$memberInfo = \app\api\model\Member::getMember(); |
|
if(!$memberInfo){ |
|
return ResponseJson::fail('用户不存在或者尚未注册'); |
|
} |
|
if($memberInfo['status']==0){ |
|
return ResponseJson::fail('您被限制登录,请联系管理员'); |
|
} |
|
$bidding = Bidding::where(['id'=>$getPost['bidding_id'],'delete_time'=>0])->findOrEmpty()->toArray(); |
|
if(!$bidding){ |
|
return ResponseJson::fail('您投标的项目不存在'); |
|
} |
|
if($bidding['status'] > 0){ |
|
return ResponseJson::fail('您投标的项目已中标'); |
|
} |
|
if($memberInfo){ |
|
if($memberInfo['is_tender']==0) return ResponseJson::fail('您暂时没有投标权限,请联系管理员'); |
|
if($getPost['file_id']){ |
|
$data = Db::name('resource')->where('id',$getPost['file_id'])->find(); |
|
$path = App::getRootPath().'/upload/'.$data['path']; |
|
|
|
if(file_exists($path)){ |
|
$tender_price = 0; |
|
if(strstr($data['tag'],'xlsx') || strstr($data['tag'],'xls')){ |
|
$excel = new Excel($path,'read'); |
|
$data = $excel->getActiveData(); |
|
foreach ($data as $key=>$val){ |
|
if($val[7] == '合计' && !empty($val[8])){ |
|
$tender_price = trim($val[8]); |
|
} |
|
} |
|
if($tender_price == 0){ |
|
return ResponseJson::fail('投标文件合计价格不规范,请重新上传'); |
|
} |
|
}elseif (strstr($data['tag'],'pdf')){ |
|
//pdf转png |
|
pdf_png($path,App::getRootPath().'/upload/watermark/',$data['md5']); |
|
$path = App::getRootPath().'/upload/watermark/'.$data['md5'].'.png'; |
|
if(file_exists($path)){ |
|
//加水印 |
|
\think\Image::open($path)->water('./logo.png')->save(App::getRootPath().'/upload/watermark/'.$data['md5'].'.jpg'); |
|
/* $image = file_get_contents($path); |
|
$res = $apiOcr->webImage($image); |
|
if(isset($res['error_code']) && !empty($res['error_code'])){ |
|
return ResponseJson::fail('图片错误,错误码:'.$res['error_code'].',错误详细信息请参考百度Ai图片识别对应错误码。'); |
|
} |
|
if(empty($res['words_result'])){ |
|
return ResponseJson::fail('上传报价图片内容无法识别,请重新上传'); |
|
} |
|
foreach ($res['words_result'] as $item){ |
|
if(strstr($item['words'],'ㄍ')){ |
|
$tender_price = trim(str_replace('ㄍ','',$item['words'])); |
|
}elseif (strstr($item['words'],'《')){ |
|
$tender_price = trim(str_replace('《','',$item['words'])); |
|
}elseif (strstr($item['words'],'》')){ |
|
$tender_price = trim(str_replace('》','',$item['words'])); |
|
}elseif (strstr($item['words'],'合计')){ |
|
$tender_price = trim(str_replace('合计','',$item['words'])); |
|
} |
|
} |
|
if (strstr($tender_price,'《')){ |
|
$tender_price = trim(str_replace('《','',$tender_price)); |
|
} |
|
if (strstr($tender_price,'》')){ |
|
$tender_price = trim(str_replace('》','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'合计')){ |
|
$tender_price = trim(str_replace('合计','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'标段1')){ |
|
$tender_price = trim(str_replace('标段1','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'标段')){ |
|
$tender_price = trim(str_replace('标段','',$tender_price)); |
|
} |
|
|
|
if(empty($tender_price)){ |
|
return ResponseJson::fail('上传报价图片合计金额无法识别,请重新上传'); |
|
}*/ |
|
$tender_price = $this->image($path); |
|
} |
|
}elseif (strstr($data['tag'],'png') || strstr($data['tag'],'jpg')){ |
|
//处理图片 |
|
\think\Image::open($path)->water('./logo.png')->save(App::getRootPath().'/upload/watermark/'.$data['md5'].'.jpg'); |
|
$tender_price = $this->image($path); |
|
} |
|
$getPost['tender_price'] = $tender_price; |
|
$ip = Bidding::get_ip(); |
|
$ip = json_decode($ip); |
|
if($ip->ret ==='ok'){ |
|
$getPost['ip'] = $ip->ip; |
|
$getPost['ip_address'] = $ip->data[0]; |
|
if(!empty($ip->data[1])){ |
|
$getPost['ip_address'].='-'.$ip->data[1]; |
|
} |
|
if($ip->data[2]){ |
|
$getPost['ip_address'].='-'.$ip->data[2]; |
|
} |
|
} |
|
}else{ |
|
return ResponseJson::fail('缺少资源ID'); |
|
} |
|
} |
|
$getPost['member_id'] = $memberInfo['id']; |
|
$result = Tender::create($getPost); |
|
return $result ? ResponseJson::success('','投标成功') : ResponseJson::fail('投标失败'); |
|
}else{ |
|
return ResponseJson::fail('会员不存在'); |
|
} |
|
} |
|
|
|
|
|
public function image($path){ |
|
//图片类 |
|
require_once App::getRootPath().'/extend/AipOcr/AipOcr.php'; |
|
$apiOcr = new \AipOcr(self::APP_ID, self::API_KEY, self::SECRET_KEY); |
|
$image = file_get_contents($path); |
|
$res = $apiOcr->webImage($image); |
|
if(isset($res['error_code']) && !empty($res['error_code'])){ |
|
return ResponseJson::fail('图片错误,错误码:'.$res['error_code'].',错误详细信息请参考百度Ai图片识别对应错误码。'); |
|
} |
|
if(empty($res['words_result'])){ |
|
return ResponseJson::fail('上传报价图片内容无法识别,请重新上传'); |
|
} |
|
$tender_price = ''; |
|
foreach ($res['words_result'] as $key => $item){ |
|
/*if ($item['words'] === '合计'){ |
|
$tender_price = $res['words_result'][$key+1]['words']; |
|
break; |
|
}else if(strstr($item['words'],'ㄍ')){ |
|
$tender_price = trim(str_replace('ㄍ','',$item['words'])); |
|
break; |
|
}elseif (strstr($item['words'],'《')){ |
|
$tender_price = trim(str_replace('《','',$item['words'])); |
|
break; |
|
}elseif (strstr($item['words'],'》')){ |
|
$tender_price = trim(str_replace('》','',$item['words'])); |
|
break; |
|
}elseif (strstr($item['words'],'合计')){ |
|
$tender_price = trim(str_replace('合计','',$item['words'])); |
|
break; |
|
}*/ |
|
if ($item['words'] === '合计'){ |
|
$tender_price = $res['words_result'][$key+1]['words']; |
|
break; |
|
} |
|
} |
|
if(strstr($tender_price,'ㄍ')){ |
|
$tender_price = trim(str_replace('ㄍ','',$tender_price)); |
|
} |
|
if (strstr($tender_price,'《')){ |
|
$tender_price = trim(str_replace('《','',$tender_price)); |
|
} |
|
if (strstr($tender_price,'》')){ |
|
$tender_price = trim(str_replace('》','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'合计')){ |
|
$tender_price = trim(str_replace('合计','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'标段1')){ |
|
$tender_price = trim(str_replace('标段1','',$tender_price)); |
|
} |
|
if(strstr($tender_price,'标段')){ |
|
$tender_price = trim(str_replace('标段','',$tender_price)); |
|
} |
|
if(empty($tender_price)){ |
|
return ResponseJson::fail('上传报价图片合计金额无法识别,请重新上传'); |
|
} |
|
return $tender_price; |
|
} |
|
/** |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2021-01-12 18:02 |
|
* 轮播 |
|
*/ |
|
public function banner() |
|
{ |
|
return ResponseJson::success(Banner::where('delete_time',0)->order('sort desc')->field('id,title,cover,cover_url')->select()->toArray()); |
|
} |
|
|
|
/** |
|
* @return \think\response\Json |
|
* @throws \think\db\exception\DataNotFoundException |
|
* @throws \think\db\exception\DbException |
|
* @throws \think\db\exception\ModelNotFoundException |
|
* @author Deng |
|
* @date 2021-01-14 17:06 |
|
* 自动结标 |
|
*/ |
|
public function auto(){ |
|
$bidding = Bidding::where(['status'=>0,'delete_time'=>0])->whereTime('open_bid_time','<',time())->select()->toArray(); |
|
Db::startTrans(); |
|
try { |
|
foreach ($bidding as $bid){ |
|
$getData = Tender::where(['bidding_id'=>$bid['id'],'status'=>0,'delete_time'=>0])->order('tender_price desc')->findOrEmpty()->toArray(); |
|
if(isset($getData['id']) && $getData['id']){ |
|
//修改投标状态 |
|
Db::name('tender')->where('id',$getData['id'])->update(['status'=>1,'update_time'=>date('Y-m-d H:i:s')]); |
|
//发送通知 |
|
// $bidding = \app\common\model\Bidding::where('id',$getData['bidding_id'])->find()->toArray(); |
|
$content= '恭喜您通过招标。请您和我司负责人'.$bid['contact_person'].'进行沟通联系方式:'.$bid['contact_person_tel']; |
|
\app\common\model\Notice::create([ |
|
'member_id' => $getData['member_id'], |
|
'bidding_id' => $bid['id'], |
|
'content' => $content, |
|
'contract_title' => $bid['project_title'] |
|
]); |
|
} |
|
|
|
//修改招标状态 |
|
\app\common\model\Bidding::where(['id'=>$bid['id']])->update(['status'=>1,'update_time'=>date('Y-m-d H:i:s')]); |
|
} |
|
db::commit(); |
|
return ResponseJson::success(); |
|
} catch (\Exception $exception) { |
|
db::rollback(); |
|
return ResponseJson::fail($exception->getMessage()); |
|
} |
|
} |
|
} |