207 lines
5.3 KiB
PHP
207 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Events\CouponCardEvent;
|
|
use App\Models\CouponCard;
|
|
use App\Models\Scenic;
|
|
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'
|
|
|
|
];
|
|
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;
|
|
}
|
|
}
|
|
}
|