diff --git a/app/.htaccess b/app/.htaccess deleted file mode 100644 index 3418e55..0000000 --- a/app/.htaccess +++ /dev/null @@ -1 +0,0 @@ -deny from all \ No newline at end of file diff --git a/app/AppService.php b/app/AppService.php deleted file mode 100644 index 96556e8..0000000 --- a/app/AppService.php +++ /dev/null @@ -1,22 +0,0 @@ -app = $app; - $this->request = $this->app->request; - - // 控制器初始化 - $this->initialize(); - } - - // 初始化 - protected function initialize() {} - - /** - * 验证数据 - * @access protected - * @param array $data 数据 - * @param string|array $validate 验证器名或者验证规则数组 - * @param array $message 提示信息 - * @param bool $batch 是否批量验证 - * @return array|string|true - * @throws ValidateException - */ - protected function validate(array $data, string|array $validate, array $message = [], bool $batch = false) - { - if (is_array($validate)) { - $v = new Validate(); - $v->rule($validate); - } else { - if (strpos($validate, '.')) { - // 支持场景 - [$validate, $scene] = explode('.', $validate); - } - $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); - $v = new $class(); - if (!empty($scene)) { - $v->scene($scene); - } - } - - $v->message($message); - - // 是否批量验证 - if ($batch || $this->batchValidate) { - $v->batch(true); - } - - return $v->failException(true)->check($data); - } -} diff --git a/app/BaseModel.php b/app/BaseModel.php deleted file mode 100644 index 2345c8e..0000000 --- a/app/BaseModel.php +++ /dev/null @@ -1,19 +0,0 @@ - $code, 'msg' => $msg]; - if ($data) { - $back_msg['data'] = $data; - } - return $back_msg; -} diff --git a/app/controller/ConsoleController.php b/app/controller/ConsoleController.php deleted file mode 100644 index 39faec9..0000000 --- a/app/controller/ConsoleController.php +++ /dev/null @@ -1,65 +0,0 @@ -', date('Y-m-d 00:00:00', strtotime('-32 days'))]])->select(); - $income = $this->getRevenueData($orders); - View::assign($income); - $servertime = date('Y-m-d H:i:s', time()); - View::assign('servertime', $servertime); - return View::fetch(); - } - // 获取收入数据总览 - private function getRevenueData($orders) - { - // 时间段 - $month_start = date('Y-m-01 00:00:00'); - $month_end = date('Y-m-d 23:59:59', strtotime('last day of this month')); - $week_start = date('Y-m-d 00:00:00', strtotime('monday this week')); - $week_end = date('Y-m-d 23:59:59', strtotime('next monday') - 1); - $yesterday_start = date('Y-m-d 00:00:00', strtotime('yesterday')); - $yesterday_end = date('Y-m-d 23:59:59', strtotime('yesterday')); - $today_start = date('Y-m-d 00:00:00'); - $today_end = date('Y-m-d 23:59:59'); - // 本月流水 - $month_income = $orders->whereBetween('create_time', [$month_start, $month_end])->column('really_price'); - // 本周流水 - $week_income = $orders->whereBetween('create_time', [$week_start, $week_end])->column('really_price'); - // 昨日流水 - $yesterday_income = $orders->whereBetween('create_time', [$yesterday_start, $yesterday_end])->column('really_price'); - // 今天流水 - $today_income = $orders->whereBetween('create_time', [$today_start, $today_end])->column('really_price'); - // 收入数据 - $income = [ - 'month_income' => \array_sum($month_income), - 'week_income' => \array_sum($week_income), - 'yesterday_income' => \array_sum($yesterday_income), - 'today_income' => \array_sum($today_income), - ]; - return $income; - } -} diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php deleted file mode 100644 index b75af60..0000000 --- a/app/controller/IndexController.php +++ /dev/null @@ -1,21 +0,0 @@ -domain(); - } -} diff --git a/app/controller/OrderController.php b/app/controller/OrderController.php deleted file mode 100644 index a29f527..0000000 --- a/app/controller/OrderController.php +++ /dev/null @@ -1,30 +0,0 @@ -request->get('id'); - $order = Order::showOrderDetail($id); - if ($order) { - View::assign($order); - return View::fetch(); - } else { - return '订单不存在'; - } - } -} diff --git a/app/controller/PayController.php b/app/controller/PayController.php deleted file mode 100644 index 74ab703..0000000 --- a/app/controller/PayController.php +++ /dev/null @@ -1,389 +0,0 @@ -method(); - $req_data = match ($req_method) { - 'GET' => $request->get(), - 'POST' => $request->post(), - default => [] - }; - if (!$req_data) { - return '参数错误'; - } - $key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key'); - if (!$key) { - return '用户禁用或不存在'; - } - $sign_str = self::getSign($req_data, $key); - if ($req_data['sign'] === $sign_str) { - // 检查商户订单 - $out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no'); - if (!$out_trade_no) { - // 创建新订单 - $order_id = Order::createOrder($req_data); - if ($order_id) { - return redirect("/Pay/console/{$order_id}"); - } else { - return '创建订单失败'; - } - } else { - return '订单提交重复'; - } - } else { - return '签名错误'; - } - } - // api提交订单 - public function mapi(Request $request) - { - if ($request->isPost()) { - $req_data = $request->post(); - if (!$req_data) { - $req_data = $request->get(); - if (!$req_data) { - return '参数错误'; - } - } - } else { - return '请使用POST方式提交'; - } - $key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key'); - if (!$key) { - return '用户禁用或不存在'; - } - $sign_str = self::getSign($req_data, $key); - if ($req_data['sign'] === $sign_str) { - // 检查商户订单 - $out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no'); - if (!$out_trade_no) { - // 创建新订单 - $order_id = Order::createOrder($req_data); - if ($order_id) { - $payurl = $request->domain() . "/Pay/console/{$order_id}"; - $info = ['code' => 1, 'msg' => '订单创建成功', 'trade_no' => $order_id, 'qrcode' => $payurl]; - return json($info); - } else { - return '创建订单失败'; - } - } else { - return '订单提交重复'; - } - } else { - return '签名错误'; - } - } - // 收银台 - public function console($order_id = '') - { - if ($order_id) { - $act_order = Order::where('order_id', $order_id)->find(); - if ($act_order) { - $qrcode = PayChannel::where('id', $act_order->cid)->value('qrcode'); - View::assign($act_order->toArray()); - $passtime = strtotime($act_order->close_time) - time(); - View::assign('passtime', $passtime > 0 ? $passtime : 0); - View::assign('payUrl', $qrcode); - return View::fetch(); - } else { - return '订单不存在'; - } - } else { - return '订单号参数错误'; - } - } - // 查询订单状态 - public function getOrderState($order_id = '') - { - if ($order_id) { - $act_order = Order::where('order_id', $order_id)->find(); - if ($act_order) { - $passtime = strtotime($act_order->close_time) - time(); - $data = []; - if ($act_order->state === 0) { - $data['order_id'] = $act_order->order_id; - $data['passtime'] = $passtime > 0 ? $passtime : 0; - $data['state'] = $act_order->state; - return json($data); - } elseif ($act_order->state === 1) { - // 通知参数 - $notify = self::crateNotify($act_order); - // 字符串签名 - $user_key = User::where('pid', $act_order->pid)->value('secret_key'); - $sign = self::getSign($notify, $user_key); - $notify['sign'] = $sign; - // 跳转通知URL - $res_return_url = $act_order->return_url . '?' . http_build_query($notify); - // 响应消息 - $data['order_id'] = $act_order->order_id; - $data['passtime'] = $passtime > 0 ? $passtime : 0; - $data['state'] = $act_order->state; - $data['return_url'] = $res_return_url; - return json($data); - } - } else { - return '订单不存在'; - } - } else { - return '订单号参数错误'; - } - } - // 验证支付结果 - public function validatePayResult(Request $request) - { - $data = $request->post(); - $order = Order::find($data['id']); - if (\strtotime($order->close_time) < \time()) { - return \json(\backMsg(1, '订单已关闭')); - } - $up_data = ['id' => $data['id'], 'patt' => $data['patt']]; - $up_res = Order::update($up_data); - if ($up_res) { - return \json(\backMsg(0, '更新成功')); - } else { - return \json(\backMsg(1, '更新失败')); - } - } - // 处理收款通知 - public function payHeart($pid = '', $aid = '', $sign = '') - { - // 检测请求参数 - if (!($pid && $aid && $sign)) { - return '参数错误'; - } - // 检测收款通知 - $payList = request()->post(); - if (!$payList) { - return json(['code' => 0, 'msg' => '空收款通知']); - } - // 签名验证 - $is_user = User::checkUser($pid, $sign); - if (!$is_user) { - return json(['code' => 0, 'msg' => '签名错误']); - } - // 当前用户账号 - $query = ['pid' => $pid, 'aid' => $aid]; - // 排除有效期内的已支付订单 - $doneOrders = Order::scope('dealOrder')->where($query)->column('platform_order'); - if ($doneOrders) { - $num = count($payList['order_no']); - for ($i = 0; $i < $num; $i++) { - if (in_array($payList['order_no'][$i], $doneOrders)) { - $payList['price'][$i] = 0; - } - } - } - if (array_sum($payList['price']) === 0) { - return json(['code' => 0, 'msg' => '查询无新订单']); - } - // 有效订单列表 - $activeOrders = Order::scope('activeOrder')->where($query)->select(); - if (!\count($activeOrders)) { - return json(['code' => 0, 'msg' => '无有效期订单']); - } - // $msg = []; 订单高并发预留 - foreach ($activeOrders as $order) { - $index = array_search($order->really_price, $payList['price']); - // 付款金额检查 - if ($index !== false) { - // 已支付订单容错查询 - $is_order_no = Order::where('platform_order', $payList['order_no'][$index])->where($query)->find(); - // 支付方式核对 - $is_payway = $order->type === $payList['payway'][$index]; - // 支付渠道核对 - $is_channel = PayChannel::where('id', $order->cid)->value('channel') === $payList['channel'][$index]; - // 全部核对通过,修改订单状态 - if (!$is_order_no && $is_payway && $is_channel) { - // 支付成功 - $set_order_state = $order->save(['state' => 1, 'pay_time' => date('Y-m-d H:i:s', time()), 'platform_order' => $payList['order_no'][$index]]); - // 订单成交通知 - if (!$set_order_state) { - return json(['code' => 0, 'msg' => '修改订单状态失败']); - } - $notify = self::crateNotify($order); - // 字符串签名 - $user_key = User::where('pid', $order->pid)->value('secret_key'); - $sign = self::getSign($notify, $user_key); - $notify['sign'] = $sign; - // 异步通知 - $res_notify = self::getHttpResponse($order->notify_url . '?' . http_build_query($notify)); - if ($res_notify === 'success') { - return json(['code' => 0, 'msg' => 'success']); - } else { - return json(['code' => 1, 'msg' => '异步通知失败']); - } - } - } - } - } - // [定时任务]获取收款明细,提交收款通知[本地版] - public function checkPayResult(Request $request) - { - $req_info = $request->get(); - $req_pid = $req_info['pid']; - $req_aid = $req_info['aid']; - // 加载配置文件 - $config = \think\facade\Config::load("payconfig/{$req_pid}_{$req_aid}", 'payconfig'); - // 用户账号配置 - $user_config = isset($config['user']) ? $config['user'] : []; - // 收款平台账号配置 - $pay_config = isset($config['pay']) ? $config['pay'] : []; - // 配置检查 - if ($user_config && $pay_config) { - // 账号配置信息 - $pid = $user_config['pid']; - $aid = $pay_config['aid']; - if (!($req_pid == $pid && $req_aid == $aid)) { - return '监听收款配置不一致'; - } - } else { - return '监听收款配置文件名错误'; - } - // 当前站点 - $user_config['host'] = \request()->domain(); - // 实例化支付类 - $Mpay = new \MpayClass($user_config); - // 获取订单 - $res_new_order = $Mpay->orderHeart(); - $new_order = json_decode($res_new_order, true); - // 检测新订单 - if ($new_order['code'] !== 1) { - return $res_new_order; - } - // 订单列表 - $order_list = $new_order['orders']; - // 检测本账号订单 - $orders = []; - foreach ($order_list as $key => $val) { - if ($pid == $val['pid'] && $aid == $val['aid'] && $val['patt'] == 1) { - $orders[] = $order_list[$key]; - } - } - if (!$orders) { - return \json(['code' => 0, 'msg' => '非本账号订单或监听模式不对']); - } - // 登陆账号 - $config = ['username' => $pay_config['account'], 'password' => $pay_config['password']]; - // 收款查询 - $query = $pay_config['query']; - // 实例监听客户端 - $payclient_name = $pay_config['payclass']; - $payclient_path = "\\payclient\\{$payclient_name}"; - $Payclient = new $payclient_path($config); - // 获取支付明细 - $records = $Payclient->payQuery($query); - if ($records) { - // 提交收款记录 - $upres = $Mpay->upRecords($records, $aid); - return $upres; - } else { - return \json(['code' => 0, 'msg' => '查询空订单'], 320); - } - } - // [定时任务]监听新订单,生成JSON文件信息 - public function checkOrder($pid = '', $sign = '') - { - if (!($pid && $sign)) { - return '参数错误'; - } - $is_user = User::checkUser($pid, $sign); - $path = runtime_path() . 'order.json'; - if ($is_user) { - $orders = Order::scope('activeOrder')->field('id,pid,aid,cid,patt')->select(); - if (!file_exists($path)) { - file_put_contents($path, '[]'); - } - $old_info = file_get_contents($path); - $num = count($orders); - if ($num > 0) { - $info = ['code' => 1, 'msg' => "有{$num}个新订单"]; - $order_list = ['code' => 1, 'msg' => "有{$num}个新订单", 'orders' => $orders]; - if ($old_info !== json_encode($order_list)) { - file_put_contents($path, json_encode($order_list)); - } - return json($info); - } else { - $info = ['code' => 0, 'msg' => '没有新订单']; - if ($old_info !== json_encode($info, 320)) { - file_put_contents($path, json_encode($info, 320)); - } - return json($info); - } - } else { - $info = ['code' => 2, 'msg' => '签名错误']; - file_put_contents($path, json_encode($info, 320)); - return json($info); - } - } - // 签名 - private static function getSign(array $param = [], string $key = ''): string - { - ksort($param); - reset($param); - $signstr = ''; - foreach ($param as $k => $v) { - if ($k != "sign" && $k != "sign_type" && $v != '') { - $signstr .= $k . '=' . $v . '&'; - } - } - $signstr = substr($signstr, 0, -1); - $signstr .= $key; - $sign = md5($signstr); - return $sign; - } - // 构建通知 - private static function crateNotify($param): array - { - $notify = [ - 'pid' => $param->pid, - 'trade_no' => $param->order_id, - 'out_trade_no' => $param->out_trade_no, - 'type' => $param->type, - 'name' => $param->name, - 'money' => $param->money, - 'trade_status' => 'TRADE_SUCCESS', - 'sign_type' => 'MD5', - ]; - // 添加扩展参数 - $notify = array_merge($notify, unserialize($param->param)); - return $notify; - } - // 请求外部资源 - private static function getHttpResponse($url, $header = [], $post = null, $timeout = 10) - { - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - if ($header) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); - } else { - $httpheader[] = "Accept: */*"; - $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; - $httpheader[] = "Connection: close"; - curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); - } - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - if ($post) { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - } - $response = curl_exec($ch); - curl_close($ch); - return $response; - } -} diff --git a/app/controller/PayManageController.php b/app/controller/PayManageController.php deleted file mode 100644 index 22c799d..0000000 --- a/app/controller/PayManageController.php +++ /dev/null @@ -1,70 +0,0 @@ -request->get('id'); - $account = PayAccount::find($id); - View::assign([ - 'id' => $id, - 'platform' => $account->getData('platform'), - 'account' => $account->account, - 'password' => $account->password, - 'state' => $account->state, - 'pattern' => $account->getData('pattern') - ]); - return View::fetch(); - } - // 添加账号 - public function addAccount() - { - return View::fetch(); - } - // 添加收款终端 - public function addChannel() - { - $aid = $this->request->get('aid'); - View::assign(['aid' => $aid]); - return View::fetch(); - } - // 编辑收款终端 - public function editChannel() - { - $cid = $this->request->get('cid'); - $channel = PayChannel::with('payAccount')->where('id', $cid)->find(); - View::assign([ - 'cid' => $channel->id, - 'platform' => $channel->payAccount->platform, - 'account' => $channel->payAccount->account, - 'channel' => $channel->channel, - 'qrcode' => $channel->qrcode, - 'last_time' => $channel->last_time, - 'state' => $channel->state, - ]); - return View::fetch(); - } - // 收款终端列表 - public function channelList() - { - $id = $this->request->get('id'); - View::assign(['id' => $id]); - return View::fetch(); - } -} diff --git a/app/controller/PluginController.php b/app/controller/PluginController.php deleted file mode 100644 index 9f20e80..0000000 --- a/app/controller/PluginController.php +++ /dev/null @@ -1,149 +0,0 @@ -findCmd('unzip')) { - $cmd = "$cmd -o -qq $zip_file -d $extract_to"; - } else if ($cmd = $this->findCmd('7z')) { - $cmd = "$cmd x -bb0 -y $zip_file -o$extract_to"; - } else if ($cmd = $this->findCmd('7zz')) { - $cmd = "$cmd x -bb0 -y $zip_file -o$extract_to"; - } - return $cmd; - } - - /** - * 使用解压命令解压 - * @param $cmd - * @return void - * @throws BusinessException - */ - protected function unzipWithCmd($cmd) {} - - /** - * 获取已安装的插件列表 - * @return array - */ - protected function getLocalPlugins() {} - - /** - * 获取已安装的插件列表 - * @param Request $request - * @return Response - */ - public function getInstalledPlugins(Request $request) {} - - - /** - * 获取本地插件版本 - * @param $name - * @return array|mixed|null - */ - protected function getPluginVersion($name) {} - - /** - * 获取webman/admin版本 - * @return string - */ - protected function getAdminVersion() {} - - /** - * 删除目录 - * @param $src - * @return void - */ - protected function rmDir($src) {} - - /** - * 获取httpclient - * @return Client - */ - protected function httpClient() {} - - /** - * 获取下载httpclient - * @return Client - */ - protected function downloadClient() {} - - /** - * 查找系统命令 - * @param string $name - * @param string|null $default - * @param array $extraDirs - * @return mixed|string|null - */ - protected function findCmd(string $name, string $default = null, array $extraDirs = []) {} -} diff --git a/app/controller/SystemController.php b/app/controller/SystemController.php deleted file mode 100644 index a03dd94..0000000 --- a/app/controller/SystemController.php +++ /dev/null @@ -1,85 +0,0 @@ - ['except' => ['login']]]; - // 用户中心 - public function index() - { - $userinfo = User::find(\session('userid'))->toArray(); - View::assign($userinfo); - View::assign('url', $this->request->domain()); - return View::fetch(); - } - // 登陆视图 - public function login() - { - if (session('?islogin')) { - return redirect('/Console/index'); - } - return View::fetch(); - } - // 修改用户 - public function setUser() - { - $userinfo = User::find(\session('userid'))->toArray(); - View::assign($userinfo); - return View::fetch(); - } -} diff --git a/app/controller/api/ConsoleController.php b/app/controller/api/ConsoleController.php deleted file mode 100644 index a5eab96..0000000 --- a/app/controller/api/ConsoleController.php +++ /dev/null @@ -1,44 +0,0 @@ -get('time') ?: 0; - $time = match ($date) { - 0 => [date('Y') . '-01-01 00:00:00', date('Y-m-d 23:59:59')], - 1 => [date('Y-m-d H:i:s', strtotime('-30 days')), date('Y-m-d 23:59:59')], - 2 => [date('Y-m-d H:i:s', strtotime('-6 months')), date('Y-m-d 23:59:59')], - 3 => [date('Y-m-d H:i:s', strtotime('-1 year')), date('Y-m-d 23:59:59')], - default => [] - }; - if (!$time) { - return json(['code' => 400, 'msg' => '参数错误']); - } - $orders = Order::whereBetweenTime('create_time', $time[0], $time[1])->where('state', 1)->field('id,type,really_price')->select(); - $data = [ - 'ordernum' => count($orders), - 'totalmoney' => \number_format(array_sum(array_column($orders->toArray(), 'really_price')), 2), - 'wxpay' => [ - 'num' => count($orders->where('type', 'wxpay')), - 'money' => \number_format(array_sum(array_column($orders->where('type', 'wxpay')->toArray(), 'really_price')), 2) - ], - 'alipay' => [ - 'num' => count($orders->where('type', 'alipay')), - 'money' => \number_format(array_sum(array_column($orders->where('type', 'alipay')->toArray(), 'really_price')), 2) - ], - 'unionpay' => [ - 'num' => count($orders->where('type', 'unionpay')), - 'money' => \number_format(array_sum(array_column($orders->where('type', 'unionpay')->toArray(), 'really_price')), 2) - ] - ]; - return json($data); - } -} diff --git a/app/controller/api/OrderController.php b/app/controller/api/OrderController.php deleted file mode 100644 index aceae75..0000000 --- a/app/controller/api/OrderController.php +++ /dev/null @@ -1,187 +0,0 @@ -request->get(); - $orders = Order::serchOrders($query)->order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]); - if ($orders) { - return json(['code' => 0, 'msg' => 'OK', 'count' => $orders->total(), 'data' => $orders->items()]); - } else { - return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); - } - } - // 修改订单支付状态 - public function changeOrderState() - { - $info = $this->request->post(); - $uporder_res = Order::update(['state' => $info['state'], 'id' => $info['id']]); - if ($uporder_res) { - return json(\backMsg(0, '修改成功')); - } else { - return json(\backMsg(1, '修改失败')); - } - } - // 手动补单 - public function doPayOrder() - { - $info = $this->request->post(); - // 修改支付状态 - $order = Order::find($info['id']); - $order->state = $info['state']; - $res = $order->save(); - if ($res) { - // 创建通知 - $notify = self::crateNotify($order); - // 字符串签名 - $user_key = User::where('pid', $order->pid)->value('secret_key'); - $sign = self::getSign($notify, $user_key); - $notify['sign'] = $sign; - // 异步通知 - $res_notify = self::getHttpResponse($order->notify_url . '?' . http_build_query($notify)); - if ($res_notify === 'success') { - return json(\backMsg(0, '订单通知成功')); - } else { - return json(\backMsg(1, '异步通知失败')); - } - } else { - return json(\backMsg(1, '支付状态修改失败')); - } - } - // 重新通知 - public function redoPayOrder() - { - $id = $this->request->post('id'); - // 修改支付状态 - $order = Order::find($id); - if ($order) { - // 创建通知 - $notify = self::crateNotify($order); - // 字符串签名 - $user_key = User::where('pid', $order->pid)->value('secret_key'); - $sign = self::getSign($notify, $user_key); - $notify['sign'] = $sign; - // 异步通知 - $res_notify = self::getHttpResponse($order->notify_url . '?' . http_build_query($notify)); - if ($res_notify === 'success') { - return json(\backMsg(0, '订单通知成功')); - } else { - return json(\backMsg(1, '异步通知失败')); - } - } else { - return json(\backMsg(1, '订单不存在')); - } - } - // 删除订单 - public function deleteOrder() - { - $id = $this->request->post('id'); - $del_res = Order::destroy($id); - if ($del_res) { - return json(\backMsg(0, '删除成功')); - } else { - return json(\backMsg(1, '删除失败')); - } - } - // 批量删除订单 - public function batchRemove() - { - $ids = $this->request->post('ids'); - if (!$ids) { - return json(\backMsg(1, '参数错误')); - } - $del_res = Order::destroy($ids); - if ($del_res) { - return json(\backMsg(0, '删除成功')); - } else { - return json(\backMsg(1, '删除失败')); - } - } - // 清空超时订单 - public function batchTimeout() - { - $ids = Order::scope('timeoutOrder')->column('id'); - if (!$ids) { - return json(\backMsg(1, '无过期订单')); - } - $batch_del_res = Order::destroy($ids); - if ($batch_del_res) { - return json(\backMsg(0, '清理成功')); - } else { - return json(\backMsg(1, '清理失败')); - } - } - - // 签名方法 - private static function getSign(array $param = [], string $key = ''): string - { - if (!$param) - return '参数错误'; - if (!$key) - return '密钥错误'; - ksort($param); - reset($param); - $signstr = ''; - foreach ($param as $k => $v) { - if ($k != "sign" && $k != "sign_type" && $v != '') { - $signstr .= $k . '=' . $v . '&'; - } - } - $signstr = substr($signstr, 0, -1); - $signstr .= $key; - $sign = md5($signstr); - return $sign; - } - // 构建通知参数 - private static function crateNotify($param): array - { - $notify = [ - 'pid' => $param->pid, - 'trade_no' => $param->order_id, - 'out_trade_no' => $param->out_trade_no, - 'type' => $param->type, - 'name' => $param->name, - 'money' => $param->money, - 'trade_status' => 'TRADE_SUCCESS', - 'sign_type' => 'MD5', - ]; - // 添加扩展参数 - $notify = array_merge($notify, unserialize($param->param)); - return $notify; - } - // 请求外部资源 - private static function getHttpResponse($url, $header = [], $post = null, $timeout = 10) - { - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - if ($header) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); - } else { - $httpheader[] = "Accept: */*"; - $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; - $httpheader[] = "Connection: close"; - curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); - } - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - if ($post) { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - } - $response = curl_exec($ch); - curl_close($ch); - return $response; - } -} diff --git a/app/controller/api/PayManageController.php b/app/controller/api/PayManageController.php deleted file mode 100644 index e0da182..0000000 --- a/app/controller/api/PayManageController.php +++ /dev/null @@ -1,135 +0,0 @@ -request->get(); - $accounts = PayAccount::serchAccount($query)->order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]); - if ($accounts) { - return json(['code' => 0, 'msg' => 'OK', 'count' => $accounts->total(), 'data' => $accounts->items()]); - } else { - return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); - } - } - // 编辑账号 - public function editAccount() - { - $info = $this->request->post(); - $up_res = PayAccount::update($info); - if ($up_res) { - $acc = PayAccount::find($info['id']); - $this->createAccountConfig($acc); - return json(\backMsg(0, '修改成功')); - } else { - return json(\backMsg(1, '修改失败')); - } - } - // 账号状态 - public function accountEnable() - { - $info = $this->request->post(); - $up_res = PayAccount::update($info); - if ($up_res) { - return json(\backMsg(0, '成功')); - } else { - return json(\backMsg(1, '失败')); - } - } - // 删除账号 - public function delAccount() - { - $ids = $this->request->post('ids'); - $res = PayAccount::destroy($ids); - $res2 = PayChannel::destroy($ids); - if ($res && $res2) { - return \json(\backMsg(0, '已删除')); - } else { - return \json(\backMsg(1, '失败')); - } - } - // 添加账号 - public function addAccount() - { - $info = $this->request->post(); - $pid = $this->request->session('pid'); - $info['pid'] = $pid; - $check_acc = PayAccount::where(['account' => $info['account'], 'pid' => $pid])->find(); - if ($check_acc) { - return \json(\backMsg(1, '账号已存在')); - } - $acc = PayAccount::create($info); - if ($acc) { - $this->createAccountConfig($acc); - return \json(\backMsg(0, '添加成功')); - } else { - return \json(\backMsg(1, '添加失败')); - } - } - // 添加收款终端 - public function addChannel() - { - $info = $this->request->post(); - $res = PayChannel::create($info); - if ($res) { - return \json(\backMsg(0, '添加成功')); - } else { - return \json(\backMsg(1, '添加失败')); - } - } - // 编辑收款终端 - public function editChannel() - { - $info = $this->request->post(); - $up_res = PayChannel::update($info); - if ($up_res) { - return json(\backMsg(0, '修改成功')); - } else { - return json(\backMsg(1, '修改失败')); - } - } - // 收款终端列表 - public function getChannelList() - { - $aid = $this->request->post('aid'); - $res = PayChannel::where(['account_id' => $aid])->order('last_time', 'desc')->select(); - if ($res) { - return \json(\backMsg(0, '获取成功', $res)); - } else { - return \json(\backMsg(1, '失败')); - } - } - // 生成账号配置 - private function createAccountConfig($acc) - { - $platform = Platform::where('platform', $acc->getData('platform'))->find(); - $user = User::where('pid', $acc->pid)->find(); - $query = \unserialize($platform->query); - $data = [ - 'pid' => $user->pid, - 'key' => $user->secret_key, - 'aid' => $acc->id, - 'platform' => $acc->getData('platform'), - 'account' => $acc->account, - 'password' => $acc->password, - 'payclass' => $platform->class_name, - 'query' => \var_export($query, \true) - ]; - $config = View::fetch('tpl/account_config', $data); - $name = "{$data['pid']}_{$data['aid']}"; - $path = "../config/payconfig/{$name}.php"; - \file_put_contents($path, $config); - } -} diff --git a/app/controller/api/PluginController.php b/app/controller/api/PluginController.php deleted file mode 100644 index 4398bb1..0000000 --- a/app/controller/api/PluginController.php +++ /dev/null @@ -1,63 +0,0 @@ -request->get(); - $data = Platform::order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]); - if ($data) { - return json(['code' => 0, 'msg' => 'OK', 'count' => $data->total(), 'data' => $data->items()]); - } else { - return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]); - } - } - // 插件启用 - public function pluginEnable() - { - $info = $this->request->post(); - $up_res = Platform::update($info); - if ($up_res) { - return json(\backMsg(0, '成功')); - } else { - return json(\backMsg(1, '失败')); - } - } - // 插件选项 - public function pluginOption() - { - // 加载平台配置 - $platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig'); - $option = []; - foreach ($platform as $key => $value) { - $option[] = ['platform' => $key, 'name' => $value]; - } - return json($option); - } - // 生成插件配置 - public function crtPlfConfig() - { - $info = Platform::where('state', 1)->field('platform, name')->select()->toArray(); - $data = []; - foreach ($info as $value) { - $data[$value['platform']] = $value['name']; - } - $config = View::fetch('tpl/platform_config', $data); - $path = "../config/extendconfig/platform.php"; - $res = \file_put_contents($path, $config); - if ($res) { - return \json(\backMsg(msg: '创建成功')); - } else { - return \json(\backMsg(1, '创建成功')); - } - } -} diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php deleted file mode 100644 index dccc2c3..0000000 --- a/app/controller/api/UserController.php +++ /dev/null @@ -1,79 +0,0 @@ - ['except' => ['login']]]; - - public function login() - { - $login_info = $this->request->post(); - $userinfo = self::checkUser($login_info); - if ($userinfo['code'] === 0) { - Session::set('userid', $userinfo['data']->id); - Session::set('pid', $userinfo['data']->pid); - Session::set('nickname', $userinfo['data']->nickname); - Session::set('userrole', $userinfo['data']->role); - Session::set('islogin', true); - return json(\backMsg(0, 'ok')); - } else { - return json($userinfo); - } - } - public function logout() - { - Session::clear(); - return json(\backMsg(0, '注销成功')); - } - public function editUser() - { - $userid = \session('userid'); - $info = $this->request->post(); - $res = User::update($info, ['id' => $userid]); - if (!$res) { - return json(\backMsg(1, '修改失败')); - } - return json(\backMsg(0, '重置成功')); - } - public function resetKey() - { - $userid = \session('userid'); - $res = User::update(['secret_key' => $this->generateKey()], ['id' => $userid]); - if (!$res) { - return json(\backMsg(1, '重置失败')); - } - return json(\backMsg(0, '重置成功')); - } - private function checkUser(array $login_info): array - { - $username = $login_info['username']; - $password = $login_info['password']; - $userinfo = User::where('username', $username)->find(); - if ($userinfo) { - if ($password === $userinfo->password) { - return ['code' => 0, 'data' => $userinfo]; - } else { - return \backMsg(1, '登陆密码错误'); - } - } else { - return \backMsg(2, '用户不存在'); - } - } - private function generateKey() - { - $bytes = openssl_random_pseudo_bytes(16, $strong); - if ($strong) { - $key = bin2hex($bytes); - return md5($key); - } else { - return false; - } - } -} diff --git a/app/event.php b/app/event.php deleted file mode 100644 index e9851bb..0000000 --- a/app/event.php +++ /dev/null @@ -1,17 +0,0 @@ - [ - ], - - 'listen' => [ - 'AppInit' => [], - 'HttpRun' => [], - 'HttpEnd' => [], - 'LogLevel' => [], - 'LogWrite' => [], - ], - - 'subscribe' => [ - ], -]; diff --git a/app/middleware.php b/app/middleware.php deleted file mode 100644 index 32d02ce..0000000 --- a/app/middleware.php +++ /dev/null @@ -1,10 +0,0 @@ -isJson(); - if ($method) { - return \json(\backMsg(404, '身份过期,请重新登陆')); - } - return redirect('/User/login'); - } - } -} diff --git a/app/model/Order.php b/app/model/Order.php deleted file mode 100644 index 9512d2f..0000000 --- a/app/model/Order.php +++ /dev/null @@ -1,191 +0,0 @@ - self::createOrderID('H'), - // 商户ID - 'pid' => $data['pid'], - // 支付类型 - 'type' => $data['type'], - // 商户订单号 - 'out_trade_no' => $data['out_trade_no'], - // 异步通知 - 'notify_url' => $data['notify_url'], - // 跳转通知 - 'return_url' => isset($data['return_url']) ? $data['return_url'] : '', - // 商品名称 - 'name' => $data['name'], - // 商品金额 - 'money' => $data['money'], - // 实际成交金额 - 'really_price' => self::checkMoney($data['money'], $data['type'], $channel['aid'], $channel['cid']), - // 用户IP - 'clientip' => isset($data['clientip']) ? $data['clientip'] : '', - // 设备类型 - 'device' => isset($data['device']) ? $data['device'] : '', - // 业务扩展参数 - 'param' => serialize(self::getParams($data)), - // 等待/过期:0, 支付成功:1 - 'state' => 0, - // 开启监听:1, 关闭监听:0 - 'patt' => $channel['patt'], - // 订单创建时间 - 'create_time' => self::getFormatTime($my_time), - // 订单关闭时间 - 'close_time' => self::getFormatTime($my_time + self::$activity_time), - // 支付时间 - 'pay_time' => self::getFormatTime($my_time), - // 收款账号id - 'aid' => $channel['aid'], - // 交易终端id - 'cid' => $channel['cid'], - ]; - $res = self::create($new_order); - if ($res->order_id) { - return $res->order_id; - } else { - return false; - } - } - // 查询订单列表 - public static function serchOrders($query) - { - $select = []; - $_select = []; - $allow_field = ['id', 'order_id', 'pid', 'type', 'out_trade_no', 'notify_url', 'return_url', 'name', 'really_price', 'money', 'clientip', 'device', 'state', 'create_time_start', 'create_time_end', 'close_time', 'pay_time', 'platform', 'platform_order', 'aid', 'cid',]; - foreach ($query as $key => $value) { - if (in_array($key, $allow_field) && isset($value)) { - if ($key === 'name') { - $select[] = ['Order.' . $key, 'like', '%' . $value . '%']; - continue; - } - if ($key === 'create_time_start') { - $select[] = ['Order.' . 'create_time', '>', $value]; - continue; - } - if ($key === 'create_time_end') { - $select[] = ['Order.' . 'create_time', '<', $value]; - continue; - } - if ($key === 'platform') { - $_select['platform'] = $value; - continue; - } - $select[] = ['Order.' . $key, '=', $value]; - } - } - return self::with('payAccount') - ->hasWhere('payAccount', function ($query) use ($_select) { - $query->where($_select); - }) - ->where($select); - } - // 查询订单详细 - public static function showOrderDetail($id) - { - $order = self::find($id); - $a_list = PayAccount::with('payChannel')->hasWhere('payChannel', ['id' => $order->cid])->where('PayAccount.id', $order->aid)->find(); - if (!$order) { - return []; - } - $order->platform = $a_list->platform ?? '···'; - $order->account = $a_list->account ?? '···'; - $order->channel = $a_list->payChannel[0]->channel ?? '···'; - $order->qrcode = $a_list->payChannel[0]->qrcode ?? '···'; - return $order->toArray(); - } - // 选择收款通道 - private static function setChannel($pid): array - { - $aids = PayAccount::where('pid', $pid)->where('state', 1)->column('id'); - $channel_info = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->find(); - if (!$channel_info || !$aids) { - return []; - } - $patt = PayAccount::find($channel_info->account_id); - $channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')]; - PayChannel::update(['last_time' => self::getFormatTime(), 'id' => $channel['cid']]); - return $channel; - } - // 获取扩展参数数组 - private static function getParams(array $data): array - { - $keys = ['pid', 'type', 'out_trade_no', 'notify_url', 'return_url', 'name', 'money', 'sign', 'sign_type']; - $params = []; - foreach ($data as $key => $value) { - if (!in_array($key, $keys)) { - $params[$key] = $value; - } - } - return $params; - } - // 检查金额 - private static function checkMoney($money, $type, $aid, $cid): float - { - $money = (float) $money; - // 查询有效订单 - $query = self::scope('activeOrder')->where(['type' => $type, 'aid' => $aid, 'cid' => $cid]); - $activeOrders = $query->column('really_price'); - $num = count($activeOrders); - if ($num > 0) { - for ($i = 0; $i < $num; $i++) { - if (in_array($money, $activeOrders)) { - $money += 0.01; - } else { - break; - } - } - } - return $money; - } - // 获取格式时间 - private static function getFormatTime($time = 0) - { - if ($time) { - return date('Y-m-d H:i:s', $time); - } - return date('Y-m-d H:i:s', time()); - } - // 生成订单号 - private static function createOrderID(string $prefix = ''): string - { - return $prefix . date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); - } - // 查询有效期内的未支付订单 - public function scopeActiveOrder($query) - { - $query->where('close_time', '>', self::getFormatTime())->where('state', 0); - } - // 查询有效期内的成交订单 - public function scopeDealOrder($query) - { - $query->where('close_time', '>', self::getFormatTime())->where('state', 1); - } - // 查询超时过期订单 - public function scopeTimeoutOrder($query) - { - $query->where('close_time', '<', self::getFormatTime())->where('state', 0); - } - // 模型多对一关联 - public function payAccount() - { - return $this->belongsTo(PayAccount::class, 'aid', 'id'); - } -} diff --git a/app/model/PayAccount.php b/app/model/PayAccount.php deleted file mode 100644 index ac7b6a8..0000000 --- a/app/model/PayAccount.php +++ /dev/null @@ -1,45 +0,0 @@ - $value) { - if (in_array($key, $allow_field) && isset($value)) { - if ($key === 'account') { - $select[] = [$key, 'like', '%' . $value . '%']; - continue; - } - $select[] = [$key, '=', $value]; - } - } - return self::withCount(['payChannel' => 'channel'])->where($select); - } - // 获取器 - public function getPlatformAttr($value) - { - // 加载平台配置 - $platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig'); - return $platform[$value]; - } - public function getPatternAttr($value) - { - // 监听模式 - $pattern = ['0' => '单次监听·被动', '1' => '连续监听·主动']; - return $pattern[$value]; - } - // 一对多关联 - public function payChannel() - { - return $this->hasMany(PayChannel::class, 'account_id', 'id'); - } -} diff --git a/app/model/PayChannel.php b/app/model/PayChannel.php deleted file mode 100644 index ed2ee6b..0000000 --- a/app/model/PayChannel.php +++ /dev/null @@ -1,16 +0,0 @@ -belongsTo(PayAccount::class, 'account_id', 'id'); - } -} diff --git a/app/model/Platform.php b/app/model/Platform.php deleted file mode 100644 index b51ea8a..0000000 --- a/app/model/Platform.php +++ /dev/null @@ -1,15 +0,0 @@ -find(); - $sign2 = md5($user->pid . $user->secret_key); - if ($sign === $sign2) { - return true; - } else { - return false; - } - } - // 创建用户 - public static function createUser(array $userinfo) - { - $last_pid = self::withTrashed()->max('pid'); - $find_username = self::withTrashed()->where(['username' => $userinfo['username']])->find(); - if ($find_username) { - return 1; // 账户已注册 - } - $pid = $last_pid ? $last_pid + 1 : 1000; - $secret = md5($pid . time() . mt_rand()); - $res = self::create(['pid' => $pid, 'secret_key' => $secret, 'username' => $userinfo['username'], 'password' => $userinfo['password'], 'nickname' => self::getNickname('小可爱', 5)]); - return $res; - } - // 随机用户昵称 - private static function getNickname($pre = '', $length = 8) - { - $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - return $pre . $randomString; - } -} diff --git a/app/provider.php b/app/provider.php deleted file mode 100644 index 73d99fa..0000000 --- a/app/provider.php +++ /dev/null @@ -1,9 +0,0 @@ - Request::class, - 'think\exception\Handle' => ExceptionHandle::class, -]; diff --git a/app/service.php b/app/service.php deleted file mode 100644 index db1ee6a..0000000 --- a/app/service.php +++ /dev/null @@ -1,9 +0,0 @@ -