This commit is contained in:
wangjinlei
2025-01-07 10:07:35 +08:00
parent a54a837670
commit 28a0c44dab
5 changed files with 203 additions and 73 deletions

View File

@@ -1422,6 +1422,11 @@ class Article extends Base
if($data['state'] == 6){
// $this->addProductionEx($data['articleId']);
$this->addArticleMainEx($data['articleId']);
//如果是免费的期刊文章,那么直接变成付款完成
if($journal_info['fee']==0){
$this->article_obj->where("article_id",$article_info['article_id'])->update(["is_bug"=>1]);
}
}
}

View File

@@ -439,7 +439,7 @@ class Base extends Controller
if($refer_start&&$v!=""){
if (strlen($v) > 500) {
$refer_start = false;
$cc_t = $this->replaceChinesePunctuation($this->removeExtraSpaces(trim($v)));
$cc_t = $this->formatMain($v);
$insert['article_id'] = $article_id;
$insert['type'] = 0;
$insert['content'] = $cc_t;
@@ -455,7 +455,7 @@ class Base extends Controller
continue;
}
$c_t = $this->replaceChinesePunctuation($this->removeExtraSpaces(trim($v)));
$c_t = $this->formatMain($v);
$insert['article_id'] = $article_id;
$insert['type'] = 0;
$insert['content'] = $c_t;
@@ -574,6 +574,11 @@ class Base extends Controller
}
public function formatMain($string){
return $this->blueIntegerChange($this->replaceChinesePunctuation($this->removeExtraSpaces($string)));
}
public function replaceChinesePunctuation($str) {
// 定义中文标点和对应的英文标点替换
$replacements = [
@@ -598,6 +603,13 @@ class Base extends Controller
return str_replace(array_keys($replacements), array_values($replacements), $str);
}
public function blueIntegerChange($string){
return preg_replace_callback('/\[(\d+)\]/', function($matches) {
return '<blue>[' . $matches[1] . ']</blue>';
}, $string);
}
public function getBoardsForJournal($journal_id, $aar = false)
{
$ca_board = [];

View File

@@ -5,7 +5,12 @@ use app\api\controller\Base;
use PaypalServerSdkLib\Authentication\ClientCredentialsAuthCredentialsBuilder;
use PaypalServerSdkLib\Environment;
use PaypalServerSdkLib\Models\Builders\AmountWithBreakdownBuilder;
use PaypalServerSdkLib\Models\Builders\ExperienceContextBuilder;
use PaypalServerSdkLib\Models\Builders\OrderApplicationContextBuilder;
use PaypalServerSdkLib\Models\Builders\OrderRequestBuilder;
use PaypalServerSdkLib\Models\Builders\PaymentSourceBuilder;
use PaypalServerSdkLib\Models\Builders\PaypalWalletBuilder;
use PaypalServerSdkLib\Models\Builders\PaypalWalletExperienceContextBuilder;
use PaypalServerSdkLib\Models\Builders\PurchaseUnitRequestBuilder;
use PaypalServerSdkLib\PaypalServerSdkClientBuilder;
use think\Db;
@@ -13,8 +18,8 @@ use think\Queue;
use think\Validate;
class Order extends base{
protected $PAYPAL_CLIENT_ID="ARyoAhBNlTMDEBb6QvJYmK0gA4cfSS6WY0Vr2uJhX3NOe7V9qVCJuNwuRHRO09WGcTgS5AkuTIgRZDcx";
protected $PAYPAL_CLIENT_SECRET="EPrmkePbt1hFGssdQkAHM11AACGKzcHoc-RjmyomOWhKJSpTDXlLdpwzjgM24XajiwwAIXyvbYd8j7Uo";
protected $PAYPAL_CLIENT_ID="ATqBigrhcNdqR8J83aDjTOoJHsAVz0U45JRY4H0stcEcv0mQrMDHQmyrydQInYd1w4lJ1ee3Wsblm2WP";
protected $PAYPAL_CLIENT_SECRET="EJL5CtykvRiMZ1apKrX4zDX03d01CuxgrUi6-D7K45NgNQAGGY0Kj0Du9tL04Zc3aDBgxgZ4JLErSQp3";
public function __construct(\think\Request $request = null)
{
@@ -32,10 +37,21 @@ class Order extends base{
return jsonError($rule->getError());
}
$article_info = $this->article_obj->where("article_id",$data['article_id'])->find();
if($article_info['is_buy']==1){
return jsonError("paid");
}
$journal_info = $this->journal_obj->where("journal_id",$article_info['journal_id'])->find();
$check = $this->order_obj->where("user_id",$article_info['user_id'])->where("article_id",$data['article_id'])->whereIn("state",[0,1])->find();
if($check){
$re['detail'] = $check;
$ii = $this->createPaypalOrder($check['real_fee']);
if(!isset($ii['jsonResponse']['status'])||$ii['jsonResponse']['status']!="CREATED"){
return jsonError("system error!");
}else{
$check['paypal_order_id'] = $ii['jsonResponse']['id'];
}
$this->order_obj->update($check);
$re['paypal'] = $ii;
return jsonSuccess($re);
}
$insert['user_id'] = $article_info['user_id'];
@@ -43,9 +59,16 @@ class Order extends base{
$insert["article_id"] = $data['article_id'];
$insert['order_fee'] = $journal_info['fee'];
$insert['real_fee'] = $journal_info['fee'];
$paypal = $this->createPaypalOrder($insert['real_fee']);
if(!isset($paypal['jsonResponse']['status'])||$paypal['jsonResponse']['status']!="CREATED"){
return jsonError("system error");
}else{
$insert['paypal_order_id'] = $paypal['jsonResponse']['id'];
}
$insert['ctime'] = time();
$id = $this->order_obj->insertGetId($insert);
$re['detail'] = $this->order_obj->where("order_id",$id)->find();
$re['paypal'] = $paypal;
return jsonSuccess($re);
}
@@ -61,16 +84,16 @@ class Order extends base{
return jsonError($rule->getError());
}
$list = $this->order_obj->where("user_id",$data['user_id'])->where("state",$data['state'])->select();
$re['list'] = $list;
foreach ($list as $k=>$v){
$article = $this->article_obj->where("article_id",$v['article_id'])->find();
$list[$k]['article_detail'] = $article;
$list[$k]['journal_detail'] = $this->journal_obj->where("journal_id",$article['journal_id'])->find();
}
$re['list'] = $list;
return jsonSuccess($re);
}
private function handleResponse($response)
{
$jsonResponse = json_decode($response->getBody(), true);
@@ -80,65 +103,45 @@ class Order extends base{
];
}
public function mytest(){
$url = 'https://api-m.sandbox.paypal.com/v1/oauth2/token';
// PayPal client credentials (replace these with your own credentials)
$clientId = $this->PAYPAL_CLIENT_ID; // 替换为您的 client_id
$clientSecret = $this->PAYPAL_CLIENT_SECRET; // 替换为您的 client_secret
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/oauth2/token'); // PayPal 沙盒环境的 URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应而不是输出
curl_setopt($ch, CURLOPT_POST, true); // 设置为 POST 请求
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ':' . $clientSecret); // 设置基本认证Basic Auth
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded' // 设置 Content-Type 为 x-www-form-urlencoded
public function preOrderDetail(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials'); // 设置表单参数
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
// 如果有错误,输出错误信息
echo 'Error: ' . curl_error($ch);
} else {
// 请求成功,解析响应
$responseData = json_decode($response, true); // 将 JSON 响应转为数组
if (isset($responseData['access_token'])) {
echo "Access Token: " . $responseData['access_token']; // 输出获取的 Access Token
} else {
echo "Error: Unable to retrieve access token. Response: " . json_encode($responseData); // 如果没有获取到 Token输出错误信息
}
if(!$rule->check($data)){
return jsonError($rule->getError());
}
curl_close($ch);
}
public function mytest1(){
$re = $this->createPaypalOrder();
$article_info = $this->article_obj->where("article_id",$data['article_id'])->find();
$journal_info = $this->journal_obj->where("journal_id",$article_info['journal_id'])->find();
$user_info = $this->user_obj->where("user_id",$article_info['user_id'])->find();
$re['article_detail'] = $article_info;
$re['journal_detail'] = $journal_info;
$re['user_detail'] = $user_info;
return jsonSuccess($re);
}
private function createPaypalOrder()
public function mytt(){
$re = $this->createPaypalOrder(600);
return jsonSuccess($re);
}
private function createPaypalOrder($fee)
{
$client = PaypalServerSdkClientBuilder::init()
->clientCredentialsAuthCredentials(
ClientCredentialsAuthCredentialsBuilder::init(
$this->PAYPAL_CLIENT_ID,
$this->PAYPAL_CLIENT_SECRET
)
)
->environment(Environment::SANDBOX)
->build();
$client = $this->createClient();
$orderBody = [
"body" => OrderRequestBuilder::init("CAPTURE", [
PurchaseUnitRequestBuilder::init(
AmountWithBreakdownBuilder::init("USD", "100")->build()
AmountWithBreakdownBuilder::init("USD", $fee)->build()
)->build(),
])->build(),
// PaymentSourceBuilder::init()->paypal(PaypalWalletBuilder::init()->experienceContext(
// PaypalWalletExperienceContextBuilder::init()->returnUrl("https://www.baidu.com")->build()
// )->build())->build(),
])->applicationContext(
OrderApplicationContextBuilder::init()->returnUrl("www.baidu.com")->build()
)->build(),
];
$apiResponse = $client->getOrdersController()->ordersCreate($orderBody);
@@ -147,4 +150,89 @@ class Order extends base{
public function testCreat(){
$client = PaypalServerSdkClientBuilder::init()
->clientCredentialsAuthCredentials(
ClientCredentialsAuthCredentialsBuilder::init(
"AeTurTFJvsivep-zB7vigyuBHX_cyzLqY5K0GCHLaOrs0eHaXA5V-fwJoVEFjlvN1jK_IqYoEbKEBKiH",
"EA-F_RYl1oJBTjHYn87L7vnNv-mWp5yRyTjmkVCOD_bu5T9nfm0E6rfNRKALj1n6AH70QKqB-mmO6tsE"
)
)
->environment(Environment::SANDBOX)
->build();
$orderBody = [
"body"=> OrderRequestBuilder::init("CAPTURE",[
]
)->build()
];
}
public function completeOrder(){
$data = $this->request->post();
$rule = new Validate([
"order_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$order_info = $this->order_obj->where("order_id",$data['order_id'])->find();
$this->captureOrder($order_info['paypal_order_id']);
$this->article_obj->where("article_id",$order_info['article_id'])->update(['is_buy'=>1]);
$this->order_obj->where("order_id",$data['order_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
public function mytest(){
$data = $this->request->post();
$rule = new Validate([
"order_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$info = $this->order_obj->where("order_id",$data['order_id'])->find();
$re = $this->getOrderStatus($info['paypal_order_id']);
return jsonSuccess($re);
}
private function getOrderStatus($orderId){
$client = $this->createClient();
return $client->getOrdersController()->ordersGet(["id"=>$orderId]);
}
private function createClient(){
return PaypalServerSdkClientBuilder::init()
->clientCredentialsAuthCredentials(
ClientCredentialsAuthCredentialsBuilder::init(
$this->PAYPAL_CLIENT_ID,
$this->PAYPAL_CLIENT_SECRET
)
)
->environment(Environment::SANDBOX)
->build();
}
private function captureOrder($orderID)
{
$client = $this->createClient();
$captureBody = [
"id" => $orderID,
];
$apiResponse = $client->getOrdersController()->ordersCapture($captureBody);
return $this->handleResponse($apiResponse);
}
}

View File

@@ -450,6 +450,20 @@ class Preaccept extends Base
}
public function clearMainsRemark(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['remark'=>"","state"=>0]);
return jsonSuccess([]);
}
public function searchDoi()
{
$data = $this->request->post();
@@ -606,7 +620,7 @@ class Preaccept extends Base
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['content'] = $this->replaceChinesePunctuation($this->removeExtraSpaces(trim($data['content'])));
$update['content'] = $this->formatMain($data['content']);
$update['state'] = 0;
$this->article_main_obj->where("am_id",$data['am_id'])->update($update);
return jsonSuccess([]);
@@ -699,8 +713,7 @@ class Preaccept extends Base
"amt_id"=>"require",
"table_data"=>"require",
"html_data"=>"require",
"title"=>"require",
"note"=>"require"
"title"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
@@ -708,7 +721,9 @@ class Preaccept extends Base
$update['table_data'] = $data['table_data'];
$update['html_data'] = $data['html_data'];
$update['title'] = $data['title'];
$update['note'] = $data['note'];
if (isset($data['note'])){
$update['note'] = $data['note'];
}
$this->article_main_table_obj->where("amt_id",$data['amt_id'])->update($update);
return jsonSuccess([]);
}

View File

@@ -913,14 +913,14 @@ class Production extends Base
}
public function bekjournal($str)
{
preg_match("/[0-9]{4}/", $str, $math);
$year = $math[0];
$frag[0] = trim(substr($str, 0, stripos($str, $year)));
$frag[1] = substr($str, stripos($str, $year));
return $frag;
}
// public function bekjournal($str)
// {
// preg_match("/[0-9]{4}/", $str, $math);
// $year = $math[0];
// $frag[0] = trim(substr($str, 0, stripos($str, $year)));
// $frag[1] = substr($str, stripos($str, $year));
// return $frag;
// }
public function prgeAuthor($author)
{
@@ -1214,10 +1214,14 @@ class Production extends Base
$mainList[] = $main_string;
}
$typesetInfo['mainText'] = json_encode($mainList);
$typesetInfo['images'] = $images;
$typesetInfo['tables'] = $tables;
$typesetInfo['images'] = $images==[]?null:$images;
$typesetInfo['tables'] = $tables==[]?null:$tables;
// $url = $this->ts_base_url."api/typeset/webGetDocx";
// return jsonSuccess($typesetInfo);
// $url = $this->ts_base_url."api/typeset/createDocx";
$url = "http://192.168.110.110:8081/typeset/createDocx";
// $url = "http://192.168.110.110:8081/typeset/testqt";
$res = object_to_array(json_decode(myPost1($url, $typesetInfo)));
@@ -1226,6 +1230,12 @@ class Production extends Base
return jsonError('create error');
}
$file_res = date('Ymd') . DS . $res['data']['file'];
$tf_insert['p_article_id'] = $p_info['p_article_id'];
$tf_insert['url'] = $file_res;
$tf_insert['ctime'] = time();
$this->production_article_frag_obj->insert($tf_insert);
return jsonSuccess($res);
}