更新代码
This commit is contained in:
85
app/Api/Controllers/AccountController.php
Normal file
85
app/Api/Controllers/AccountController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 10:58 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
|
||||
use App\Api\Resources\AccountLogsResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\User;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api');
|
||||
$this->user = \Auth::guard('api')->user();
|
||||
$this->uid = \Auth::guard('api')->id();
|
||||
// $this->user = User::find(824);
|
||||
// $this->uid = 824;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$rewardtotal = $this->user->account->logs()->where('type', 'cash')->where('rule_id', 2)->sum('variable');
|
||||
$freezingTotal = $this->user->account->logs()->where('type', 'cash')->where('frozen', 1)->sum('variable');
|
||||
$logs = $this->user->account->logs()->where('type', 'cash')->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'cash'=>$this->user->account->cash,
|
||||
'rewardTotal' => $rewardtotal,
|
||||
'freezingTotal' => $freezingTotal,
|
||||
'logLists' => AccountLogsResource::collection($logs),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function score(Request $request)
|
||||
{
|
||||
$type = $request->logType;
|
||||
$logs = $this->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();
|
||||
$scoreExplain = \Params::get('score_explain');
|
||||
|
||||
$scoreExplain = str_replace("\n", "<br />", $scoreExplain);
|
||||
$scoreExplain = str_replace("\r", "<br />", $scoreExplain);
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'score'=>$this->user->account->score,
|
||||
'scoreExplain' => $scoreExplain,
|
||||
'logLists' => AccountLogsResource::collection($logs),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
124
app/Api/Controllers/AddressController.php
Normal file
124
app/Api/Controllers/AddressController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/1
|
||||
* Time: 1:25 PM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\AddressResource;
|
||||
use RuLong\Area\Models\Area;
|
||||
use RuLong\Area\Models\UserAddress;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api');
|
||||
$this->user = \Auth::guard('api')->user();
|
||||
$this->uid = \Auth::guard('api')->id();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序收货地址列表页数据,页面初始化时请求该接口
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$addresses = $this->user->addresses()->orderBy('is_default', 'desc')->orderBy('id', 'desc')->get();
|
||||
return AddressResource::collection($addresses)->additional([
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序编辑收货地址,页面初始化时请求该接口
|
||||
*/
|
||||
public function detail(UserAddress $address)
|
||||
{
|
||||
return $this->success(new AddressResource($address));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建保存/编辑更新操作 小程序新建、编辑页面点击保存时请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$address = [];
|
||||
if ($request->id) {
|
||||
$address = UserAddress::find($request->id);
|
||||
}
|
||||
$data = [
|
||||
'name' => $request->name,
|
||||
'mobile' => $request->mobile,
|
||||
'province_sn' => $request->province_sn,
|
||||
'city_sn' => $request->city_sn,
|
||||
'area_sn' => $request->area_sn,
|
||||
'address' => $request->address,
|
||||
];
|
||||
if (!empty($address)) {
|
||||
$res = \Address::update($address, $data);
|
||||
} else {
|
||||
$res = \Address::store(
|
||||
[
|
||||
'user_id' => $this->uid,
|
||||
'name' => $request->name,
|
||||
'mobile' => $request->mobile,
|
||||
'province_sn' => $request->province_sn,
|
||||
'city_sn' => $request->city_sn,
|
||||
'area_sn' => $request->area_sn,
|
||||
'address' => $request->address,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
return $this->success(['msg' => '修改成功']);
|
||||
} else {
|
||||
return $this->failed('修改失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序删除收货地址,地址管理页请求该接口
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if (\Address::destroy($id)) {
|
||||
return $this->success(['msg' => '操作成功']);
|
||||
} else {
|
||||
return $this->failed('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市区三级联动返回数据,小程序新建/编辑收货地址中切换省市区时出现。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function areas(Request $request)
|
||||
{
|
||||
$psn = $request->psn;
|
||||
if ($psn == 0) {
|
||||
$areas = Area::where('psn', $psn)->where('depth', 1)->select(DB::raw('sn as id'), 'sn', 'psn', 'name', DB::raw('depth as type'))->get() ?? [];
|
||||
} else {
|
||||
$areas = Area::where(['psn' => $psn])->select(DB::raw('sn as id'), 'sn', 'psn', 'name', DB::raw('depth as type'))->get() ?? [];
|
||||
}
|
||||
if ($areas) {
|
||||
return $this->success($areas);
|
||||
} else {
|
||||
return $this->failed('请选择省份/城市');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
131
app/Api/Controllers/AuthController.php
Normal file
131
app/Api/Controllers/AuthController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Sms\Models\Sms as SmsModel;
|
||||
use Validator;
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api', ['except' => ['login','smsCode']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param Request $request [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
|
||||
// $info = $request->userInfo;
|
||||
$code = $request->code;
|
||||
|
||||
$app = app('wechat.mini_program');
|
||||
|
||||
$jscode = $app->auth->session($code);
|
||||
$user = User::where('unionid', $jscode->unionid)->first();
|
||||
$token = Auth::guard('api')->login($user);
|
||||
return $this->success([
|
||||
'access_token' => $token,
|
||||
'access_type' => 'Bearer',
|
||||
'expires_in' => Auth::guard('api')->factory()->getTTL() * 60,
|
||||
'userInfo' => [
|
||||
'uid' => $user->id ?? '',
|
||||
'avatar' => $user->info->headimgurl ?? '',
|
||||
'nickname' => $user->info->nickname ?? '',
|
||||
'openid' => $jscode->openid ?? ''
|
||||
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新TOKEN
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
return $this->success([
|
||||
'access_token' => Auth::guard('api')->refresh(true),
|
||||
'access_type' => 'Bearer',
|
||||
'expires_in' => Auth::guard('api')->factory()->getTTL() * 60,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::guard('api')->logout(true);
|
||||
return $this->message('退出登录成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
* @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|mobile|exists:users',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.exists' => '手机号码不存在',
|
||||
]);
|
||||
break;
|
||||
case 'BIND':
|
||||
// 绑定手机号,要不存在才可以
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|unique:users',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.unique' => '手机号码已经绑定',
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
|
||||
$res = SmsModel::verify_code($request->mobile);
|
||||
if ($res !== true) {
|
||||
return $this->failed($res);
|
||||
}
|
||||
|
||||
try {
|
||||
\Sms::send($mobile, $channel);
|
||||
return $this->success('验证码发送成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->failed($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
84
app/Api/Controllers/CallbackController.php
Normal file
84
app/Api/Controllers/CallbackController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/21
|
||||
* Time: 3:21 PM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Events\VipPaid;
|
||||
use App\Models\Payment;
|
||||
use App\Models\VipPament;
|
||||
|
||||
class CallbackController
|
||||
{
|
||||
/**
|
||||
* 订单付款回掉地址。
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public function index()
|
||||
{
|
||||
$app = app('wechat.payment.mini');
|
||||
$response = $app->handlePaidNotify(function ($message, $fail) {
|
||||
$payment = Payment::where('trade_no', $message['out_trade_no'])->first();
|
||||
if (!$payment || $payment->paid_at) {
|
||||
return true;
|
||||
}
|
||||
if ($message['return_code'] === 'SUCCESS') {
|
||||
// return_code 表示通信状态,不代表支付状态
|
||||
// 用户是否支付成功
|
||||
if (array_get($message, 'result_code') === 'SUCCESS') {
|
||||
$payment->state = 'SUCCESS';
|
||||
$payment->paid_at = $message['time_end'];
|
||||
} elseif (array_get($message, 'result_code') === 'FAIL') {
|
||||
$payment->state = 'INIT';
|
||||
}
|
||||
} else {
|
||||
return $fail('通信失败,请稍后再通知我');
|
||||
}
|
||||
$payment->save(); // 保存订单
|
||||
$payment->order->paid();
|
||||
return true; // 返回处理完成
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开通vip,付款回掉地址。
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function vip()
|
||||
{
|
||||
$payment = app('wechat.payment.mini');
|
||||
$response = $payment->handlePaidNotify(function ($message, $fail) {
|
||||
$vip_payment = VipPament::where('trade_no', $message['out_trade_no'])->first();
|
||||
if (!$vip_payment || $vip_payment->paid_at) {
|
||||
return true;
|
||||
}
|
||||
if ($message['return_code'] === 'SUCCESS') {
|
||||
// return_code 表示通信状态,不代表支付状态
|
||||
// 用户是否支付成功
|
||||
if (array_get($message, 'result_code') === 'SUCCESS') {
|
||||
$vip_payment->state = 'SUCCESS';
|
||||
$vip_payment->paid_at = $message['time_end'];
|
||||
} elseif (array_get($message, 'result_code') === 'FAIL') {
|
||||
$vip_payment->state = 'INIT';
|
||||
}
|
||||
} else {
|
||||
return $fail('通信失败,请稍后再通知我');
|
||||
}
|
||||
$vip_payment->save(); // 保存订单
|
||||
event(new VipPaid($vip_payment));
|
||||
return true; // 返回处理完成
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
252
app/Api/Controllers/CartController.php
Normal file
252
app/Api/Controllers/CartController.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\AddressResource;
|
||||
use App\Api\Resources\CartResource;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Freight;
|
||||
use App\Models\GoodsParams;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Api\Resources\CartSellerResource;
|
||||
use App\Models\Seller;
|
||||
use RuLong\Area\Models\UserAddress;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序,购物车页面数据接口
|
||||
*
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$lists = Cart::where('user_id', $this->uid)->orderBy('id', 'desc')->get();
|
||||
$data = [];
|
||||
foreach ($lists as $cart) {
|
||||
if (!isset($carts[$cart->params->goods->seller_id])) {
|
||||
$carts[$cart->params->goods->seller_id] = [];
|
||||
}
|
||||
if ($cart->params->stock < 1) {
|
||||
$cart->delete();
|
||||
} else {
|
||||
if ($cart->number > $cart->params->stock) {
|
||||
$cart->number = $cart->params->stock;
|
||||
$cart->save();
|
||||
}
|
||||
array_push($carts[$cart->params->goods->seller_id], $cart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($carts as $key => $seller_item) {
|
||||
$seller_cart = [];
|
||||
$seller_cart['seller'] = new CartSellerResource(Seller::find($key));
|
||||
foreach ($seller_item as $cart_item) {
|
||||
$seller_cart['goods_list'][] = new CartResource($cart_item);
|
||||
}
|
||||
array_push($data, $seller_cart);
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序,商品详情页,点击加入购物车请求接口
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$user_id = $this->uid;
|
||||
$result = Cart::where(['user_id' => $user_id, 'params_id' => $request->params_id])->first();
|
||||
$params = GoodsParams::find($request->params_id);
|
||||
if ($result) {
|
||||
$result->number += $request->number;
|
||||
$result->save();
|
||||
} else {
|
||||
$result = Cart::create([
|
||||
'user_id' => $this->uid,
|
||||
'params_id' => $request->params_id,
|
||||
'goods_id' => $params->goods_id, //保存goods_id是为了下架商品时,删除购物车
|
||||
'number' => $request->number,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
return $this->success(['msg' => '成功加入购物车', 'cartGoodsCount' => Cart::where('user_id', $this->uid)->count()]);
|
||||
} else {
|
||||
return $this->failed('加入失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序,购物车页,点击增减商品数量请求接口
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function setnum(Request $request)
|
||||
{
|
||||
$cart = Cart::find($request->id);
|
||||
$cart->number = $request->number;
|
||||
if ($cart->save()) {
|
||||
return $this->success(['msg' => '操作成功', 'number' => $cart->number]);
|
||||
} else {
|
||||
return $this->failed('加入失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序,确认订单页请求的接口
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function sure(Request $request)
|
||||
{
|
||||
$data = array();
|
||||
$carts = array();
|
||||
$cart_amount = 0;
|
||||
$cart_score = 0;
|
||||
$cart_freight = 0;
|
||||
$address = $request->addressId ? UserAddress::find($request->addressId) : null;
|
||||
foreach (explode(',', $request->cart_ids) as $key => $value) {
|
||||
$cart = Cart::find($value);
|
||||
if ($cart) {
|
||||
if ($cart->params->stock < 1) {
|
||||
$cart->delete();
|
||||
} else {
|
||||
if ($cart->number < $cart->params->stock) {
|
||||
if (!isset($carts[$cart->params->goods->seller_id])) {
|
||||
$carts[$cart->params->goods->seller_id] = [];
|
||||
}
|
||||
array_push($carts[$cart->params->goods->seller_id], $cart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($carts as $key => $seller_item) {
|
||||
$seller_cart = [];
|
||||
$seller_cart['seller'] = new CartSellerResource(Seller::find($key));
|
||||
$seller_cart['express'] = ['type1' => 1, 'type2' => 0]; //配送方式,type1-快递,type2-自取
|
||||
$seller_cart['remark'] = '';//买家留言
|
||||
//获取店铺运费、金额、积分小计
|
||||
$seller_total = self::sellerTotal($key, $seller_item, $address);
|
||||
|
||||
//格式化单店铺小计
|
||||
foreach ($seller_total as $k => $v) {
|
||||
$seller_cart['total'][$k] = number_format($v, 2);
|
||||
$seller_cart['totalOriginal'][$k] = $v;
|
||||
|
||||
}
|
||||
|
||||
//计算全部店铺总和
|
||||
$cart_amount += $seller_total['amount'];
|
||||
$cart_score += $seller_total['score'];
|
||||
$cart_freight += $seller_total['freightPrice'];
|
||||
|
||||
foreach ($seller_item as $cart_item) {
|
||||
$seller_cart['goods_list'][] = new CartResource($cart_item);
|
||||
}
|
||||
array_push($data, $seller_cart);
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'cartData' => $data,
|
||||
'cartTotal' => [
|
||||
'amount' => number_format($cart_amount, 2),
|
||||
'score' => number_format($cart_score, 2),
|
||||
'freight' => number_format($cart_freight, 2),
|
||||
'freightOriginal' => $cart_freight,
|
||||
'orderPrice' => number_format($cart_amount + $cart_freight, 2),
|
||||
'orderPriceOriginal' => $cart_amount + $cart_freight
|
||||
|
||||
],
|
||||
'address' => $address ? new AddressResource($address) : []
|
||||
],
|
||||
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺商品金额、运费金额、积分金额总和
|
||||
*
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
private function sellerTotal($seller_id, $seller_item, $address = null)
|
||||
{
|
||||
$amount = 0;
|
||||
$freightPrice = \Params::get('default_freight');
|
||||
$heavy = 0;
|
||||
$score = 0;
|
||||
foreach ($seller_item as $cart_item) {
|
||||
$params = GoodsParams::find($cart_item->params_id);
|
||||
$amount += $cart_item->number * $params->price;
|
||||
if ($params->is_free_freight == 0) {
|
||||
$heavy += $cart_item->number * $params->heavy;
|
||||
}
|
||||
$score += $cart_item->number * $params->score;
|
||||
}
|
||||
|
||||
if ($heavy === 0) {
|
||||
$freightPrice = 0; //包邮
|
||||
} else {
|
||||
//计算每个商户订单的运费
|
||||
if (!empty($address)) {
|
||||
$freight = Freight::where(['seller_id' => $seller_id, 'area_id' => $address->province->id])->first();
|
||||
if ($freight) {
|
||||
$freightPrice = $freight->basic;
|
||||
if ($freight->heavy < $heavy) {
|
||||
$freightPrice += ceil($heavy - $freight->heavy) * $freight->added;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'freightPrice' => $freightPrice,
|
||||
'score' => $score,
|
||||
'amount' => $amount - $score,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序,购物车页面,点击删除商品请求的接口
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function delete(Cart $cart)
|
||||
{
|
||||
|
||||
if ($cart->delete()) {
|
||||
return $this->success(['msg' => '操作成功']);
|
||||
} else {
|
||||
return $this->failed('加入失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
app/Api/Controllers/Controller.php
Normal file
12
app/Api/Controllers/Controller.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Helpers\ApiResponse;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use ValidatesRequests, ApiResponse;
|
||||
}
|
||||
56
app/Api/Controllers/FullController.php
Normal file
56
app/Api/Controllers/FullController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/23
|
||||
* Time: 2:10 PM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserAccount\Models\UserAccountLog;
|
||||
use App\User;
|
||||
|
||||
class FullController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户满仓任务完成信息接口,小程序访问满仓页面时请求该接口。
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$isfull = $this->user->account->act_a > 0 ? true : false;//是否满仓
|
||||
$fullOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'FULL_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();//满仓订单
|
||||
$canCreateOrder = !$fullOrder && $isfull ? true : false;//是否可以创建满仓订单
|
||||
$log = UserAccountLog::where('user_id', $this->uid)->where('rule_id', 4)->orderBy('id', 'asc')->first();//完成时间
|
||||
$finished_share_num = $this->user->identity->childrentime([Carbon::today()->toDateTimeString(), Carbon::tomorrow()->toDateTimeString()]);//完成数量
|
||||
return [
|
||||
'data' => [
|
||||
'isfull' => $isfull,
|
||||
'finished_share_num' => $finished_share_num,
|
||||
'unfinished_share_num' => $finished_share_num >= 10 ? 0 : 10 - $finished_share_num,
|
||||
'finished_at' => $log->created_at ?? '',
|
||||
'fullOrder' => [
|
||||
'canCreateOrder' => $canCreateOrder,
|
||||
'order_id' => $fullOrder->id ?? '',
|
||||
],
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
300
app/Api/Controllers/GoodsController.php
Normal file
300
app/Api/Controllers/GoodsController.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\ChannelIndexResource;
|
||||
use App\Api\Resources\GoodsDetailResource;
|
||||
use App\Api\Resources\GoodsGiftDetailResource;
|
||||
use App\Api\Resources\GoodsGiftListResource;
|
||||
use App\Api\Resources\GoodsListResource;
|
||||
use App\Api\Resources\GoodsParamsDetailResource;
|
||||
use App\Api\Resources\GoodsParamsListResource;
|
||||
use App\Api\Resources\GoodsParamsScoreDetailResource;
|
||||
use App\Models\Category;
|
||||
use App\Models\Goods;
|
||||
use App\Models\GoodsParams;
|
||||
use App\Models\Seller;
|
||||
use App\Models\VipPament;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Order\Models\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GoodsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$addresses = User::find(824)->addresses()->orderBy('is_default', 'desc')->orderBy('id', 'desc')->get();
|
||||
return $this->success($addresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情 小程序商品详情页请求该接口。
|
||||
* @param \App\Models\Goods $good
|
||||
* @return array
|
||||
*/
|
||||
public function show(Goods $good,Request $request)
|
||||
{
|
||||
$type = $request->get('type', 'cashScore');
|
||||
if($type == 'score'){
|
||||
$params_count = $good->params()->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price = score')->count();
|
||||
if($params_count == 0){
|
||||
return $this->failed('商品已下架');
|
||||
}else{
|
||||
return $this->success(new GoodsParamsScoreDetailResource($good));
|
||||
}
|
||||
}elseif($type == 'cashScore'){
|
||||
$params_count = $good->params()->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->count();
|
||||
if($params_count == 0){
|
||||
return $this->failed('商品已下架');
|
||||
}else{
|
||||
return $this->success(new GoodsParamsDetailResource($good));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 相关商品 小程序商品详情页请求该接口。
|
||||
* @param \App\Models\Goods $good
|
||||
* @return array
|
||||
*/
|
||||
public function related(Goods $good)
|
||||
{
|
||||
$data = $good->seller->goods()->where('status', 1)->limit(6)->get();
|
||||
return GoodsListResource::collection($data)->additional([
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表 小程序点击某一分类页面请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function lists(Request $request)
|
||||
{
|
||||
$category = $request->get('categoryId', '');
|
||||
$title = $request->get('title', '');
|
||||
$type = $request->get('type', 'cashScore');
|
||||
$data = [];
|
||||
switch ($type){
|
||||
case 'cash':
|
||||
$data = GoodsParams::whereHas('goods', function ($query) use($title,$category)
|
||||
{
|
||||
return $query->when($category, function ($query) use ($category) {
|
||||
$category_ids = Category::where('id',$category)->orWhere('parent_id', $category)->pluck('id');
|
||||
return $query->whereIn('goods.category_id', $category_ids);
|
||||
})->when($title, function ($query) use ($title) {
|
||||
return $query->where('goods.title', 'like', "%$title%");
|
||||
})->where('status',1);
|
||||
})->where('status', 1)->where('stock', '>', 0)->where('score', '=', 0)->where('price', '>', 0)->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(original) as original'),DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id'))
|
||||
->groupBy('goods_id')
|
||||
->orderBy('price','asc')
|
||||
->with('goods')
|
||||
->paginate(20);
|
||||
break;
|
||||
case 'score':
|
||||
$data = GoodsParams::whereHas('goods', function ($query) use($title,$category)
|
||||
{
|
||||
return $query->when($category, function ($query) use ($category) {
|
||||
$category_ids = Category::where('id',$category)->orWhere('parent_id', $category)->pluck('id');
|
||||
return $query->whereIn('goods.category_id', $category_ids);
|
||||
})->when($title, function ($query) use ($title) {
|
||||
return $query->where('goods.title', 'like', "%$title%");
|
||||
})->where('status',1);
|
||||
})->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price = score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(original) as original'),DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id'))
|
||||
->groupBy('goods_id')
|
||||
->orderBy('price','asc')
|
||||
->with('goods')
|
||||
->paginate(20);
|
||||
break;
|
||||
case 'cashScore':
|
||||
$data = GoodsParams::whereHas('goods', function ($query) use($title,$category)
|
||||
{
|
||||
return $query->when($category, function ($query) use ($category) {
|
||||
$category_ids = Category::where('id',$category)->orWhere('parent_id', $category)->pluck('id');
|
||||
return $query->whereIn('goods.category_id', $category_ids);
|
||||
})->when($title, function ($query) use ($title) {
|
||||
return $query->where('goods.title', 'like', "%$title%");
|
||||
})->where('status',1);
|
||||
})->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(original) as original'),DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id'))
|
||||
->groupBy('goods_id')
|
||||
->with('goods')
|
||||
->orderBy('price','asc')
|
||||
->paginate(20);
|
||||
break;
|
||||
}
|
||||
return GoodsParamsListResource::collection($data)->additional([
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商品分类 小程序点击某一分类页面请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function category(Request $request)
|
||||
{
|
||||
$categoryId = $request->get('id', '');
|
||||
$categoryLists = Category::where('parent_id', 1)->orderBy('sort', 'desc')->orderBy('created_at', 'desc')->get();
|
||||
$currentCategory = Category::find($categoryId);
|
||||
return [
|
||||
'data' => [
|
||||
'currentCategory' => new ChannelIndexResource($currentCategory),
|
||||
'categoryLists' => ChannelIndexResource::collection($categoryLists),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商品满仓列表 小程序点击满仓赠品请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function fullLists(Request $request)
|
||||
{
|
||||
$title = $request->get('title', '');
|
||||
$fullGoodsLists = Goods::where('status', 1)
|
||||
->when($title, function ($query) use ($title) {
|
||||
return $query->where('title', 'like', "%$title%");
|
||||
})
|
||||
->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1);
|
||||
})
|
||||
->where('is_mall_gift', 1)->get();
|
||||
|
||||
$isfull = $this->user->account->act_a > 0 ? true : false;
|
||||
$fullOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'FULL_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateOrder = !$fullOrder && $isfull ? true : false;
|
||||
return [
|
||||
'data' => [
|
||||
'isfull' => $isfull,
|
||||
'fullGoodsLists' => GoodsGiftListResource::collection($fullGoodsLists),
|
||||
'canCreateOrder' => $canCreateOrder,
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* vip赠品列表 小程序点击vip赠品请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function vipLists(Request $request)
|
||||
{
|
||||
$title = $request->get('title', '');
|
||||
$vipGoodsLists = Goods::where('status', 1)
|
||||
->when($title, function ($query) use ($title) {
|
||||
return $query->where('title', 'like', "%$title%");
|
||||
})
|
||||
->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1);
|
||||
})
|
||||
->where('is_seller_gift', 1)->get();
|
||||
|
||||
//最近的上级总裁的商品。
|
||||
$parentMallLists = [];
|
||||
$parent_ids = array_reverse(array_filter(explode(',', $this->user->relation->bloodline)));
|
||||
foreach ($parent_ids as $key => $parent_id) {
|
||||
$parent_seller[$key] = Seller::where(['status' => 1, 'user_id' => $parent_id])->first();
|
||||
if ($parent_seller[$key]) {
|
||||
$parentMallLists = $parent_seller[$key]->goods()->where('is_seller_gift', 1)->get();
|
||||
if ($parentMallLists && $parentMallLists->count() > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$defaultMallLists = Goods::where('status', 1)->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1);
|
||||
})
|
||||
->where('is_seller_gift', 1)->where('seller_id', 1)->get();
|
||||
|
||||
$vipPay = VipPament::where(['user_id' => $this->uid, 'state' => 'SUCCESS'])->first();
|
||||
|
||||
if ($vipPay && $vipPay->type == 'CDKEY') {
|
||||
$vipGoodsLists = !empty($parentMallLists) && $parentMallLists->count() > 0 ? [] : $defaultMallLists;
|
||||
}
|
||||
|
||||
$isVipUser = $vipPay ? true : false;
|
||||
$vipOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'VIP_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateOrder = !$vipOrder && $isVipUser ? true : false;
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'parentMallLists' => !empty($parentMallLists) && $parentMallLists->count() > 0 ? GoodsGiftListResource::collection($parentMallLists) : [],//最近上级的店铺赠品
|
||||
'vipGoodsLists' => !empty($vipGoodsLists) && $vipGoodsLists->count() > 0 ? GoodsGiftListResource::collection($vipGoodsLists) : [],//可选的全部赠品
|
||||
'isVipUser' => $isVipUser,//是否是vip
|
||||
'canCreateOrder' => $canCreateOrder//是否可以创建订单
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 满仓赠品详情 小程序点击满仓赠品查看赠品详情请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function fullGift(Goods $good)
|
||||
{
|
||||
$isfull = $this->user->account->act_a > 0 ? true : false;
|
||||
$fullOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'FULL_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateOrder = !$fullOrder && $isfull ? true : false;
|
||||
return [
|
||||
'data' => [
|
||||
'isfull' => $isfull,
|
||||
'canCreateOrder' => $canCreateOrder,
|
||||
'goods' => new GoodsGiftDetailResource($good),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* vip赠品详情 小程序点击vip赠品查看赠品详情请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function vipGift(Goods $good)
|
||||
{
|
||||
$vipPay = VipPament::where(['user_id' => $this->uid, 'state' => 'SUCCESS'])->first();
|
||||
$isVipUser = $vipPay ? true : false;
|
||||
|
||||
$vipOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'VIP_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateOrder = !$vipOrder && $isVipUser ? true : false;
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'goods' => new GoodsGiftDetailResource($good),
|
||||
'isVipUser' => $isVipUser,//是否是vip
|
||||
'canCreateOrder' => $canCreateOrder//是否可以创建订单
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
65
app/Api/Controllers/IndexController.php
Normal file
65
app/Api/Controllers/IndexController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\GoodsParamsListResource;
|
||||
use App\Api\Resources\SellerListResource;
|
||||
use App\Models\GoodsParams;
|
||||
use App\Models\Seller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$goodsLists = GoodsParams::whereHas('goods', function ($query) {
|
||||
return $query->where('status', 1);
|
||||
})->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id'))
|
||||
->groupBy('goods_id')
|
||||
->orderBy('price', 'asc')
|
||||
->paginate(10);
|
||||
|
||||
|
||||
|
||||
$page = $request->page ?? 1; //获取当前页码
|
||||
|
||||
if ($page > 1) {
|
||||
//页码大于1,AJAX调用分页
|
||||
if ($goodsLists->count() > 0) {
|
||||
return [
|
||||
'data' => [
|
||||
'goodsLists' => GoodsParamsListResource::collection($goodsLists),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
} else {
|
||||
//无内容提示到最后一页
|
||||
return $this->failed('已经到最后一页');
|
||||
}
|
||||
}else{
|
||||
$sellers = Seller::with(['storage'])->orderBy('sort', 'desc')->limit(12)->get();
|
||||
$recommendSellerGoods = GoodsParams::whereHas('goods', function ($query) {
|
||||
return $query->where('status', 1)->where('seller_id', 1);
|
||||
})->where('status', 1)->where('stock', '>', 0)->where('score', '>', 0)->whereRaw('price > score')->select('goods_id', DB::raw('any_value(stock) as stock'), DB::raw('any_value(status) as status'), DB::raw('any_value(price) as price'), DB::raw('any_value(score) as score'), DB::raw('any_value(id) as id'))
|
||||
->groupBy('goods_id')
|
||||
->orderBy('price', 'asc')
|
||||
->limit(8)->get();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'goodsLists' => GoodsParamsListResource::collection($goodsLists),
|
||||
'sellers' => SellerListResource::collection($sellers),
|
||||
'recommendSellerGoods' => GoodsParamsListResource::collection($recommendSellerGoods)
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
275
app/Api/Controllers/KeysController.php
Normal file
275
app/Api/Controllers/KeysController.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 11:35 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\Cdkey;
|
||||
use App\Models\KeysApply;
|
||||
use App\Models\KeysOrder;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Image;
|
||||
use QrCode;
|
||||
|
||||
class KeysController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $this->user;
|
||||
|
||||
if ($user->identity->identity_id == 0) {
|
||||
return $this->failed('请开通VIP后继续操作');
|
||||
}
|
||||
// 已使用 USED 未使用 EMPTY
|
||||
$status = $request->status ?? 'EMPTY';
|
||||
|
||||
$keys = Cdkey::where('belong_uid', $user->id)
|
||||
->when($status, function ($query) use ($status) {
|
||||
if ($status == 'USED') {
|
||||
$query->whereNotNull('used_at');
|
||||
} elseif ($status == 'EMPTY') {
|
||||
$query->whereNull('used_at');
|
||||
}
|
||||
})
|
||||
->get();
|
||||
|
||||
$useNum = Cdkey::where('belong_uid', $user->id)
|
||||
->whereNotNull('used_at')
|
||||
->count();
|
||||
$notUseNum = Cdkey::where('belong_uid', $user->id)
|
||||
->whereNull('used_at')
|
||||
->count();
|
||||
return view('keys.index', compact('keys', 'status', 'useNum', 'notUseNum'));
|
||||
}
|
||||
|
||||
public function show(Cdkey $cdkey)
|
||||
{
|
||||
if ($cdkey->belong_uid != $this->uid) {
|
||||
return $this->failed('没有权限查看激活码');
|
||||
}
|
||||
$code = \App\Helpers\CDKEY::generator($cdkey->code, 'svg', 129);
|
||||
return view('keys.show', compact('code', 'cdkey'));
|
||||
}
|
||||
|
||||
public function manage(Request $request)
|
||||
{
|
||||
$user = $this->user;
|
||||
if ($user->id == 1757) {
|
||||
$user = User::find(62);
|
||||
}
|
||||
if ($user->identity->identity_id < 2) {
|
||||
return $this->failed('没有激活码管理权限');
|
||||
}
|
||||
$count = KeysApply::where('user_id', $user->id)->whereIn('status', [0, 1])->sum('num');
|
||||
return view('keys.manage', compact('count'));
|
||||
}
|
||||
|
||||
|
||||
public function doManage(Request $request)
|
||||
{
|
||||
$user = $this->user;
|
||||
if ($user->id == 1757) {
|
||||
$user = User::find(62);
|
||||
}
|
||||
if ($user->identity->identity_id < 2) {
|
||||
return $this->failed('没有激活码管理权限');
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
$data['user_id'] = $user->id;
|
||||
$apply = KeysApply::create($data);
|
||||
if ($apply) {
|
||||
if ($apply->is_print == 0) {
|
||||
if (self::callback($apply->user_id)) {
|
||||
$apply->status = 1;
|
||||
$apply->save();
|
||||
return $this->success('申请成功');
|
||||
}
|
||||
}
|
||||
return $this->success('申请成功');
|
||||
} else {
|
||||
return $this->failed('申请失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付完成之后,直接生产虚拟卡
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-12-23T17:47:51+0800
|
||||
* @return function [description]
|
||||
*/
|
||||
public function callback($user_id)
|
||||
{
|
||||
$codes = [];
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$codes[$i]['belong_uid'] = $user_id;
|
||||
$codes[$i]['code'] = $this->random();
|
||||
$codes[$i]['is_print'] = 0;
|
||||
$codes[$i]['effective_at'] = now();
|
||||
$codes[$i]['created_at'] = now();
|
||||
$codes[$i]['updated_at'] = now();
|
||||
}
|
||||
return Cdkey::insert($codes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生随机字串,可用来自动生成密码 17010
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-09-14T17:00:34+0800
|
||||
* @param integer $len [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
private function random($len = 10): string
|
||||
{
|
||||
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
|
||||
$chars = str_repeat($chars, 4);
|
||||
$chars = str_shuffle($chars);
|
||||
$str = substr($chars, 0, $len);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getCode(Cdkey $cdkey)
|
||||
{
|
||||
$user = $this->user;
|
||||
$URL = \App\Helpers\CDKEY::encode($cdkey->code);
|
||||
|
||||
$qrCode = QrCode::format('png')->size(235)->margin(0)->generate($URL);
|
||||
$fileUrl = '/home/wwwroot/Wow/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('storage/headimgurl/' . $user->id . '.jpg'));
|
||||
$image = Image::make('img/share_bg2018.jpg'); //获取背景图片
|
||||
// ->insert(sprintf('%010d', $cdkey->id), 'bottom-left', 314, 200)
|
||||
$image->text('VIP' . sprintf('%09d', $cdkey->id), 270, 880, function ($font) {
|
||||
$font->file('fonts/yahei.ttf')->color('#333')->size(30);
|
||||
});
|
||||
return $image
|
||||
->insert($qrCode, 'top-left', 257, 610)
|
||||
->insert($headimg, 'bottom-left', 314, 200)
|
||||
->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 order()
|
||||
{
|
||||
$user = $this->user;
|
||||
|
||||
if ($user->identity->identity_id == 0) {
|
||||
return $this->failed('请开通VIP后继续操作');
|
||||
}
|
||||
|
||||
$order = KeysOrder::create([
|
||||
'user_id' => $user->id,
|
||||
'type' => '',
|
||||
'amount' => 990,
|
||||
]);
|
||||
|
||||
return $this->success(['orderid' => $order->id]);
|
||||
|
||||
}
|
||||
|
||||
public function giving(Request $request)
|
||||
{
|
||||
$user_id = $request->user_id ?? '';
|
||||
if (!$user_id || !is_numeric($user_id)) {
|
||||
return $this->failed('请输入正确的编号');
|
||||
}
|
||||
$user = User::find($user_id);
|
||||
if (!$user || $user->identity->identity_id == 0) {
|
||||
return $this->failed('用户不存在或不是会员');
|
||||
}
|
||||
$order = KeysOrder::create([
|
||||
'user_id' => $user->id,
|
||||
'type' => '',
|
||||
'amount' => 990,
|
||||
]);
|
||||
return $this->success(['orderid' => $order->id, 'nickname' => $user->info->nickname, 'user_id' => $user->id]);
|
||||
}
|
||||
|
||||
public function balance(Request $request, KeysOrder $order)
|
||||
{
|
||||
if ($this->user->paypass) {
|
||||
if ($this->user->paypass !== md5($request->paypass)) {
|
||||
return $this->failed('支付密码验证失败');
|
||||
}
|
||||
} else {
|
||||
return $this->failed('请您先设置支付密码', route('settings.pwd'));
|
||||
}
|
||||
|
||||
$order = KeysOrder::where('trade_no', $request->trade_no)->first();
|
||||
if ($this->user->account->cash < $order->amount) {
|
||||
return $this->failed('账户余额不足');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($order) {
|
||||
$this->user->rule('balance_pay', -$order->amount, false, $order->trade_no);
|
||||
$order->state = 'SUCCESS';
|
||||
$order->paid_at = Carbon::now();
|
||||
$order->save();
|
||||
event(new \App\Events\KeysPaid($order));
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
return $this->failed($e->getmessage());
|
||||
}
|
||||
return $this->success('支付成功');
|
||||
}
|
||||
|
||||
public function wechat(Request $request, KeysOrder $order)
|
||||
{
|
||||
$user = $this->user;
|
||||
$openid = $user->openid;
|
||||
if ($user->main_id > 0) {
|
||||
$openid = $user->mainuser->openid;
|
||||
}
|
||||
|
||||
$app = app('wechat.payment');
|
||||
$result = $app->order->unify([
|
||||
'body' => '申请激活码',
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'total_fee' => $order->amount * 100,
|
||||
'notify_url' => route('notify.keys'),
|
||||
'trade_type' => 'JSAPI',
|
||||
'openid' => $openid,
|
||||
]);
|
||||
|
||||
$json = $app->jssdk->bridgeConfig($result['prepay_id']);
|
||||
|
||||
return view('keys.pay', compact('order', 'json'));
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Api/Controllers/MessageController.php
Normal file
36
app/Api/Controllers/MessageController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MessageController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$echoStr = $_GET["echostr"];
|
||||
if (self::checkSignature()) {
|
||||
echo $echoStr;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkSignature()
|
||||
{
|
||||
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
$token = 'BiX5ygs8lIOP6EtrKF6kCktebp7rWgzy';
|
||||
$tmpArr = array($token, $timestamp, $nonce);
|
||||
sort($tmpArr, SORT_STRING);
|
||||
$tmpStr = implode($tmpArr);
|
||||
$tmpStr = sha1($tmpStr);
|
||||
if ($tmpStr == $signature) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
447
app/Api/Controllers/OrdersController.php
Normal file
447
app/Api/Controllers/OrdersController.php
Normal file
@@ -0,0 +1,447 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/11
|
||||
* Time: 4:13 PM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\AddressResource;
|
||||
use App\Api\Resources\BuyNowGoodsResource;
|
||||
use App\Api\Resources\CartSellerResource;
|
||||
use App\Api\Resources\OrdersListResource;
|
||||
use App\Logistics\Logistic;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Freight;
|
||||
use App\Models\GoodsParams;
|
||||
use App\Models\Seller;
|
||||
use App\Models\VipPament;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use RuLong\Area\Models\UserAddress;
|
||||
use RuLong\Order\Exceptions\OrderException;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\Order\Models\OrderDetail;
|
||||
|
||||
class OrdersController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api');
|
||||
$this->user = \Auth::guard('api')->user();
|
||||
$this->uid = \Auth::guard('api')->id();
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序我的订单列表请求该接口。
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$orders = Order::where('user_id', $this->uid)
|
||||
->where('state', '<>', Order::ORDER_CLOSED)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
return OrdersListResource::collection($orders)->additional([
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序查看订单详情请求该接口。
|
||||
* @param $orderid
|
||||
* @return array
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$order = Order::find($id);
|
||||
return [
|
||||
'data' => new OrdersListResource($order),
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序取消订单该接口。
|
||||
* @param $orderid
|
||||
* @return array
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$order = Order::find($id);
|
||||
try {
|
||||
$order->close();
|
||||
return $this->success(['msg' => '签收成功']);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failed('签收失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序签收订单请求该接口。
|
||||
* @param $orderid
|
||||
* @return array
|
||||
*/
|
||||
public function sign($id)
|
||||
{
|
||||
$order = Order::find($id);
|
||||
try {
|
||||
$order->signin();
|
||||
return $this->success(['msg' => '签收成功']);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failed('签收失败' . $e->getmessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序物流跟踪请求该接口。
|
||||
* @param $orderid
|
||||
* @return array
|
||||
*/
|
||||
public function logistic($id)
|
||||
{
|
||||
$order = Order::find($id);
|
||||
$message = Logistic::getMessage($order->express->company ?? '', $order->express->number ?? ''); //类型csn,编号
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'order_info' => new OrdersListResource($order),
|
||||
'logistic_info' => [
|
||||
'code' => $message['code'],
|
||||
'name' => $message['code'] == 'OK' ? $message['name'] : '',
|
||||
'no' => $message['code'] == 'OK' ? $message['no'] : '',
|
||||
'logisticLists' => $message['code'] == 'OK' ? $message['list'] : [],
|
||||
],
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序购物车下单确认订单数据接口
|
||||
* 购物车下单,每个店铺产生一个订单,order表中的订单类型为商品订单GOODS,order表中的订单商品id为0;
|
||||
* 商品订单GOODS,商家结算运费=用户支付运费。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function cartSure(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
|
||||
$otherParams = $request->otherParams;
|
||||
$carts = array();
|
||||
$address = UserAddress::find($request->addressId);
|
||||
foreach (explode(',', $request->cart_ids) as $key => $value) {
|
||||
$cart = Cart::find($value);
|
||||
if ($cart) {
|
||||
if ($cart->params->stock < 1) {
|
||||
$cart->delete();
|
||||
} else {
|
||||
if ($cart->number < $cart->params->stock) {
|
||||
if (!isset($carts[$cart->params->goods->seller_id])) {
|
||||
$carts[$cart->params->goods->seller_id] = [];
|
||||
}
|
||||
array_push($carts[$cart->params->goods->seller_id], $cart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($carts as $key => $seller_item) {
|
||||
//获取店铺运费、金额、积分小计
|
||||
$seller_total[$key] = self::sellerTotal($key, $seller_item, $address);
|
||||
|
||||
$score_order[$key] = $seller_total[$key]['score'];
|
||||
//账户积分
|
||||
if ($this->user->account->score < $seller_total[$key]['score']) {
|
||||
throw new OrderException('积分不足');
|
||||
}
|
||||
|
||||
$express_type[$key] = 1;
|
||||
$remark[$key] = '';
|
||||
$items[$key] = array();
|
||||
//店铺配送方式及店铺留言
|
||||
foreach ($otherParams as $other) {
|
||||
if ($other['seller_id'] === $key) {
|
||||
$express_type[$key] = $other['express'];
|
||||
$remark[$key] = $other['remark'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($seller_item as $cart_item) {
|
||||
$params = GoodsParams::find($cart_item->params_id);
|
||||
array_push($items[$key], new OrderDetail(['goods' => $params, 'number' => $cart_item->number]));
|
||||
$cart_item->delete();
|
||||
}
|
||||
|
||||
//Orders::create(用户id,店铺id,订单类型及赠品id,订单商品,收货地址,买家留言,商品总价,可兑换积分,店铺总运费,配送方式,结算总运费)
|
||||
\Orders::create($this->uid, $key, ['type' => 'GOODS', 'id' => 0], $items[$key], $address, $remark[$key], null, $score_order[$key], $seller_total[$key]['freightPrice'], $express_type[$key], $seller_total[$key]['freightPrice']);
|
||||
}
|
||||
});
|
||||
$order = Order::where('user_id', $this->uid)->where('state', 'UNPAY')->orderBy('created_at', 'desc')->first();
|
||||
return [
|
||||
'data' => ['orderid' => $order->id, 'actualPrice' => $order->total - $order->score],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'msg' => $e->getmessage(),
|
||||
'status' => 'ERROR',
|
||||
'status_code' => 400,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车多店铺生成多订单,计算店铺商品金额、运费金额、积分金额总和
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
private function sellerTotal($seller_id, $seller_item, $address = null)
|
||||
{
|
||||
$amount = 0;
|
||||
$freightPrice = \Params::get('default_freight');
|
||||
$heavy = 0;
|
||||
$score = 0;
|
||||
foreach ($seller_item as $cart_item) {
|
||||
$params = GoodsParams::find($cart_item->params_id);
|
||||
$amount += $cart_item->number * $params->price;
|
||||
if ($params->is_free_freight == 0) {
|
||||
$heavy += $cart_item->number * $params->heavy;
|
||||
}
|
||||
$score += $cart_item->number * $params->score;
|
||||
}
|
||||
|
||||
if ($heavy === 0) {
|
||||
$freightPrice = 0; //包邮
|
||||
} else {
|
||||
//计算每个商户订单的运费
|
||||
if (!empty($address)) {
|
||||
$freight = Freight::where(['seller_id' => $seller_id, 'area_id' => $address->province->id])->first();
|
||||
if ($freight) {
|
||||
$freightPrice = $freight->basic;
|
||||
if ($freight->heavy < $heavy) {
|
||||
$freightPrice += ceil($heavy - $freight->heavy) * $freight->added;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'freightPrice' => $freightPrice,
|
||||
'score' => $score,
|
||||
'amount' => $amount - $score,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 单品立即购买,包括普通商品,vip赠品,满仓赠品
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function buyNow(Request $request)
|
||||
{
|
||||
$address = $request->addressId ? UserAddress::find($request->addressId) : null;
|
||||
$params_id = $request->params_id;
|
||||
$number = $request->number;
|
||||
$item_type = $request->item_type;
|
||||
$params = GoodsParams::find($params_id);
|
||||
|
||||
$seller = Seller::find($params->goods->seller_id);
|
||||
|
||||
$amount = $params->price * $number;
|
||||
$score = 0;
|
||||
|
||||
$freightPrice = \Params::get('default_freight');
|
||||
|
||||
if ($item_type == 'VIP_GIFT') {
|
||||
//确认是否有领取权限
|
||||
if (self::canTakeVipGift() !== true) {
|
||||
return $this->failed('没有权限领取');
|
||||
}
|
||||
$amount = 0;
|
||||
$freightPrice = 9; //赠品固定运费9元
|
||||
|
||||
} elseif ($item_type == 'FULL_GIFT') {
|
||||
//确认是否有领取权限
|
||||
if (self::canTakeFullGift() !== true) {
|
||||
return $this->failed('没有权限领取');
|
||||
}
|
||||
$amount = 0;
|
||||
//计算运费
|
||||
$heavy = $number * $params->heavy;
|
||||
$freightPrice = self::freightPrice($seller->id, $heavy, $address);
|
||||
|
||||
} elseif ($item_type == 'GOODS') {
|
||||
$score = $params->score * $number;
|
||||
$amount -= $score;
|
||||
//计算运费
|
||||
$heavy = $number * $params->heavy;
|
||||
$freightPrice = self::freightPrice($seller->id, $heavy, $address);
|
||||
}
|
||||
return [
|
||||
'data' => [
|
||||
'seller' => new CartSellerResource($seller),
|
||||
'goods' => new BuyNowGoodsResource($params),
|
||||
'number' => $number,
|
||||
'item_type' => $item_type,
|
||||
'total' => [
|
||||
'amount' => number_format($amount, 2),
|
||||
'score' => number_format($score, 2),
|
||||
'freight' => $freightPrice,
|
||||
'freightOriginal' => $freightPrice,
|
||||
'orderPrice' => $amount + $freightPrice,
|
||||
|
||||
],
|
||||
'express' => [
|
||||
'type1' => 1,
|
||||
'type2' => 0,
|
||||
],
|
||||
'address' => $address ? new AddressResource($address) : [],
|
||||
],
|
||||
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 单品生成订单,,包括商品订单、vip赠品订单、满仓赠品订单
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
//收货地址
|
||||
$address = UserAddress::find($request->addressId);
|
||||
|
||||
//请求参数
|
||||
$params_id = $request->params_id;
|
||||
$number = $request->number;
|
||||
$express_type = $request->express_type;
|
||||
$remark = $request->remark;
|
||||
$item_type = $request->item_type;
|
||||
|
||||
//立即购买的商品规格
|
||||
$params = GoodsParams::find($params_id);
|
||||
|
||||
//商户id
|
||||
$seller_id = $params->goods->seller_id;
|
||||
|
||||
//积分计算
|
||||
$score = $params->score * $number;
|
||||
|
||||
$score_order = 0;
|
||||
|
||||
if ($item_type == 'GOODS') {
|
||||
$score_order = $score;
|
||||
}
|
||||
|
||||
if ($this->user->account->score < $score_order) {
|
||||
throw new OrderException('积分不足');
|
||||
}
|
||||
|
||||
//运费计算
|
||||
$heavy = $number * $params->heavy;
|
||||
$freightPrice = self::freightPrice($seller_id, $heavy, $address);
|
||||
|
||||
//商品详情
|
||||
$items = array();
|
||||
array_push($items, new OrderDetail(['goods' => $params, 'number' => $number]));
|
||||
|
||||
//订单类型 GOODS:商品订单 VIP_GIFT:赠品订单 FULL_GIFT:满仓订单
|
||||
$order_item = [
|
||||
'type' => $item_type,
|
||||
'id' => $item_type == 'GOODS' ? 0 : $params->id,
|
||||
];
|
||||
|
||||
//生成订单
|
||||
\Orders::create($this->uid, $seller_id, $order_item, $items, $address, $remark, null, $score_order, $freightPrice, $express_type, $freightPrice);
|
||||
|
||||
});
|
||||
$order = Order::where('user_id', $this->uid)->where('state', 'UNPAY')->orderBy('created_at', 'desc')->first();
|
||||
return [
|
||||
'data' => ['orderid' => $order->id, 'actualPrice' => $order->total - $order->score],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'msg' => $e->getmessage(),
|
||||
'status' => 'ERROR',
|
||||
'status_code' => 400,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单品订单运费计算
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
private function freightPrice($seller_id, $heavy, $address = null)
|
||||
{
|
||||
//运费计算
|
||||
$freightPrice = \Params::get('default_freight');
|
||||
|
||||
if ($heavy === 0) {
|
||||
$freightPrice = 0; //包邮
|
||||
} else {
|
||||
//计算每个商户订单的运费
|
||||
if (!empty($address)) {
|
||||
$freight = Freight::where(['seller_id' => $seller_id, 'area_id' => $address->province->id])->first();
|
||||
if ($freight) {
|
||||
$freightPrice = $freight->basic;
|
||||
if ($freight->heavy < $heavy) {
|
||||
$freightPrice = ceil($heavy - $freight->heavy) * $freight->added;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $freightPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否可以领取vip赠品
|
||||
* @param
|
||||
* @return boolean
|
||||
*/
|
||||
private function canTakeVipGift()
|
||||
{
|
||||
$vipPay = VipPament::where(['user_id' => $this->uid, 'state' => 'SUCCESS'])->first();
|
||||
$isVipUser = $vipPay ? true : false;
|
||||
$vipOrders = Order::where(['user_id' => $this->uid, 'item_type' => 'VIP_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canTakeVipGift = !$vipOrders && $isVipUser ? true : false;
|
||||
return $canTakeVipGift;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否可以领取满仓赠品
|
||||
* @param
|
||||
* @return boolean
|
||||
*/
|
||||
private function canTakeFullGift()
|
||||
{
|
||||
$isfull = $this->user->account->act_a > 0 ? true : false;
|
||||
$fullOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'FULL_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canTakeFullGift = !$fullOrder && $isfull ? true : false;
|
||||
return $canTakeFullGift;
|
||||
}
|
||||
}
|
||||
64
app/Api/Controllers/PayController.php
Normal file
64
app/Api/Controllers/PayController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/21
|
||||
* Time: 11:26 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class PayController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api');
|
||||
$this->user = \Auth::guard('api')->user();
|
||||
$this->uid = \Auth::guard('api')->id();
|
||||
}
|
||||
|
||||
private function getpayOrder(Order $order, $type)
|
||||
{
|
||||
$payOrder = Payment::create([
|
||||
'order_id' => $order->id,
|
||||
'type' => $type,
|
||||
'amount' => $order->total - $order->score,
|
||||
]);
|
||||
return $payOrder;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$orderid = $request->orderId;
|
||||
$order = Order::find($orderid);
|
||||
|
||||
// $app = app('wechat.mini_program');
|
||||
// $wechatMessage = $app->auth->session($request->code);
|
||||
// $openid = $wechatMessage->openid;
|
||||
|
||||
$openid = $request->openid;
|
||||
$payOrder = $this->getpayOrder($order, 'WECHAT');
|
||||
$payment = app('wechat.payment.mini');
|
||||
$result = $payment->order->unify([
|
||||
'body' => '商城订单',
|
||||
'out_trade_no' => $payOrder->trade_no,
|
||||
'total_fee' => 0.01 * 100,
|
||||
'notify_url' => 'http://mapi.bohaimingpin.com/callback/index',
|
||||
'trade_type' => 'JSAPI',
|
||||
'openid' => $openid,
|
||||
]);
|
||||
|
||||
if ($result['return_code'] == 'SUCCESS' && isset($result['prepay_id'])) {
|
||||
$json = $payment->jssdk->bridgeConfig($result['prepay_id']);
|
||||
return $this->success($json);
|
||||
} else {
|
||||
return $this->failed($result['return_msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
97
app/Api/Controllers/SellersController.php
Normal file
97
app/Api/Controllers/SellersController.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 11:33 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\GoodsListResource;
|
||||
use App\Api\Resources\GoodsParamsListResource;
|
||||
use App\Api\Resources\SellerListResource;
|
||||
use App\Models\Goods;
|
||||
use App\Models\Seller;
|
||||
use App\User;
|
||||
|
||||
class SellersController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// if ($this->user->identity->identity_id == 0) {
|
||||
// return $this->failed('请开通VIP后继续操作');
|
||||
// }
|
||||
|
||||
$sellers = Seller::with(['storage'])->get();
|
||||
|
||||
return SellerListResource::collection($sellers)->additional([
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Seller $seller)
|
||||
{
|
||||
// if ($this->user->identity->identity_id == 0) {
|
||||
// return $this->failed('请开通VIP后继续操作');
|
||||
// }
|
||||
|
||||
$hotGoods = Goods::with(['storage'])
|
||||
->where('status', 1)
|
||||
->where('seller_id', $seller->id)
|
||||
->where('status', 1)
|
||||
->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1)->where('score', '>', 0)->whereRaw('price > score');
|
||||
})
|
||||
->select('id', 'title', 'description', 'storage_id', 'score')
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(500)
|
||||
->get();
|
||||
|
||||
$hotGoodsScore = Goods::with(['storage'])
|
||||
->where('status', 1)
|
||||
->where('seller_id', $seller->id)
|
||||
->where('status', 1)
|
||||
->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1)->where('score', '>', 0)->whereRaw('price = score');
|
||||
})
|
||||
->select('id', 'title', 'description', 'storage_id', 'score')
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(500)
|
||||
->get();
|
||||
|
||||
$hotGoodsCash = Goods::with(['storage'])
|
||||
->where('status', 1)
|
||||
->where('seller_id', $seller->id)
|
||||
->where('status', 1)
|
||||
->whereHas('params', function ($query) {
|
||||
return $query->where('stock', '>', 0)->where('status', 1)->where('score', 0);
|
||||
})
|
||||
->select('id', 'title', 'description', 'storage_id', 'score')
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(500)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'seller_info' => new SellerListResource($seller),
|
||||
'hotGoods' => GoodsParamsListResource::collection($hotGoods),
|
||||
'hotGoodsScore' => GoodsParamsListResource::collection($hotGoodsScore),
|
||||
'hotGoodsCash' => GoodsParamsListResource::collection($hotGoodsCash),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
109
app/Api/Controllers/SettingsController.php
Normal file
109
app/Api/Controllers/SettingsController.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 11:20 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\UserInfoResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
use App\User;
|
||||
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
|
||||
public function doWechatNo(Request $request)
|
||||
{
|
||||
$post = $request->post();
|
||||
$result = $this->user->info()->update([
|
||||
'wechat_no' => $post['wechatNo'],
|
||||
]);
|
||||
if ($result) {
|
||||
return $this->success('信息更新成功');
|
||||
} else {
|
||||
return $this->failed('信息更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function doPaypass(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'password' => 'required|confirmed|between:6,32',
|
||||
], [
|
||||
'password.required' => '登录密码必须填写',
|
||||
'password.between' => '登录密码应在:min-:max位之间',
|
||||
'password.confirmed' => '确认密码错误',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
$data = $request->all();
|
||||
if ($this->user->paypass) {
|
||||
if ($this->user->paypass != md5($data['oldpassword'])) {
|
||||
return $this->failed('原密码错误');
|
||||
}
|
||||
}
|
||||
$password = $request->post('password');
|
||||
$this->user->paypass = $password;
|
||||
$this->user->save();
|
||||
return $this->success('支付密码设置成功');
|
||||
}
|
||||
|
||||
public function doRealname(Request $request)
|
||||
{
|
||||
$post = $request->post();
|
||||
$result = $this->user->info()->update([
|
||||
'realname' => $post['realname'],
|
||||
]);
|
||||
if ($result) {
|
||||
return $this->success('信息更新成功');
|
||||
} else {
|
||||
return $this->failed('信息更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function doMobile(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|unique:users',
|
||||
'code' => 'required|sms_check:mobile,BIND',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.unique' => '手机号码已经绑定',
|
||||
'code.required' => '验证码必须填写',
|
||||
'code.sms_check' => '验证码不正确',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
|
||||
$mobile = $request->mobile;
|
||||
|
||||
$user = $this->user;
|
||||
|
||||
$user->mobile = $mobile;
|
||||
$user->save();
|
||||
|
||||
return $this->success('手机号绑定成功');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
106
app/Api/Controllers/TeamController.php
Normal file
106
app/Api/Controllers/TeamController.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 11:16 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
|
||||
use App\Api\Resources\MySharesResource;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
use RuLong\Identity\Models\UserIdentity;
|
||||
|
||||
class TeamController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
public function index(Request $request, $node = 0)
|
||||
{
|
||||
$user = $this->user;
|
||||
if ($this->uid == 3 || $this->uid == 10 || $this->uid == 12 || $this->uid == 824) {
|
||||
$user = User::find(62);
|
||||
}
|
||||
|
||||
$ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->when($node, function ($q) use ($node, $user) {
|
||||
$q->where('layer', $user->relation->layer + $node);
|
||||
})->orderBy('layer', 'asc')->pluck('user_id') ?: [0];
|
||||
|
||||
$lists = UserIdentity::whereIn('user_id', $ids)->limit(500)->get();
|
||||
|
||||
$children = [];
|
||||
$children_count = 0;
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
$layer_ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', $user->relation->layer + $i)->pluck('user_id') ?: [0];
|
||||
|
||||
$children[$i] = UserIdentity::whereIn('user_id', $layer_ids)->count();
|
||||
|
||||
$children_count += $children[$i];
|
||||
}
|
||||
return [
|
||||
'data' => [
|
||||
'node' => $node,
|
||||
'childrenCount' => $children_count,
|
||||
'lists' => MySharesResource::collection($lists),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
public function novip(Request $request, $node = 0)
|
||||
{
|
||||
$user = $this->user;
|
||||
if ($this->uid == 3 || $this->uid == 10 || $this->uid == 12 || $this->uid == 824) {
|
||||
$user = User::find(62);
|
||||
}
|
||||
|
||||
$ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', '<=', $user->relation->layer + 6)->when($node, function ($q) use ($node, $user) {
|
||||
$q->where('layer', $user->relation->layer + $node);
|
||||
})->orderBy('layer', 'asc')->pluck('user_id') ?: [0];
|
||||
|
||||
$ids = UserIdentity::whereIn('user_id', $ids)->pluck('user_id') ?: [0];
|
||||
$lists = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->where('layer', '<=', $user->relation->layer + 6)
|
||||
->when($node, function ($q) use ($node, $user) {
|
||||
$q->where('layer', $user->relation->layer + $node);
|
||||
})
|
||||
->whereNotIn('user_id', $ids)
|
||||
->orderBy('layer', 'asc')->limit(500)->get();
|
||||
|
||||
$children = [];
|
||||
$children_count = 0;
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
$layer_ids = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->where('layer', $user->relation->layer + $i)->pluck('user_id') ?: [0];
|
||||
|
||||
$layer_ids = UserIdentity::whereIn('user_id', $layer_ids)->pluck('user_id') ?: [0];
|
||||
$children[$i] = UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")
|
||||
->whereNotIn('user_id', $layer_ids)
|
||||
->where('layer', $user->relation->layer + $i)->count();
|
||||
|
||||
$children_count += $children[$i];
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'node' => $node,
|
||||
'childrenCount' => $children_count,
|
||||
'lists' => MySharesResource::collection($lists),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
27
app/Api/Controllers/UserController.php
Normal file
27
app/Api/Controllers/UserController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Api\Resources\UserInfoResource;
|
||||
use Validator;
|
||||
use App\User;
|
||||
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.api');
|
||||
$this->user = \Auth::guard('api')->user();
|
||||
$this->uid = \Auth::guard('api')->id();
|
||||
// $this->user = User::find(824);
|
||||
// $this->uid = 824;
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
return $this->success(new UserInfoResource($this->user));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
96
app/Api/Controllers/VipController.php
Normal file
96
app/Api/Controllers/VipController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/23
|
||||
* Time: 2:10 PM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use App\Models\VipPament;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\Order\Models\Order;
|
||||
|
||||
class VipController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户vip开通状态及信息接口,小程序访问开通vip页面时请求该接口。
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$vipPay = VipPament::where(['user_id' => $this->uid, 'state' => 'SUCCESS'])->first();
|
||||
|
||||
$isVipUser = $vipPay ? true : false;
|
||||
$vipOrder = Order::where(['user_id' => $this->uid, 'item_type' => 'VIP_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateOrder = !$vipOrder && $isVipUser ? true : false;
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'isVipUser' => $isVipUser,//是否是vip
|
||||
'vipOrder' => [
|
||||
'canCreateOrder' => $canCreateOrder,//是否可以创建订单
|
||||
'order_id' => $vipOrder->id ?? '',
|
||||
],
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 开通vip微信支付,小程序开通vip,去付款时请求该接口。
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function wechat(Request $request)
|
||||
{
|
||||
|
||||
$vipOrder = $this->getpayOrder('WECHAT');
|
||||
$openid = $request->openid;
|
||||
$app = app('wechat.payment.mini');
|
||||
$result = $app->order->unify([
|
||||
'body' => '开通会员',
|
||||
'out_trade_no' => $vipOrder->trade_no,
|
||||
'total_fee' => 99 * 100,
|
||||
'notify_url' => route('callback.vip'),
|
||||
'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->failed($result['return_msg']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getpayOrder($type)
|
||||
{
|
||||
$vipOrder = VipPament::where(['user_id' => $this->uid, 'state' => 'INIT'])->first();
|
||||
if (!$vipOrder) {
|
||||
$vipOrder = VipPament::create([
|
||||
'user_id' => $this->uid,
|
||||
'seller_id' => 1,
|
||||
'goods_id' => 1,
|
||||
'type' => $type,
|
||||
'amount' => 99.00,
|
||||
]);
|
||||
}
|
||||
return $vipOrder;
|
||||
}
|
||||
}
|
||||
187
app/Api/Controllers/WithdrawController.php
Normal file
187
app/Api/Controllers/WithdrawController.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/26
|
||||
* Time: 11:01 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
|
||||
use App\Api\Resources\WithdrawLogsResource;
|
||||
use App\Models\Bank;
|
||||
use App\Models\Withdraw;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Validator;
|
||||
|
||||
class WithdrawController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth.api');
|
||||
// $this->user = \Auth::guard('api')->user();
|
||||
// $this->uid = \Auth::guard('api')->id();
|
||||
$this->user = User::find(824);
|
||||
$this->uid = 824;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if ($this->user->identity->identity_id == 0) {
|
||||
return $this->failed('请开通VIP后继续操作');
|
||||
}
|
||||
$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', $this->uid)->orderBy('id', 'desc')->get();
|
||||
$withdraw_total = sprintf("%.2f", abs($this->user->account->logs()->whereIn('rule_id', [10, 11])->sum('variable')));
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'withdraw_total' => $withdraw_total,
|
||||
'withdraw_explain' => $withdraw_explain,
|
||||
'logsLists' => WithdrawLogsResource::collection($logs),
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if ($this->user->identity->identity_id == 0) {
|
||||
return $this->failed('请开通VIP后继续操作');
|
||||
}
|
||||
$week_num = 1;
|
||||
$week_start = Carbon::now()->startOfWeek()->toDateTimeString();
|
||||
$week_end = Carbon::now()->endOfWeek()->toDateTimeString();
|
||||
|
||||
$num = Withdraw::where('user_id', $this->uid)->whereBetween('created_at', [$week_start, $week_end])->where('state', '<>', 2)->count();
|
||||
if ($num > 0) {
|
||||
$week_num = 0;
|
||||
}
|
||||
|
||||
$banks = Bank::orderBy('sort', 'asc')->get();
|
||||
|
||||
$withdraw_explain = \Params::get('withdraw_explain');
|
||||
|
||||
$withdraw_explain = str_replace("\n", "<br />", $withdraw_explain);
|
||||
$withdraw_explain = str_replace("\r", "<br />", $withdraw_explain);
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'week_num' => $week_num,
|
||||
'banks' => $banks,
|
||||
'withdraw_explain' => $withdraw_explain,
|
||||
],
|
||||
'status' => 'SUCCESS',
|
||||
'status_code' => 200,
|
||||
];
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($this->user->identity->identity_id == 0) {
|
||||
return $this->failed('请开通VIP后继续操作');
|
||||
}
|
||||
$week_start = Carbon::now()->startOfWeek()->toDateTimeString();
|
||||
$week_end = Carbon::now()->endOfWeek()->toDateTimeString();
|
||||
|
||||
$num = Withdraw::where('user_id', $this->uid)->whereBetween('created_at', [$week_start, $week_end])->where('state', '<>', 2)->count();
|
||||
if ($num > 0) {
|
||||
return $this->failed('您本周已提现过,下周再来吧~');
|
||||
}
|
||||
if ($this->user->paypass) {
|
||||
if ($this->user->paypass !== md5($request->paypass)) {
|
||||
return $this->failed('支付密码验证失败');
|
||||
}
|
||||
} else {
|
||||
return $this->failed('请您先设置支付密码', route('settings.pwd'));
|
||||
}
|
||||
if (empty($request->way)) {
|
||||
return $this->failed('请选择提现方式');
|
||||
} elseif ($request->way == 'WenxinNo') {
|
||||
if (empty($request->wechat)) {
|
||||
return $this->failed('请输入微信号,工作人员会在1-2个工作日内为您转款');
|
||||
}
|
||||
} elseif ($request->way == 'Alipay') {
|
||||
if (empty($request->alipay)) {
|
||||
return $this->failed('请输入支付宝账号,工作人员会在1-2个工作日内为您转款');
|
||||
}
|
||||
} elseif ($request->way == 'Wechat') {
|
||||
if ($request->money > 200) {
|
||||
return $this->failed('单次提现金额最大200元');
|
||||
}
|
||||
} elseif ($request->way == 'Bankcard') {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'mobile' => 'required|mobile|unique:users',
|
||||
'code' => 'required|sms_check:mobile,BIND',
|
||||
], [
|
||||
'mobile.required' => '手机号码必须填写',
|
||||
'mobile.mobile' => '手机号码格式不正确',
|
||||
'mobile.unique' => '手机号码已经绑定',
|
||||
'code.required' => '验证码必须填写',
|
||||
'code.sms_check' => '验证码不正确',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
if (!preg_match("/^([\x{4e00}-\x{9fa5}]+)$/u", $request->payee)) {
|
||||
return $this->failed('请输入确认的收款人姓名');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->money < 100) {
|
||||
return $this->failed('提现金额必须大于等于100元');
|
||||
}
|
||||
|
||||
if ($request->money > $this->user->account->cash) {
|
||||
return $this->failed('账户余额不足');
|
||||
}
|
||||
if (empty($request->openid)) {
|
||||
return $this->failed('未获取到微信信息');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($request) {
|
||||
$tax = round($request->money * 0.05, 3);
|
||||
$take = $request->money - $tax;
|
||||
Withdraw::create([
|
||||
'user_id' => $this->uid,
|
||||
'amount' => $request->money,
|
||||
'tax' => $tax, //手续费
|
||||
'take' => $take, //实到金额
|
||||
'balance' => $this->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 : '',
|
||||
'payee' => $request->has('payee') ? $request->payee : '',
|
||||
'state' => 0,
|
||||
]);
|
||||
|
||||
if ($request->way == 'Bankcard') {
|
||||
$userinfo = $this->user->info;
|
||||
$userinfo->bank_no = $request->bank_no;
|
||||
$userinfo->bank_name = $request->bank_name;
|
||||
$userinfo->payee = $request->payee;
|
||||
$userinfo->save();
|
||||
}
|
||||
$this->user->rule('withdraw', -$request->money);
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
return $this->failed($e->getmessage());
|
||||
}
|
||||
return $this->success('申请提现成功,等待管理员审核');
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user