diff --git a/app/data/controller/UserTransfer.php b/app/data/controller/UserTransfer.php index ac51dc46b..9f324d461 100644 --- a/app/data/controller/UserTransfer.php +++ b/app/data/controller/UserTransfer.php @@ -3,6 +3,7 @@ namespace app\data\controller; use app\data\service\UserService; +use app\data\service\UserUpgradeService; use think\admin\Controller; use think\admin\extend\CodeExtend; use think\admin\service\AdminService; @@ -20,6 +21,25 @@ class UserTransfer extends Controller */ private $table = 'DataUserTransfer'; + /** + * 奖励提现配置 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function config() + { + $this->skey = 'TransferRule'; + $this->title = '奖励提现配置'; + if ($this->request->isGet()) { + $this->data = sysdata($this->skey); + $this->fetch(); + } else { + sysdata($this->skey, $this->request->post()); + $this->success('配置修改成功'); + } + } + /** * 用户提现管理 * @menu true diff --git a/app/data/controller/api/auth/Rebate.php b/app/data/controller/api/auth/Rebate.php index d6ac93973..cf7b96175 100644 --- a/app/data/controller/api/auth/Rebate.php +++ b/app/data/controller/api/auth/Rebate.php @@ -3,6 +3,8 @@ namespace app\data\controller\api\auth; use app\data\controller\api\Auth; +use app\data\service\UserUpgradeService; +use think\admin\extend\CodeExtend; /** * 用户返利管理 @@ -28,4 +30,55 @@ class Rebate extends Auth $query = $this->_query($this->table)->where(['uid' => $this->uuid]); $query->like('create_at#date')->order('id desc')->page(true, false, false, 15); } + + /** + * 提交用户提现审核 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function addUsed() + { + if (!empty($this->user['status'])) { + $this->error('账户异常,请联系客服'); + } + $data = $this->_vali([ + 'amount.require' => '提现金额不能为空', + 'remark.default' => '用户主动提交审核', + ]); + $params = sysdata('TransferRule') ?: []; + if (empty($params['transfer_state'])) $this->error('提现功能已经关闭'); + [$total, $count] = UserUpgradeService::instance()->syncRebate($this->uuid); + if ($total - $count - $data['amount'] < 0) $this->error('可提现金额不足'); + if ($data['amount'] < $params['transfer_min']) $this->error("提现不能少于{$params['transfer_min']}元"); + if ($data['amount'] > $params['transfer_max']) $this->error("提现不能大于{$params['transfer_max']}元"); + $result = $this->app->db->name('DataUserTransfer')->insert([ + 'uid' => $this->uuid, + 'code' => CodeExtend::uniqidDate(20, 'T'), + 'openid' => $this->user['openid1'], + 'status' => $params['transfer_audit'] > 0 ? 2 : 1, + 'amount' => $data['amount'], + 'remark' => $data['remark'], + ]); + if ($result !== false) { + UserUpgradeService::instance()->syncRebate($this->uuid); + $this->success('提交申请成功'); + } else { + $this->error('提交申请失败'); + } + } + + /** + * 获取用户提现记录 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getUsed() + { + $date = input('date', date('Y-m-')); + $map = [['mid', '=', $this->mid], ['create_at', 'like', "{$date}%"]]; + $query = $this->_query('DataUserTransfer')->in('status')->order('id desc'); + $this->success('获取提现记录', $query->where($map)->page(true, false, false, 15)); + } } \ No newline at end of file diff --git a/app/data/service/UserUpgradeService.php b/app/data/service/UserUpgradeService.php index 12ad88daf..b5ffe7d35 100644 --- a/app/data/service/UserUpgradeService.php +++ b/app/data/service/UserUpgradeService.php @@ -69,13 +69,13 @@ class UserUpgradeService extends Service */ public function syncRebate(int $uuid): array { - $total = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount>0 and deleted=0")->sum('amount')); - $count = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount<0 and deleted=0")->sum('amount')); - $lockd = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=0 and amount<0 and deleted=0")->sum('amount')); + $count = abs($this->app->db->name('DataUserTransfer')->where("uid='{$uuid}' and status>0")->sum('amount')); + $total = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and deleted=0")->sum('amount')); + $locks = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=0 and deleted=0")->sum('amount')); $this->app->db->name('DataUser')->where(['id' => $uuid])->update([ - 'rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $lockd, + 'rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $locks, ]); - return [$total, $count, $lockd]; + return [$total, $count, $locks]; } /** diff --git a/app/data/view/user_transfer/config.html b/app/data/view/user_transfer/config.html new file mode 100644 index 000000000..a8bd1195e --- /dev/null +++ b/app/data/view/user_transfer/config.html @@ -0,0 +1,73 @@ +
+
+ +
+ 是否开启提现 + Transfer State +
+ {php} $data['transfer_state'] = $data['transfer_state'] ?? 0; {/php} + {foreach ['关闭用户提现', '开启用户提现'] as $k => $v} + {if $data.transfer_state eq $k} + + {else} + + {/if}{/foreach} +
+
+ +
+ 提现金额范围 + Transfer Range +
+
+ +
+   + - +
+ +
+
+
+ +
+ 提现是否需要审核 + Transfer Audit +
+ {php} $data['transfer_audit'] = $data['transfer_audit'] ?? 0; {/php} + {foreach ['提现无需审核', '提现需要审核'] as $k => $v} + {if $data.transfer_audit eq $k} + + {else} + + {/if}{/foreach} +
+
+ +
+ 用户提现描述内容 + Transfer Remark + +
+ +
+ +
+ +
+ + +
+ + +
\ No newline at end of file diff --git a/app/data/view/user_transfer/index.html b/app/data/view/user_transfer/index.html index 07534574b..a14127e05 100644 --- a/app/data/view/user_transfer/index.html +++ b/app/data/view/user_transfer/index.html @@ -1,6 +1,9 @@ {extend name="../../admin/view/main"} {block name="button"} + +提现配置 + 打款服务