first commit
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Home;
|
||||
|
||||
use App\Exceptions\RuleValidationException;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Models\Pay;
|
||||
use Germey\Geetest\Geetest;
|
||||
use Illuminate\Database\DatabaseServiceProvider;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 商品服务层.
|
||||
* @var \App\Service\PayService
|
||||
*/
|
||||
private $goodsService;
|
||||
|
||||
/**
|
||||
* 支付服务层
|
||||
* @var \App\Service\PayService
|
||||
*/
|
||||
private $payService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->goodsService = app('Service\GoodsService');
|
||||
$this->payService = app('Service\PayService');
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$goods = $this->goodsService->withGroup();
|
||||
return $this->render('static_pages/home', ['data' => $goods], __('dujiaoka.page-title.home'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function buy(int $id)
|
||||
{
|
||||
try {
|
||||
$goods = $this->goodsService->detail($id);
|
||||
$this->goodsService->validatorGoodsStatus($goods);
|
||||
// 有没有优惠码可以展示
|
||||
if (count($goods->coupon)) {
|
||||
$goods->open_coupon = 1;
|
||||
}
|
||||
$formatGoods = $this->goodsService->format($goods);
|
||||
// 加载支付方式.
|
||||
$client = Pay::PAY_CLIENT_PC;
|
||||
if (app('Jenssegers\Agent')->isMobile()) {
|
||||
$client = Pay::PAY_CLIENT_MOBILE;
|
||||
}
|
||||
$formatGoods->payways = $this->payService->pays($client);
|
||||
return $this->render('static_pages/buy', $formatGoods, $formatGoods->gd_name);
|
||||
} catch (RuleValidationException $ruleValidationException) {
|
||||
return $this->err($ruleValidationException->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 极验行为验证
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function geetest(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'user_id' => @Auth::user()?@Auth::user()->id:'UnLoginUser',
|
||||
'client_type' => 'web',
|
||||
'ip_address' => \Illuminate\Support\Facades\Request::ip()
|
||||
];
|
||||
$status = Geetest::preProcess($data);
|
||||
session()->put('gtserver', $status);
|
||||
session()->put('user_id', $data['user_id']);
|
||||
return Geetest::getResponseStr();
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装页面
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function install(Request $request)
|
||||
{
|
||||
return view('common/install');
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行安装
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function doInstall(Request $request)
|
||||
{
|
||||
try {
|
||||
$dbConfig = config('database');
|
||||
$mysqlDB = [
|
||||
'host' => $request->input('db_host'),
|
||||
'port' => $request->input('db_port'),
|
||||
'database' => $request->input('db_database'),
|
||||
'username' => $request->input('db_username'),
|
||||
'password' => $request->input('db_password'),
|
||||
];
|
||||
$dbConfig['connections']['mysql'] = array_merge($dbConfig['connections']['mysql'], $mysqlDB);
|
||||
// Redis
|
||||
$redisDB = [
|
||||
'host' => $request->input('redis_host'),
|
||||
'password' => $request->input('redis_password', 'null'),
|
||||
'port' => $request->input('redis_port'),
|
||||
];
|
||||
$dbConfig['redis']['default'] = array_merge($dbConfig['redis']['default'], $redisDB);
|
||||
config(['database' => $dbConfig]);
|
||||
DB::purge();
|
||||
// db测试
|
||||
DB::connection()->select('select 1 limit 1');
|
||||
// redis测试
|
||||
Redis::set('dujiaoka_com', 'ok');
|
||||
Redis::get('dujiaoka_com');
|
||||
// 获得文件模板
|
||||
$envExamplePath = base_path() . DIRECTORY_SEPARATOR . '.env.example';
|
||||
$envPath = base_path() . DIRECTORY_SEPARATOR . '.env';
|
||||
$installLock = base_path() . DIRECTORY_SEPARATOR . 'install.lock';
|
||||
$installSql = database_path() . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'install.sql';
|
||||
$envTemp = file_get_contents($envExamplePath);
|
||||
$postData = $request->all();
|
||||
// 临时写入key
|
||||
$postData['app_key'] = 'base64:' . base64_encode(
|
||||
Encrypter::generateKey(config('app.cipher'))
|
||||
);
|
||||
foreach ($postData as $key => $item) {
|
||||
$envTemp = str_replace('{' . $key . '}', $item, $envTemp);
|
||||
}
|
||||
// 写入配置
|
||||
file_put_contents($envPath, $envTemp);
|
||||
// 导入sql
|
||||
DB::unprepared(file_get_contents($installSql));
|
||||
// 写入安装锁
|
||||
file_put_contents($installLock, 'install ok');
|
||||
return 'success';
|
||||
} catch (\RedisException $exception) {
|
||||
return 'Redis配置错误 :' . $exception->getMessage();
|
||||
} catch (QueryException $exception) {
|
||||
return '数据库配置错误 :' . $exception->getMessage();
|
||||
} catch (\Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Home;
|
||||
|
||||
use App\Exceptions\RuleValidationException;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Models\Order;
|
||||
use App\Service\OrderProcessService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
*
|
||||
* Class OrderController
|
||||
* @package App\Http\Controllers\Home
|
||||
* @author: Assimon
|
||||
* @email: Ashang@utf8.hk
|
||||
* @blog: https://utf8.hk
|
||||
* Date: 2021/5/30
|
||||
*/
|
||||
class OrderController extends BaseController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 订单服务层
|
||||
* @var \App\Service\OrderService
|
||||
*/
|
||||
private $orderService;
|
||||
|
||||
/**
|
||||
* 订单处理层.
|
||||
* @var OrderProcessService
|
||||
*/
|
||||
private $orderProcessService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->orderService = app('Service\OrderService');
|
||||
$this->orderProcessService = app('Service\OrderProcessService');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function createOrder(Request $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$this->orderService->validatorCreateOrder($request);
|
||||
$goods = $this->orderService->validatorGoods($request);
|
||||
$this->orderService->validatorLoopCarmis($request);
|
||||
// 设置商品
|
||||
$this->orderProcessService->setGoods($goods);
|
||||
// 优惠码
|
||||
$coupon = $this->orderService->validatorCoupon($request);
|
||||
// 设置优惠码
|
||||
$this->orderProcessService->setCoupon($coupon);
|
||||
$otherIpt = $this->orderService->validatorChargeInput($goods, $request);
|
||||
$this->orderProcessService->setOtherIpt($otherIpt);
|
||||
// 数量
|
||||
$this->orderProcessService->setBuyAmount($request->input('by_amount'));
|
||||
// 支付方式
|
||||
$this->orderProcessService->setPayID($request->input('payway'));
|
||||
// 下单邮箱
|
||||
$this->orderProcessService->setEmail($request->input('email'));
|
||||
// ip地址
|
||||
$this->orderProcessService->setBuyIP($request->getClientIp());
|
||||
// 查询密码
|
||||
$this->orderProcessService->setSearchPwd($request->input('search_pwd', ''));
|
||||
// 创建订单
|
||||
$order = $this->orderProcessService->createOrder();
|
||||
DB::commit();
|
||||
// 设置订单cookie
|
||||
$this->queueCookie($order->order_sn);
|
||||
return redirect(url('/bill', ['orderSN' => $order->order_sn]));
|
||||
} catch (RuleValidationException $exception) {
|
||||
DB::rollBack();
|
||||
return $this->err($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置订单cookie.
|
||||
* @param string $orderSN 订单号.
|
||||
*/
|
||||
private function queueCookie(string $orderSN) : void
|
||||
{
|
||||
// 设置订单cookie
|
||||
$cookies = Cookie::get('dujiaoka_orders');
|
||||
if (empty($cookies)) {
|
||||
Cookie::queue('dujiaoka_orders', json_encode([$orderSN]));
|
||||
} else {
|
||||
$cookies = json_decode($cookies, true);
|
||||
array_push($cookies, $orderSN);
|
||||
Cookie::queue('dujiaoka_orders', json_encode($cookies));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结账
|
||||
*
|
||||
* @param string $orderSN
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function bill(string $orderSN)
|
||||
{
|
||||
$order = $this->orderService->detailOrderSN($orderSN);
|
||||
if (empty($order)) {
|
||||
return $this->err(__('dujiaoka.prompt.order_does_not_exist'));
|
||||
}
|
||||
if ($order->status == Order::STATUS_EXPIRED) {
|
||||
return $this->err(__('dujiaoka.prompt.order_is_expired'));
|
||||
}
|
||||
return $this->render('static_pages/bill', $order, __('dujiaoka.page-title.bill'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单状态监测
|
||||
*
|
||||
* @param string $orderSN 订单号
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function checkOrderStatus(string $orderSN)
|
||||
{
|
||||
$order = $this->orderService->detailOrderSN($orderSN);
|
||||
// 订单不存在或者已经过期
|
||||
if (!$order || $order->status == Order::STATUS_EXPIRED) {
|
||||
return response()->json(['msg' => 'expired', 'code' => 400001]);
|
||||
}
|
||||
// 订单已经支付
|
||||
if ($order->status == Order::STATUS_WAIT_PAY) {
|
||||
return response()->json(['msg' => 'wait....', 'code' => 400000]);
|
||||
}
|
||||
// 成功
|
||||
if ($order->status > Order::STATUS_WAIT_PAY) {
|
||||
return response()->json(['msg' => 'success', 'code' => 200]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过订单号展示订单详情
|
||||
*
|
||||
* @param string $orderSN 订单号.
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function detailOrderSN(string $orderSN)
|
||||
{
|
||||
$order = $this->orderService->detailOrderSN($orderSN);
|
||||
// 订单不存在或者已经过期
|
||||
if (!$order) {
|
||||
return $this->err(__('dujiaoka.prompt.order_does_not_exist'));
|
||||
}
|
||||
return $this->render('static_pages/orderinfo', ['orders' => [$order]], __('dujiaoka.page-title.order-detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单号查询
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function searchOrderBySN(Request $request)
|
||||
{
|
||||
return $this->detailOrderSN($request->input('order_sn'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过邮箱查询
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function searchOrderByEmail(Request $request)
|
||||
{
|
||||
if (
|
||||
!$request->has('email') ||
|
||||
(
|
||||
dujiaoka_config_get('is_open_search_pwd', \App\Models\BaseModel::STATUS_CLOSE) == \App\Models\BaseModel::STATUS_OPEN &&
|
||||
!$request->has('search_pwd')
|
||||
)
|
||||
) {
|
||||
return $this->err(__('dujiaoka.prompt.server_illegal_request'));
|
||||
}
|
||||
$orders = $this->orderService->withEmailAndPassword($request->input('email'), $request->input('search_pwd',''));
|
||||
if (!$orders) {
|
||||
return $this->err(__('dujiaoka.prompt.no_related_order_found'));
|
||||
}
|
||||
return $this->render('static_pages/orderinfo', ['orders' => $orders], __('dujiaoka.page-title.order-detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过浏览器缓存查询
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function searchOrderByBrowser(Request $request)
|
||||
{
|
||||
$cookies = Cookie::get('dujiaoka_orders');
|
||||
if (empty($cookies)) {
|
||||
return $this->err(__('dujiaoka.prompt.no_related_order_found_for_cache'));
|
||||
}
|
||||
$orderSNS = json_decode($cookies, true);
|
||||
$orders = $this->orderService->byOrderSNS($orderSNS);
|
||||
return $this->render('static_pages/orderinfo', ['orders' => $orders], __('dujiaoka.page-title.order-detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单查询页
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*
|
||||
* @author assimon<ashang@utf8.hk>
|
||||
* @copyright assimon<ashang@utf8.hk>
|
||||
* @link http://utf8.hk/
|
||||
*/
|
||||
public function orderSearch(Request $request)
|
||||
{
|
||||
return $this->render('static_pages/searchOrder', [], __('dujiaoka.page-title.order-search'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user