259 lines
7.5 KiB
PHP
259 lines
7.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Events\CouponCardEvent;
|
|
use App\Models\CouponCard;
|
|
use App\Models\Scenic;
|
|
use App\Models\UploadQrcode;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use DB;
|
|
use App\Models\AdminLog;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Event;
|
|
use Ixudra\Curl\Facades\Curl;
|
|
|
|
class HandleController extends BaseController
|
|
{
|
|
public function handle($type, Request $request)
|
|
{
|
|
switch ($type) {
|
|
case 'del':
|
|
return $this->delete($request);
|
|
break;
|
|
case 'edit':
|
|
return $this->editField($request);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 软删除开启
|
|
* @param $table
|
|
* @return int
|
|
*/
|
|
public function deletType($table)
|
|
{
|
|
|
|
switch ($table) {
|
|
case 'merchants':
|
|
case 'gateways':
|
|
case 'gateway_winds':
|
|
//商户开启软删除
|
|
return 1;
|
|
case 'servers':
|
|
return 1;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function editField(Request $request)
|
|
{
|
|
$table = $request->input('table'); // 表名
|
|
$id_name = $request->input('id_name', 'id'); // 表主键id名
|
|
$id_value = $request->input('id_value'); // 表主键id值
|
|
$field = $request->input('field'); // 修改哪个字段
|
|
$value = $request->input('value'); // 修改字段值
|
|
if ($table == '' or $id_name == '' or $id_value == '' or $field == '' or $value == '') {
|
|
$data = [
|
|
'error' => 1,
|
|
'msg' => '参数不正确'
|
|
|
|
];
|
|
return response()->json($data);
|
|
}
|
|
$model = DB::table($table)->where($id_name, $id_value)->update([$field => $value]);
|
|
|
|
if ($table == 'gateways') {
|
|
write_gateway();//更新支付通道信息
|
|
}
|
|
if ($table == 'merchants') {
|
|
write_merchant();//更新商户信息
|
|
}
|
|
|
|
if ($model) {
|
|
$data = [
|
|
'error' => 0,
|
|
'msg' => '设置成功'
|
|
|
|
];
|
|
return response()->json($data);
|
|
} else {
|
|
$data = [
|
|
'error' => 0,
|
|
'msg' => '设置失败'
|
|
|
|
];
|
|
return response()->json($data);
|
|
}
|
|
}
|
|
|
|
private function send2ZhanxinDel(){
|
|
// $data = [];
|
|
// $chanxinconfig = config('qrcodeurl.zhanxin');
|
|
// Curl::to($chanxinconfig['baseurl'] . $chanxinconfig['del'])->witData($data)->post();
|
|
}
|
|
|
|
public function delete(Request $request)
|
|
{
|
|
$id = $request->input('id');
|
|
$type_id = $request->input('type_id', 'id');
|
|
$table = $request->input('table');
|
|
$handle_str = $request->input('handle_str');
|
|
if ($table == '') {
|
|
$table = $request->input('model');
|
|
}
|
|
$rdel = $this->deletType($table);
|
|
|
|
if ($id == '') {
|
|
$data = [
|
|
'error' => 1,
|
|
'msg' => '编号不能为空',
|
|
'type' => 'del'
|
|
|
|
];
|
|
return response()->json($data);
|
|
}
|
|
if ($table == '') {
|
|
$data = [
|
|
'error' => 1,
|
|
'msg' => '没有选择数据表',
|
|
'type' => 'del'
|
|
|
|
];
|
|
return response()->json($data);
|
|
}
|
|
|
|
|
|
$id_arr = explode(",", $id);
|
|
if (count($id_arr) <= 0) {
|
|
$data = [
|
|
'error' => 1,
|
|
'msg' => '编号不能为空',
|
|
'type' => 'del'
|
|
|
|
];
|
|
return response()->json($data);
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
$result = DB::table($table)->whereIn($type_id, $id_arr);
|
|
|
|
$this->eventCustom($table, $id_arr);
|
|
|
|
if ($rdel) {
|
|
$result = $result->update(['deleted_at' => date('Y-m-d H:i:s', time())]);
|
|
} else {
|
|
$result = $result->delete();
|
|
|
|
}
|
|
|
|
if ($result && $this->deleteCustom($table, $id_arr)) {
|
|
|
|
|
|
DB::commit();
|
|
|
|
$this->insertLog($handle_str . '删除 ID:' . implode('、', $id_arr));
|
|
$data = [
|
|
'error' => 0,
|
|
'msg' => '删除成功',
|
|
'type' => 'del'
|
|
|
|
];
|
|
|
|
if ($table == 'upload_qrcodes') {
|
|
$where[] = [function ($query) use ($id_arr) {
|
|
$query->whereIn('id', $id_arr);
|
|
}];
|
|
$res = DB::table($table)->where($where)->get(['id', 'uid']);
|
|
$uidArr = [];
|
|
foreach ($res as $r) {
|
|
$uidArr[] = $r->uid;
|
|
}
|
|
$uidArr = array_unique($uidArr);
|
|
Log::channel('zhanxin')->info('删除请求数据', $uidArr);
|
|
foreach ($uidArr as $r) {
|
|
$this->delUid($r);
|
|
}
|
|
}
|
|
return response()->json($data);
|
|
}
|
|
DB::rollBack();
|
|
$data = [
|
|
'error' => 1,
|
|
'msg' => '删除失败',
|
|
'type' => 'del'
|
|
|
|
];
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function deleteCustom($table, $id)
|
|
{
|
|
switch ($table) {
|
|
case 'merchants_bak':
|
|
//商户需要删除费率表
|
|
$r = DB::table('merchant_ratios')->whereIn('merchant_id', $id)->delete();
|
|
$money_r = DB::table('merchant_wallets')->whereIn('merchant_id', $id)->delete();
|
|
return $r && $money_r;
|
|
break;
|
|
case 'merchants':
|
|
write_merchant();//更新商户信息
|
|
break;
|
|
case 'gateways':
|
|
write_gateway();//更新通道信息
|
|
break;
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function eventCustom($table, $id)
|
|
{
|
|
switch ($table) {
|
|
|
|
case 'merchants':
|
|
//更新商户汇率表
|
|
write_merchant_ratio();
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
private function delUid($uid){
|
|
$ts = time();
|
|
$chanxinconfig = config('qrcodeurl.zhanxin');
|
|
$data['userid'] = $uid;
|
|
$data['ts'] = strval($ts);
|
|
$str = 'uid=' . $uid . '&ts=' . $ts . '&' . $chanxinconfig['secret'];
|
|
Log::channel('zhanxin')->info('删除请求' . $str, []);
|
|
$data['key'] = strtolower(md5($str));
|
|
Log::channel('zhanxin')->info('删除请求数据', $data);
|
|
$url = $chanxinconfig['baseurl'] . $chanxinconfig['del'];
|
|
$data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
|
|
$curl = curl_init();
|
|
$headerArray = array("Content-type:application/json;charset='utf-8'", "Accept:application/json");
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_URL => $url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
|
CURLOPT_HTTPHEADER => $headerArray,
|
|
));
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
$response = curl_exec($curl);
|
|
curl_close($curl);
|
|
Log::channel('zhanxin')->info('删除返回数据' . $response, is_array($response) ? $response : []);
|
|
return $response;
|
|
}
|
|
}
|