wesley.chen 7 年之前
父節點
當前提交
0b308d68ed

+ 24 - 31
app/Http/Controllers/Admin/Card/InfoController.php

xqd xqd xqd xqd xqd
@@ -8,6 +8,7 @@
  */
 namespace App\Http\Controllers\Admin\Card;
 use App\Http\Controllers\Admin\Controller;
+use App\Models\ProductCategoryModel;
 use Illuminate\Http\Request;
 use App\Repositories\Base\Criteria\OrderBy;
 use App\Repositories\Card\Criteria\MultiWhere;
@@ -28,10 +29,11 @@ class InfoController extends Controller
         if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
         $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
         }else{
-            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+            $query = $query->pushCriteria(new OrderBy('status','ASC'));
         }
-        $list = $query->paginate();
-        return view('admin.card.info.index',compact('list'));
+        $list = $query->paginate(10);
+        $product = ProductCategoryModel::all();
+        return view('admin.card.info.index',compact('list','product'));
     }
 
 
@@ -47,33 +49,6 @@ class InfoController extends Controller
     }
 
 
-    /**
-     * 添加
-     * 
-     */
-    public function create(Request $request)
-    {
-        if($request->method() == 'POST') {
-            return $this->_createSave();
-        }
-        return view('admin.card.info.edit');
-    }
-
-    /**
-     * 保存修改
-     */
-    private function _createSave(){
-        $data = (array) request('data');
-        $id = $this->repository->create($data);
-        if($id) {
-            $url[] = array('url'=>U( 'Card/Info/index'),'title'=>'返回列表');
-            $url[] = array('url'=>U( 'Card/Info/create'),'title'=>'继续添加');
-            $this->showMessage('添加成功',$url);
-        }else{
-            $url[] = array('url'=>U( 'Card/Info/index'),'title'=>'返回列表');
-            return $this->showWarning('添加失败',$url);
-        }
-    }
     
     /**
      * 
@@ -93,7 +68,9 @@ class InfoController extends Controller
      * 保存修改
      */
     private function _updateSave() {
-        $data = (array) request('data');
+        $post = (array) request('data');
+        $data['remark'] = $post['remark'];
+        $data['status'] = 2;
         $ok = $this->repository->update(request('id'),$data);
         if($ok) {
             $url[] = array('url'=>U( 'Card/Info/index'),'title'=>'返回列表');
@@ -135,4 +112,20 @@ class InfoController extends Controller
             return  $this->showWarning("操作失败");
         }
     }
+
+    public function store(Request $request)
+    {
+        $data = (array) request('data');
+        $product_id =(array) request('product_id');
+        $data['product_id'] = implode(',',$product_id);
+
+        $number = $request->count;
+
+        for ($i =0 ;$i<$number;$i++){
+            $data['card_no'] = time() . $i;
+            $this->repository->create($data);
+        }
+
+        return back();
+    }
 }

+ 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',
+                'get', 'area', 'get_province', 'get_city', 'get_county', 'test','getProducts','getProduct','getStores','getSchedule','createOrder'
 
             ]
         ]);

+ 580 - 0
app/Http/Controllers/Api/V1/HomeController.php

xqd
@@ -0,0 +1,580 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Helper\AttachmentHelper;
+use App\Models\BaseAttachmentModel;
+use App\Models\OrderInfoModel;
+use App\Models\ProductCategoryModel;
+use App\Models\ProductInfoModel;
+use App\Models\ProductScheduleModel;
+use App\Models\StoreInfoModel;
+use App\Models\UserScheduleModel;
+use EasyWeChat\Factory;
+use Illuminate\Http\Request;
+use App\Services\Base\Attachment;
+use App\Services\Base\ErrorCode;
+use Validator, Response;
+
+class HomeController extends Controller
+{
+
+    protected $app;
+
+    public function __construct()
+    {
+        $config = [
+            'app_id' => 'wxdeff0d78ebe3e744',
+            'secret' => '44cf7fc6e0d4012f180c7f04d47d344d',
+
+            // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
+            'response_type' => 'array',
+        ];
+
+        $this->app = Factory::miniProgram($config);
+    }
+
+    /**
+     * @api {post} /api/home/login 登陆(login)
+     * @apiDescription 登陆(login)
+     * @apiGroup Photo
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}    [code](必填)
+     * @apiParam {string}    [nickName](必填)
+     * @apiParam {string}    [avatar](必填)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "userinfo": {
+     *              "id": "",
+     *              "nickname": "",
+     *              "openid": ""
+     *          }
+     *
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function login(Request $request)
+    {
+        $code = $request->get('code');
+        $session = $this->app->auth->session($code);
+        \Log::info(json_encode($session));
+        $openid = $session['openid'];
+
+        $userinfo = UserInfoModel::where('openid', $openid)->first(['id', 'nickname', 'openid', 'has_agreed']);
+
+        if ($userinfo) {
+            return $this->api(compact('userinfo'));
+        } else {
+            $data['openid'] = $openid;
+            $data['nickname'] = $request->get('nickName');
+            $data['avatar'] = $request->get('avatar');
+
+            $userinfo = UserInfoModel::create($data);
+
+            return $this->api(compact('userinfo'));
+        }
+
+    }
+
+    /**
+     * @api {get} /api/home/getproducts 获取产品列表
+     * @apiDescription 获取产品列表
+     * @apiGroup Photo
+     * @apiPermission None
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "products": [
+     *
+     *          ]
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function getProducts()
+    {
+        $products = ProductCategoryModel::OrderBy('id', 'desc')->get(['id', 'name', 'img']);
+        return $this->api(compact('products'));
+    }
+
+    /**
+     * @api {get} /api/home/getproduct  获取产品详情及规格
+     * @apiDescription 获取产品详情及规格
+     * @apiGroup Photo
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}    [id](必填)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "product": {
+     *                  "id": 1,
+     *                  "name": "证件照",
+     *                  "detail": "",                                                          //产品详情
+     *                  "img": "/upload/images/20180712/696aa5b6187bd8b1e7eb4f7962a5a3cb.jpg",
+     *                  "spec": [                                                              //规格
+     *                        {
+     *                          "id": 1,
+     *                          "name": "证件照",
+     *                          "img": "",
+     *                          "category_id": 1,
+     *                          "origin_price": 299,                                           //原价
+     *                          "current_price": 199,                                          //折后价
+     *
+     *                         }
+     *                       ]
+     * }
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function getProduct(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'id' => 'required',
+            ],
+            [
+                'id.required' => '产品id不能为空!',
+            ]
+        );
+
+
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $id = $request->get('id');
+        $product = ProductCategoryModel::with(['spec'])->select(['id', 'name', 'img', 'detail'])->find($id);
+        return $this->api(compact('product'));
+    }
+
+    /**
+     * @api {get} /api/home/getstores 获取店铺列表
+     * @apiDescription 获取店铺列表
+     * @apiGroup Photo
+     * @apiPermission None
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "stores": [
+     *              {
+     *                  "id": "",
+     *                  "name": "",         //店铺名字
+     *                  "img": "",          //店铺图片
+     *                  "address": "",      //店铺地址
+     *                  "phone": "",        //店铺电话
+     *                  "lat": "",          //店铺纬度
+     *                  "lon": ""           //店铺经度
+     *              }
+     *          ]
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function getStores()
+    {
+        $stores = StoreInfoModel::get(['id', 'name', 'img', 'address', 'phone', 'lat', 'lon']);
+        return $this->api(compact('stores'));
+    }
+
+
+    /**
+     * @api {get} /api/home/getschedule 获取店铺排期
+     * @apiDescription 获取店铺排期
+     * @apiGroup Photo
+     * @apiPermission None
+     * @apiVersion 0.1.0
+     * @apiParam {string}    [day](必填)
+     * @apiParam {string}    [storeid](必填)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *          am_schedule": [
+     *          {
+     *              "time": "2018-07-19 09:00:00",
+     *              "remain": 3                       可预订人数,0表示该时间段人数已满
+     *          },
+     *          {
+     *              "time": "2018-07-19 10:00:00",
+     *              "remain": 0
+     *          },
+     *          {
+     *              "time": "2018-07-19 11:00:00",
+     *              "remain": 3
+     *          }
+     *      ]
+     *
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function getSchedule(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'day' => 'required',
+                'store_id' => 'required',
+            ],
+            [
+                'day.required' => '日期不能为空!',
+                'store_id.required' => '店铺id不能为空!',
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+
+        $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;
+
+        $ams = $this->cut_time_part($am_start, $am_end, $min);
+        $am_schedule = $this->formatSchedule($ams, $max, $storeid);
+
+        $pms = $this->cut_time_part($pm_start, $pm_end, $min);
+        $pm_schedule = $this->formatSchedule($pms, $max, $storeid);
+
+        return $this->api(compact('am_schedule', 'pm_schedule'));
+    }
+
+    /**
+     * @api {get} /api/home/createorder 创建订单
+     * @apiDescription 创建订单
+     * @apiGroup Photo
+     * @apiPermission None
+     * @apiVersion 0.1.0
+     * @apiParam {string}    [user_id](必填)
+     * @apiParam {string}    [store_id](必填)
+     * @apiParam {string}    [product_id](必填)
+     * @apiParam {string}    [schedule_time](必填)
+     * @apiParam {string}    [username](必填)
+     * @apiParam {string}    [phone](必填)
+     * @apiParam {string}    [email](必填)
+     * @apiParam {string}    [sex](必填)
+     * @apiParam {string}    [comment](可填)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *          "order": {
+     *                  "id": 27,
+     *                  "out_trade_no": "xxg1531993028",            //订单编号
+     *                  "username": "lee",                          //联系人
+     *                  "phone": "13407570876",                     //联系电话
+     *                  "email": "154@qq.com",                      //邮箱
+     *                  "schedule_time": "2018-07-19 11:00:00",     //预约时间
+     *                  "status": 0,
+     *                  "store_id": "1",
+     *                  "storename": "青羊店",                        //店铺名称
+     *                  "product_name": "证件照",                     //产品名称
+     *                  "service_time": "约120分钟",                  //服务时长
+     *                  "price": 199,                                //应付金额
+     *                  "deposit": 100                               //定金
+     *              }
+     *
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function createOrder(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'user_id' => 'required',
+                'store_id' => 'required',
+                'product_id' => 'required',
+                'schedule_time' => 'required',
+                'username' => 'required',
+                'phone' => 'required',
+                'email' => 'required',
+                'sex' => 'sex',
+
+            ],
+            [
+                'user_id.required' => 'user_id不能为空!',
+                'store_id.required' => '店铺id不能为空!',
+                'product_id.required' => '产品id不能为空!',
+                'schedule_time.required' => '预约时间不能为空!',
+                'username.required' => 'username不能为空!',
+                'phone.required' => 'phone不能为空!',
+                'email.required' => 'email不能为空!',
+                'sex.required' => 'sex不能为空!',
+
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+
+        $orderdata = $request->all();
+        $scheduledata = [
+            'time' => $request->get('schedule_time'),
+            'user_id' => $request->get('user_id'),
+            'username' => $request->get('username'),
+            'phone' => $request->get('phone'),
+            'store_id' => $request->get('store_id'),
+        ];
+
+        $schedule = UserScheduleModel::create($scheduledata);
+
+        $product = ProductInfoModel::find(request('product_id'));
+
+        $orderdata['schedule_id'] = $schedule->id;
+        $orderdata['out_trade_no'] = 'xxg' . strtotime(now());
+        $orderdata['price'] = $product->current_price;
+        $orderdata['deposit'] = $product->deposit;
+
+        $res = OrderInfoModel::create($orderdata);
+
+        $order = OrderInfoModel::select(['id', 'out_trade_no', 'username', 'phone', 'email', 'schedule_time', 'status', 'store_id', 'price', 'deposit'])->find($res->id);
+        $store = $order->store();
+
+
+        $order['storename'] = $store;
+        $order['product_name'] = $product->name;
+        $order['service_time'] = $product->service_time;
+
+
+        return $this->api(compact('order'));
+    }
+
+    /**
+     * @api {post} /api/home/pay   获取微信支付签名信息
+     * @apiDescription  获取微信支付签名信息
+     * @apiGroup Photo
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [userid]   用户ID(必填)
+     * @apiParam {string}    [orderid]  订单号(必填)
+     * @apiParam {int}    [couponid]  优惠券id(可填)
+     * @apiParam {int}    [cardid]    抵扣卡id(可填;抵扣卡和优惠券不能同时使用)
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": {
+     *              "appId":"wx1c2357232cd25f65",
+     *              "timeStamp":"1524907589",
+     *              "nonceStr":"5ae43e45eb499",
+     *              "package":"prepay_id=wx28172629917401724160128f0238805782",
+     *              "signType":"MD5",
+     *              "paySign":"8E9CF26B2B83C22471D023CBBDC36EDF"
+     *          }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function pay(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'userid' => 'required',
+                'orderid' => 'required',
+            ],
+            [
+                'userid.required' => 'userid不能为空!',
+                'orderid.required' => 'orderid不能为空!',
+
+            ]
+        );
+
+
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+
+        $user = UserInfoModel::find(request('userid'));
+        $order = OrderInfoModel::find($request->get('orderid'));
+
+
+        \Log::info($this->options());
+
+        $app = Factory::payment($this->options());
+
+        $result = $app->order->unify([
+            'body' => '高考志愿助手 - 付费查询',
+            'out_trade_no' => $order->out_trade_no,
+            'total_fee' => $money * 100,
+            'trade_type' => 'JSAPI',
+            'notify_url' => url('/api/home/notify'),
+            'openid' => $user->openid
+        ]);
+
+        \Log::info($result);
+
+        if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
+            $payment = Factory::payment($this->options());
+            $jssdk = $payment->jssdk;
+
+            $json = $jssdk->bridgeConfig($result['prepay_id']);
+            \Log::info($json);
+
+            return $this->api(compact('json'));
+        } else {
+            $msg = "签名失败,请稍后再试!";
+
+            return $this->api(compact('msg'));
+        }
+    }
+
+
+//下面是回调函数
+    public function notify()
+    {
+        $app = Factory::payment($this->options());
+        \Log::info("wechat notify start!");
+        return $app->handlePaidNotify(function ($notify, $successful) {
+            \Log::info($notify);
+            if ($notify['result_code'] == 'SUCCESS') {
+                $user = UserInfoModel::where('openid', $notify['openid'])->first();
+                $data['order_no'] = $notify['out_trade_no'];
+                $data['price'] = $notify['total_fee'] / 100;
+                $data['user_id'] = $user->id;
+
+
+                OrderInfoModel::create($data);
+                $user->save();
+            } else {
+                return $successful('通信失败,请稍后再通知我');
+            }
+            return true;
+        });
+
+    }
+
+    public function couponList(){
+
+    }
+
+    public function myCoupon(){
+
+    }
+
+    //格式化排期
+    function cut_time_part($start, $end, $min = 30, $format = true)
+    {
+        $start = strtotime($start);
+        $end = strtotime($end);
+        $nums = ($end - $start) / ($min * 60);
+
+        $parts = ($end - $start) / $nums;
+
+        $last = ($end - $start) % $nums;
+        if ($last > 0) {
+            $parts = ($end - $start - $last) / $nums;
+        }
+        for ($i = 1; $i <= $nums; $i++) {
+            $_end = $start + $parts * $i;
+            $arr[] = array($start + $parts * ($i - 1), $_end);
+        }
+
+        $len = count($arr) - 1;
+        $arr[$len][1] = $arr[$len][1] + $last;
+        if ($format) {
+            foreach ($arr as $key => $value) {
+                $arr[$key] = date("Y-m-d H:i:s", $value[0]);
+            }
+        }
+        return $arr;
+    }
+
+    //格式化排期
+    public function formatSchedule($arrs, $max, $storeid)
+    {
+        $arr = [];
+        foreach ($arrs as $k => $item) {
+            $count = UserScheduleModel::where('time', $item)->where('store_id', $storeid)->count();
+            $remain = $max - $count;
+            $arr[$k]['time'] = $item;
+            $arr[$k]['remain'] = $remain;
+        }
+        return $arr;
+    }
+
+
+}

+ 20 - 1
app/Models/CardInfoModel.php

xqd
@@ -40,7 +40,26 @@ class CardInfoModel extends BaseModel
         'price',
         'status',
         'user_id',
-        'remark'
+        'remark',
+        'end_time',
+        'product_id',
+        'min_price',
+        'qrcode'
     ];
 
+    public function status(){
+        switch ($this->status){
+            case 1:
+                return '已激活';
+                break;
+            case 2:
+                return '已核销';
+                break;
+            default:
+                return '未激活';
+                break;
+        }
+
+    }
+
 }

+ 13 - 1
app/Models/OrderInfoModel.php

xqd
@@ -45,11 +45,23 @@ class OrderInfoModel extends BaseModel
         'schedule_time',
         'status',
         'user_id',
-        'comment'
+        'comment',
+        'product_id',
+        'schedule_id',
+        'price',
+        'deposit'
     ];
 
   public function store(){
       return (new StoreInfoModel())->find($this->store_id)->name;
   }
 
+    public function getstore(){
+        return $this->belongsTo('App\Models\StoreInfoModel','store_id');
+    }
+
+  public function product(){
+      return $this->belongsTo('App\Models\ProductInfoModel','product_id');
+  }
+
 }

+ 4 - 0
app/Models/ProductCategoryModel.php

xqd
@@ -41,4 +41,8 @@ class ProductCategoryModel extends BaseModel
         'detail'
     ];
 
+    public function spec(){
+        return $this->hasMany('App\Models\ProductInfoModel','category_id','id');
+    }
+
 }

+ 3 - 1
app/Models/ProductInfoModel.php

xqd
@@ -39,7 +39,9 @@ class ProductInfoModel extends BaseModel
         'name',
         'category_id',
         'origin_price',
-        'current_price'
+        'current_price',
+        'deposit',
+        'service_time'
     ];
 
     public function catename(){

+ 10 - 11
app/Repositories/Card/Criteria/MultiWhere.php

xqd xqd
@@ -9,12 +9,11 @@
 namespace App\Repositories\Card\Criteria;
 
 
-
-
 use App\Repositories\Base\Criteria;
 use App\Repositories\Contracts\RepositoryInterface as Repository;
 
-class MultiWhere extends Criteria {
+class MultiWhere extends Criteria
+{
 
     private $search = [];
 
@@ -29,17 +28,17 @@ class MultiWhere extends Criteria {
     }
 
     /**
-    * @param $model
-    * @param RepositoryInterface $repository
-    * @return mixed
-    */
+     * @param $model
+     * @param RepositoryInterface $repository
+     * @return mixed
+     */
     public function apply($model, Repository $repository)
     {
-          if(isset($this->search['updated_at']) && $this->search['updated_at']) {
-                                    $model = $model->where('updated_at',$this->search['updated_at']);
-                                 }
+        if (isset($this->search['keyword']) && $this->search['keyword']) {
+            $model = $model->where('card_no', $this->search['keyword']);
+        }
 
-         return $model;
+        return $model;
     }
 
 }

+ 35 - 0
database/migrations/2018_07_18_070747_add_end_time_to_card_info.php

xqd
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddEndTimeToCardInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('card_info', function (Blueprint $table) {
+            $table->date('end_time')->after('remark')->nullable()->comment('有效期');
+            $table->string('product_id',255)->after('end_time')->nullable()->comment('可用产品');
+            $table->double('min_price')->after('price')->nullable()->comment('最低可用价格');
+            $table->string('qrcode',255)->after('min_price')->nullable()->comment('二维码');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('card_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 36 - 0
database/migrations/2018_07_19_070039_add_am_start_to_product_schedule.php

xqd
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAmStartToProductSchedule extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('product_schedule', function (Blueprint $table) {
+            $table->dropColumn(['am_time','pm_time']);
+            $table->string('am_start',64)->comment('上午开始时间');
+            $table->string('am_end',64)->comment('上午结束时间');
+            $table->string('pm_start',64)->comment('下午开始时间');
+            $table->string('pm_end',64)->comment('下午结束时间');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('product_schedule', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 35 - 0
database/migrations/2018_07_19_074808_add_product_id_to_order_info.php

xqd
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddProductIdToOrderInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('order_info', function (Blueprint $table) {
+            $table->integer('product_id')->after('user_id')->comment('产品id');
+            $table->integer('schedule_id')->after('user_id')->comment('预约号');
+            $table->double('price')->after('user_id')->comment('订单价格');
+            $table->double('deposit')->after('user_id')->nullable()->comment('定金');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('order_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2018_07_19_074943_add_service_time_product_info.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddServiceTimeProductInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('product_info', function (Blueprint $table) {
+            $table->string('service_time',64)->after('current_price')->comment('服务时长');
+            $table->double('deposit')->after('service_time')->nullable()->comment('定金');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('product_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 58 - 77
resources/views/admin/card/info/edit.blade.php

xqd
@@ -2,103 +2,84 @@
 
 @section('content')
 
-<?php
-    if(!isset($data)) $data = array();
-    if(!$data && session("data")){
+    <?php
+    if (!isset($data)) $data = array();
+    if (!$data && session("data")) {
         $data = session("data");
     }
-    if(!$data && session('_old_input')){
+    if (!$data && session('_old_input')) {
         $data = session("_old_input");
     }
-?>
-	<div class="row">
-		<div class="col-sm-12">
-			<div class="ibox float-e-margins">
-				<div class="ibox-title">
-					<h5>抵扣卡列表</h5>
-					<div class="ibox-tools">
-						<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
-						</a>
-					</div>
-				</div>
-				<div class="ibox-content">
+    ?>
+    <div class="row">
+        <div class="col-sm-12">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <h5>抵扣卡列表</h5>
+                    <div class="ibox-tools">
+                        <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
+                        </a>
+                    </div>
+                </div>
+                <div class="ibox-content">
                     @if(role('Card/Info/index'))
-				    <div class="row">
-    					<div class="col-sm-3 pull-right">
-    					   <a href="{{ U('Card/Info/index')}}" class="btn btn-sm btn-primary pull-right">返回列表</a>
-    					</div>
-					</div>
+                        <div class="row">
+                            <div class="col-sm-3 pull-right">
+                                <a href="{{ U('Card/Info/index')}}" class="btn btn-sm btn-primary pull-right">返回列表</a>
+                            </div>
+                        </div>
                     @endif
 
-		            <div class="row">
+                    <div class="row">
                         <div class="col-lg-10">
-                            <form name="form_product" id="form-validation" action="" class="form-horizontal form-validation" accept-charset="UTF-8" method="post">
+                            <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">
+                                        <input id="data_card_no" name="data[card_no]" class="form-control"
+                                               value="{{ $data['card_no'] or ''}}" disabled required=""
+                                               aria-required="true"
+                                               placeholder="">
+                                    </div>
+                                </div>
+
+                                <div class="form-group">
+
+                                    <label class="control-label col-sm-3">备注</label>
+
+                                    <div class="col-sm-9">
+
+                                        <input id="data_remark" name="data[remark]" class="form-control"
+                                               value="{{ $data['remark'] or ''}}" required="" aria-required="true"
+                                               placeholder="姓名--电话">
+                                    </div>
+
+                                </div>
 
-                                    
-                <div class="form-group">
-                                    
-                 <label class="control-label col-sm-3">优惠卡编号</label>
-                                    
-                   <div class="col-sm-9">
-                     <input id="data_card_no" name="data[card_no]" class="form-control" value="{{ $data['card_no'] or ''}}" required="" aria-required="true"  placeholder=""> 
-                    </div>
-                                
-                </div>    
-                <div class="form-group">
-                                    
-                 <label class="control-label col-sm-3">金额</label>
-                                    
-                   <div class="col-sm-9">
-                     <input id="data_price" name="data[price]" class="form-control" value="{{ $data['price'] or ''}}" required="" aria-required="true"  placeholder=""> 
-                    </div>
-                                
-                </div>    
-                <div class="form-group">
-                                    
-                 <label class="control-label col-sm-3">0:未激活;1:已激活,未使用;2:已使用</label>
-                                    
-                   <div class="col-sm-9">
-                     <input id="data_status" name="data[status]" class="form-control" value="{{ $data['status'] or ''}}" required="" aria-required="true"  placeholder=""> 
-                    </div>
-                                
-                </div>    
-                <div class="form-group">
-                                    
-                 <label class="control-label col-sm-3">用户ID</label>
-                                    
-                   <div class="col-sm-9">
-                     <input id="data_user_id" name="data[user_id]" class="form-control" value="{{ $data['user_id'] or ''}}" required="" aria-required="true"  placeholder=""> 
-                    </div>
-                                
-                </div>    
-                <div class="form-group">
-                                    
-                 <label class="control-label col-sm-3">备注</label>
-                                    
-                   <div class="col-sm-9">
-                     <input id="data_remark" name="data[remark]" class="form-control" value="{{ $data['remark'] or ''}}" required="" aria-required="true"  placeholder=""> 
-                    </div>
-                                
-                </div>
-                                
                                 <div class="form-group">
                                     <label class="control-label col-sm-3">&nbsp;</label>
                                     <div class="col-sm-9">
-                                        <input type="hidden" name="_referer" value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
+                                        <input type="hidden" name="_referer"
+                                               value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
                                         <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
                                         <input type="submit" class="btn btn-success" style="margin-right:20px;">
-                                        <input type="reset" class="btn btn-default" >
+                                        <input type="reset" class="btn btn-default">
                                     </div>
                                 </div>
-        
+
                             </form>
                         </div>
                         <!-- /.col-lg-10 -->
                     </div>
                     <!-- /.row -->
-				</div>
-			</div>
-		</div>
-	</div>
+                </div>
+            </div>
+        </div>
+    </div>
 
 @endsection

+ 80 - 24
resources/views/admin/card/info/index.blade.php

xqd xqd xqd xqd xqd
@@ -17,7 +17,7 @@
 
                             <div class="col-sm-4">
                                 <div class="input-group">
-                                    <input type="text" value="{{Request::get('keyword')}}" placeholder="请输入关键词"
+                                    <input type="text" value="{{Request::get('keyword')}}" placeholder="请输入优惠卡编号"
                                            name="keyword" class="input-sm form-control">
                                     <span class="input-group-btn">
 									<button type="submit" class="btn btn-sm btn-primary">搜索</button>
@@ -40,8 +40,9 @@
                             <th class="sorting" data-sort="id"> ID</th>
                             <th class="sorting" data-sort="card_no"> 优惠卡编号</th>
                             <th class="sorting" data-sort="price"> 金额</th>
-                            <th class="sorting" data-sort="status"> 0:未激活;1:已激活,未使用;2:已使用</th>
-                            <th class="sorting" data-sort="user_id"> 用户ID</th>
+                            <th class="sorting" data-sort="min_price">最低使用价格</th>
+                            <th class="sorting" data-sort="end_time">有效期</th>
+                            <th class="sorting" data-sort="status"> 状态</th>
                             <th class="sorting" data-sort="remark"> 备注</th>
                             <th class="sorting" data-sort="created_at"> 创建时间</th>
                             <th width="22%">相关操作</th>
@@ -55,32 +56,23 @@
                                     <td>{{ $item->id }}</td>
                                     <td>{{ $item->card_no }}</td>
                                     <td>{{ $item->price }}</td>
-                                    <td>{{ $item->status }}</td>
-                                    <td>{{ $item->user_id }}</td>
+                                    <td>{{ $item->min_price }}</td>
+                                    <td>{{ $item->end_time }}</td>
+                                    <td>{{ $item->status() }}</td>
                                     <td>{{ $item->remark }}</td>
                                     <td>{{ $item->created_at }}</td>
                                     <td>
                                         <div class="btn-group">
-                                            <button data-toggle="dropdown"
-                                                    class="btn btn-warning btn-sm dropdown-toggle"
-                                                    aria-expanded="false">
-                                                操作 <span class="caret"></span>
-                                            </button>
-                                            <ul class="dropdown-menu">
 
 
-                                                @if(role('Card/Info/update'))
-                                                    <li><a href="{{ U('Card/Info/update',['id'=>$item->id])}}"
-                                                           class="font-bold">修改</a></li>
-                                                @endif
 
-                                                @if(role('Card/Info/destroy'))
-                                                    <li class="divider"></li>
-                                                    <li><a href="{{ U('Card/Info/destroy',['id'=>$item->id])}}"
-                                                           onclick="return confirm('你确定执行删除操作?');">删除</a></li>
+
+                                                @if(role('Card/Info/update') && $item->status <2 )
+                                                    <button onclick="window.location.href='{{ U('Card/Info/update',['id'=>$item->id])}}'"
+                                                            class="btn btn-warning">核销
+                                                    </button>
                                                 @endif
 
-                                            </ul>
                                         </div>
                                         @if(role('Card/Info/view'))
                                             <button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Card/Info/view',['id'=>$item->id])}}'});"
@@ -123,15 +115,71 @@
                             <div class="ibox float-e-margins">
                                 <div class="ibox-content">
 
-                                    <form name="form_product" id="form-validation" action=""
+                                    <form name="form_product" id="form-validation" action="{{ U('Card/Info/store') }}"
                                           class="form-horizontal form-validation" accept-charset="UTF-8" method="post">
                                         <div class="form-group">
-                                            <label class="control-label col-sm-3">兑换卡名称</label>
+
+                                            <label class="control-label col-sm-3">数量</label>
+
+                                            <div class="col-sm-9">
+                                                <input id="data_count" name="count" class="form-control"
+                                                       value="" required=""
+                                                       aria-required="true"
+                                                       placeholder="">
+                                            </div>
+
+                                        </div>
+                                        <div class="form-group" id="data_discount_price">
+
+                                            <label class="control-label col-sm-3">优惠金额</label>
+
+                                            <div class="col-sm-9">
+                                                <input name="data[price]" class="form-control"
+                                                       value="{{ $data['price'] or ''}}" placeholder="">
+                                            </div>
+
+                                        </div>
+                                        <div class="form-group">
+
+                                            <label class="control-label col-sm-3">最低使用价格</label>
 
                                             <div class="col-sm-9">
-                                                <input id="data_name" name="data[name]" class="form-control" required=""
-                                                       aria-required="true" placeholder="">
+                                                <input id="data_min_price" name="data[min_price]" class="form-control"
+                                                       value="{{ $data['min_price'] or ''}}" required=""
+                                                       aria-required="true"
+                                                       placeholder="">
                                             </div>
+
+                                        </div>
+
+                                        <div class="form-group">
+
+                                            <label class="control-label col-sm-3">可用产品</label>
+                                            <div class="col-md-6">
+                                                <select name="product_id[]" multiple="multiple" id="product-select"
+                                                        class="form-control">
+                                                    @foreach($product as $item)
+                                                        <option value="{{$item->id}}">
+                                                            {{$item->name}}
+                                                        </option>
+                                                    @endforeach
+                                                </select>
+                                            </div>
+
+                                        </div>
+
+                                        <div class="form-group">
+
+                                            <label class="control-label col-sm-3">有限期</label>
+
+                                            <div class="col-sm-9">
+
+                                                <input class="form-control layer-date" id="data_time"
+                                                       name="data[end_time]" placeholder="YYYY-MM-DD hh:mm:ss"
+                                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
+                                                       value="{{ $data['time'] or ''}}">
+                                            </div>
+
                                         </div>
 
 
@@ -162,4 +210,12 @@
             </small>
         </div>
     </div>
+@endsection
+@section('footer')
+    <script type="text/javascript">
+        $(function () {
+            $('#product-select').multiSelect();
+        });
+
+    </script>
 @endsection

+ 2 - 2
resources/views/admin/store/info/edit.blade.php

xqd
@@ -77,8 +77,8 @@
 
                                 </div>
 
-                                <input type="hidden" name="lon" id="lon" value="{{$data['lon'] or ''}}">
-                                <input type="hidden" name="lat" id="lat" value="{{$data['lat'] or ''}}">
+                                <input type="hidden" name="data[lon]" id="lon" value="{{$data['lon'] or ''}}">
+                                <input type="hidden" name="data[lat]" id="lat" value="{{$data['lat'] or ''}}">
 
                                 <div class="form-group">
 

+ 32 - 45
routes/api.php

xqd
@@ -19,48 +19,35 @@ use Illuminate\Http\Request;
 
 
 
-//
-//$api = app('Dingo\Api\Routing\Router');
-//
-//$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
-//    // test
-//    $api->get('test', [
-//        'as' => 'test',
-//        'uses' => 'AuthController@test',
-//    ]);
-//    // Auth
-//    // signin
-//    $api->post('auth/login', [
-//        'as' => 'auth.login',
-//        'uses' => 'AuthController@login',
-//    ]);
-//    $api->post('auth/logout', [
-//        'as' => 'auth.logout',
-//        'uses' => 'AuthController@logout',
-//    ]);
-//    $api->post('auth/code', [
-//        'as' => 'auth.code',
-//        'uses' => 'AuthController@getCode',
-//    ]);
-//    // signup
-//    $api->post('auth/register', [
-//        'as' => 'auth.register',
-//        'uses' => 'AuthController@register',
-//    ]);
-//    $api->post('auth/password', [
-//        'as' => 'auth.reset',
-//        'uses' => 'AuthController@setPassword',
-//    ]);
-//    $api->post('auth/check_password', [
-//        'as' => 'auth.check_password',
-//        'uses' => 'AuthController@check_password',
-//    ]);
-//    $api->post('auth/reset', [
-//        'as' => 'auth.reset',
-//        'uses' => 'AuthController@reset',
-//    ]);
-//    $api->get('auth/is_login', [
-//        'as' => 'auth.is_login',
-//        'uses' => 'AuthController@isLogin',
-//    ]);
-//});
+
+$api = app('Dingo\Api\Routing\Router');
+
+$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
+
+    $api->get('home/login', [
+        'as' => 'home.login',
+        'uses' => 'HomeController@login',
+    ]);
+
+    $api->get('home/getproducts', [
+        'as' => 'home.getProducts',
+        'uses' => 'HomeController@getProducts',
+    ]);
+    $api->get('home/getproduct', [
+        'as' => 'home.getProduct',
+        'uses' => 'HomeController@getProduct',
+    ]);
+    $api->get('home/getstores', [
+        'as' => 'home.getStores',
+        'uses' => 'HomeController@getStores',
+    ]);
+    $api->get('home/getschedule', [
+        'as' => 'home.getschedule',
+        'uses' => 'HomeController@getSchedule',
+    ]);
+    $api->post('home/createorder', [
+        'as' => 'home.createorder',
+        'uses' => 'HomeController@createOrder',
+    ]);
+
+});