|
| xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
use App\Helper\AttachmentHelper;
|
|
|
use App\Models\BaseAttachmentModel;
|
|
|
+use App\Models\CardInfoModel;
|
|
|
use App\Models\CouponInfoModel;
|
|
|
use App\Models\OrderInfoModel;
|
|
|
use App\Models\ProductCategoryModel;
|
|
| xqd
@@ -88,7 +89,7 @@ class HomeController extends Controller
|
|
|
$session = $this->app->auth->session($code);
|
|
|
\Log::info(json_encode($session));
|
|
|
|
|
|
- $openid = 'olAS94uwfTdsL3nDnvG67p_v5Vks';
|
|
|
+ $openid = $session['openid'];
|
|
|
|
|
|
if (!$openid) {
|
|
|
$data = [
|
|
| xqd
@@ -317,6 +318,16 @@ class HomeController extends Controller
|
|
|
* "message": "传入参数不正确",
|
|
|
* "data": null or []
|
|
|
* }
|
|
|
+ * {
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "code": 10004,
|
|
|
+ * "msg": "店铺休假,请改天再约"
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
*/
|
|
|
public function getSchedule(Request $request)
|
|
|
{
|
|
| xqd
@@ -336,12 +347,19 @@ class HomeController extends Controller
|
|
|
|
|
|
$day = $request->get('day');
|
|
|
$storeid = $request->get('store_id');
|
|
|
- $am_start = $day . ' ' . ProductScheduleModel::first()->am_start;
|
|
|
- $am_end = $day . ' ' . ProductScheduleModel::first()->am_end;
|
|
|
- $pm_start = $day . ' ' . ProductScheduleModel::first()->pm_start;
|
|
|
- $pm_end = $day . ' ' . ProductScheduleModel::first()->pm_end;
|
|
|
- $max = ProductScheduleModel::first()->max;
|
|
|
- $min = ProductScheduleModel::first()->interval;
|
|
|
+
|
|
|
+ $isholiday = ProductScheduleModel::where('store_id', $storeid)->where('holiday_start', '<=', $day)->where('holiday_end', '>=', $day)->first();
|
|
|
+ if ($isholiday) {
|
|
|
+ $data = ['code' => 10004, 'msg' => '店铺休假,请改天再约'];
|
|
|
+ return $this->api($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ $am_start = $day . ' ' . ProductScheduleModel::where('store_id', $storeid)->first()->am_start;
|
|
|
+ $am_end = $day . ' ' . ProductScheduleModel::where('store_id', $storeid)->first()->am_end;
|
|
|
+ $pm_start = $day . ' ' . ProductScheduleModel::where('store_id', $storeid)->first()->pm_start;
|
|
|
+ $pm_end = $day . ' ' . ProductScheduleModel::where('store_id', $storeid)->first()->pm_end;
|
|
|
+ $max = ProductScheduleModel::where('store_id', $storeid)->first()->max;
|
|
|
+ $min = ProductScheduleModel::where('store_id', $storeid)->first()->interval;
|
|
|
|
|
|
$ams = $this->cut_time_part($am_start, $am_end, $min);
|
|
|
$am_schedule = $this->formatSchedule($ams, $max, $storeid);
|
|
| xqd
@@ -428,10 +446,10 @@ class HomeController extends Controller
|
|
|
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => 401,
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -533,16 +551,16 @@ class HomeController extends Controller
|
|
|
{
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
|
|
|
|
if (request('status')) {
|
|
|
- $orders = OrderInfoModel::where('user_id',$user->id)->where('status', request('status'))->get(['id', 'out_trade_no', 'username', 'schedule_time', 'product_id', 'status', 'store_id']);
|
|
|
+ $orders = OrderInfoModel::where('user_id', $user->id)->where('status', request('status'))->get(['id', 'out_trade_no', 'username', 'schedule_time', 'product_id', 'status', 'store_id']);
|
|
|
} else {
|
|
|
$orders = OrderInfoModel::where('user_id', $user->id)->where('status', '>', 0)->paginate(5);
|
|
|
}
|
|
| xqd
@@ -632,6 +650,7 @@ class HomeController extends Controller
|
|
|
* @apiPermission Passport
|
|
|
* @apiVersion 0.1.0
|
|
|
* @apiParam {string} orderid 订单号,创建订单后返回
|
|
|
+ * @apiParam {int} paytype 支付类型:0:全款支付;1:定金支付
|
|
|
* @apiParam {int} [couponid] 优惠券id
|
|
|
* @apiParam {int} [cardid] 抵扣卡id(抵扣卡和优惠券不能同时使用)
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
| xqd
@@ -665,9 +684,11 @@ class HomeController extends Controller
|
|
|
$validator = Validator::make($request->all(),
|
|
|
[
|
|
|
'orderid' => 'required',
|
|
|
+ 'paytype' => 'required',
|
|
|
],
|
|
|
[
|
|
|
'orderid.required' => 'orderid不能为空!',
|
|
|
+ 'paytype.required' => 'paytype不能为空!',
|
|
|
|
|
|
]
|
|
|
);
|
|
| xqd
@@ -679,10 +700,10 @@ class HomeController extends Controller
|
|
|
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -691,6 +712,25 @@ class HomeController extends Controller
|
|
|
|
|
|
\Log::info($this->options());
|
|
|
|
|
|
+ if(request('paytype') ==0 ){
|
|
|
+ $money = $order->price;
|
|
|
+ }else{
|
|
|
+ $money = $order->deposit;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(request('couponid')){
|
|
|
+ $coupon = CouponInfoModel::find(request('couponid'));
|
|
|
+ if($coupon->type == 1){
|
|
|
+ $money = $money * ($coupon->discount/10);
|
|
|
+ }else{
|
|
|
+ $money = $money - $coupon->discount_price;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(request('cardid')){
|
|
|
+ $discount = CardInfoModel::find(request('cardid'))->price;
|
|
|
+ $money = $money - $discount;
|
|
|
+ }
|
|
|
$app = Factory::payment($this->options());
|
|
|
|
|
|
$result = $app->order->unify([
|
|
| xqd
@@ -732,8 +772,6 @@ class HomeController extends Controller
|
|
|
$data['order_no'] = $notify['out_trade_no'];
|
|
|
$data['price'] = $notify['total_fee'] / 100;
|
|
|
$data['user_id'] = $user->id;
|
|
|
-
|
|
|
-
|
|
|
OrderInfoModel::create($data);
|
|
|
$user->save();
|
|
|
} else {
|
|
| xqd
@@ -790,10 +828,10 @@ class HomeController extends Controller
|
|
|
{
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -858,10 +896,10 @@ class HomeController extends Controller
|
|
|
{
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -935,10 +973,10 @@ class HomeController extends Controller
|
|
|
}
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -972,13 +1010,103 @@ class HomeController extends Controller
|
|
|
return $this->api($data);
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {get} /api/home/activecard 激活兑换卡
|
|
|
+ * @apiDescription 激活兑换卡
|
|
|
+ * @apiGroup Coupon
|
|
|
+ * @apiPermission Passport
|
|
|
+ * @apiVersion 0.1.0
|
|
|
+ * @apiParam {int} card_no 兑换卡编号
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
+ * {
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": true
|
|
|
+ * }
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
+ * {
|
|
|
+ * "state": false,
|
|
|
+ * "code": 1000,
|
|
|
+ * "message": "传入参数不正确",
|
|
|
+ * "data": null or []
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * {
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "code": "10006",
|
|
|
+ * "msg": "该兑换卡已经失效"
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * 可能出现的错误代码:
|
|
|
+ * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
+ * 1005 CLIENT_WRONG_PARAMS 该兑换卡不存在
|
|
|
+ * 1006 CLIENT_WRONG_PARAMS 该兑换卡已经失效
|
|
|
+ */
|
|
|
+ public function activeCard(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(),
|
|
|
+ [
|
|
|
+ 'card_no' => 'card_no',
|
|
|
+
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'card_id.required' => 'card_no不能为空!'
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
|
|
|
+ }
|
|
|
+ $user = Auth('api')->user();
|
|
|
+
|
|
|
+ if (!$user) {
|
|
|
+ $data = [
|
|
|
+ 'code' => '401',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
+ ];
|
|
|
+ return $this->api($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ $isExisted = CardInfoModel::where('card_no', request('card_no'))->count();
|
|
|
+ if (!$isExisted) {
|
|
|
+ $data = [
|
|
|
+ 'code' => '10005',
|
|
|
+ 'msg' => '该兑换卡不存在',
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $this->api($data);
|
|
|
+ }
|
|
|
+ $isActived = CardInfoModel::where('card_no', request('card_no'))->whereIn('status', [1, 2])->first();
|
|
|
+ $end_time = CardInfoModel::where('card_no', request('card_no'))->first()->end_time;
|
|
|
+
|
|
|
|
|
|
+ if ($isActived || ($end_time < now())) {
|
|
|
+ $data = [
|
|
|
+ 'code' => '10006',
|
|
|
+ 'msg' => '该兑换卡已经失效',
|
|
|
+ ];
|
|
|
+ return $this->api($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ $card = CardInfoModel::where('card_no', request('card_no'))->first();
|
|
|
+ $card->status = 1;
|
|
|
+ $card->user_id = $user->id;
|
|
|
+ $ok = $card->save();
|
|
|
+ return $this->api($ok);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @api {get} /api/home/usablecoupon 获取订单可用的优惠券
|
|
|
- * @apiDescription 获取订单可用的优惠券
|
|
|
+ * @api {get} /api/home/usablecoupon 获取订单可用的优惠券/兑换卡
|
|
|
+ * @apiDescription 获取订单可用的优惠券/兑换卡
|
|
|
* @apiGroup Coupon
|
|
|
* @apiPermission Passport
|
|
|
* @apiVersion 0.1.0
|
|
| xqd
@@ -989,9 +1117,9 @@ class HomeController extends Controller
|
|
|
* "status": true,
|
|
|
* "status_code": 0,
|
|
|
* "message": "",
|
|
|
- * "data":
|
|
|
+ * "data":{
|
|
|
+ * "usablecoupons":[ //可用的优惠券
|
|
|
* ...
|
|
|
- * [
|
|
|
* {
|
|
|
* "id": 1,
|
|
|
* "coupon_id": 1,
|
|
| xqd
@@ -1010,8 +1138,28 @@ class HomeController extends Controller
|
|
|
* "updated_at": "2018-07-21 07:41:59"
|
|
|
* }
|
|
|
* }
|
|
|
- * ]
|
|
|
* ...
|
|
|
+ * ],
|
|
|
+ *
|
|
|
+ * "usableCards": [ //可用兑换卡
|
|
|
+ * ...
|
|
|
+ * {
|
|
|
+ * "id": 7,
|
|
|
+ * "card_no": "15319090241",
|
|
|
+ * "price": 50,
|
|
|
+ * "min_price": 100,
|
|
|
+ * "status": 1,
|
|
|
+ * "user_id": 1,
|
|
|
+ * "remark": "",
|
|
|
+ * "end_time": "2019-07-31",
|
|
|
+ * "product_id": "1,2",
|
|
|
+ * "deleted_at": null,
|
|
|
+ * "created_at": "2018-07-18 10:17:04",
|
|
|
+ * "updated_at": "2018-08-09 02:11:36"
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * ...
|
|
|
+ * }
|
|
|
* }
|
|
|
* @apiErrorExample {json} Error-Response:
|
|
|
* HTTP/1.1 400 Bad Request
|
|
| xqd
@@ -1038,10 +1186,10 @@ class HomeController extends Controller
|
|
|
);
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -1067,7 +1215,10 @@ class HomeController extends Controller
|
|
|
|
|
|
});
|
|
|
|
|
|
- return $this->api($usablecoupons);
|
|
|
+ $usableCards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>=', now())->where('product_id', 'like', '%' . request('product_id') . '%')->get();
|
|
|
+
|
|
|
+
|
|
|
+ return $this->api(compact('usablecoupons', 'usableCards'));
|
|
|
|
|
|
|
|
|
}
|
|
| xqd
@@ -1126,10 +1277,10 @@ class HomeController extends Controller
|
|
|
|
|
|
$user = Auth('api')->user();
|
|
|
|
|
|
- if(!$user){
|
|
|
+ if (!$user) {
|
|
|
$data = [
|
|
|
'code' => '401',
|
|
|
- 'msg' => 'token已过期,请重新登录',
|
|
|
+ 'msg' => 'token已过期,请重新登录',
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|