作者 何书鹏

佣金提现

... ... @@ -174,6 +174,32 @@ class User extends Model
return $user;
}
/**
* 用户佣金增加
* @return [type] [description]
*/
public static function commissionAdd($user = null, $origin_money = 0, $type = '', $item_id = 0)
{
$money = sprintf("%.2f", $origin_money); // 保留两位小数
if (is_numeric($user)) {
$user = User::where('id', $user)->find();
}
if (!is_null($user) && $money > 0) {
$user->commission = Db::raw('commission + ' . $money);
$user->save(); // 增加钱包余额
// 记录 UserCommissionLog
\app\api\model\UserCommissionLog::doAdd($user, $money, $type, $item_id, 1);
return $user;
}
Log::write($type . "--commissionAdd---增加失败 - 金额为:"
. $money . " - 用户 id 为" . (is_null($user) ? 'no user' : $user->id));
return $user;
}
public static function moneyReduce($user = null, $origin_money = 0, $type = '', $item_id = 0, $ext = [])
{
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 佣金提现
... ... @@ -71,4 +72,40 @@ class UserCommissionApply extends Backend
return $this->view->fetch();
}
public function applyOper($id)
{
$status = $this->request->post('status', -1);
$status_msg = $this->request->post('status_msg', '');
$apply = $this->model->get($id);
if ($apply->status != 0) {
$this->error('该提现申请已处理,不能重复处理');
}
$apply = Db::transaction(function () use ($apply, $status, $status_msg) {
$apply->status = $status;
$apply->status_msg = $status_msg;
$apply->save();
if ($status == -1) {
// 把提现的金额重新加回去
\addons\shopro\model\User::commissionAdd($apply->user_id, $apply->money, 'cash_error', $apply->id);
}
// 提现结果通知
// $user = \addons\shopro\model\User::where('id', $apply['user_id'])->find();
// $user->notify(
// new \addons\shopro\notifications\Wallet([
// 'apply' => $apply,
// 'event' => 'wallet_apply'
// ])
// );
return $apply;
});
return $this->success('操作成功', null, $apply);
}
}
... ...
... ... @@ -17,7 +17,7 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('user_commission_apply/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('user_commission_apply/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('user_commission_apply/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('user_commission_apply/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('user_commission_apply/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
... ... @@ -30,7 +30,7 @@
</ul>
</div>
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('user_commission_apply/recyclebin')?'':'hide'}" href="user_commission_apply/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('user_commission_apply/recyclebin')?'':'hide'}" href="user_commission_apply/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('user_commission_apply/edit')}"
... ...
... ... @@ -50,7 +50,7 @@ class UserCommissionLog extends Model
}
public static function doAdd($user, $wallet, $type, $item_id, $is_add = 0, $ext = [])
public static function doAdd($user, $wallet, $type, $item_id, $is_add = 0)
{
// $self = new self();
... ...
... ... @@ -54,71 +54,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'user_commission_apply/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'user_commission_apply/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'user_commission_apply/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
$(document).on("click", ".withdrawrefuse", function () {
let id = $(this).attr("data-id")
let sta=$(this).attr("data-sta")
Layer.prompt({title: __('请输入驳回理由'), formType: 0}, function (value, index) {
Backend.api.ajax({
url: "shopro/user_wallet_apply/applyOper/id/" + id,
url: "user_commission_apply/applyOper/id/" + id,
data: {
status:sta,
status_msg:value
... ... @@ -131,11 +72,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
});
$(document).on("click", ".withdrawreal", function () {
let id = $(this).attr("data-id")
let sta=$(this).attr("data-sta")
Backend.api.ajax({
url: "shopro/user_wallet_apply/applyOper/id/" + id,
url: "user_commission_apply/applyOper/id/" + id,
data: {
status:sta,
status_msg:''
... ... @@ -146,6 +88,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
});
// 为表格绑定事件
Table.api.bindevent(table);
},
... ... @@ -161,7 +104,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// 初始化表格
table.bootstrapTable({
url: 'shopro/user_wallet_apply/recyclebin' + location.search,
url: 'user_commission_apply/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
... ... @@ -187,7 +130,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'shopro/user_wallet_apply/restore',
url: 'user_commission_apply/restore',
refresh: true
},
{
... ... @@ -195,7 +138,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'shopro/user_wallet_apply/destroy',
url: 'user_commission_apply/destroy',
refresh: true
}
],
... ...