| 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|