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.
199 lines
8.0 KiB
199 lines
8.0 KiB
<?php
|
|
namespace app\api\controller\wanlshop;
|
|
|
|
use app\common\controller\Api;
|
|
use app\admin\model\wanlshop\Invoice;
|
|
use app\admin\model\wanlshop\Xuepingxian;
|
|
use app\common\model\User;
|
|
use app\admin\model\user\redpocket\Log as Redlog;
|
|
use Darabonba\OpenApi\OpenApiClient;
|
|
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
|
|
|
|
use Darabonba\OpenApi\Models\Config;
|
|
use Darabonba\OpenApi\Models\Params;
|
|
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
|
use Darabonba\OpenApi\Models\OpenApiRequest;
|
|
use think\Db;
|
|
use think\Exception;
|
|
/**
|
|
* WanlShop文章接口
|
|
*/
|
|
class Aliorc extends Api
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
/**
|
|
* 使用AK&SK初始化账号Client
|
|
* @return OpenApiClient Client
|
|
*/
|
|
public static function createClient(){
|
|
$config = get_addon_config('alioss');
|
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
|
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html。
|
|
$config = new Config([
|
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
|
"accessKeyId" => $config['accessKeyId'],
|
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
|
"accessKeySecret" => $config['accessKeySecret']
|
|
]);
|
|
// Endpoint 请参考 https://api.aliyun.com/product/ocr-api
|
|
$config->endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
|
|
return new OpenApiClient($config);
|
|
}
|
|
|
|
/**
|
|
* API 相关
|
|
* @return Params OpenApi.Params
|
|
*/
|
|
public static function createApiInfo(){
|
|
$params = new Params([
|
|
// 接口名称
|
|
"action" => "RecognizeAllText",
|
|
// 接口版本
|
|
"version" => "2021-07-07",
|
|
// 接口协议
|
|
"protocol" => "HTTPS",
|
|
// 接口 HTTP 方法
|
|
"method" => "POST",
|
|
"authType" => "AK",
|
|
"style" => "V3",
|
|
// 接口 PATH
|
|
"pathname" => "/",
|
|
// 接口请求体内容格式
|
|
"reqBodyType" => "json",
|
|
// 接口响应体内容格式
|
|
"bodyType" => "json"
|
|
]);
|
|
return $params;
|
|
}
|
|
|
|
/**
|
|
* @param string[] $args
|
|
* @return void
|
|
*/
|
|
public static function main($args){
|
|
|
|
$client = self::createClient();
|
|
$params = self::createApiInfo();
|
|
|
|
$query = OpenApiUtilClient::query($args);
|
|
// runtime options
|
|
$runtime = new RuntimeOptions([]);
|
|
$request = new OpenApiRequest([
|
|
"query" => $query
|
|
]);
|
|
// 复制代码运行请自行打印 API 的返回值
|
|
// 返回值实际为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。
|
|
$return = $client->callApi($params, $request, $runtime);
|
|
return $return['body']['Data']['SubImages']['0']['KvInfo']['Data'];
|
|
}
|
|
/**
|
|
* getInvoicedata 发票核验接口
|
|
* @return Params OpenApi.Params
|
|
*/
|
|
public function getInvoicedata(){
|
|
// $argv = ["Url"=>'https://stationery.njrenzhou.cn/uploads/20241112/dd75ab4fc093b0bf69a8fb825e0d19bd.png',"Type"=>"Invoice"];
|
|
if($this->request->isPost()){
|
|
$config = get_addon_config('wanlshop');
|
|
$uid = $this->auth->id;
|
|
|
|
$url = $this->request->post('url');
|
|
$argv = ["Url"=>$url,"Type"=>"Invoice"];
|
|
$Invoice = new Invoice();
|
|
$return = self::main($argv);
|
|
|
|
$data = $Invoice->where('invoiceNumber',$return['invoiceNumber'])->find();
|
|
//如果存在则返回错误
|
|
if($data) return $this->error("发票已核销过请勿重复扫描");
|
|
//如果不存在则添加数据
|
|
$insert['fp_url'] = $url;
|
|
$insert['invoiceNumber'] = $return['invoiceNumber'];
|
|
$insert['totalAmount'] = $return['totalAmount'];
|
|
$insert['invoiceAmountPreTax'] = $return['invoiceAmountPreTax'];
|
|
$insert['invoiceTax'] = $return['invoiceTax'];
|
|
$insert['invoiceTax'] = $return['invoiceTax'];
|
|
$insert['status'] = 0;
|
|
$insert['uid'] = $uid;
|
|
DB::startTrans();
|
|
try {
|
|
//计算发票信息给的红包比例
|
|
$userinfo = User::get($uid);
|
|
$sendnum = round($return['totalAmount']*$config['fapiao']['givered']/100);
|
|
$insert['redpocket_num'] = $sendnum;
|
|
$insert['createtime'] = date("Y-m-d H:i:s",time());
|
|
$log['old_num'] = $userinfo['redpocket'];
|
|
$log['uid'] = $uid;
|
|
$userinfo->redpocket = bcadd($userinfo->redpocket,$sendnum);
|
|
$log['now_num'] = $userinfo['redpocket'];
|
|
$log['createtime'] = date("Y-m-d H:i:s",time());
|
|
$log['content'] = "上传发票【{$insert['invoiceNumber']}】,获得奖励红包{$sendnum}个";
|
|
$log['number'] = $sendnum;
|
|
$log['type'] = 3;
|
|
$log['pm'] = 0;
|
|
$lastid = $Invoice->insertGetId($insert);
|
|
//查询用户信息
|
|
if( $lastid && $userinfo->save()){
|
|
$log['link_id'] =$lastid;
|
|
Redlog::insert($log);
|
|
DB::commit();
|
|
}else{
|
|
throw new Exception("发票核验失败");
|
|
}
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
return $this->error($e->getMessage());
|
|
}
|
|
$this->success('发票核验成功');
|
|
}
|
|
$this->error('非法请求');
|
|
}
|
|
|
|
public function getxuepingxian(){
|
|
if($this->request->isPost()) {
|
|
$config = get_addon_config('wanlshop');
|
|
$cardno = $this->request->post('cardno');
|
|
$username = $this->request->post('username');
|
|
$uid = $this->auth->id;
|
|
//查询是否含有学平险信息
|
|
$xpxinfo = Xuepingxian::where('cardno',$cardno)->where('status',0)->find();
|
|
if(empty($xpxinfo)) $this->error("保单号无效");
|
|
DB::startTrans();
|
|
try {
|
|
//计算发票信息给的红包比例
|
|
$userinfo = User::get($uid);
|
|
$sendred = $config['fapiao']['studentBXred'];
|
|
$sendmoney = $config['fapiao']['studentBXmoney'];
|
|
//学平险核验红包数
|
|
$xpxinfo['redpocket'] =$sendred;
|
|
//学平险核验余额数
|
|
$xpxinfo['money'] = $sendmoney;
|
|
$xpxinfo['uid'] = $uid;
|
|
$xpxinfo['status'] = 1;
|
|
//获得红包日志信息
|
|
$log['old_num'] = $userinfo['redpocket'];
|
|
$log['uid'] = $uid;
|
|
$userinfo->redpocket = bcadd($userinfo->redpocket,$sendred);
|
|
$log['now_num'] = $userinfo['redpocket'];
|
|
$log['createtime'] = date("Y-m-d H:i:s",time());
|
|
$log['content'] = "学平险核验保单【{$cardno}】,获得奖励红包{$sendred}个";
|
|
$log['number'] = $sendred;
|
|
$log['type'] = 4;
|
|
$log['pm'] = 0;
|
|
//查询用户信息
|
|
if($xpxinfo->save() && $userinfo->save()){
|
|
$log['link_id'] = $xpxinfo['id'];
|
|
Redlog::insert($log);
|
|
User::money($sendmoney, $uid, "学平险核验保单【{$cardno}】,获得余额奖励{$sendmoney}元",1);
|
|
DB::commit();
|
|
}else{
|
|
throw new Exception("学平险保单核验失败");
|
|
}
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
return $this->error($e->getMessage());
|
|
}
|
|
$this->success('学平险保单核验成功');
|
|
}
|
|
$this->error('非法请求');
|
|
}
|
|
} |