更新代码
This commit is contained in:
70
app/Http/Controllers/AccountController.php
Normal file
70
app/Http/Controllers/AccountController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$reward_total = Auth::user()->account->logs()->where('type', 'cash')->where('rule_id', 2)->sum('variable');
|
||||
$freezing_total = Auth::user()->account->logs()->where('type', 'cash')->where('frozen', 1)->sum('variable');
|
||||
$logs = Auth::user()->account->logs()->where('type', 'cash')->orderBy('created_at', 'desc')->get();
|
||||
return view('account.index', compact('reward_total', 'freezing_total', 'logs'));
|
||||
}
|
||||
|
||||
public function coupon(Request $request, $type = 'unuse')
|
||||
{
|
||||
if ($type == 'unuse') {
|
||||
$status = 0;
|
||||
} else {
|
||||
$status = 1;
|
||||
}
|
||||
$list = CouponUserLog::with('info')->where('user_id', Auth::id())->where('status', $status)->get();
|
||||
return view('account.coupon', compact('type', 'list'));
|
||||
}
|
||||
|
||||
// public function score(Request $request)
|
||||
// {
|
||||
// $type = $request->logType;
|
||||
// $logs = Auth::user()->account->logs()
|
||||
// ->when($type, function ($query) use ($type) {
|
||||
// switch ($type) {
|
||||
// case 'ALL':
|
||||
// break;
|
||||
// case 'PLUS':
|
||||
// $query->where('variable', '>', 0);
|
||||
// break;
|
||||
// case 'MINUS':
|
||||
// $query->where('variable', '<', 0);
|
||||
// break;
|
||||
// case 'EXPIRE':
|
||||
// $query->where('variable', '>', 0);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// })
|
||||
// ->where('type', 'score')
|
||||
// ->orderBy('created_at', 'desc')->get();
|
||||
// $score_explain = \Params::get('score_explain');
|
||||
|
||||
// $score_explain = str_replace("\n", "<br />", $score_explain);
|
||||
// $score_explain = str_replace("\r", "<br />", $score_explain);
|
||||
|
||||
// return view('account.score', compact('logs', 'score_explain'));
|
||||
// }
|
||||
|
||||
}
|
||||
71
app/Http/Controllers/ActivityController.php
Normal file
71
app/Http/Controllers/ActivityController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Image;
|
||||
use QrCode;
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class ActivityController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
View::share('nav', 1);
|
||||
}
|
||||
|
||||
public function index(Category $category)
|
||||
{
|
||||
if (in_array($category->id, [13, 14])) {
|
||||
$categorys = Category::with('storage')->where('parent_id', $category->id)->orderby('sort', 'asc')->get();
|
||||
$category_ids = Category::where('parent_id', $category->id)->pluck('id');
|
||||
} else {
|
||||
$categorys = Category::with('storage')->where('parent_id', $category->parent_id)->orderby('sort', 'asc')->get();
|
||||
$category_ids = Category::where('id', $category->id)->pluck('id');
|
||||
}
|
||||
$activitys = Activity::inRandomOrder()->whereIn('category_id', $category_ids)->get();
|
||||
|
||||
return view('activity.index', compact('activitys', 'categorys', 'category'));
|
||||
}
|
||||
|
||||
public function show(Activity $activity)
|
||||
{
|
||||
return view('activity.show', compact('activity'));
|
||||
}
|
||||
|
||||
public function create(Request $request, Activity $activity)
|
||||
{
|
||||
return view('activity.create', compact('activity'));
|
||||
}
|
||||
|
||||
//生成核销二维码
|
||||
public function qrcode(Request $request)
|
||||
{
|
||||
$orderid = $request->orderid;
|
||||
$order = Order::find($orderid);
|
||||
|
||||
if (!$order) {
|
||||
return Image::canvas(200, 200)->text('没有这个订单', 50, 100, function ($font) {
|
||||
$font->file('fonts/yahei.ttf')->color('#1f1f1f')->size(21);
|
||||
})->response('jpg');
|
||||
} elseif ($order->item_type != 'ACTIVITY') {
|
||||
return Image::canvas(200, 200)->text('订单类型不对', 50, 100, function ($font) {
|
||||
$font->file('fonts/yahei.ttf')->color('#1f1f1f')->size(21);
|
||||
})->response('jpg');
|
||||
}
|
||||
|
||||
if (!$order->canActivityAudit()) {
|
||||
return $this->error('订单状态不对');
|
||||
}
|
||||
|
||||
$activity = $order->detail->item_id;
|
||||
$qrCode = Image::make(QrCode::size(3000)->format('png')->margin(1)->generate(route('sellers.verification', ['orderid' => $orderid])))->resize(230, 230);
|
||||
return $qrCode->response('jpg');
|
||||
}
|
||||
|
||||
}
|
||||
121
app/Http/Controllers/AddressController.php
Normal file
121
app/Http/Controllers/AddressController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Area\Models\UserAddress;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 4);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$addresses = Auth::user()->addresses()->orderBy('is_default', 'desc')->orderBy('id', 'desc')->get();
|
||||
|
||||
if ($addresses->isEmpty()) {
|
||||
return redirect()->route('addresses.create');
|
||||
}
|
||||
return view('address.index', compact('addresses'));
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
# code...
|
||||
}
|
||||
public function create(Request $request)
|
||||
{
|
||||
$provinces = \Area::index(0);
|
||||
return view('address.create', compact('provinces'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
\Address::store(
|
||||
[
|
||||
'user_id' => Auth::id(),
|
||||
'name' => $request->name,
|
||||
'mobile' => $request->mobile,
|
||||
'province_sn' => $request->province_sn,
|
||||
'city_sn' => $request->city_sn,
|
||||
'area_sn' => $request->area_sn,
|
||||
'address' => $request->address,
|
||||
]
|
||||
);
|
||||
$address = UserAddress::where('user_id', Auth::id())->orderBy('id', 'desc')->first();
|
||||
if ($request->def) {
|
||||
\Address::setDefault($address);
|
||||
}
|
||||
if ($request->callback) {
|
||||
$callback = $request->callback . '?address=' . $address->id;
|
||||
} else {
|
||||
$callback = route('addresses.index');
|
||||
}
|
||||
return $this->success('地址创建成功', $callback);
|
||||
}
|
||||
|
||||
public function edit(UserAddress $address)
|
||||
{
|
||||
$provinces = \Area::index(0);
|
||||
$cities = \Area::index($address->province_sn);
|
||||
$areas = \Area::index($address->city_sn);
|
||||
return view('address.edit', compact('address', 'provinces', 'cities', 'areas'));
|
||||
}
|
||||
|
||||
public function update(Request $request, UserAddress $address)
|
||||
{
|
||||
if (\Address::update($address, $request->all())) {
|
||||
return $this->success('修改成功', route('addresses.index'));
|
||||
} else {
|
||||
return $this->error('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
if (\Address::destroy($id)) {
|
||||
return $this->success('删除成功', route('addresses.index'));
|
||||
} else {
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
|
||||
public function select(Request $request)
|
||||
{
|
||||
$callback = $request->has('callback') ? $request->callback : route('orders.create');
|
||||
$addresses = Auth::user()->addresses()->orderBy('is_default', 'desc')->orderBy('id', 'desc')->get();
|
||||
return view('address.change', compact('addresses', 'callback'));
|
||||
}
|
||||
|
||||
public function areas(Request $request)
|
||||
{
|
||||
if (empty($request->psn)) {
|
||||
return ['msg' => '请选择省份', 'code' => 0];
|
||||
}
|
||||
|
||||
$areas = \Area::sub($request->psn);
|
||||
|
||||
if ($areas) {
|
||||
return response()->json(['msg' => '', 'code' => 1, 'data' => $areas]);
|
||||
} else {
|
||||
return ['msg' => '请选择省份/城市', 'code' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
public function setdef($id)
|
||||
{
|
||||
if (\Address::setDefault(UserAddress::find($id))) {
|
||||
return $this->success('设置成功', route('addresses.index'));
|
||||
} else {
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
}
|
||||
72
app/Http/Controllers/AgencyController.php
Normal file
72
app/Http/Controllers/AgencyController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Seller;
|
||||
use App\Models\SellerLesson;
|
||||
use App\Models\SellerLessonLog;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AgencyController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
View::share('nav', 2);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$user = User::find(1);
|
||||
if (!$user->agency || $user->agency->status != 1) {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
$category = $request->category;
|
||||
|
||||
$sellers = Seller::with(['category'])
|
||||
->withCount('lesson')
|
||||
->where('agency_id', $user->agency->id)
|
||||
->when(is_numeric($category), function ($q) use ($category) {
|
||||
$q->where('category_id', $category);
|
||||
})
|
||||
->get();
|
||||
$categoryids = Seller::where('agency_id', $user->agency->id)->groupBy('category_id')->pluck('category_id')->toArray();
|
||||
$categorys = Category::whereIn('id', $categoryids)->get();
|
||||
return view('agency.index', compact('sellers', 'categorys'));
|
||||
}
|
||||
|
||||
public function lesson(Request $request, Seller $seller)
|
||||
{
|
||||
$lessons = SellerLesson::withCount('logs')->where('seller_id', $seller->id)->get();
|
||||
return view('agency.lesson', compact('lessons', 'seller'));
|
||||
}
|
||||
|
||||
public function data()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$user = User::find(1);
|
||||
if (!$user->agency || $user->agency->status != 1) {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
$dayBetween = [Carbon::today()->toDateTimeString(), Carbon::today()->addSecond(86399)->toDateTimeString()];
|
||||
|
||||
$sellerids = Seller::where('agency_id', $user->agency->id)->pluck('id')->toArray();
|
||||
$lessonids = SellerLesson::whereIn('seller_id', $sellerids)->pluck('id')->toArray();
|
||||
|
||||
$data = [
|
||||
'seller_count' => count($sellerids), //机构总数
|
||||
'lessons_count' => count($lessonids), //课程总数
|
||||
'apply_lesson_all' => SellerLessonLog::whereIn('lesson_id', $lessonids)->count(), //报名总数
|
||||
'apply_lesson_day' => SellerLessonLog::whereIn('lesson_id', $lessonids)->whereBetween('created_at', $dayBetween)->count(), //今日报名数
|
||||
];
|
||||
return view('agency.data', compact('data'));
|
||||
}
|
||||
|
||||
}
|
||||
28
app/Http/Controllers/AjaxResponse.php
Normal file
28
app/Http/Controllers/AjaxResponse.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
trait AjaxResponse
|
||||
{
|
||||
|
||||
public function success($message = '', $redirect = null)
|
||||
{
|
||||
return [
|
||||
'status' => 'SUCCESS',
|
||||
'statusCode' => 200,
|
||||
'message' => $message,
|
||||
'redirect' => $redirect,
|
||||
];
|
||||
}
|
||||
|
||||
public function error($message = '', $redirect = null)
|
||||
{
|
||||
return [
|
||||
'status' => 'ERROR',
|
||||
'statusCode' => 400,
|
||||
'message' => $message,
|
||||
'redirect' => $redirect,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
431
app/Http/Controllers/AuthController.php
Normal file
431
app/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,431 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Rules\Checkmobile;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Sms\Models\Sms as SmsModel;
|
||||
use Validator;
|
||||
use \Illuminate\Support\Facades\URL;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except(['logout', 'smsCode']);
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
{
|
||||
if ($request->isMethod('post')) {
|
||||
$request->validate([
|
||||
'mobile' => ['required', 'unique:users', new Checkmobile],
|
||||
'verify' => ['required', 'size:4', function ($attribute, $value, $fail) use ($request) {
|
||||
if ($value != SmsModel::where('mobile', $request->mobile)->where('used', 0)->latest()->value('code')) {
|
||||
return $fail('验证码不正确');
|
||||
}
|
||||
}],
|
||||
'password' => 'required|between:6,32|confirmed',
|
||||
'password_confirmation' => 'required|between:6,32',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.unique' => '手机号已经注册',
|
||||
'verify.required' => '验证码必须填写',
|
||||
'verify.size' => '验证码长度为:size位',
|
||||
'password.required' => '登录密码必须填写',
|
||||
'password.between' => '登录密码有误',
|
||||
'password.confirmed' => '确认密码与登录密码不一致',
|
||||
'password_confirmation.required' => '确认密码必须填写',
|
||||
'password_confirmation.between' => '确认密码有误',
|
||||
]);
|
||||
|
||||
$Original = session('Original');
|
||||
if ($Original) {
|
||||
$app = app('wechat.official_account');
|
||||
|
||||
$openUser = $app->user->get($Original['openid']);
|
||||
$Original['subscribe_at'] = $openUser->subscribe_time;
|
||||
$Original['subscribe_scene'] = $openUser->subscribe_scene;
|
||||
$Original['qr_scene'] = $openUser->qr_scene;
|
||||
$Original['qr_scene_str'] = $openUser->qr_scene_str;
|
||||
}
|
||||
|
||||
$parent_id = session('parent_id', 0);
|
||||
$seller_id = 0;
|
||||
if ($parent_id) {
|
||||
$parent = User::find($parent_id);
|
||||
$seller_id = $parent->seller_id ?? '0';
|
||||
}
|
||||
|
||||
$findUser = User::where('openid', $Original['openid'])->first();
|
||||
if ($findUser) {
|
||||
return $this->success('注册失败:此微信已被使用');
|
||||
}
|
||||
$user = User::updateOrCreate(
|
||||
[
|
||||
'openid' => $Original['openid'],
|
||||
'mobile' => $request->mobile,
|
||||
'seller_id' => $seller_id,
|
||||
'password' => $request->password,
|
||||
],
|
||||
[
|
||||
'parent_id' => session('parent_id', 0),
|
||||
'info' => [
|
||||
'nickname' => $Original['nickname'],
|
||||
'headimgurl' => $Original['headimgurl'],
|
||||
'sex' => $Original['sex'],
|
||||
'country' => $Original['country'],
|
||||
'province' => $Original['province'],
|
||||
'city' => $Original['city'],
|
||||
'subscribe_at' => $Original['subscribe_at'] ?? null,
|
||||
'subscribe_scene' => $Original['subscribe_scene'] ?? null,
|
||||
'qr_scene' => $Original['qr_scene'] ?? null,
|
||||
'qr_scene_str' => $Original['qr_scene_str'] ?? null,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
Session::forget('parent_id');
|
||||
|
||||
// 实现注册完自动登录
|
||||
Auth::login($user);
|
||||
event(new Registered($user));
|
||||
|
||||
return $this->success('注册成功', route('baby'));
|
||||
} else {
|
||||
if (Session::has('Original') === false) {
|
||||
$app = app('wechat.official_account');
|
||||
$app['config']->set('oauth.callback', 'register/auth/wechat');
|
||||
return $app->oauth->redirect();
|
||||
}
|
||||
return view('auth.register');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录 *
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:47:02+0800
|
||||
* @param Request $request
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
if ($request->isMethod('POST')) {
|
||||
$Original = session('Original');
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|exists:users',
|
||||
'password' => 'required|between:6,32',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.exists' => '手机号码不存在',
|
||||
'password.required' => '登录密码必须填写',
|
||||
'password.between' => '登录密码应在:min-:max位之间',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$cert = [
|
||||
'mobile' => $request->mobile,
|
||||
'password' => $request->password,
|
||||
];
|
||||
|
||||
if (Auth::attempt($cert, true)) {
|
||||
$reback = $request->r ?: route('index.index');
|
||||
return $this->success('登录成功', $reback);
|
||||
} else {
|
||||
return $this->error('用户名或密码不存在');
|
||||
}
|
||||
} else {
|
||||
return view('auth.login');
|
||||
}
|
||||
}
|
||||
|
||||
public function regwechat()
|
||||
{
|
||||
$app = app('wechat.official_account');
|
||||
$weUser = $app->oauth->user();
|
||||
$Original = $weUser->getOriginal();
|
||||
Session::put('Original', $Original);
|
||||
return redirect()->route('register');
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录 、微信快速注册 *
|
||||
* 注册完之后,在这里没有办法判断推荐关系
|
||||
*
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:44:34+0800
|
||||
* @param Request $request
|
||||
*/
|
||||
public function wechat(Request $request)
|
||||
{
|
||||
|
||||
if (strpos($request->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false) {
|
||||
$app = app('wechat.official_account');
|
||||
$app['config']->set('oauth.callback', 'login/wechatCallback');
|
||||
return $app->oauth->redirect();
|
||||
} else {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
}
|
||||
|
||||
public function wechatCallback(Request $request)
|
||||
{
|
||||
try {
|
||||
$app = app('wechat.official_account');
|
||||
$weUser = $app->oauth->user();
|
||||
$callback = $request['callback'] ?? '';
|
||||
$openUser = $app->user->get($weUser->id);
|
||||
$oldUser = User::where('openid', $weUser->id)->first();
|
||||
if ($oldUser) {
|
||||
$oldUser->info->update([
|
||||
'headimgurl' => $weUser->getOriginal()['headimgurl'],
|
||||
'sex' => $weUser->getOriginal()['sex'],
|
||||
'country' => $weUser->getOriginal()['country'],
|
||||
'province' => $weUser->getOriginal()['province'],
|
||||
'city' => $weUser->getOriginal()['city'],
|
||||
'subscribe_at' => $openUser->subscribe_time ?? null,
|
||||
'subscribe_scene' => $openUser->subscribe_scene ?? '',
|
||||
'qr_scene' => $openUser->qr_scene ?? '',
|
||||
'qr_scene_str' => $openUser->qr_scene_str ?? '',
|
||||
]);
|
||||
Auth::login($oldUser, true);
|
||||
if ($callback) {
|
||||
$callback = base64_decode($callback);
|
||||
return redirect($callback);
|
||||
} else {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
} else {
|
||||
// $user = User::updateOrCreate(
|
||||
// [
|
||||
// 'openid' => $weUser->id,
|
||||
// ],
|
||||
// [
|
||||
// 'parent_id' => session('parent_id', 1),
|
||||
// 'info' => [
|
||||
// 'nickname' => $weUser->getOriginal()['nickname'],
|
||||
// 'headimgurl' => $weUser->getOriginal()['headimgurl'],
|
||||
// 'sex' => $weUser->getOriginal()['sex'],
|
||||
// 'country' => $weUser->getOriginal()['country'],
|
||||
// 'province' => $weUser->getOriginal()['province'],
|
||||
// 'city' => $weUser->getOriginal()['city'],
|
||||
// 'source' => 'Web',
|
||||
// 'subscribe_at' => $openUser->subscribe_time ?? null,
|
||||
// 'subscribe_scene' => $openUser->subscribe_scene ?? '',
|
||||
// 'qr_scene' => $openUser->qr_scene ?? '',
|
||||
// 'qr_scene_str' => $openUser->qr_scene_str ?? '',
|
||||
// ],
|
||||
// ]
|
||||
// );
|
||||
// event(new Registered($user));
|
||||
// Auth::login($user, true);
|
||||
// if ($callback) {
|
||||
// $callback = base64_decode($callback);
|
||||
// return redirect($callback);
|
||||
// } else {
|
||||
// return redirect()->route('vip.create');
|
||||
// }
|
||||
return redirect()->route('register');
|
||||
}
|
||||
/**
|
||||
* 这个注册完成事件,只能把 updateOrCreate 这个方法拆分开来使用了
|
||||
*/
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码登录 *
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:46:10+0800
|
||||
* @param Request $request
|
||||
*/
|
||||
public function bycode(Request $request)
|
||||
{
|
||||
if ($request->isMethod('POST')) {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|exists:users',
|
||||
'code' => 'required|sms_check:mobile,BYCODE',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.exists' => '手机号码不存在',
|
||||
'code.required' => '验证码必须填写',
|
||||
'code.sms_check' => '验证码不正确',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$user = User::where('mobile', $request->mobile)->first();
|
||||
try {
|
||||
Auth::login($user, true);
|
||||
return $this->success('登录成功', route('user.index'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
return view('auth.bycode');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 找回密码
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:46:34+0800
|
||||
* @param Request $request
|
||||
*/
|
||||
public function forgot(Request $request)
|
||||
{
|
||||
if ($request->isMethod('POST')) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|exists:users',
|
||||
'code' => 'required|sms_check:mobile,FORGOT',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.exists' => '手机号码不存在',
|
||||
'code.required' => '验证码必须填写',
|
||||
'code.sms_check' => '验证码不正确',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$request->session()->put('reset_mobile', $request->mobile);
|
||||
|
||||
return $this->success('身份验证成功', Url::temporarySignedRoute('forgot.reset', now()->addHour()));
|
||||
} else {
|
||||
return view('auth.forgot');
|
||||
}
|
||||
}
|
||||
|
||||
public function reset(Request $request)
|
||||
{
|
||||
if ($request->isMethod('POST')) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'password' => 'required|between:6,32',
|
||||
], [
|
||||
'password.required' => '登录密码必须填写',
|
||||
'password.mobile' => '登录密码应在:min-:max位之间',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$reset_mobile = $request->session()->pull('reset_mobile');
|
||||
$password = $request->password;
|
||||
|
||||
try {
|
||||
$user = User::where('mobile', $reset_mobile)->first();
|
||||
$user->password = $password;
|
||||
$user->save();
|
||||
return $this->success('密码重置成功', route('login'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->success('密码重置失败', route('forgot'));
|
||||
}
|
||||
} else {
|
||||
return view('auth.reset');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:46:45+0800
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
session()->flush();
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:49:55+0800
|
||||
* @return
|
||||
*/
|
||||
public function smsCode(Request $request)
|
||||
{
|
||||
$channel = $request->channel;
|
||||
$mobile = $request->mobile;
|
||||
switch ($channel) {
|
||||
case 'BYCODE':
|
||||
case 'FORGOT':
|
||||
// 验证码登录,必须要手机号存在才行
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => ['required', 'exists:users', new Checkmobile],
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.exists' => '手机号码不存在',
|
||||
]);
|
||||
break;
|
||||
case 'BIND':
|
||||
// 绑定手机号,要不存在才可以
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => ['required', 'unique:users', new Checkmobile],
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.unique' => '手机号码已经绑定',
|
||||
]);
|
||||
break;
|
||||
case 'BINDLast':
|
||||
$channel = 'DEFAULT';
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => ['required', new Checkmobile],
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$res = SmsModel::verify_code($request->mobile);
|
||||
if ($res !== true) {
|
||||
return $this->error($res);
|
||||
}
|
||||
|
||||
try {
|
||||
$code = \Sms::send($mobile, $channel);
|
||||
$config = config('rulong_sms');
|
||||
if ($config['debug'] != true) {
|
||||
return $this->success('验证码发送成功');
|
||||
} else {
|
||||
return $this->success('验证码发送成功' . $code);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
93
app/Http/Controllers/CartController.php
Normal file
93
app/Http/Controllers/CartController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\GoodsParams;
|
||||
use App\Models\SellerLesson;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth')->except(['store']);
|
||||
View::share('nav', 3);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$lists = Cart::mine()->with('lesson')->orderBy('id', 'desc')->get();
|
||||
|
||||
$gifts = GoodsParams::whereHas('goods', function ($query) {
|
||||
$query->where('status', 1)->where('is_seller_gift', 1);
|
||||
})->where('stock', '>', 0)->get();
|
||||
|
||||
$coupon_list = CouponUserLog::with('info')->whereHas('info', function ($query) {
|
||||
$query->where('type', 'lesson')
|
||||
->where('start_at', '<=', date('Y-m-d H:i:s', time()))
|
||||
->where('end_at', '>=', date('Y-m-d H:i:s', time()));
|
||||
})->where('user_id', Auth::id())->where('status', 0)->get();
|
||||
|
||||
$coupon = $coupon_list->sortByDesc(function ($coupon, $key) {
|
||||
return $coupon->info->bouns;
|
||||
})->first();
|
||||
|
||||
$apply_lesson_price = \Params::get('apply_lesson_price');
|
||||
return view('cart.index', compact('lists', 'gifts', 'coupon', 'apply_lesson_price'));
|
||||
}
|
||||
|
||||
public function show(Request $request, $params_id)
|
||||
{
|
||||
$info = GoodsParams::with('goods.storage')->find($params_id);
|
||||
return view('cart.show', compact('info'));
|
||||
}
|
||||
|
||||
public function delete(Cart $cart)
|
||||
{
|
||||
if ($cart->delete()) {
|
||||
return $this->success('取消成功');
|
||||
} else {
|
||||
return $this->error('取消失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function store(SellerLesson $lesson)
|
||||
{
|
||||
if (Auth::guest()) {
|
||||
return $this->error('请登录后在进行此操作', route('login'));
|
||||
}
|
||||
|
||||
$user_id = Auth::id();
|
||||
$max_num = \Params::get('lesson_num');
|
||||
$count = Cart::where('user_id', $user_id)->count();
|
||||
|
||||
if ($count >= $max_num) {
|
||||
return $this->error('您已经报满' . $max_num . '个机构课程请前去支付', route('cart.index'));
|
||||
}
|
||||
|
||||
$info = Cart::where('lesson_id', $lesson->id)->where('user_id', $user_id)->first();
|
||||
if ($info) {
|
||||
return $this->error('您已经报名此课程');
|
||||
}
|
||||
|
||||
$seller = Cart::where('seller_id', $lesson->organ->id)->where('user_id', $user_id)->first();
|
||||
if ($seller) {
|
||||
return $this->error('一个机构只能报名一门课程');
|
||||
}
|
||||
|
||||
$result = Cart::create([
|
||||
'user_id' => Auth::id(),
|
||||
'lesson_id' => $lesson->id,
|
||||
'seller_id' => $lesson->organ->id,
|
||||
'number' => 1,
|
||||
]);
|
||||
return $this->success('报名成功', route('cart.index'));
|
||||
|
||||
}
|
||||
}
|
||||
70
app/Http/Controllers/Controller.php
Normal file
70
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Area\Models\Area;
|
||||
use RuLong\Order\Models\Order;
|
||||
use Session;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, AjaxResponse;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request['share_uid']) {
|
||||
session(['parent_id' => $request['share_uid']]);
|
||||
}
|
||||
|
||||
// $this->middleware('auth');
|
||||
|
||||
//检查是否有礼品
|
||||
self::checkGift();
|
||||
}
|
||||
|
||||
//获取当前定位数组
|
||||
public function getDefaultLocation()
|
||||
{
|
||||
$lat = session('lat', '45.76021');
|
||||
$lng = session('lng', '126.66835');
|
||||
$city = session('city', '');
|
||||
$area = session('area', '');
|
||||
$real_area = session('real_area', '');
|
||||
$history_area = session('history_area', '');
|
||||
if (!$area) {
|
||||
$area = Area::where('sn', '230100')->first();
|
||||
}
|
||||
|
||||
if (!$real_area) {
|
||||
session::put('real_area', $area);
|
||||
$real_area = session('real_area', '');
|
||||
}
|
||||
$location = [
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'city' => $city,
|
||||
'area' => $area,
|
||||
'real_area' => $real_area,
|
||||
'history_area' => $history_area,
|
||||
];
|
||||
return $location;
|
||||
}
|
||||
|
||||
public function checkGift()
|
||||
{
|
||||
if (Auth::user()) {
|
||||
$gift = Order::where('user_id', Auth::id())->where('item_type', 'GIFT')->where('state', 'UNADDRESS')->first();
|
||||
if ($gift) {
|
||||
$url = ($gift->type == 'lesson') ? route('gifts.unpay') : route('lottery.logs', ['type' => 'goods']);
|
||||
View::share('show_gift_url', $url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
app/Http/Controllers/CouponController.php
Normal file
29
app/Http/Controllers/CouponController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
}
|
||||
|
||||
public function select(Request $request)
|
||||
{
|
||||
$coupon_list = CouponUserLog::with('info')->whereHas('info', function ($query) {
|
||||
$query->where('type', 'lesson')
|
||||
->where('start_at', '<=', date('Y-m-d H:i:s', time()))
|
||||
->where('end_at', '>=', date('Y-m-d H:i:s', time()));
|
||||
})->where('user_id', Auth::id())->where('status', 0)->get();
|
||||
|
||||
return view('coupon.select', compact('coupon_list'));
|
||||
}
|
||||
|
||||
}
|
||||
266
app/Http/Controllers/DataController.php
Normal file
266
app/Http/Controllers/DataController.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Agency;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Seller;
|
||||
use App\Models\Withdraw;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Identity\Models\IdentityLog;
|
||||
use RuLong\Identity\Models\UserIdentity;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserAccount\Models\UserAccount;
|
||||
|
||||
class DataController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
$this->todayTime = [Carbon::today()->toDateTimeString(), Carbon::today()->addSecond(86399)->toDateTimeString()];
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
$today = [
|
||||
'reg' => User::whereBetween('created_at', $this->todayTime)->count(),
|
||||
'counselor' => UserIdentity::whereHas('user')->where('identity_id', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'agency' => UserIdentity::whereHas('user')->where('identity_id', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'manage' => UserIdentity::whereHas('user')->where('identity_id', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'teacher' => UserIdentity::whereHas('user')->where('identity_id', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'salesman' => User::whereBetween('created_at', $this->todayTime)->where('is_salesman', 1)->count(),
|
||||
];
|
||||
|
||||
$all = [
|
||||
'reg' => User::count(),
|
||||
'counselor' => UserIdentity::whereHas('user')->where('identity_id', 1)->count(),
|
||||
'agency' => UserIdentity::whereHas('user')->where('identity_id', 2)->count(),
|
||||
'manage' => UserIdentity::whereHas('user')->where('identity_id', 3)->count(),
|
||||
'teacher' => UserIdentity::whereHas('user')->where('identity_id', 4)->count(),
|
||||
'salesman' => User::where('is_salesman', 1)->count(),
|
||||
];
|
||||
return view('data.users', compact('today', 'all'));
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$state = [
|
||||
'PAID', 'DELIVER', 'DELIVERED', 'SIGNED', 'COMPLETED', 'UNUSE', 'USED', 'UNADDRESS',
|
||||
];
|
||||
$today = [
|
||||
'all' => Order::whereIn('state', $state)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'activity_all' => Order::whereIn('state', $state)->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'activity' => [
|
||||
'buy' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'give' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
],
|
||||
'gift_all' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'gift' => [
|
||||
'lesson' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lesson')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'lottery' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lottery')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
],
|
||||
];
|
||||
|
||||
$all = [
|
||||
'all' => Order::whereIn('state', $state)->count(),
|
||||
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->count(),
|
||||
'activity_all' => Order::whereIn('state', $state)->where('item_type', 'ACTIVITY')->count(),
|
||||
'activity' => [
|
||||
'buy' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->count(),
|
||||
'give' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'ACTIVITY')->count(),
|
||||
],
|
||||
'gift_all' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->count(),
|
||||
'gift' => [
|
||||
'lesson' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lesson')->count(),
|
||||
'lottery' => Order::whereIn('state', $state)->where('item_type', 'GIFT')->where('type', 'lottery')->count(),
|
||||
],
|
||||
];
|
||||
return view('data.orders', compact('today', 'all'));
|
||||
}
|
||||
|
||||
public function withdraw()
|
||||
{
|
||||
|
||||
$all = [
|
||||
//申请提现额
|
||||
'withdraw' => [
|
||||
'all' => Withdraw::sum('amount'),
|
||||
],
|
||||
|
||||
//实际转账额
|
||||
'cash' => [
|
||||
'all' => Withdraw::whereIn('state', [0, 1])->sum('take'),
|
||||
'pass' => Withdraw::where('state', 1)->sum('take'),
|
||||
'no' => Withdraw::where('state', -1)->sum('take'),
|
||||
],
|
||||
'user' => [
|
||||
'all' => Withdraw::where('state', '>=', 0)->count('user_id'),
|
||||
'pass' => Withdraw::where('state', 1)->groupBy('user_id')->count('user_id'),
|
||||
'no' => Withdraw::where('state', -1)->groupBy('user_id')->count('user_id'),
|
||||
],
|
||||
'account' => [
|
||||
'all_account' => UserAccount::sum('cash'),
|
||||
'user_count' => UserAccount::count(),
|
||||
],
|
||||
];
|
||||
|
||||
$today = [
|
||||
//申请提现额
|
||||
'withdraw' => [
|
||||
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->whereIn('state', [0, 1])->sum('amount'),
|
||||
'pass' => Withdraw::where('state', 1)->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
||||
'no' => Withdraw::where('state', -1)->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
||||
],
|
||||
|
||||
//实际转账额
|
||||
'cash' => [
|
||||
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->whereIn('state', [0, 1])->sum('take'),
|
||||
'pass' => Withdraw::where('state', 1)->whereBetween('created_at', $this->todayTime)->sum('take'),
|
||||
'no' => Withdraw::where('state', -1)->whereBetween('created_at', $this->todayTime)->sum('take'),
|
||||
],
|
||||
'user' => [
|
||||
'all' => Withdraw::whereBetween('created_at', $this->todayTime)->where('state', '>=', 0)->count('user_id'),
|
||||
'pass' => Withdraw::where('state', 1)->groupBy('user_id')->whereBetween('created_at', $this->todayTime)->count('user_id'),
|
||||
'no' => Withdraw::where('state', -1)->groupBy('user_id')->whereBetween('created_at', $this->todayTime)->count('user_id'),
|
||||
],
|
||||
'account' => [
|
||||
'all_account' => UserAccount::whereBetween('created_at', $this->todayTime)->sum('cash'),
|
||||
'user_count' => UserAccount::whereBetween('created_at', $this->todayTime)->count(),
|
||||
],
|
||||
];
|
||||
|
||||
return view('data.withdraw', compact('today', 'all', 'nav'));
|
||||
}
|
||||
|
||||
public function upgrade()
|
||||
{
|
||||
$today = [
|
||||
'counselor_all' => IdentityLog::where('after', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'agency' => IdentityLog::where('after', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'manage' => IdentityLog::where('after', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'teacher' => IdentityLog::where('after', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'counselor' => [
|
||||
'auto' => IdentityLog::where('after', 1)->where('channel', 'AutoUp')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'empty' => IdentityLog::where('after', 1)->where('channel', 'AdminUp')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
],
|
||||
];
|
||||
|
||||
$all = [
|
||||
'all' => IdentityLog::whereIn('after', [1, 2, 3, 4])->count(),
|
||||
'counselor_all' => IdentityLog::where('after', 1)->count(),
|
||||
'agency' => IdentityLog::where('after', 2)->count(),
|
||||
'manage' => IdentityLog::where('after', 3)->count(),
|
||||
'teacher' => IdentityLog::where('after', 4)->count(),
|
||||
'counselor' => [
|
||||
'auto' => IdentityLog::where('after', 1)->where('channel', 'AutoUp')->count(),
|
||||
'empty' => IdentityLog::where('after', 1)->where('channel', 'AdminUp')->count(),
|
||||
],
|
||||
];
|
||||
return view('data.upgrade', compact('today', 'all'));
|
||||
}
|
||||
|
||||
public function account()
|
||||
{
|
||||
$all = [
|
||||
'all' => Payment::where('state', 'SUCCESS')->sum('amount'),
|
||||
'lesson' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'LESSON')->where('type', 'order');})->where('state', 'SUCCESS')->sum('amount'),
|
||||
'activity' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'ACTIVITY')->where('type', 'order');})->where('state', 'SUCCESS')->sum('amount'),
|
||||
];
|
||||
|
||||
$today = [
|
||||
'all' => Payment::where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
||||
'lesson' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'LESSON')->where('type', 'order');})->where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
||||
'activity' => Payment::whereHas('order', function ($query) {$query->where('item_type', 'ACTIVITY')->where('type', 'order');})->where('state', 'SUCCESS')->whereBetween('created_at', $this->todayTime)->sum('amount'),
|
||||
];
|
||||
return view('data.account', compact('all', 'today'));
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$state = [
|
||||
'PAID', 'DELIVER', 'DELIVERED', 'SIGNED', 'COMPLETED', 'UNUSE', 'USED', 'UNADDRESS',
|
||||
];
|
||||
|
||||
$today = [
|
||||
'user' => [
|
||||
'reg' => User::whereBetween('created_at', $this->todayTime)->count(),
|
||||
'counselor' => UserIdentity::where('identity_id', 1)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'agency' => UserIdentity::where('identity_id', 2)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'manage' => UserIdentity::where('identity_id', 3)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'teacher' => UserIdentity::where('identity_id', 4)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'salesman' => User::whereBetween('created_at', $this->todayTime)->where('is_salesman', 1)->count(),
|
||||
],
|
||||
'order' => [
|
||||
'all' => Order::whereIn('state', $state)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'activity' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'lesson_gift' => Order::whereIn('state', $state)->where('type', 'lesson')->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'lottery_gift' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'GIFT')->whereBetween('created_at', $this->todayTime)->count(),
|
||||
],
|
||||
];
|
||||
|
||||
$all = [
|
||||
'user' => [
|
||||
'reg' => User::count(),
|
||||
'counselor' => UserIdentity::where('identity_id', 1)->count(),
|
||||
'agency' => UserIdentity::where('identity_id', 2)->count(),
|
||||
'manage' => UserIdentity::where('identity_id', 3)->count(),
|
||||
'teacher' => UserIdentity::where('identity_id', 4)->count(),
|
||||
'salesman' => User::where('is_salesman', 1)->count(),
|
||||
],
|
||||
'order' => [
|
||||
'all' => Order::whereIn('state', $state)->count(),
|
||||
'lesson' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'LESSON')->count(),
|
||||
'activity' => Order::whereIn('state', $state)->where('type', 'order')->where('item_type', 'ACTIVITY')->count(),
|
||||
'lesson_gift' => Order::whereIn('state', $state)->where('type', 'lesson')->where('item_type', 'GIFT')->count(),
|
||||
'lottery_gift' => Order::whereIn('state', $state)->where('type', 'lottery')->where('item_type', 'GIFT')->count(),
|
||||
],
|
||||
];
|
||||
return view('data.index', compact('today', 'all'));
|
||||
}
|
||||
|
||||
public function salesman(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if (!$user->is_salesman) {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
$today = [
|
||||
'agency' => Agency::where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'organ' => Seller::where('type', 'organ')->where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'seller' => Seller::where('type', 'seller')->where('salesman_id', $user->id)->whereBetween('created_at', $this->todayTime)->count(),
|
||||
'agency_organ' => Seller::whereHas('agency', function ($query) use ($user) {
|
||||
$query->where('salesman_id', $user->id);
|
||||
})->whereBetween('created_at', $this->todayTime)->count(),
|
||||
];
|
||||
|
||||
$all = [
|
||||
'agency' => Agency::where('salesman_id', $user->id)->count(),
|
||||
'organ' => Seller::where('type', 'organ')->where('salesman_id', $user->id)->count(),
|
||||
'seller' => Seller::where('type', 'seller')->where('salesman_id', $user->id)->count(),
|
||||
'agency_organ' => Seller::whereHas('agency', function ($query) use ($user) {
|
||||
$query->where('salesman_id', $user->id);
|
||||
})->count(),
|
||||
];
|
||||
|
||||
$organs = Seller::whereHas('agency', function ($query) use ($user) {
|
||||
$query->where('salesman_id', $user->id);
|
||||
})
|
||||
->distinct('id')
|
||||
->orWhere('salesman_id', $user->id)
|
||||
->get();
|
||||
|
||||
return view('data.salesman', compact('today', 'all', 'organs'));
|
||||
}
|
||||
|
||||
}
|
||||
89
app/Http/Controllers/FavoriteController.php
Normal file
89
app/Http/Controllers/FavoriteController.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\Favorite;
|
||||
use App\Models\Seller;
|
||||
use App\Models\SellerLesson;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class FavoriteController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
View::share('nav', 2);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$type = $request->type ?? 'SellerLesson';
|
||||
$item_type = "App\Models\\" . $type;
|
||||
$lists = Favorite::mine()->where('item_type', $item_type)->get();
|
||||
return view('favorite.index', compact('lists', 'type'));
|
||||
}
|
||||
|
||||
public function lesson(Request $request, SellerLesson $lesson)
|
||||
{
|
||||
$favorite = Favorite::where('item_type', 'App\Models\SellerLesson')->where('item_id', $lesson->id)->where('user_id', Auth::id())->first();
|
||||
|
||||
if (!$lesson) {
|
||||
return $this->error('没有这个课程');
|
||||
}
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
return $this->success('课程取消收藏成功');
|
||||
} else {
|
||||
Auth::user()->lessonFavorite()->create([
|
||||
'item_id' => $lesson->id,
|
||||
'item_type' => get_class($lesson),
|
||||
]);
|
||||
return $this->success('课程收藏成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function seller(Request $request, Seller $seller)
|
||||
{
|
||||
$favorite = Favorite::where('item_type', 'App\Models\Seller')->where('item_id', $seller->id)->where('user_id', Auth::id())->first();
|
||||
|
||||
if (!$seller) {
|
||||
return $this->error('没有这个机构');
|
||||
}
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
return $this->success('机构取消收藏成功');
|
||||
} else {
|
||||
Auth::user()->sellerFavorite()->create([
|
||||
'item_id' => $seller->id,
|
||||
'item_type' => get_class($seller),
|
||||
]);
|
||||
return $this->success('机构收藏成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function activity(Request $request, Activity $activity)
|
||||
{
|
||||
$favorite = Favorite::where('item_type', 'App\Models\Activity')->where('item_id', $activity->id)->where('user_id', Auth::id())->first();
|
||||
|
||||
if (!$activity) {
|
||||
return $this->error('没有这个生活/服务');
|
||||
}
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
return $this->success('生活/服务取消收藏成功');
|
||||
} else {
|
||||
Auth::user()->sellerFavorite()->create([
|
||||
'item_id' => $activity->id,
|
||||
'item_type' => get_class($activity),
|
||||
]);
|
||||
return $this->success('生活/服务收藏成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
122
app/Http/Controllers/GiftController.php
Normal file
122
app/Http/Controllers/GiftController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\Order\Models\OrderExpress;
|
||||
|
||||
class GiftController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
View::share('nav', 2);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$orders = Order::where('user_id', Auth::id())
|
||||
->Gift()
|
||||
->where('state', '<>', Order::ORDER_CLOSED)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return view('gifts.index', compact('orders'));
|
||||
}
|
||||
|
||||
//活动和优惠券 未支付
|
||||
public function unpay()
|
||||
{
|
||||
$orders = Order::UnAddress()
|
||||
->Gift()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('gifts.index', compact('orders'));
|
||||
}
|
||||
|
||||
//已支付报名课程和活动
|
||||
public function paid()
|
||||
{
|
||||
$orders = Order::UnDeliver()
|
||||
->Gift()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('gifts.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function delivered()
|
||||
{
|
||||
$orders = Order::Delivered()
|
||||
->Gift()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('gifts.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function signed()
|
||||
{
|
||||
$orders = Order::Delivered()
|
||||
->Gift()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('gifts.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function show($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
return view('orders.show', compact('order'));
|
||||
}
|
||||
|
||||
public function sign($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
try {
|
||||
$order->signin();
|
||||
return $this->success('签收成功', route('gifts.signed'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('签收失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
//设置收货地址
|
||||
public function address(Request $request, Order $order)
|
||||
{
|
||||
$callback = $request->callback;
|
||||
if ($request->isMethod('post')) {
|
||||
if ($request->address_id) {
|
||||
$address = \Address::get($request->address_id);
|
||||
} else {
|
||||
$address = \Address::store(
|
||||
[
|
||||
'user_id' => Auth::id(),
|
||||
'name' => $request->name,
|
||||
'mobile' => $request->mobile,
|
||||
'province_sn' => $request->province_sn,
|
||||
'city_sn' => $request->city_sn,
|
||||
'area_sn' => $request->area_sn,
|
||||
'address' => $request->address,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$express = new OrderExpress(['instance' => $address]);
|
||||
$order->express()->save($express);
|
||||
$order->state = Order::ORDER_PAID;
|
||||
$order->save();
|
||||
return $this->success('设置地址成功', $callback);
|
||||
} else {
|
||||
$provinces = \Area::index(0);
|
||||
$address_list = \Address::lists(Auth::id());
|
||||
return view('gifts.address', compact('provinces', 'order', 'address_list', 'callback'));
|
||||
}
|
||||
}
|
||||
}
|
||||
315
app/Http/Controllers/IndexController.php
Normal file
315
app/Http/Controllers/IndexController.php
Normal file
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use App\Models\Seller;
|
||||
use App\Models\SellerLesson;
|
||||
use App\Models\SellerLessonLog;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use DB;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Area\Models\OpenArea as Area;
|
||||
use Session;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth')->except(['location', 'getlocation', 'getOrgans']);
|
||||
View::share('nav', 1);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
|
||||
$adverts = Advert::limit(\Params::get('advert_limit'))->orderBy('sort', 'asc')->get(); //banner
|
||||
$c_lists = Category::with('storage')->where('parent_id', 1)
|
||||
// ->orderBy('sort', 'asc')
|
||||
// ->orderBy('created_at', 'desc')
|
||||
->inRandomOrder()
|
||||
->limit(10)->get(); //分类
|
||||
|
||||
$organs = $this->getDefaultOrgans($request); //机构列表
|
||||
$organ = $user->organ;
|
||||
//推荐课程
|
||||
$recommend = $this->getRecommend();
|
||||
|
||||
//都在看
|
||||
$watching_ids = SellerLessonLog::where('status', 1)->groupBy('lesson_id')->inRandomOrder()->take(3)->pluck('lesson_id');
|
||||
$watchings = SellerLesson::with(['organ' => function ($query) use ($lat, $lng) {
|
||||
$query->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'));
|
||||
}])->whereIn('seller_id', $watching_ids)->get();
|
||||
|
||||
$data = [
|
||||
'couponlogs' => $user->couponlog()->where('status', 0)->count(),
|
||||
'lessonlogs' => SellerLessonLog::where('user_id', $user->id)->where('status', 1)->count(),
|
||||
];
|
||||
return view('index.index', compact('adverts', 'organs', 'c_lists', 'user', 'data', 'recommend', 'watchings'));
|
||||
}
|
||||
|
||||
//获取推荐课程
|
||||
public function getRecommend()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
|
||||
$organ = $user->organ;
|
||||
$find = SellerLesson::when($area, function ($query) use ($area) {
|
||||
$query->whereHas('organ', function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
});
|
||||
})->count();
|
||||
|
||||
if ($find) {
|
||||
$area = Area::where('sn', '230100')->first();
|
||||
}
|
||||
|
||||
//推荐课程
|
||||
$recommend = SellerLesson::with(['organ' => function ($query) use ($lat, $lng) {
|
||||
$query->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'));
|
||||
}])->when(!empty($organ->toArray()), function ($q) use ($organ) {
|
||||
$q->where('seller_id', $organ->id);
|
||||
})->when(empty($organ->toArray()) && $area, function ($query) use ($area) {
|
||||
$query->whereHas('organ', function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
});
|
||||
})->inRandomOrder()->first();
|
||||
return $recommend;
|
||||
}
|
||||
|
||||
//通用获取组织
|
||||
public function getDefaultOrgans($request)
|
||||
{
|
||||
$page = $request->page ?? 0; //获取当前页码
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
|
||||
$user = Auth::user();
|
||||
if (!$area) {
|
||||
return collect([]);
|
||||
}
|
||||
|
||||
$organCateIds = [];
|
||||
if ($user && $user->organ) {
|
||||
$organCateIds = $user->organ->top_cate_id;
|
||||
}
|
||||
|
||||
$pageNum = 5;
|
||||
|
||||
if ($user && $user->organ && $user->organ->id > 0 && !$page) {
|
||||
$myorgan = Seller::with(['storage'])->where('id', Auth::user()->seller_id)->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'))->first();
|
||||
}
|
||||
|
||||
$organs = Seller::with('storage')
|
||||
->where('type', 'organ')
|
||||
->when($area, function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
})
|
||||
->when($organCateIds, function ($query) use ($organCateIds) {
|
||||
$query->whereNotIn('category_id', $organCateIds);
|
||||
})
|
||||
->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'))
|
||||
->orderBy('distance', 'asc')
|
||||
->orderBy('id', 'asc')
|
||||
->get();
|
||||
// ->paginate($pageNum);
|
||||
|
||||
if ($user && $user->organ && $user->organ->id > 0 && !$page) {
|
||||
$organs->prepend($myorgan);
|
||||
}
|
||||
|
||||
return $organs;
|
||||
}
|
||||
|
||||
//分页加载更多组织
|
||||
public function getOrgans(Request $request)
|
||||
{
|
||||
$organs = $this->getDefaultOrgans($request);
|
||||
if ($organs->count() > 0) {
|
||||
$html = response(view('index.organs', compact('organs')))->getContent();
|
||||
return $this->success($html);
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
|
||||
//搜索课程
|
||||
public function search(Request $request)
|
||||
{
|
||||
$title = $request->title;
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
|
||||
// $lists = SellerLesson::where('status', 1)->where('title', 'like', "%" . $request->title . "%")->get();
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$organCateIds = $lessonids = [];
|
||||
if ($user->organ) {
|
||||
$organCateIds = $user->organ->top_cate_id;
|
||||
$lessonids = SellerLesson::whereIn('category_id', $organCateIds)->where('seller_id', '<>', $user->organ->id)->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
$lists = SellerLesson::with(['organ.storage', 'organ' => function ($query) use ($lat, $lng) {
|
||||
$query->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'));
|
||||
}])->when($area, function ($query) use ($area) {
|
||||
$query->whereHas('organ', function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
});
|
||||
})->when(!empty($lessonids), function ($q) use ($lessonids) {
|
||||
$q->whereNotIn('id', $lessonids);
|
||||
})->where('status', 1)->where('title', 'like', "%" . $request->title . "%")->get();
|
||||
|
||||
return view('index.search', compact('lists'));
|
||||
}
|
||||
|
||||
public function pass()
|
||||
{
|
||||
$user = Auth::user();
|
||||
if ($user->info->update(['pass_at' => date('Y-m-d 23:59:59')])) {
|
||||
return $this->success('今日不再提示');
|
||||
} else {
|
||||
return $this->error('设置失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function subscribe()
|
||||
{
|
||||
return view('index.subscribe');
|
||||
}
|
||||
|
||||
public function location(Request $request)
|
||||
{
|
||||
$lat = $request->lat;
|
||||
$lng = $request->lng;
|
||||
|
||||
if (!$lat || !$lng) {
|
||||
return $this->error('设置失败');
|
||||
}
|
||||
|
||||
$location = Parent::getDefaultLocation();
|
||||
|
||||
if (!$location['real_area']) {
|
||||
$url = "http://api.map.baidu.com/geocoder";
|
||||
$client = new Client();
|
||||
$response = $client->request('GET', $url, [
|
||||
'timeout' => 30,
|
||||
'query' => [
|
||||
'location' => $lat . "," . $lng,
|
||||
'output' => 'json',
|
||||
],
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() == 200) {
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$city = $data['result']['addressComponent']['city'];
|
||||
} else {
|
||||
return $this->location($url);
|
||||
}
|
||||
$area = Area::where('name', $city)->first();
|
||||
|
||||
//如果地址没有开通,默认哈尔滨
|
||||
if ($area->status != 1) {
|
||||
$area = Area::where('sn', '230100')->first();
|
||||
$lat = $area->lat;
|
||||
$lng = $area->lng;
|
||||
}
|
||||
|
||||
Session::put('lat', $lat);
|
||||
Session::put('lng', $lng);
|
||||
Session::put('area', $area);
|
||||
Session::put('real_area', $area);
|
||||
return $this->success($city);
|
||||
} else {
|
||||
Session::put('lat', $lat);
|
||||
Session::put('lng', $lng);
|
||||
return $this->error(json_encode($location));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//设置地区
|
||||
public function getLocation(Request $request)
|
||||
{
|
||||
|
||||
$area = $request->area;
|
||||
$title = $request->title;
|
||||
|
||||
if ($area) {
|
||||
$area = Area::find($area);
|
||||
Session::put('area', $area);
|
||||
Session::push('history_area', $area);
|
||||
$url = route('index.index');
|
||||
if ($request->callback) {
|
||||
$url = $request->callback;
|
||||
}
|
||||
return $this->success('设置成功', $url);
|
||||
} else {
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
$real_area = $location['real_area'];
|
||||
$historys = $location['history_area'];
|
||||
|
||||
if (empty($lat) || empty($lng) || empty($area)) {
|
||||
return redirect()->route('index.index');
|
||||
}
|
||||
|
||||
$lists = Area::where('city', $area->city)->where('depth', 3)->where('status', 1)->get();
|
||||
if ($title) {
|
||||
$all_list = Area::where('status', 1)->where('name', 'like', "%" . $title . "%")->where('depth', 2)->orderBy('name_first_char', 'asc')->get();
|
||||
} else {
|
||||
$all_list = Area::where('status', 1)->where('depth', 2)->orderBy('name_first_char', 'asc')->get();
|
||||
}
|
||||
|
||||
$hots = Area::where('status', 1)->where('hot', 1)->get();
|
||||
return view('index.location', compact('area', 'lists', 'all_list', 'real_area', 'hots', 'historys'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
148
app/Http/Controllers/LessonsController.php
Normal file
148
app/Http/Controllers/LessonsController.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\Category;
|
||||
use App\Models\SellerLesson;
|
||||
use App\Models\SellerLessonLog;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class LessonsController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth')->except(['show', 'category']);
|
||||
View::share('nav', 3);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$type = $request->type ?? 'unoverdue';
|
||||
|
||||
$lists = SellerLessonLog::with('lesson')->whereHas('lesson', function ($query) use ($type) {
|
||||
if ($type == 'unoverdue') {
|
||||
$query->where('end_at', '>=', date('Y-m-d H:i:s', strtotime("+1 days", time())));
|
||||
} else {
|
||||
$query->where('end_at', '<=', date('Y-m-d H:i:s', strtotime("+1 days", time())));
|
||||
}
|
||||
})->where('user_id', Auth::id())->where('status', 1)->get();
|
||||
|
||||
view()->share('nav', 3);
|
||||
|
||||
return view('lesson.index', compact('lists', 'type'));
|
||||
}
|
||||
|
||||
public function show(SellerLesson $lesson)
|
||||
{
|
||||
if (Auth::guest()) {
|
||||
$favorite = collect();
|
||||
} else {
|
||||
$favorite = Auth::user()->lessonFavorite()->where('item_id', $lesson->id)->first();
|
||||
}
|
||||
|
||||
$cart = Cart::where('user_id', Auth::id())->where('lesson_id', $lesson->id)->first();
|
||||
return view('lesson.show', compact('lesson', 'favorite', 'cart'));
|
||||
}
|
||||
|
||||
//分类
|
||||
public function category(Request $request)
|
||||
{
|
||||
$category_id = $request->category_id;
|
||||
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
$category = Category::find($category_id);
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$organCateIds = [];
|
||||
if ($user && $user->organ) {
|
||||
$organCateIds = $user->organ->top_cate_id;
|
||||
}
|
||||
|
||||
$lists = SellerLesson::with(['organ' => function ($query) use ($lat, $lng) {
|
||||
$query->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'));
|
||||
}])->when(is_numeric($category_id), function ($query) use ($category_id) {
|
||||
$query->whereHas('category', function ($q) use ($category_id) {
|
||||
$q->where('id', $category_id)->Orwhere('parent_id', $category_id);
|
||||
});
|
||||
})->when($area, function ($query) use ($area) {
|
||||
$query->whereHas('organ', function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
});
|
||||
})->when(in_array($category_id, $organCateIds), function ($q) use ($user) {
|
||||
$q->where('seller_id', $user->organ->id);
|
||||
})->where('status', 1)->get();
|
||||
|
||||
$search_id = ($category->parent_id == 1) ? $category->id : $category->parent_id;
|
||||
$categorys = Category::with('storage')->where('parent_id', $search_id)
|
||||
->orderBy('sort', 'asc')
|
||||
->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return view('lesson.category', compact('lists', 'categorys', 'search_id'));
|
||||
}
|
||||
|
||||
public function report(Request $request)
|
||||
{
|
||||
return view('lesson.report');
|
||||
}
|
||||
|
||||
//所有课程
|
||||
public function all(Request $request)
|
||||
{
|
||||
|
||||
$user = Auth::user();
|
||||
$category_id = $request->category_id ?? '';
|
||||
|
||||
$location = Parent::getDefaultLocation();
|
||||
$lat = $location['lat'];
|
||||
$lng = $location['lng'];
|
||||
$area = $location['area'];
|
||||
|
||||
$organCateIds = [];
|
||||
if ($user && $user->organ) {
|
||||
$organCateIds = $user->organ->top_cate_id;
|
||||
}
|
||||
|
||||
$lists = SellerLesson::with(['organ' => function ($query) use ($lat, $lng) {
|
||||
$query->select('id', 'name', 'storage_id', 'user_id', 'category_id', DB::raw('round(ACOS(SIN((' . $lat . ' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((' . $lat . ' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((' . $lng . ' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380,2) as distance'));
|
||||
}])->when(is_numeric($category_id), function ($query) use ($category_id) {
|
||||
$query->whereHas('category', function ($q) use ($category_id) {
|
||||
$q->where('id', $category_id)->Orwhere('parent_id', $category_id);
|
||||
});
|
||||
})->when($area, function ($query) use ($area) {
|
||||
$query->whereHas('organ', function ($query) use ($area) {
|
||||
if ($area->depth == 2) {
|
||||
$query->where('city_sn', $area->sn);
|
||||
} elseif ($area->depth == 3) {
|
||||
$query->where('area_sn', $area->sn);
|
||||
} else {
|
||||
$query->where('province_sn', $area->sn);
|
||||
}
|
||||
});
|
||||
})->when(in_array($category_id, $organCateIds), function ($q) use ($user) {
|
||||
$q->where('seller_id', $user->organ->id);
|
||||
})->where('status', 1)->get();
|
||||
|
||||
$lists = $lists->sortBy('button_value');
|
||||
|
||||
$categorys = Category::with('storage')->where('parent_id', 1)
|
||||
->orderBy('sort', 'asc')
|
||||
->get();
|
||||
|
||||
return view('lesson.all', compact('lists', 'categorys'));
|
||||
}
|
||||
}
|
||||
125
app/Http/Controllers/LotteryController.php
Normal file
125
app/Http/Controllers/LotteryController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\Lottery as LotteryEvent;
|
||||
use App\Models\Lottery;
|
||||
use App\Models\LotteryGift;
|
||||
use App\Models\LotteryLog;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
/**
|
||||
* 抽奖
|
||||
*/
|
||||
class LotteryController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
View::share('nav', 2);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$lottery = Lottery::find(1);
|
||||
return view('lottery.index', compact('lottery'));
|
||||
}
|
||||
|
||||
//抽奖
|
||||
public function draw()
|
||||
{
|
||||
$lottery = Lottery::find(1);
|
||||
|
||||
if (!$lottery) {
|
||||
return $this->error('没有这个活动');
|
||||
} elseif ($lottery->status != 1 || $lottery->start_at->timestamp > time()) {
|
||||
return $this->error('活动没有开启');
|
||||
} elseif ($lottery->end_at->timestamp <= time()) {
|
||||
return $this->error('活动已经结束');
|
||||
}
|
||||
|
||||
$list = LotteryGift::with(['item'])
|
||||
->where('lottery_id', 1)
|
||||
->orderBy('chance', 'asc')
|
||||
->get();
|
||||
// $newlist = collect([]);
|
||||
// foreach ($list as $key => $gift) {
|
||||
// $newlist->put($gift->site, $gift);
|
||||
// }
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if ($user->lottery_num == 0) {
|
||||
return $this->error('您没有抽奖机会');
|
||||
}
|
||||
|
||||
$gift = self::get_rand($list);
|
||||
$user->decrement('lottery_num');
|
||||
if ($user->id == 1) {
|
||||
$gift = LotteryGift::find(15);
|
||||
}
|
||||
if (empty($gift) || $gift->number == 0 || $gift->type == 0) {
|
||||
return $this->error(['site' => 6, 'win' => '很遗憾', 'title' => '您没有中奖!', 'lottery_num' => $user->lottery_num]);
|
||||
} else {
|
||||
$gift->decrement('number');
|
||||
|
||||
$log = $lottery->logs()->create([
|
||||
'user_id' => $user->id,
|
||||
'gift_id' => $gift->id,
|
||||
]);
|
||||
|
||||
event(new LotteryEvent($log));
|
||||
return $this->success(['site' => $gift->site, 'win' => '恭喜您', 'title' => '抽中了 ' . $gift->item->getTitle(), 'lottery_num' => $user->lottery_num, 'allnum' => $gift->allnum, 'randNum' => $gift->randNum]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_rand($gifts)
|
||||
{
|
||||
$result = '';
|
||||
|
||||
$allnum = $gifts->sum('chance');
|
||||
//概率数组循环
|
||||
foreach ($gifts as $gift) {
|
||||
$randNum = mt_rand(1, $allnum);
|
||||
if ($randNum <= $gift->chance) {
|
||||
$gift->randNum = $randNum;
|
||||
$gift->allnum = $allnum;
|
||||
$result = $gift;
|
||||
break;
|
||||
} else {
|
||||
$allnum -= $gift->chance;
|
||||
}
|
||||
}
|
||||
unset($gifts);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function logs(Request $request)
|
||||
{
|
||||
$type = $request->type ?? 'goods';
|
||||
$class = LotteryGift::$class;
|
||||
$item_type = $class[$type];
|
||||
|
||||
$lists = LotteryLog::with(['gift.item'])->whereHas('gift', function ($query) use ($item_type) {
|
||||
$query->where('type', 1)->where('item_type', $item_type);
|
||||
})->where('user_id', Auth::id())->get();
|
||||
|
||||
view()->share('title', '抽奖礼品');
|
||||
|
||||
return view('lottery.logs', compact('lists', 'type'));
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return view('lottery.message');
|
||||
}
|
||||
}
|
||||
43
app/Http/Controllers/NotifyController.php
Normal file
43
app/Http/Controllers/NotifyController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\VipPaid;
|
||||
use App\Models\Payment;
|
||||
use App\Models\VipPament;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NotifyController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function payment(Request $request)
|
||||
{
|
||||
$app = app('wechat.payment');
|
||||
|
||||
return $app->handlePaidNotify(function ($message, $fail) {
|
||||
$payment = Payment::where('trade_no', $message['out_trade_no'])->first();
|
||||
$payment->state = 'SUCCESS';
|
||||
$payment->paid_at = $message['time_end'];
|
||||
$payment->save();
|
||||
$payment->order->paid();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public function vip(Request $request)
|
||||
{
|
||||
$app = app('wechat.payment');
|
||||
return $app->handlePaidNotify(function ($message, $fail) {
|
||||
$vip_payment = VipPament::where('trade_no', $message['out_trade_no'])->first();
|
||||
$vip_payment->state = 'SUCCESS';
|
||||
$vip_payment->paid_at = $message['time_end'];
|
||||
$vip_payment->save();
|
||||
event(new VipPaid($vip_payment));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
243
app/Http/Controllers/OrderController.php
Normal file
243
app/Http/Controllers/OrderController.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\Cart;
|
||||
use App\Models\GoodsParams;
|
||||
use App\Models\UserBaby;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\Order\Models\OrderDetail;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
View::share('nav', 2);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$orders = Order::where('user_id', Auth::id())
|
||||
->CouponAndActivity()
|
||||
->where('state', '<>', Order::ORDER_CLOSED)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
//活动和优惠券 未支付
|
||||
public function unpay()
|
||||
{
|
||||
$orders = Order::Unpaid()
|
||||
->CouponAndActivity()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
//已支付报名课程和活动
|
||||
public function paid()
|
||||
{
|
||||
$orders = Order::UnUse()
|
||||
->CouponAndActivity()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
//已使用的报名课程和活动
|
||||
public function used()
|
||||
{
|
||||
$orders = Order::StateUsed()
|
||||
->CouponAndActivity()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function delivered()
|
||||
{
|
||||
$orders = Order::Delivered()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function signed()
|
||||
{
|
||||
$orders = Order::Signed()
|
||||
->where('user_id', Auth::id())
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return view('orders.index', compact('orders'));
|
||||
}
|
||||
|
||||
public function show($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
return view('orders.show', compact('order'));
|
||||
}
|
||||
|
||||
public function pay($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
return view('orders.pay', compact('order'));
|
||||
}
|
||||
|
||||
public function sign($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
try {
|
||||
$order->signin();
|
||||
return $this->success('签收成功', route('orders.signed'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('签收失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
try {
|
||||
$order->close();
|
||||
return $this->success('取消订单成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('取消订单失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
//创建课程订单
|
||||
public function LessonStore(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'cart_ids.*' => 'required',
|
||||
], [
|
||||
'cart_ids.*.required' => '没有课程',
|
||||
]);
|
||||
|
||||
if (!isset($request->cart_ids)) {
|
||||
return $this->error('请选择课程后进行支付');
|
||||
}
|
||||
|
||||
if (!$request->has('baby_id')) {
|
||||
return $this->error('没有检测到宝宝信息,请先去录入宝宝信息。', route('baby', ['callback' => route('cart.index')]));
|
||||
}
|
||||
|
||||
// $lesson_num = \Params::get('lesson_num');
|
||||
// if ($lesson_num > count($request->cart_ids)) {
|
||||
// return $this->error('请选够' . $lesson_num . '门课程后进行支付');
|
||||
// }
|
||||
|
||||
$gift_nums = GoodsParams::where('stock', '>', 0)
|
||||
->whereHas('goods', function ($q) {
|
||||
$q->where('status', 1)->where('is_seller_gift', 1);
|
||||
})
|
||||
->count();
|
||||
|
||||
if ($gift_nums > 0 && !isset($request->gifts_id)) {
|
||||
return $this->error('请选择赠品');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
$baby = UserBaby::find($request->baby_id);
|
||||
|
||||
$item = [
|
||||
'id' => $request->gifts_id ?? 0,
|
||||
'item_type' => 'LESSON',
|
||||
'name' => $baby->name,
|
||||
'age' => $baby->age,
|
||||
'mobile' => $baby->mobile,
|
||||
];
|
||||
|
||||
$amount = \Params::get('apply_lesson_price');
|
||||
|
||||
$score_order = 0;
|
||||
$score = 0;
|
||||
$heavy = 0;
|
||||
$windup_freight = 0;
|
||||
$express_type = isset($request['express_type']) ? $request['express_type'] : 0;
|
||||
$address = null;
|
||||
$windup_freight = 0;
|
||||
$items = [];
|
||||
|
||||
if ($request->coupon_id) {
|
||||
$coupon = CouponUserLog::find($request->coupon_id);
|
||||
if ($coupon) {
|
||||
$score_order = $coupon->info->bouns;
|
||||
}
|
||||
} elseif (Auth::user()->identity->identity_id > 0) {
|
||||
$amount -= 100;
|
||||
}
|
||||
|
||||
foreach ($request->cart_ids as $key => $cart_id) {
|
||||
$cart = Cart::find($cart_id);
|
||||
if ($cart) {
|
||||
array_push($items, new OrderDetail(['goods' => $cart->lesson, 'number' => 1]));
|
||||
}
|
||||
}
|
||||
|
||||
\Orders::create(Auth::id(), 1, $item, $items, $address, $request->remark, $amount, $score_order, 0, $express_type, $windup_freight, $coupon ?? []);
|
||||
|
||||
});
|
||||
|
||||
$order = Order::where('user_id', Auth::id())->where('state', 'UNPAY')->orderBy('created_at', 'desc')->first();
|
||||
Auth::user()->info->update([
|
||||
'baby_age' => $request->age,
|
||||
'baby_name' => $request->name,
|
||||
'baby_mobile' => $request->mobile,
|
||||
]);
|
||||
return $this->success('订单创建成功', route('pay.lesson', $order));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('订单创建失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function activityStore(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
$item = [
|
||||
'id' => 0,
|
||||
'item_type' => 'ACTIVITY',
|
||||
];
|
||||
|
||||
$score = 0;
|
||||
$score_order = 0;
|
||||
$heavy = 0;
|
||||
$windup_freight = 0;
|
||||
$express_type = isset($request['express_type']) ? $request['express_type'] : 0;
|
||||
$address = null;
|
||||
$windup_freight = 0;
|
||||
$items = [];
|
||||
$activity = Activity::find($request->activity_id);
|
||||
array_push($items, new OrderDetail(['goods' => $activity, 'number' => $request->number]));
|
||||
$amount = $activity->price * $request->number;
|
||||
\Orders::create(Auth::id(), 1, $item, $items, $address, $request->remark, $amount, $score_order, 0, $express_type, $windup_freight);
|
||||
|
||||
});
|
||||
|
||||
$order = Order::where('user_id', Auth::id())->where('state', 'UNPAY')->orderBy('created_at', 'desc')->first();
|
||||
return $this->success('订单创建成功', route('pay.order', $order));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('订单创建失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/Http/Controllers/PayController.php
Normal file
131
app/Http/Controllers/PayController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Coupon\Models\CouponUse;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class PayController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
private function getpayOrder(Order $order, $type)
|
||||
{
|
||||
$payOrder = Payment::create([
|
||||
'order_id' => $order->id,
|
||||
'type' => $type,
|
||||
'amount' => $order->total - $order->score,
|
||||
]);
|
||||
return $payOrder;
|
||||
}
|
||||
|
||||
public function lesson(Request $request, $orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
$coupon = '';
|
||||
if ($request->has('coupon_id')) {
|
||||
$coupon = CouponUserLog::find($request->coupon_id);
|
||||
}
|
||||
|
||||
// $coupon_list = CouponUserLog::with('info')->whereHas('info', function ($query) {
|
||||
// $query->where('type', 'lesson')
|
||||
// ->where('start_at', '<=', date('Y-m-d H:i:s', time()))
|
||||
// ->where('end_at', '>=', date('Y-m-d H:i:s', time()));
|
||||
// })->where('user_id', Auth::id())->where('status', 0)->get();
|
||||
|
||||
// $coupon = $coupon_list->sortByDesc(function ($coupon, $key) {
|
||||
// return $coupon->info->bouns;
|
||||
// })->first();
|
||||
|
||||
$apply_lesson_price = \Params::get('apply_lesson_price');
|
||||
|
||||
return view('pay.lesson', compact('order', 'coupon', 'apply_lesson_price'));
|
||||
}
|
||||
|
||||
public function order(Request $request, $orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
return view('pay.order', compact('order'));
|
||||
}
|
||||
|
||||
public function wechatnew(Request $request, $orderid)
|
||||
{
|
||||
$order = Order::where('orderid', $orderid)->firstOrFail();
|
||||
$openid = $order->user->openid;
|
||||
if ($request->has('coupon') && $request->coupon) {
|
||||
$coupon = CouponUserLog::find($request->coupon);
|
||||
$order->score = $coupon->info->bouns;
|
||||
$order->save();
|
||||
if ($order->couponuse && $order->couponuse->coupon_id != $coupon->id) {
|
||||
$order->couponuse()->delete();
|
||||
}
|
||||
if ($order->couponuse) {
|
||||
if ($order->couponuse->coupon_id != $coupon->id) {
|
||||
$order->couponuse()->delete();
|
||||
$order->couponuse()->save(new CouponUse(['order_id' => $order->id, 'coupon_id' => $coupon->id]));
|
||||
} else {
|
||||
$order->couponuse()->update(['updated_at' => time()]);
|
||||
|
||||
}
|
||||
} else {
|
||||
$order->couponuse()->save(new CouponUse(['order_id' => $order->id, 'coupon_id' => $coupon->id]));
|
||||
}
|
||||
} else {
|
||||
$order->score = 0;
|
||||
$order->save();
|
||||
$order->couponuse()->delete();
|
||||
}
|
||||
|
||||
$amount = $order->amount - $order->score;
|
||||
|
||||
$payOrder = $this->getpayOrder($order, 'WECHAT');
|
||||
if ($amount != $payOrder->amount) {
|
||||
$payOrder->amount = $amount;
|
||||
$payOrder->save();
|
||||
}
|
||||
$app = app('wechat.payment');
|
||||
|
||||
$amount = $payOrder->amount;
|
||||
$result = $app->order->unify([
|
||||
'body' => '商城订单',
|
||||
'out_trade_no' => $payOrder->trade_no,
|
||||
'total_fee' => $amount * 100,
|
||||
'notify_url' => route('notify.payment'),
|
||||
'trade_type' => 'JSAPI',
|
||||
'openid' => $openid,
|
||||
]);
|
||||
|
||||
if ($result['return_code'] == 'SUCCESS' && isset($result['prepay_id'])) {
|
||||
$json = $app->jssdk->bridgeConfig($result['prepay_id']);
|
||||
return $this->success($json);
|
||||
} else {
|
||||
return $this->error($result['return_msg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function ok(Request $request)
|
||||
{
|
||||
return view('pay.ok');
|
||||
|
||||
// $user = Auth::user();
|
||||
// $openid = $user->openid;
|
||||
// if (empty($openid) && $user->main_id > 0) {
|
||||
// $openid = $user->mainuser->openid;
|
||||
// }
|
||||
// $app = app('wechat.official_account');
|
||||
// $wxuser = $app->user->get($openid);
|
||||
// if ($wxuser->subscribe == 0) {
|
||||
// return view('pay.subscribe'); //强制关注公众号
|
||||
// } else {
|
||||
// return view('pay.ok');
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
10
app/Http/Controllers/ReportController.php
Normal file
10
app/Http/Controllers/ReportController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
10
app/Http/Controllers/ReportLogController.php
Normal file
10
app/Http/Controllers/ReportLogController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ReportLogController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
10
app/Http/Controllers/SellerTeacherController.php
Normal file
10
app/Http/Controllers/SellerTeacherController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SellerTeacherController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
155
app/Http/Controllers/SellersController.php
Normal file
155
app/Http/Controllers/SellersController.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Seller;
|
||||
use App\Models\SellerLesson;
|
||||
use App\Models\SellerLessonLog;
|
||||
use App\Models\SellerTeacher;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class SellersController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth')->except(['verification']);
|
||||
view()->share('nav', 1);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$sellers = Seller::with(['storage'])->orderBy('sort', 'desc')->get();
|
||||
|
||||
return view('sellers.index', compact('sellers'));
|
||||
}
|
||||
|
||||
public function show(Seller $seller)
|
||||
{
|
||||
$favorite = \Auth::user()->sellerFavorite()->where('item_id', $seller->id)->first();
|
||||
$lists = SellerTeacher::where('seller_id', $seller->id)->get();
|
||||
$user = Auth::user();
|
||||
return view('sellers.show', compact('seller', 'favorite', 'lists', 'user'));
|
||||
}
|
||||
|
||||
//商户管理
|
||||
public function seller(Request $request)
|
||||
{
|
||||
|
||||
$type = $request->type ?? 'activity';
|
||||
$status = $request->status ?? '';
|
||||
$seller = Auth::user()->seller;
|
||||
if (!$seller || $seller->type != 'seller') {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
if ($type == 'activity') {
|
||||
$lists = Activity::with('seller')->where('seller_id', $seller->id)->get();
|
||||
} else {
|
||||
$lists = ActivityLog::with(['activity.seller'])->whereHas('activity', function ($query) use ($seller) {
|
||||
$query->where('seller_id', $seller->id);
|
||||
})->whereHas('order', function ($query) {
|
||||
$query->whereNotNull('paid_at');
|
||||
})->when($status, function ($query) use ($status) {
|
||||
switch ($status) {
|
||||
case 1:
|
||||
$query->whereNotNull('used_at');
|
||||
break;
|
||||
case 2:
|
||||
$query->whereNull('used_at');
|
||||
break;
|
||||
}
|
||||
})->orderBy('created_at', 'desc')->get();
|
||||
}
|
||||
|
||||
return view('sellers.seller', compact('type', 'lists', 'status'));
|
||||
}
|
||||
|
||||
//机构管理
|
||||
public function organ(Request $request)
|
||||
{
|
||||
$type = $request->type ?? 'lesson';
|
||||
$user = Auth::user();
|
||||
$organ = $user->organ;
|
||||
//有机构 并且身份是机构负责人
|
||||
if (!$organ || $user->identity->identity_id !== 3) {
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
if ($type == 'lesson') {
|
||||
$lists = SellerLesson::where('seller_id', $organ->id)->get();
|
||||
} else {
|
||||
$lists = SellerLessonLog::whereHas('lesson', function ($query) use ($organ) {
|
||||
$query->where('seller_id', $organ->id);
|
||||
})->whereHas('order', function ($query) {
|
||||
$query->whereNotNull('paid_at');
|
||||
})->orderBy('created_at', 'desc')->get();
|
||||
}
|
||||
return view('sellers.organ', compact('type', 'lists'));
|
||||
}
|
||||
|
||||
//机构内课程
|
||||
public function lessons(Request $request, Seller $seller)
|
||||
{
|
||||
$lists = $seller->lesson;
|
||||
return view('sellers.lessons', compact('seller', 'lists'));
|
||||
}
|
||||
|
||||
//核销
|
||||
public function verification(Request $request)
|
||||
{
|
||||
$orderid = $request->orderid;
|
||||
$order = Order::with(['details', 'user.info'])->where('id', $orderid)->first();
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
if (Auth::guest()) {
|
||||
return $this->error('您没有登录', route('login'));
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
if (!$user->seller) {
|
||||
return $this->error('您没有审核权限');
|
||||
}
|
||||
|
||||
if (!$order->canActivityAudit()) {
|
||||
return $this->error('订单状态不对');
|
||||
}
|
||||
|
||||
if ($order->item_type != 'ACTIVITY') {
|
||||
return $this->error('订单类型不对');
|
||||
}
|
||||
|
||||
if (!$order->activitylog) {
|
||||
return $this->error('没有查到这个服务的购买记录');
|
||||
}
|
||||
|
||||
if (!$order->activitylog->activity) {
|
||||
return $this->error('没有这个服务');
|
||||
} elseif ($order->activitylog->activity->status === 0) {
|
||||
return $this->error('服务还未开始');
|
||||
} elseif ($order->activitylog->activity->status == '-1') {
|
||||
return $this->error('服务已经结束');
|
||||
}
|
||||
|
||||
if ($order->activitylog->activity->seller->id != $user->seller->id) {
|
||||
return $this->error('您没有这个服务的审核权限');
|
||||
}
|
||||
|
||||
if ($order->activitylog()->update(['scan_people_id' => $user->id, 'used_at' => Carbon::today()->toDateTimeString()])) {
|
||||
$order->used();
|
||||
return $this->success('审核成功', url()->full());
|
||||
} else {
|
||||
return $this->error('审核失败');
|
||||
}
|
||||
} else {
|
||||
return view('sellers.verification', compact('order'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
83
app/Http/Controllers/ShareController.php
Normal file
83
app/Http/Controllers/ShareController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Image;
|
||||
use QrCode;
|
||||
|
||||
class ShareController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
}
|
||||
|
||||
public function user(User $user)
|
||||
{
|
||||
session(['parent_id' => $user->id]);
|
||||
// return redirect()->route('vip.create');
|
||||
}
|
||||
|
||||
public function index(User $user)
|
||||
{
|
||||
$user = Auth::user();
|
||||
return view('share.index', compact('user'));
|
||||
}
|
||||
|
||||
public function mine(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$qrCode = Image::make(QrCode::size(3000)->format('png')->margin(0)->generate(route('index.index') . '?share_uid=' . $user->id))->resize(230, 230);
|
||||
return $qrCode->response('jpg');
|
||||
}
|
||||
|
||||
public function getnewCode()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$qrCode = QrCode::format('png')->size(126)->margin(0)->generate(route('index.index') . '?share_uid=' . $user->id);
|
||||
// $headimg = Image::make($user->info->headimgurl);
|
||||
$fileUrl = '/home/wwwroot/BabyClass/storage/app/public/headimgurl/' . $user->id . '.jpg';
|
||||
if (!file_exists($fileUrl)) {
|
||||
$headimgurl = file_get_contents($user->info->headimgurl);
|
||||
file_put_contents($fileUrl, $headimgurl);
|
||||
}
|
||||
|
||||
$headimg = self::getCircle(Image::make($fileUrl)->resize(65, 65));
|
||||
|
||||
$image = Image::make('img/new_code2.png'); //获取背景图片
|
||||
|
||||
return $image->insert($headimg, 'top-left', 205, 730)
|
||||
->insert($qrCode, 'top-left', 51, 853)
|
||||
->text('我是' . $user->info->nickname ?: '宝宝课', 288, 760, function ($font) {
|
||||
$font->file('fonts/yahei.ttf')->color('#000000')->size(18);
|
||||
})
|
||||
->response('jpg');
|
||||
}
|
||||
|
||||
//裁剪图片成圆形
|
||||
public function getCircle($img)
|
||||
{
|
||||
$r = $img->width() / 2;
|
||||
$new = Image::canvas(164, 164);
|
||||
for ($x = 0; $x < $img->width(); $x++) {
|
||||
for ($y = 0; $y < $img->height(); $y++) {
|
||||
$c = $img->pickColor($x, $y, 'array');
|
||||
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
|
||||
$new->pixel($c, $x, $y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
public function newcode()
|
||||
{
|
||||
return view('share.newcode', compact('user'));
|
||||
}
|
||||
|
||||
}
|
||||
110
app/Http/Controllers/TeamController.php
Normal file
110
app/Http/Controllers/TeamController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
|
||||
class TeamController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成为会员的6层用户,这个写的比较清晰
|
||||
* @Author:<Leady>
|
||||
* @Date:2019-01-07T10:12:29+0800
|
||||
* @param Request $request [description]
|
||||
* @param integer $node [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function index(Request $request, $node = 0)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$page = $request->page ?? 1; //获取当前页码
|
||||
|
||||
$lists = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%") //血缘有关
|
||||
->where('layer', '<=', $user->relation->layer + 6) //向下6层
|
||||
// ->whereHas('identity', function ($query) use ($user) {
|
||||
// //存在大于会员身份
|
||||
// $query->where('identity_id', '>', 0);
|
||||
// })
|
||||
// ->orderBy('layer', 'asc')->orderBy('user_id', 'asc')->paginate(50); //层正序,分页50。
|
||||
->orderBy('layer', 'asc')->orderBy('user_id', 'asc')->get(); //层正序,分页50。
|
||||
if ($page > 1) {
|
||||
//页码大于1,AJAX调用分页
|
||||
if ($lists->count() > 0) {
|
||||
//内容大于0返回渲染的页面HTML内容
|
||||
$html = response(view('team.item', compact('lists')))->getContent();
|
||||
return $this->success($html);
|
||||
} else {
|
||||
//无内容提示到最后一页
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
} else {
|
||||
//正常渲染访问页面
|
||||
$listsCount = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->where('layer', '<=', $user->relation->layer + 6)
|
||||
// ->whereHas('identity', function ($query) use ($user) {
|
||||
// $query->where('identity_id', '>', 0);
|
||||
// })
|
||||
->orderBy('layer', 'asc')->count();
|
||||
return view('team.index', compact('user', 'lists', 'listsCount'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 未成为会员的6层用户,这个写的比较乱
|
||||
* @Author:<Leady>
|
||||
* @Date:2019-01-07T10:12:01+0800
|
||||
* @param Request $request [description]
|
||||
* @param integer $node [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function novip(Request $request, $node = 0)
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (Auth::id() == 3 || Auth::id() == 1757 || Auth::id() == 12 || Auth::id() == 824) {
|
||||
//测试人员查看指定人员关系
|
||||
$user = User::find(62);
|
||||
}
|
||||
$page = $request->page ?? 1; //获取当前页码
|
||||
|
||||
//列举下6层所有会员
|
||||
$ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->where('layer', '<=', $user->relation->layer + 6)
|
||||
->whereHas('identity', function ($query) use ($user) {
|
||||
$query->where('identity_id', '>', 0);
|
||||
})
|
||||
->pluck('user_id') ?: [0];
|
||||
//排除会员查询6层血缘关系
|
||||
$lists = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->where('layer', '<=', $user->relation->layer + 6)
|
||||
->whereNotIn('user_id', $ids)
|
||||
->orderBy('layer', 'asc')->orderBy('layer', 'asc')->orderBy('user_id', 'asc')->paginate(50);
|
||||
|
||||
//以下步骤同INDEX事件
|
||||
if ($page > 1) {
|
||||
if ($lists->count() > 0) {
|
||||
$html = response(view('team.item', compact('lists')))->getContent();
|
||||
return $this->success($html);
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
} else {
|
||||
$children_count = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->where('layer', '<=', $user->relation->layer + 6)
|
||||
->whereNotIn('user_id', $ids)
|
||||
->orderBy('layer', 'asc')->count();
|
||||
return view('team.novip', compact('user', 'lists', 'children_count'));
|
||||
}
|
||||
}
|
||||
}
|
||||
108
app/Http/Controllers/TestController.php
Normal file
108
app/Http/Controllers/TestController.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\Lottery;
|
||||
use App\Events\WithdrawCompleted;
|
||||
use App\Models\LotteryGift;
|
||||
use App\Models\Seller;
|
||||
use App\Models\Withdraw;
|
||||
use App\Notifications\Registered as RegisteredNotify;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use EasyWeChat\Kernel\Messages\Image;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Order\Events\OrderCreated as OrderCreatedEvent;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserAccount\Events\AccountRuleExecuted;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
Order::withTrashed()->whereNotNull('deleted_at')->forceDelete();
|
||||
die();
|
||||
$info = Withdraw::find(11);
|
||||
event(new WithdrawCompleted($info));
|
||||
|
||||
die();
|
||||
$users = User::whereIn('id', [42, 38, 37, 39])->get();
|
||||
foreach ($users as $key => $user) {
|
||||
$user->account()->delete();
|
||||
$user->info()->delete();
|
||||
$user->logins()->delete();
|
||||
$user->cart()->delete();
|
||||
$user->couponlog()->delete();
|
||||
$user->lessonFavorite()->delete();
|
||||
User::withTrashed()->where('id', $user->id)->forceDelete();
|
||||
}
|
||||
|
||||
die();
|
||||
$order = Order::find(49);
|
||||
|
||||
event(new OrderCreatedEvent($order));
|
||||
|
||||
die();
|
||||
$user = User::find(1);
|
||||
$user->rule('Point', 100, false, []);
|
||||
|
||||
die();
|
||||
$seller = Seller::find(7);
|
||||
$category_ids = $seller->top_cate_id;
|
||||
dd($category_ids);
|
||||
|
||||
die();
|
||||
$user = User::find(1);
|
||||
$log = $user->account->logs()->where('id', 1)->first();
|
||||
event(new AccountRuleExecuted($user->account, $log));
|
||||
die();
|
||||
if ($user->relation->parent_id > 0) {
|
||||
\Notification::send($user->parent, new RegisteredNotify($user));
|
||||
}
|
||||
die();
|
||||
$mediaId = 'fysQHODFoeIoO-ZEDRFVBmtkCAjqXnYco1HeyFKy_kg';
|
||||
$text = new Image($mediaId);
|
||||
$text->toXmlArray(); // or $text->mediaId = $media;
|
||||
die();
|
||||
$order = Order::find(14);
|
||||
$params_ids = $order->details()->pluck('item_id')->toArray();
|
||||
|
||||
dd($order->user->cart()->whereIn('lesson_id', $params_ids)->delete());
|
||||
Cart::where('user_id', $order->user_id)->whereIn('lesson_id', $params_ids)->delete();
|
||||
die();
|
||||
$list = LotteryGift::get();
|
||||
|
||||
foreach ($list as $key => $gift) {
|
||||
$log = $gift->lottery->logs()->create([
|
||||
'user_id' => Auth::id(),
|
||||
'gift_id' => $gift->id,
|
||||
]);
|
||||
event(new Lottery($log));
|
||||
}
|
||||
|
||||
dd(route('RuLong.ueditor.server'));
|
||||
dd(2);
|
||||
$one = Seller::first();
|
||||
$olist = collect($one);
|
||||
|
||||
dump(collect()->count());
|
||||
dump($olist);
|
||||
dump($olist->count());
|
||||
$list = Seller::get();
|
||||
dump($list);
|
||||
|
||||
dd('stop');
|
||||
$list = Order::where('state', 'UNPAY')->whereIn('user_id', [1, 2, 3, 4, 5, 6, 7, 8, 9, 14])->get();
|
||||
|
||||
foreach ($list as $key => $order) {
|
||||
event(new OrderCreated($order));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
166
app/Http/Controllers/UserController.php
Normal file
166
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\LotteryLog;
|
||||
use App\Models\Param;
|
||||
use App\Models\SellerLessonLog;
|
||||
use App\Models\Team;
|
||||
use App\Rules\Checkmobile;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$orderCount = [
|
||||
'unpay' => Order::Unpaid()->CouponAndActivity()->where('user_id', Auth::id())->count(),
|
||||
'paid' => Order::UnUse()->CouponAndActivity()->where('user_id', Auth::id())->count(),
|
||||
'delivered' => Order::StateUsed()->CouponAndActivity()->where('user_id', Auth::id())->count(),
|
||||
'gifts' => Order::gift()->mine()->count(),
|
||||
'lottery_gifts' => LotteryLog::where('user_id', Auth::id())->count(),
|
||||
'favorites' => $user->favorite_num,
|
||||
'couponlogs' => $user->couponlog()->where('status', 0)->count(),
|
||||
'lessonlogs' => SellerLessonLog::where('user_id', $user->id)->where('status', 1)->count(),
|
||||
|
||||
];
|
||||
$children_count = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->count();
|
||||
$children_count_day = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->whereBetween('created_at', [Carbon::today()->toDateTimeString(), Carbon::tomorrow()->toDateTimeString()])->count();
|
||||
$children_count_tomorrow = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->whereBetween('created_at', [Carbon::yesterday()->toDateTimeString(), Carbon::today()->toDateTimeString()])->count();
|
||||
|
||||
$baby_service = Param::where('name', 'baby_service')->first();
|
||||
return view('user.index', compact('orderCount', 'user', 'children_count', 'children_count_day', 'children_count_tomorrow', 'baby_service'));
|
||||
}
|
||||
|
||||
//收益规则
|
||||
public function rules()
|
||||
{
|
||||
return view('user.rules');
|
||||
}
|
||||
|
||||
//联盟合作
|
||||
public function alliance(Request $request)
|
||||
{
|
||||
return view('user.alliance');
|
||||
}
|
||||
|
||||
//0元代理
|
||||
public function agency(Request $request)
|
||||
{
|
||||
return view('user.agency');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存提交的代理和联盟申请
|
||||
* @param Request $request [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'mobile' => ['required', new Checkmobile],
|
||||
'wechat' => 'required',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'wechat.required' => '微信昵称必须填写',
|
||||
]);
|
||||
|
||||
$info = Team::where('user_id', Auth::id())->where('type', $request->type)->first();
|
||||
if ($info) {
|
||||
return $this->error('您已经提交过了,请等待我们的客服人员联系您。');
|
||||
}
|
||||
$info = Team::create([
|
||||
'user_id' => Auth::id(),
|
||||
'mobile' => $request->mobile,
|
||||
'wechat' => $request->wechat,
|
||||
'type' => $request->type,
|
||||
]);
|
||||
if ($info) {
|
||||
return $this->success('提交成功', route('user.index'));
|
||||
} else {
|
||||
return $this->error('提交失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 孩子信息
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function baby(Request $request)
|
||||
{
|
||||
$callback = $request->callback ? $request->callback : route('index.index');
|
||||
return view('user.baby', compact('callback'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存孩子信息
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function babyrun(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'mobile' => ['required', new Checkmobile],
|
||||
'name' => 'required',
|
||||
'age' => 'required',
|
||||
'sex' => 'required',
|
||||
'relation' => 'required',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'name.required' => '姓名必须填写',
|
||||
'age.required' => '年龄必须选择',
|
||||
'sex.required' => '请选择性别',
|
||||
'relation.required' => '请选择与孩子的关系',
|
||||
]);
|
||||
$callback = $request->callback;
|
||||
$data = $request->except(['callback']);
|
||||
$user = Auth::user();
|
||||
if ($user->babys()->create($data)) {
|
||||
return $this->success('提交成功', $callback);
|
||||
} else {
|
||||
return $this->error('提交失败');
|
||||
}
|
||||
}
|
||||
|
||||
// public function relation()
|
||||
// {
|
||||
// return view('user.relation');
|
||||
// }
|
||||
|
||||
// public function relationrun(Request $request)
|
||||
// {
|
||||
// $parentId = $request->parentId ?? '';
|
||||
// if ($parentId) {
|
||||
// $info = User::find((int) $parentId);
|
||||
// if (!$info || $info->identity->identity_id === 0) {
|
||||
// return $this->error('推荐人不存在或不是会员');
|
||||
// }
|
||||
// $user = Auth::user();
|
||||
// $relation = $user->relation;
|
||||
// $relation->bloodline = $info->relation->bloodline . $info->id . ',';
|
||||
// $relation->layer = $info->relation->layer + 1;
|
||||
// $relation->parent_id = $info->id;
|
||||
// if ($relation->save()) {
|
||||
// return $this->success('绑定成功', route('user.index'));
|
||||
// } else {
|
||||
// return $this->error('绑定失败');
|
||||
// }
|
||||
// } else {
|
||||
// return $this->error('请输入推荐人编号');
|
||||
// }
|
||||
// }
|
||||
}
|
||||
53
app/Http/Controllers/WeChatController.php
Normal file
53
app/Http/Controllers/WeChatController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\WechatHandlers\EventMessageHandler;
|
||||
use App\Http\WechatHandlers\FileMessageHandler;
|
||||
use App\Http\WechatHandlers\ImageMessageHandler;
|
||||
use App\Http\WechatHandlers\LinkMessageHandler;
|
||||
use App\Http\WechatHandlers\LocationMessageHandler;
|
||||
use App\Http\WechatHandlers\ShortVideoMessageHandler;
|
||||
use App\Http\WechatHandlers\TextMessageHandler;
|
||||
use App\Http\WechatHandlers\TransferMessageHandler;
|
||||
use App\Http\WechatHandlers\VideoMessageHandler;
|
||||
use App\Http\WechatHandlers\VoiceMessageHandler;
|
||||
use EasyWeChat\Kernel\Messages\Message;
|
||||
use Overtrue\LaravelWeChat\Controllers\Controller;
|
||||
|
||||
class WeChatController extends Controller
|
||||
{
|
||||
|
||||
public function serve()
|
||||
{
|
||||
$app = app('wechat.official_account');
|
||||
$app->server->push(TextMessageHandler::class, Message::TEXT);
|
||||
$app->server->push(ImageMessageHandler::class, Message::IMAGE);
|
||||
$app->server->push(VoiceMessageHandler::class, Message::VOICE);
|
||||
$app->server->push(VideoMessageHandler::class, Message::VIDEO);
|
||||
$app->server->push(ShortVideoMessageHandler::class, Message::SHORT_VIDEO);
|
||||
$app->server->push(LocationMessageHandler::class, Message::LOCATION);
|
||||
$app->server->push(LinkMessageHandler::class, Message::LINK);
|
||||
$app->server->push(FileMessageHandler::class, Message::FILE);
|
||||
$app->server->push(EventMessageHandler::class, Message::EVENT);
|
||||
$app->server->push(TransferMessageHandler::class, Message::TRANSFER);
|
||||
return $app->server->serve();
|
||||
}
|
||||
|
||||
public function publish()
|
||||
{
|
||||
$app = app('wechat.official_account');
|
||||
$buttons = [
|
||||
["name" => '博海名品',
|
||||
"type" => "view",
|
||||
"url" => route('index.index'),
|
||||
],
|
||||
["name" => '个人中心',
|
||||
"type" => "view",
|
||||
"url" => route('user.index'),
|
||||
],
|
||||
|
||||
];
|
||||
$res = $app->menu->create($buttons);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
245
app/Http/Controllers/WithdrawController.php
Normal file
245
app/Http/Controllers/WithdrawController.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\WithdrawCompleted;
|
||||
use App\Models\Withdraw;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Session;
|
||||
use Validator;
|
||||
|
||||
class WithdrawController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->middleware('auth');
|
||||
view()->share('nav', 2);
|
||||
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user_id = $request->user_id;
|
||||
if ($user_id) {
|
||||
$user = User::find($user_id);
|
||||
} else {
|
||||
$user = Auth::user();
|
||||
}
|
||||
|
||||
$withdraw_explain = \Params::get('withdraw_explain');
|
||||
|
||||
$withdraw_explain = str_replace("\n", "<br />", $withdraw_explain);
|
||||
$withdraw_explain = str_replace("\r", "<br />", $withdraw_explain);
|
||||
$logs = Withdraw::where('user_id', $user->id)->orderBy('id', 'desc')->get();
|
||||
$withdraw_total = sprintf("%.2f", abs($user->account->logs()->whereIn('rule_id', [1, 2])->sum('variable')));
|
||||
return view('withdraw.index', compact('logs', 'withdraw_total', 'withdraw_explain'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
die();
|
||||
$week_start = Carbon::now()->startOfWeek()->toDateTimeString();
|
||||
$week_end = Carbon::now()->endOfWeek()->toDateTimeString();
|
||||
|
||||
$num = Withdraw::where('user_id', Auth::id())->whereBetween('created_at', [$week_start, $week_end])->where('state', '<>', 2)->count();
|
||||
if ($num > 0) {
|
||||
return $this->error('您本周已提现过,下周再来吧~');
|
||||
}
|
||||
|
||||
if (empty($request->way)) {
|
||||
return $this->error('请选择提现方式');
|
||||
} elseif ($request->way == 'WenxinNo') {
|
||||
if (empty($request->wechat)) {
|
||||
return $this->error('请输入微信号,工作人员会在1-2个工作日内为您转款');
|
||||
}
|
||||
} elseif ($request->way == 'Alipay') {
|
||||
if (empty($request->alipay)) {
|
||||
return $this->error('请输入支付宝账号,工作人员会在1-2个工作日内为您转款');
|
||||
}
|
||||
} elseif ($request->way == 'Wechat') {
|
||||
if ($request->money > 200) {
|
||||
return $this->error('单次提现金额最大200元');
|
||||
}
|
||||
} elseif ($request->way == 'Bankcard') {
|
||||
$request->validate([
|
||||
'bank_name' => 'required',
|
||||
'bank_address' => 'required',
|
||||
'bank_no' => 'required',
|
||||
'payee' => 'required|min:2|max:8',
|
||||
], [
|
||||
'bank_name.required' => '收款银行必须填写',
|
||||
'bank_address.required' => '收款支行必须填写',
|
||||
'bank_no.required' => '银行卡号必须填写',
|
||||
'payee.required' => '收款人必须填写',
|
||||
'payee.min' => '收款人不能少于:min个汉字',
|
||||
'payee.max' => '收款人不能多于:max个汉字',
|
||||
]);
|
||||
if (!preg_match("/^([\x{4e00}-\x{9fa5}]+)$/u", $request->payee)) {
|
||||
return $this->error('请输入确认的收款人姓名');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->money < 100) {
|
||||
return $this->error('提现金额必须大于等于100元');
|
||||
}
|
||||
|
||||
if ($request->money > Auth::user()->account->cash) {
|
||||
return $this->error('账户余额不足');
|
||||
}
|
||||
|
||||
if (empty($request->openid)) {
|
||||
return $this->error('未获取到微信信息');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
|
||||
$tax = round($request->money * 0.05, 3);
|
||||
$take = $request->money - $tax;
|
||||
Withdraw::create([
|
||||
'user_id' => Auth::id(),
|
||||
'amount' => $request->money,
|
||||
'tax' => $tax, //手续费
|
||||
'take' => $take, //实到金额
|
||||
'balance' => Auth::user()->account->cash - $request->money,
|
||||
'openid' => $request->openid,
|
||||
'way' => $request->way,
|
||||
'wechat' => $request->has('wechat') ? $request->wechat : '',
|
||||
'alipay' => $request->has('alipay') ? $request->alipay : '',
|
||||
'bank_no' => $request->has('bank_no') ? $request->bank_no : '',
|
||||
'bank_name' => $request->has('bank_name') ? $request->bank_name : '',
|
||||
'bank_name' => $request->has('bank_address') ? $request->bank_address : '',
|
||||
'payee' => $request->has('payee') ? $request->payee : '',
|
||||
'state' => 0,
|
||||
]);
|
||||
|
||||
if ($request->way == 'Bankcard') {
|
||||
$userinfo = Auth::user()->info;
|
||||
$userinfo->bank_no = $request->bank_no;
|
||||
$userinfo->bank_name = $request->bank_name;
|
||||
$userinfo->bank_address = $request->bank_address;
|
||||
$userinfo->payee = $request->payee;
|
||||
$userinfo->save();
|
||||
}
|
||||
|
||||
Auth::user()->rule('withdraw', -$request->money);
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getmessage());
|
||||
}
|
||||
return $this->success('申请提现成功,等待管理员审核', route('withdraw.index'));
|
||||
|
||||
}
|
||||
|
||||
public function wechat(Request $request)
|
||||
{
|
||||
|
||||
$withdraw_min = \Params::get('withdraw_min');
|
||||
$withdraw_max = \Params::get('withdraw_max');
|
||||
return view('withdraw.wechat', compact('withdraw_min', 'withdraw_max'));
|
||||
}
|
||||
|
||||
public function wechatdo(Request $request)
|
||||
{
|
||||
// $user = Auth::user();
|
||||
// if (!in_array($user->id, [1, 7])) {
|
||||
// return $this->error('暂未开通');
|
||||
// }
|
||||
$data = $request->all();
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'amount' => 'required|integer',
|
||||
], [
|
||||
'amount.required' => '提现金额必须填写',
|
||||
'amount.integer' => '提现金额必须是整数',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$withdraw_min = \Params::get('withdraw_min');
|
||||
$withdraw_max = \Params::get('withdraw_max');
|
||||
|
||||
if ($request->amount < $withdraw_min) {
|
||||
return $this->error('单次最少提现金额为' . $withdraw_min);
|
||||
}
|
||||
|
||||
if ($request->amount > $user->account->cash) {
|
||||
return $this->error('账户余额不足,当前提现金额为' . $user->account->cash);
|
||||
}
|
||||
|
||||
if ($request->amount > $withdraw_max) {
|
||||
return $this->error('单次最多提现金额为' . $withdraw_max);
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'code' => 'required|sms_check:mobile,DEFAULT',
|
||||
], [
|
||||
'code.required' => '验证码必须填写',
|
||||
'code.sms_check' => '验证码不正确',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$in_data = [
|
||||
'amount' => $request->amount,
|
||||
'tax' => 0,
|
||||
'type' => 'Wechat',
|
||||
'take' => $request->amount,
|
||||
'user_id' => $user->id,
|
||||
];
|
||||
|
||||
$info = Withdraw::create($in_data);
|
||||
|
||||
if ($info) {
|
||||
$app = app('wechat.payment');
|
||||
$no = 'W' . date('YmdHis') . str_pad(rand(0, 9999), 4, "0", STR_PAD_LEFT);
|
||||
$str = $app->transfer->toBalance([
|
||||
'partner_trade_no' => $no,
|
||||
'openid' => $user->openid,
|
||||
'check_name' => 'NO_CHECK',
|
||||
'amount' => $info->take * 100,
|
||||
'desc' => '提现到账',
|
||||
]);
|
||||
if ($str->return_code == 'SUCCESS' && $str->result_code == 'SUCCESS') {
|
||||
$user->rule('withdraw', -$info->take, true);
|
||||
$info->remark = '微信自动到账';
|
||||
$info->partner_trade_no = $no;
|
||||
$info->state = 1;
|
||||
$info->save();
|
||||
event(new WithdrawCompleted($info));
|
||||
|
||||
return $this->success('提现成功,查看提现记录请点击《跳转》,继续提现点击《取消》。', route('withdraw.index'));
|
||||
} else {
|
||||
$info->remark = $str->return_msg . ',' . $str->err_code_des;
|
||||
$info->state = -1;
|
||||
$info->save();
|
||||
\Log::error($str);
|
||||
return $this->error('系统繁忙。');
|
||||
}
|
||||
} else {
|
||||
return $this->error('提现失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function code()
|
||||
{
|
||||
$app = app('wechat.official_account');
|
||||
$user = $app->oauth->user();
|
||||
Session::put('withdraw_openid', $user->id);
|
||||
return redirect()->route('withdraw.create');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user