You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
4.2 KiB
PHP
111 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class AspNetZhuanController extends Controller
|
|
{
|
|
public static $request;
|
|
public static $JF_BaseUrl = "http://220.174.210.111:82/jifen.aspx";//积分预存款Url
|
|
|
|
//获取用户积分和预存款
|
|
public static function GetJiFen_YuCunKuan($type, $ghzid)
|
|
{
|
|
$res = self::Get(self::$JF_BaseUrl . '?type=' . $type . '&ghzid=' . $ghzid,"查询剩余积分/预存款");
|
|
if ($type == 1) return $res['剩余积分'];
|
|
if ($type == 2) return $res['剩余预存款'];
|
|
}
|
|
//获取本次账单可使用的积分
|
|
public static function GetEnableCount($ghzid,$ysje,$ssje)
|
|
{
|
|
$res = self::Get(self::$JF_BaseUrl . '?type=3' . '&ghzid=' . $ghzid. '&ysje=' . $ysje. '&ssje=' . $ssje,"查询本单积分");
|
|
return $res['本次账单可抵扣积分'];
|
|
}
|
|
//使用积分
|
|
public static function UseJiFen($ghzid,$jifen,$yyid,$caozuorenid,$caozuorenmigncheng,$beizhu,$dingdanshijian){
|
|
$res = self::Get(self::$JF_BaseUrl . '?type=4' . '&ghzid=' . $ghzid. '&jifen=' . $jifen.'&yyid='.$yyid.'&caozuorenid='.$caozuorenid.'&caozuorenmigncheng='.urlencode($caozuorenmigncheng).'&beizhu='.urlencode($beizhu).'&dingdanshijian='.urlencode($dingdanshijian),"积分变更");
|
|
return true;
|
|
}
|
|
//使用预存款
|
|
public static function UseYuCunKuan($ghzid,$yucunkuan,$yyid,$yucunkuanleixing,$caozuorenid,$caozuorenmigncheng,$beizhu,$dingdanshijian)
|
|
{
|
|
$res = self::Get(self::$JF_BaseUrl . '?type=5' . '&ghzid=' . $ghzid. '&yucunkuan=' . $yucunkuan.'&yyid='.$yyid.'&yucunkuanleixing='.$yucunkuanleixing.'&caozuorenid='.$caozuorenid.'&caozuorenmigncheng='.urlencode($caozuorenmigncheng).'&beizhu='.urlencode($beizhu).'&dingdanshijian='.urlencode($dingdanshijian),"预存款变更");
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
public static function Get($url,$mark)
|
|
{
|
|
self::RequestLog($url, [], $mark, '.Net转发');
|
|
$response = Http::get($url);
|
|
if ($response->successful()) {
|
|
$res = $response->json();
|
|
|
|
self::$request->response_data = json_encode($res, JSON_UNESCAPED_UNICODE);
|
|
self::$request->save();
|
|
|
|
if ($res['code'] == "200") {
|
|
return $res;
|
|
} else {
|
|
throw new HttpResponseException(\Yz::echoError1("查询用户积分预存款失败:" . $res['msg']));
|
|
}
|
|
} else {
|
|
$status = $response->status();
|
|
// 获取响应体作为字符串
|
|
$body = $response->body();
|
|
|
|
self::$request->response_data = $body;
|
|
self::$request->save();
|
|
|
|
throw new HttpResponseException(\Yz::echoError1("查询用户积分预存款失败,status:" . $status . "body:" . $body));
|
|
}
|
|
}
|
|
|
|
public static function RequestLog($url, $post_data, $mark, $code = 0)
|
|
{
|
|
self::CheckTableName();
|
|
foreach ($post_data as $key => $post_datum) {
|
|
$str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE), 'utf-8');
|
|
$str_size = $str_len / 1024;
|
|
if ($str_size > 10) {
|
|
$post_data["$key"] = 'Row size too large';
|
|
}
|
|
}
|
|
$post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
|
|
self::$request->code = $code;
|
|
self::$request->mark = $mark;
|
|
self::$request->post_data = $post_data == '[]' ? '{}' : $post_data;
|
|
self::$request->request_url = $url;
|
|
self::$request->save();
|
|
}
|
|
|
|
public static function CheckTableName()
|
|
{
|
|
$table_name = 'zz_peis_log_' . date('ym');
|
|
$table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0];
|
|
if ($table_count->c === 0) {
|
|
Schema::create($table_name, function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('code', 50)->index();
|
|
$table->string('mark', 50)->index();
|
|
$table->text('post_data');
|
|
$table->text('response_data')->nullable();
|
|
$table->string('request_url', 1000);
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
self::$request = new \App\Models\PEISLog();
|
|
self::$request->setTable($table_name);
|
|
}
|
|
|
|
}
|