getList($where, '*', $post['page'], $post['pageSize'], 'sort asc,id asc'); return app('json')->success([ 'list' => $list[1], 'total' => $list[0], 'page' => $post['page'], 'pageSize' => $post['pageSize'] ]); } /** * 充值配置详情 * @param Request $request * @return mixed */ public function configDetail(Request $request) { $post = UtilService::getMore([ ['id', 0] ], $request); if ($post['id'] <= 0) { return app('json')->fail('参数错误'); } $rechargeConfig = new RechargeConfig(); $config = $rechargeConfig->getById($post['id']); if (!$config) { return app('json')->fail('充值配置不存在'); } return app('json')->success($config); } /** * 添加充值配置 * @param Request $request * @return mixed */ public function configAdd(Request $request) { $post = UtilService::getMore([ ['title', ''], ['price', 0], ['integral', 0], ['give_integral', 0], ['sort', 0], ['is_show', 1], ['is_default', 0], ['min_price', 0], ['max_price', 0], ['content', ''] ], $request); if (empty($post['title'])) { return app('json')->fail('套餐名称不能为空'); } if ($post['price'] <= 0) { return app('json')->fail('充值金额必须大于0'); } if ($post['integral'] <= 0) { return app('json')->fail('获得积分必须大于0'); } $rechargeConfig = new RechargeConfig(); $data = [ 'title' => $post['title'], 'price' => $post['price'], 'integral' => $post['integral'], 'give_integral' => $post['give_integral'], 'sort' => $post['sort'], 'is_show' => $post['is_show'], 'is_default' => $post['is_default'], 'min_price' => $post['min_price'], 'max_price' => $post['max_price'], 'content' => $post['content'], 'add_time' => time(), 'update_time' => time() ]; $result = $rechargeConfig->saveData($data); if (!$result) { return app('json')->fail('添加失败'); } return app('json')->success('添加成功'); } /** * 编辑充值配置 * @param Request $request * @return mixed */ public function configEdit(Request $request) { $post = UtilService::getMore([ ['id', 0], ['title', ''], ['price', 0], ['integral', 0], ['give_integral', 0], ['sort', 0], ['is_show', 1], ['is_default', 0], ['min_price', 0], ['max_price', 0], ['content', ''] ], $request); if ($post['id'] <= 0) { return app('json')->fail('参数错误'); } if (empty($post['title'])) { return app('json')->fail('套餐名称不能为空'); } if ($post['price'] <= 0) { return app('json')->fail('充值金额必须大于0'); } if ($post['integral'] <= 0) { return app('json')->fail('获得积分必须大于0'); } $rechargeConfig = new RechargeConfig(); $config = $rechargeConfig->getById($post['id']); if (!$config) { return app('json')->fail('充值配置不存在'); } $data = [ 'title' => $post['title'], 'price' => $post['price'], 'integral' => $post['integral'], 'give_integral' => $post['give_integral'], 'sort' => $post['sort'], 'is_show' => $post['is_show'], 'is_default' => $post['is_default'], 'min_price' => $post['min_price'], 'max_price' => $post['max_price'], 'content' => $post['content'], 'update_time' => time() ]; $result = $rechargeConfig->updateConfig($post['id'], $data); if (!$result) { return app('json')->fail('编辑失败'); } return app('json')->success('编辑成功'); } /** * 删除充值配置 * @param Request $request * @return mixed */ public function configDelete(Request $request) { $post = UtilService::getMore([ ['id', 0] ], $request); if ($post['id'] <= 0) { return app('json')->fail('参数错误'); } $rechargeConfig = new RechargeConfig(); $config = $rechargeConfig->getById($post['id']); if (!$config) { return app('json')->fail('充值配置不存在'); } $result = $rechargeConfig->deleteData($post['id']); if (!$result) { return app('json')->fail('删除失败'); } return app('json')->success('删除成功'); } /** * 充值订单列表(后台) * @param Request $request * @return mixed */ public function orderList(Request $request) { $post = UtilService::getMore([ ['page', 1], ['pageSize', 20], ['order_id', ''], ['uid', ''], ['nickname', ''], ['mobile', ''], ['pay_type', ''], ['paid', ''], ['status', ''], ['time', []] ], $request); $where = []; if (!empty($post['order_id'])) { $where['order_id'] = $post['order_id']; } if (!empty($post['uid'])) { $where['uid'] = $post['uid']; } if (!empty($post['nickname'])) { $where['nickname'] = $post['nickname']; } if (!empty($post['mobile'])) { $where['mobile'] = $post['mobile']; } if (!empty($post['pay_type'])) { $where['pay_type'] = $post['pay_type']; } if (!empty($post['paid'])) { $where['paid'] = $post['paid']; } if (!empty($post['status'])) { $where['status'] = $post['status']; } if (!empty($post['time']) && !empty($post['time'][0]) && !empty($post['time'][1])) { $where['time'] = $post['time']; } $rechargeOrder = new RechargeOrder(); $list = $rechargeOrder->getAdminList($where, '*', $post['page'], $post['pageSize']); return app('json')->success([ 'list' => $list[1], 'total' => $list[0], 'page' => $post['page'], 'pageSize' => $post['pageSize'] ]); } /** * 充值订单详情(后台) * @param Request $request * @return mixed */ public function orderDetail(Request $request) { $post = UtilService::getMore([ ['id', 0] ], $request); if ($post['id'] <= 0) { return app('json')->fail('参数错误'); } $rechargeOrder = new RechargeOrder(); $order = $rechargeOrder->getById($post['id']); if (!$order) { return app('json')->fail('订单不存在'); } // 获取用户信息 $userModel = new User(); $user = $userModel->where('uid', $order['uid'])->find(); $order['user_info'] = $user ? [ 'nickname' => $user['nickname'], 'mobile' => $user['mobile'], 'avatar' => $user['avatar'] ] : []; return app('json')->success($order); } /** * 后台手动充值(系统充值) * @param Request $request * @return mixed */ public function systemRecharge(Request $request) { $post = UtilService::getMore([ ['uid', 0], ['price', 0], ['integral', 0], ['give_integral', 0], ['remark', ''] ], $request); if ($post['uid'] <= 0) { return app('json')->fail('用户ID错误'); } if ($post['price'] <= 0) { return app('json')->fail('充值金额必须大于0'); } if ($post['integral'] <= 0) { return app('json')->fail('获得积分必须大于0'); } $userModel = new User(); $user = $userModel->where('uid', $post['uid'])->find(); if (!$user) { return app('json')->fail('用户不存在'); } $rechargeOrder = new RechargeOrder(); $totalIntegral = $post['integral'] + $post['give_integral']; // 创建系统充值订单 $orderSn = $rechargeOrder->createOrder($post['uid'], 0, $post['price'], $post['integral'], $post['give_integral'], 'system', $request->admin_id, $post['remark']); if (!$orderSn) { return app('json')->fail('创建订单失败'); } // 直接完成支付(系统充值无需支付) $updateResult = $rechargeOrder->updatePayStatus($orderSn, 'system_' . time(), '系统充值'); if (!$updateResult) { return app('json')->fail('更新订单状态失败'); } // 增加用户积分 $userModel->where('uid', $post['uid'])->inc('score', $totalIntegral)->inc('score_in', $totalIntegral)->inc('total_recharge', $post['price'])->update(); // 记录积分明细 $scoreDetail = new UserScoreDetail(); $scoreDetail->incomeScore($post['uid'], $totalIntegral, $orderSn, 'income_score', [ 'o_id' => $rechargeOrder->getByOrderSn($orderSn)['id'] ], $rechargeOrder->getByOrderSn($orderSn)['id']); return app('json')->success([ 'order_id' => $orderSn, 'price' => $post['price'], 'integral' => $post['integral'], 'give_integral' => $post['give_integral'], 'total_integral' => $totalIntegral ]); } /** * 关闭充值订单 * @param Request $request * @return mixed */ public function closeOrder(Request $request) { $post = UtilService::getMore([ ['order_id', ''] ], $request); if (empty($post['order_id'])) { return app('json')->fail('订单号不能为空'); } $rechargeOrder = new RechargeOrder(); $order = $rechargeOrder->getByOrderSn($post['order_id']); if (!$order) { return app('json')->fail('订单不存在'); } if ($order['paid'] == 1) { return app('json')->fail('已支付的订单不能关闭'); } $result = $rechargeOrder->closeOrder($post['order_id']); if (!$result) { return app('json')->fail('关闭订单失败'); } return app('json')->success('关闭订单成功'); } }