wesley 7 سال پیش
والد
کامیت
990411aa8b

+ 5 - 2
app/Http/Controllers/Admin/Product/ScheduleController.php

xqd xqd xqd
@@ -8,6 +8,7 @@
  */
 namespace App\Http\Controllers\Admin\Product;
 use App\Http\Controllers\Admin\Controller;
+use App\Models\StoreInfoModel;
 use Illuminate\Http\Request;
 use App\Repositories\Base\Criteria\OrderBy;
 use App\Repositories\Product\Criteria\MultiWhere;
@@ -56,7 +57,8 @@ class ScheduleController extends Controller
         if($request->method() == 'POST') {
             return $this->_createSave();
         }
-        return view('admin.product.schedule.edit');
+        $stores = StoreInfoModel::all();
+        return view('admin.product.schedule.edit',compact('stores'));
     }
 
     /**
@@ -86,7 +88,8 @@ class ScheduleController extends Controller
             return $this->_updateSave();
         }
         $data = $this->repository->find($request->get('id'));
-        return view('admin.product.schedule.edit',compact('data'));
+        $stores = StoreInfoModel::all();
+        return view('admin.product.schedule.edit',compact('data','stores'));
     }
 
     /**

+ 1 - 1
app/Http/Controllers/Api/V1/Controller.php

xqd
@@ -21,7 +21,7 @@ class Controller extends BaseController
         $this->middleware('auth:api', [
             'except' => [
                 'upload', 'getCode', 'reset', 'login', 'get', 'register', 'alipayNotify', 'wechatpayNotify',
-                'get', 'area', 'get_province', 'get_city', 'get_county', 'test','getProducts','getProduct','getStores','getSchedule','orderDetail','notify'
+                'get', 'area', 'get_province', 'get_city', 'get_county', 'test','getProducts','getProduct','getStores','getSchedule','orderDetail','notify','activeCard'
 
             ]
         ]);

+ 183 - 32
app/Http/Controllers/Api/V1/HomeController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd 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;
@@ -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 = [
@@ -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)
     {
@@ -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);
@@ -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);
         }
@@ -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);
         }
@@ -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:
@@ -665,9 +684,11 @@ class HomeController extends Controller
         $validator = Validator::make($request->all(),
             [
                 'orderid' => 'required',
+                'paytype' => 'required',
             ],
             [
                 'orderid.required' => 'orderid不能为空!',
+                'paytype.required' => 'paytype不能为空!',
 
             ]
         );
@@ -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);
         }
@@ -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([
@@ -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 {
@@ -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);
         }
@@ -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);
         }
@@ -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);
         }
@@ -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
@@ -989,9 +1117,9 @@ class HomeController extends Controller
      *     "status": true,
      *     "status_code": 0,
      *     "message": "",
-     *     "data":
+     *     "data":{
+     *          "usablecoupons":[           //可用的优惠券
      * ...
-     *          [
      *                  {
      *                      "id": 1,
      *                      "coupon_id": 1,
@@ -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
@@ -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);
         }
@@ -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'));
 
 
     }
@@ -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);
         }

+ 8 - 1
app/Models/ProductScheduleModel.php

xqd
@@ -38,8 +38,15 @@ class ProductScheduleModel extends BaseModel
         'pm_start',
         'am_end',
         'pm_end',
+        'store_id',
         'interval',
-        'max'
+        'max',
+        'holiday_start',
+        'holiday_end',
     ];
 
+    public function store(){
+        return (new StoreInfoModel())->find($this->store_id)->name;
+    }
+
 }

+ 34 - 0
database/migrations/2018_08_08_095701_add_store_id_to_product_schedule.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddStoreIdToProductSchedule extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('product_schedule', function (Blueprint $table) {
+            $table->integer('store_id')->comment('店铺ID');
+            $table->date('holiday_start')->nullable()->comment('休假开始时间');
+            $table->date('holiday_end')->nullable()->comment('休假结束时间');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('product_schedule', function (Blueprint $table) {
+            //
+        });
+    }
+}

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 840
public/apidoc/api_data.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 840
public/apidoc/api_data.json


+ 1 - 14
public/apidoc/api_project.js

xqd
@@ -1,14 +1 @@
-define({
-  "name": "",
-  "version": "0.0.0",
-  "description": "",
-  "sampleUrl": false,
-  "defaultVersion": "0.0.0",
-  "apidoc": "0.3.0",
-  "generator": {
-    "name": "apidoc",
-    "time": "2018-07-27T08:05:27.543Z",
-    "url": "http://apidocjs.com",
-    "version": "0.17.6"
-  }
-});
+define({
  "name": "",
  "version": "0.0.0",
  "description": "",
  "sampleUrl": false,
  "defaultVersion": "0.0.0",
  "apidoc": "0.3.0",
  "generator": {
    "name": "apidoc",
    "time": "2018-08-09T02:57:15.287Z",
    "url": "http://apidocjs.com",
    "version": "0.17.6"
  }
});

+ 1 - 14
public/apidoc/api_project.json

xqd
@@ -1,14 +1 @@
-{
-  "name": "",
-  "version": "0.0.0",
-  "description": "",
-  "sampleUrl": false,
-  "defaultVersion": "0.0.0",
-  "apidoc": "0.3.0",
-  "generator": {
-    "name": "apidoc",
-    "time": "2018-07-27T08:05:27.543Z",
-    "url": "http://apidocjs.com",
-    "version": "0.17.6"
-  }
-}
+{
  "name": "",
  "version": "0.0.0",
  "description": "",
  "sampleUrl": false,
  "defaultVersion": "0.0.0",
  "apidoc": "0.3.0",
  "generator": {
    "name": "apidoc",
    "time": "2018-08-09T02:57:15.287Z",
    "url": "http://apidocjs.com",
    "version": "0.17.6"
  }
}

+ 0 - 0
public/apidoc/utils/send_sample_request.js


+ 1 - 1
readme.md

xqd
@@ -4,7 +4,7 @@
 - git clone 到本地
 - 执行 `composer install`,`npm install`创建好数据库
 - 配置 **.env** 中数据库连接信息,没有.env请复制.env.example命名为.env
-- 执行 `php artisan key:generate`
+- 执行 `wr`
 - 执行 `php artisan migrate`
 - 执行 `php artisan db:seed`
 - storage下所有目录 和 bootstrap/cache 目录应该是可写的

+ 47 - 0
resources/views/admin/product/schedule/edit.blade.php

xqd xqd
@@ -35,6 +35,23 @@
                             <form name="form_product" id="form-validation" action=""
                                   class="form-horizontal form-validation" accept-charset="UTF-8" method="post">
 
+                                <div class="form-group">
+
+                                    <label class="control-label col-sm-3">预约店铺</label>
+
+                                    <div class="col-sm-9">
+                                        <select class="form-control" name="data[store_id]" required>
+                                            @foreach($stores as $item)
+                                                <option value="{{$item->id}}"
+                                                        @if(isset($data['store_id']) && $data['store_id'] == $item->id) selected @endif>
+                                                    {{$item->name}}
+                                                </option>
+                                            @endforeach
+                                        </select>
+                                    </div>
+
+                                </div>
+
 
                                 <div class="form-group">
 
@@ -116,6 +133,36 @@
 
                                 </div>
 
+
+                                <div class="form-group">
+
+                                    <label class="control-label col-sm-3">休假日期</label>
+
+
+                                    <div class="col-sm-9">
+                                        <div class="row">
+                                            <div class="col-sm-3">
+                                                <input id="holiday_start" type="date"
+                                                       name="data[holiday_start]"
+                                                       class="form-control col-sm-3"
+                                                       value="{{ $data['holiday_start'] or ''}}"
+                                                       placeholder="">
+                                            </div>
+                                            <div class="col-sm-3">
+                                                <input id="holiday_end" type="date"
+                                                       name="data[holiday_end]"
+                                                       class="form-control col-sm-3"
+                                                       value="{{ $data['holiday_end'] or ''}}"
+                                                       placeholder="">
+                                            </div>
+                                        </div>
+
+
+                                    </div>
+
+                                </div>
+
+
                                 <div class="form-group">
                                     <label class="control-label col-sm-3">&nbsp;</label>
                                     <div class="col-sm-9">

+ 3 - 3
resources/views/admin/product/schedule/index.blade.php

xqd xqd
@@ -26,18 +26,17 @@
                             </div>
                         </form>
                         @if(role('Product/Schedule/create'))
-                            @if(!count($list))
                                 <div class="col-sm-3 pull-right">
                                     <a href="{{ U('Product/Schedule/create')}}"
                                        class="btn btn-sm btn-primary pull-right">添加</a>
-                                </div>
-                            @endif
+                                </div
                         @endif
                     </div>
 
                     <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                         <thead>
                         <tr>
+                            <th class="sorting" data-sort="store_id">店铺</th>
                             <th class="sorting" data-sort="am_time"> 营业时间:上午</th>
                             <th class="sorting" data-sort="pm_time"> 营业时间:下午</th>
                             <th class="sorting" data-sort="interval"> 时间间隔:分钟</th>
@@ -51,6 +50,7 @@
                         @if(isset($list))
                             @foreach($list as $key => $item)
                                 <tr>
+                                    <td>{{ $item->store() }}</td>
                                     <td>{{ $item->am_start.'--'.$item->am_end }}</td>
                                     <td>{{ $item->pm_start.'--'.$item->pm_end }}</td>
                                     <td>{{ $item->interval }}</td>

+ 4 - 1
routes/api.php

xqd
@@ -90,7 +90,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'home.notify',
         'uses' => 'HomeController@pay',
     ]);
-
+    $api->any('home/activecard', [
+        'as' => 'home.activeCard',
+        'uses' => 'HomeController@activeCard',
+    ]);
 
 
 

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است