* @date 2020/7/9 9:39 * * @return mixed * @throws \think\exception\DbException */ public function index() { $where = []; //组合搜索 !empty(input('name')) && $where[] = ['name', 'like', '%' . input('name') . '%']; !empty(input('mobile')) && $where[] = ['mobile', 'eq', input('mobile')]; $withdraw = model('common/UsersWithdraw'); return IResponse::paginate($withdraw->where($where)->order(['created_at'=>'desc'])->with(['user']) ->paginate(input('limit'),false)); } /** * 更新数据 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/6/11 14:20 * * @param $id * @return \think\response\Json */ public function update($id) { // 接收数据 $params = $this->request->param(); // 查询用户 $withdraw = model('common/UsersWithdraw')->findBy($id); // 状态操作 $valid = $this->validate($params, [ 'status|配置参数' => 'require|integer' ]); // 错误返回 (true !== $valid) && IResponse::failure($valid); // 更新信息 $withdraw->updateBy($id, $params); Db::startTrans(); try { if ($params['status'] == 2) { // 查用户 $user = model('common/Users')->getBy($withdraw['user_id']); // 更新资金 $user->where(['id' => $withdraw['user_id']])->setDec('balance', $withdraw['amount']); // 写入资金记录 model('common/UsersBalanceRecord')->storeBy([ 'user_id' => $withdraw['user_id'], 'dec_amount' => $withdraw['amount'], 'aft_amount' => round($user['balance'] - $withdraw['amount']), 'remark' => '主动提现,¥' . $withdraw['amount'] . ',单号;' . $withdraw['draw_no'] ]); // 加载配置 $wechat = sys_config('', 'wechat'); $config = [ // 前面的appid什么的也得保留哦 'app_id' => $wechat['mini_appid'], 'mch_id' => $wechat['pay_mch_id'], 'key' => $wechat['pay_secret_key'], // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) 'cert_path' => $wechat['cert_path'], // XXX: 绝对路径!!!! 'key_path' => $wechat['key_path'], // XXX: 绝对路径!!!! // 'notify_url' => 'https://api.gxrrj.cn/api/v1/wechat/notify', // 'notify_url' => 'http://rrj.gxnwsoft.com/api/v1/wechat/refundNotify', // 'sandbox' => true ]; // 创建应用实例 $app = Factory::payment($config); $result = $app->transfer->toBalance([ 'partner_trade_no' => $withdraw['draw_no'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) 'openid' => $user['open_id'], 'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 're_user_name' => $withdraw['realname'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名 'amount' => $withdraw['amount'] * 100, // 企业付款金额,单位为分 'desc' => '用户提现', // 企业付款操作说明信息。必填 ]); app()->log(json_encode($result)); } Db::commit(); } catch (\Exception | GuzzleException $e) { Db::rollback(); } return IResponse::success('成功'); } /** * 删除 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/6/11 14:26 * * @param $id * @return \think\response\Json */ public function delete($id) { model('common/UsersWithdraw')->deleteBy($id); return IResponse::success([],'删除提现申请单成功'); } /** * 用户批量操作 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/6/11 14:34 * * @return mixed */ public function plectron(){ // 收参数 $params = $this->request->param(); foreach (str2arr($params['ids']) as $id){ $withdraw = model('common/UsersWithdraw')->getBy($id); if ($this->request->isDelete()){ $withdraw->deleteBy($id); }else // 等待审核状态下才做更新 if ($withdraw['status'] == 1){ $withdraw->allowField(true)->updateBy($id, $params); Db::startTrans(); try { if ($params['status'] == 2){ // 查用户 $user = model('common/Users')->getBy($withdraw['user_id']); // 更新资金 $user->where(['id' => $withdraw['user_id']])->setDec('balance', $withdraw['amount']); // 写入资金记录 model('common/UsersBalanceRecord')::create([ 'user_id' => $withdraw['user_id'], 'dec_amount' => $withdraw['amount'], 'aft_amount' => round($user['balance'] - $withdraw['amount']), 'remark' => '主动提现,¥' . $withdraw['amount'] . ',单号;' . $withdraw['draw_no'] ], true); } Db::commit(); }catch (\Exception $e){ Db::rollback(); } } } return IResponse::success([],'操作成功'); } }