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.
112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Models\CheckoutApply;
|
|
use App\Models\User;
|
|
use App\Utils\Tools;
|
|
use App\Controllers\AdminController;
|
|
use App\Services\AdminDataMasker;
|
|
use App\Services\AdminPermission;
|
|
|
|
use App\Utils\SafeDatatables as Datatables;
|
|
use App\Utils\DatatablesHelper;
|
|
|
|
class CheckoutController extends AdminController
|
|
{
|
|
public function index($request, $response, $args)
|
|
{
|
|
$table_config['total_column'] = Array("op" => "操作", "id" => "ID", "email" => "用户邮箱", "userid" => "用户ID",
|
|
"money" => "提现金额", "zhifubao" => "支付宝", "datetime" => "申请时间", "endtime" => "处理时间",
|
|
"status" => "状态");
|
|
$table_config['default_show_column'] = Array("op", "id", "email", "money", "zhifubao", "datetime", "endtime", "status");
|
|
$table_config['ajax_url'] = 'checkout/ajax';
|
|
|
|
return $this->view()->assign('table_config', $table_config)->display('admin/checkout.tpl');
|
|
}
|
|
|
|
public function deal($request, $response, $args)
|
|
{
|
|
$id = $request->getParam('id');
|
|
$apply = CheckoutApply::find($id);
|
|
|
|
$applyUser = User::find($apply->userid);
|
|
|
|
if ($applyUser != null) {
|
|
$aff_before = $applyUser->aff_money;
|
|
$apply_money = $apply->money;
|
|
$aff_after = $aff_before - $apply_money;
|
|
$applyUser->aff_money = $aff_after;
|
|
$applyUser->save();
|
|
|
|
$apply->endtime = time();
|
|
$apply->status = 1;
|
|
$apply->save();
|
|
|
|
$rs['ret'] = 1;
|
|
$rs['msg'] = "已处理提现成功,用户佣金由".$aff_before."元减为".$aff_after."元";
|
|
}
|
|
else {
|
|
$apply->delete();
|
|
$rs['ret'] = 0;
|
|
$rs['msg'] = "提现用户不存在,已删除本次申请";
|
|
}
|
|
|
|
return $response->getBody()->write(json_encode($rs));
|
|
}
|
|
|
|
public function ajax($request, $response, $args)
|
|
{
|
|
$datatables = new Datatables(new DatatablesHelper());
|
|
|
|
$total_column = Array("op" => "操作", "id" => "ID", "email" => "用户邮箱", "userid" => "用户ID",
|
|
"money" => "提现金额", "zhifubao" => "支付宝", "datetime" => "申请时间", "endtime" => "处理时间",
|
|
"status" => "状态");
|
|
|
|
$key_str = '';
|
|
foreach($total_column as $single_key => $single_value) {
|
|
if($single_key == 'op') {
|
|
$key_str .= 'id as op';
|
|
continue;
|
|
}
|
|
|
|
$key_str .= ','.$single_key;
|
|
}
|
|
$datatables->query('Select '.$key_str.' from checkout_apply');
|
|
|
|
$datatables->edit('op', function ($data) {
|
|
if (!AdminPermission::isSuperAdmin()) {
|
|
return '<span class="text-muted">只读</span>';
|
|
}
|
|
return ' <a class="btn btn-brand-accent" '.($data['status'] == 1 ? 'disabled' : 'id="deal" value="'.$data['id'].'" href="javascript:void(0);" onClick="deal_modal_show(\''.$data['id'].'\')"').'>'.($data['status'] == 1 ? '已处理' : '处理').'</a>';
|
|
});
|
|
|
|
$datatables->edit('email', function ($data) {
|
|
return AdminDataMasker::email($data['email']);
|
|
});
|
|
|
|
$datatables->edit('zhifubao', function ($data) {
|
|
return AdminDataMasker::paymentAccount($data['zhifubao']);
|
|
});
|
|
|
|
$datatables->edit("endtime", function ($data) {
|
|
return ($data['status'] == 0 ? '未处理': date('Y-m-d H:i:s', $data['endtime']));
|
|
});
|
|
|
|
$datatables->edit('status', function ($data) {
|
|
return $data['status'] == 0 ? "待处理" : "已处理";
|
|
});
|
|
|
|
$datatables->edit('money', function ($data) {
|
|
return $data['money']."元";
|
|
});
|
|
|
|
$datatables->edit('datetime', function ($data) {
|
|
return date('Y-m-d H:i:s', $data['datetime']);
|
|
});
|
|
|
|
$body = $response->getBody();
|
|
$body->write($datatables->generate());
|
|
}
|
|
}
|