| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Helper\AttachmentHelper;
- use App\Models\BaseAttachmentModel;
- use App\Models\BusinessServiceModel;
- use App\Models\CardInfoModel;
- use App\Models\CouponInfoModel;
- use App\Models\OrderInfoModel;
- use App\Models\PaidInfoModel;
- use App\Models\ProductCategoryModel;
- use App\Models\ProductInfoModel;
- use App\Models\ProductScheduleModel;
- use App\Models\SettingInfoModel;
- use App\Models\StoreInfoModel;
- use App\Models\UserCouponRelationModel;
- use App\Models\UserInfoModel;
- use App\Models\UserScheduleModel;
- use Carbon\Carbon;
- use EasyWeChat\Factory;
- use function foo\func;
- use Illuminate\Http\Request;
- use App\Services\Base\Attachment;
- use App\Services\Base\ErrorCode;
- use Validator, Response, Auth, Cache;
- class HomeController extends Controller
- {
- protected $app;
- protected $setting;
- public function __construct()
- {
- $this->setting = SettingInfoModel::first();
- $config = [
- 'app_id' => $this->setting->app_id,
- 'secret' => $this->setting->app_secret,
- // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
- 'response_type' => 'array',
- ];
- $this->app = Factory::miniProgram($config);
- }
- /**
- * @api {post} /api/home/login 登陆(login)
- * @apiDescription 登陆(login)
- * @apiGroup Login
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {string} code 小程序登陆后返回的code
- * @apiParam {string} nickName 微信昵称
- * @apiParam {string} avatar 微信头像
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjUzMzYwMzNlNzIwOTE3YjE0NDc4YjgxMWY5MmI4MjBmMThlNDgxNjJjZGFkYmEwNGI3ZjliZTNmZjRlMTY2YjU4NGU4MzJhN2RmYzY2ZTcxIn0.eyJhdWQiOiIxIiwianRpIjoiNTMzNjAzM2U3MjA5MTdiMTQ0NzhiODExZjkyYjgyMGYxOGU0ODE2MmNkYWRiYTA0YjdmOWJlM2ZmNGUxNjZiNTg0ZTgzMmE3ZGZjNjZlNzEiLCJpYXQiOjE1MzI0MjA3NDAsIm5iZiI6MTUzMjQyMDc0MCwiZXhwIjoxNTYzOTU2NzQwLCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.YnuRiJI9jlt-KeQ480UEpLWCUU8FEJvlTRtAdjOlP0BWmcdo0E9rGS4hriYnpfJOn09Cw0aRYuc4dgQYL_JWD2fodlGg1LRIvPTOtvM5TiwM86kQJawvfFw7X7p9nOhxrFa5Tyir0cdTcV0SmQbq8KIptjdR8j7wUTByKhONexBXtNnlZSpw70ckTQrAstkn97IDwPo04hhGhf6eDPc8ler0HONiAVqbRvvNG6yHShJarP1hxyXrYN2BM0N7dtLD_8Sr8XaXL6ie4rRFVM4fNwpn74DkiDwXY6-5Xet6mzPvvzARAmU5vJ7JHhcL1N7m7poNp6YCx_mZAZ1z8PGDKrtQWoVeAmIxo7qtI6jvgvUpEFnJQ-KHCunXflNBL-vIYW4o3llnYqku1pcBdAUfkYLjYUgB3EZio280_8q-6Q24VAMiHZ58AjYvHHJJssdOa3dVHGD9Iq2z1dWR6gmZ4MgGCunCcAe9L_CbDm7VtMq3nKj4a1WScRiMD5nlKAHgy4O32rtNXqDr5T-eV-QNa4ZOv4VZ1AR-WE4RkO4ArKPaFxgSa9mak98PU8NHcPaJ_B3eDbvtwtMloTXWSQP08cmUPXKjEwXvszdkUt-ZWirw5Sd22h3qMdCI3gcvzT4_rnDKCEk37P09fUIK8LZrS4s2xOhueHziMzheAF0QekI",
- * "user": {
- * "id": 2,
- * "nickname": "roger",
- * "openid": "olAS94uwfTdsL3nDnvG67p_v5Vks",
- * "mobile": "13788765546",
- * "avatar": "https://wx.qlogo.cn/mmopen/vi_32/IOcxico8l4A7W3qxDeA53Id5kVAj2ibUGvQib9QibicTp5c1RNshDj6EKz2PKWp3reHfib0xxT4wa7jJzcb7a4EggkVw/132",
- * }
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- * 500 获取openid失败
- */
- public function login(Request $request)
- {
- $code = $request->get('code');
- $session = $this->app->auth->session($code);
- \Log::info(json_encode($session));
- $openid = $session['openid'];
- if (!$openid) {
- $data = [
- 'code' => 500,
- 'msg' => '获取openid失败!'
- ];
- return $this->api($data);
- }
- $userinfo = UserInfoModel::where('openid', $openid)->first(['id', 'nickname', 'openid']);
- if (!$userinfo) {
- $data['openid'] = $openid;
- $data['nickname'] = $request->get('nickName');
- $data['avatar'] = $request->get('avatar');
- $userinfo = UserInfoModel::create($data);
- }
- if (Auth::loginUsingId($userinfo->id)) {
- $user = Auth::user();
- $token = $user->createToken($user->id . '-' . $user->openid)->accessToken;
- return $this->api(compact('token', 'user'));
- } else {
- return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
- }
- }
- /**
- * @api {get} /api/home/getproducts 获取产品列表
- * @apiDescription 获取产品列表
- * @apiGroup Product
- * @apiPermission None
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": [
- * ...
- * {
- * "id": 2,
- * "name": "履历照",
- * "img": "/upload/images/20180712/ab83f15f31ba33e17e195a20d5307e37.jpg"
- * },
- * ...
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- */
- public function getProducts()
- {
- $products = ProductCategoryModel::OrderBy('sort', 'desc')->get(['id', 'name', 'img']);
- return $this->api($products);
- }
- /**
- * @api {get} /api/home/getproduct 获取产品详情及规格
- * @apiDescription 获取产品详情及规格
- * @apiGroup Product
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} id 产品的id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "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($product);
- }
- /**
- * @api {get} /api/home/getstores 获取店铺列表
- * @apiDescription 获取店铺列表
- * @apiGroup Store
- * @apiPermission None
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": [
- * ...
- * {
- * "id": 1,
- * "name": "青羊店",
- * "img": "/upload/images/20180712/696aa5b6187bd8b1e7eb4f7962a5a3cb.jpg",
- * "address": "四川省成都市青羊区新华西路街道江汉路33号新华宾馆",
- * "phone": "18380257014",
- * "lat": "30.675999", //店铺纬度
- * "lon": "104.064465" //店铺经度
- * },
- * ...
- * ]
- * }
- * @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($stores);
- }
- /**
- * @api {get} /api/home/getschedule 获取店铺排期
- * @apiDescription 获取店铺排期
- * @apiGroup Store
- * @apiPermission None
- * @apiVersion 0.1.0
- * @apiParam {string} day 要预约的日期,如:2018-7-19
- * @apiParam {string} store_id 要预约的店铺ID
- * @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
- * }
- * ],
- * "pm_schedule": [
- * {
- * "time": "2018-07-19 14:00:00",
- * "remain": 3
- * },
- * {
- * "time": "2018-07-19 15:00:00",
- * "remain": 0
- * },
- * {
- * "time": "2018-07-19 16:00:00",
- * "remain": 3
- * }
- * ]
- *
- *
- * }
- * @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": 10004,
- * "msg": "店铺休假,请改天再约"
- * }
- * }
- *
- */
- 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');
- $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);
- $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 {post} /api/home/createorder 创建订单
- * @apiDescription 创建订单
- * @apiGroup Order
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} store_id 预约店铺ID
- * @apiParam {int} product_id 产品规格ID
- * @apiParam {string} schedule_time 预约时间
- * @apiParam {string} username 到店人姓名
- * @apiParam {string} phone 联系方式
- * @apiParam {string} email 邮箱(接受照片用)
- * @apiParam {int} sex 性别 (0:男;1:女)
- * @apiParam {string} [comment] 备注
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "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(),
- [
- 'store_id' => 'required',
- 'product_id' => 'required',
- 'schedule_time' => 'required',
- 'username' => 'required',
- 'phone' => 'required',
- 'email' => 'required',
- 'sex' => 'required',
- ],
- [
- '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());
- }
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => 401,
- 'msg' => 'token已过期,请重新登录',
- ];
- return $this->api($data);
- }
- $orderdata = $request->all();
- $scheduledata = [
- 'time' => $request->get('schedule_time'),
- 'user_id' => $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' . date('Ymdhms');
- $orderdata['price'] = $product->current_price ? $product->current_price : $product->origin_price;
- $orderdata['deposit'] = $product->deposit;
- $orderdata['user_id'] = $user->id;
- $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($order);
- }
- /**
- * @api {get} /api/home/myorders 我的订单列表
- * @apiDescription 我的订单列表
- * @apiGroup Order
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} [status] 订单状态:1:已付款,未完成拍摄;2:拍摄完成;3:已取消
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "current_page": 1, //当前页
- * "data": [
- * ...
- * {
- * "id": 3,
- * "out_trade_no": "s10003", //订单编号
- * "username": "roger",
- * "sex": 0,
- * "phone": "13407570876",
- * "email": "154@qq.com",
- * "store_id": "1",
- * "schedule_time": "2018-07-19 10:00:00", //预约时间
- * "status": 2,
- * "user_id": 1,
- * "product_id": 1,
- * "schedule_id": null,
- * "comment": "",
- * "created_at": "2018-07-19 08:53:02",
- * "updated_at": "2018-07-19 08:53:02",
- * "price": null,
- * "deposit": null,
- * "storename": "青羊店",
- * "product_name": "证件照"
- * },
- * ...
- * ],
- * "first_page_url": "http://dev.xxg.com/api/home/myorders?page=1", //首页地址
- * "from": 1,
- * "last_page": 2,
- * "last_page_url": "http://dev.xxg.com/api/home/myorders?page=2", //最后一页地址
- * "next_page_url": "http://dev.xxg.com/api/home/myorders?page=2", //下一页地址
- * "path": "http://dev.xxg.com/api/home/myorders",
- * "per_page": 5, //每页显示数量
- * "prev_page_url": null, //上一页地址
- * "to": 5,
- * "total": 7
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- */
- public function myOrders(Request $request)
- {
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => '401',
- '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']);
- } else {
- $orders = OrderInfoModel::where('user_id', $user->id)->where('status', '>', 0)->paginate(5);
- }
- foreach ($orders as $order) {
- $store = $order->store();
- $product = ProductInfoModel::find($order->product_id);
- $order['storename'] = $store;
- $order['product_name'] = $product->name;
- }
- return $this->api($orders);
- }
- /**
- * @api {get} /api/home/orderdetail 获取订单详情
- * @apiDescription 获取订单详情
- * @apiGroup Order
- * @apiPermission None
- * @apiVersion 0.1.0
- * @apiParam {int} order_id 订单ID
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "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 //定金
- * "photo": [ //照片
- * ]
- * "paidinfo": {
- * "id": 3,
- * "order_id": "27",
- * "order_price": 199, //订单价格
- * "type": 0, //付款类型 0:全款 1:定金
- * "paid_price": 199, //支付金额
- * }
- * }
- *
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- */
- public function orderDetail(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'order_id' => 'required',
- ],
- [
- 'order_id.required' => 'order_id不能为空!',
- ]
- );
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $order = OrderInfoModel::with(['paidinfo'])->select(['id', 'out_trade_no', 'username', 'phone', 'email', 'schedule_time', 'status', 'store_id', 'price', 'deposit', 'product_id', 'photo'])->find(request('order_id'));
- $photo = $order->photo;
- $order->photo = explode(',', $photo);
- $store = $order->store();
- $product = ProductInfoModel::find($order->product_id);
- $order['storename'] = $store;
- $order['product_name'] = $product->name;
- $order['service_time'] = $product->service_time;
- return $this->api($order);
- }
- /**
- * @api {post} /api/home/createbusiness 创建企业咨询
- * @apiDescription 创建企业咨询
- * @apiGroup Order
- * @apiPermission None
- * @apiVersion 0.1.0
- * @apiParam {string} company 公司名称
- * @apiParam {string} username 联系人姓名
- * @apiParam {string} phone 联系方式
- * @apiParam {string} email 邮箱
- * @apiParam {string} comment 拍摄要求
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "company": "斯尔克",
- * "username": "梁女士",
- * "phone": "13546554325",
- * "email": "sdfsa@163.com",
- * "comment": "sfaaafda",
- * "updated_at": "2018-08-13 06:09:07",
- * "created_at": "2018-08-13 06:09:07",
- * "id": 4
- * }
- *
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- */
- public function createBusiness(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'company' => 'required',
- 'username' => 'required',
- 'phone' => 'required',
- 'email' => 'required',
- 'comment' => 'required',
- ],
- [
- 'company.required' => 'company不能为空!',
- 'username.required' => 'username不能为空!',
- 'phone.required' => 'phone不能为空!',
- 'email.required' => 'email不能为空!',
- 'comment.required' => 'comment不能为空!',
- ]
- );
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->all();
- $business = BusinessServiceModel::create($data);
- return $this->api($business);
- }
- /**
- * @api {post} /api/home/pay 订单支付
- * @apiDescription 订单支付
- * @apiGroup Order
- * @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:
- * 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(),
- [
- 'orderid' => 'required',
- 'paytype' => 'required',
- ],
- [
- 'orderid.required' => 'orderid不能为空!',
- 'paytype.required' => 'paytype不能为空!',
- ]
- );
- 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);
- }
- $order = OrderInfoModel::find($request->get('orderid'));
- \Log::info($this->options());
- if (request('paytype') == 0) {
- $money = $order->price;
- } else {
- $money = $order->deposit;
- }
- $order->paytype = request('paytype');
- $order->out_trade_no = 'xxg' . date('Ymdhms');
- $order->save();
- 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([
- 'body' => '小相馆 -' . $order->out_trade_no,
- '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') {
- $order = OrderInfoModel::where('out_trade_no', $notify['out_trade_no'])->first();
- $order->status = 1;
- $order->save();
- $data['order_no'] = $notify['out_trade_no'];
- $data['order_id'] = $order->id;
- $data['order_price'] = $order->price;
- $data['paid_price'] = $notify['total_fee'] / 100;
- $data['type'] = $order->paytype;
- PaidInfoModel::create($data);
- } else {
- return $successful('通信失败,请稍后再通知我');
- }
- return true;
- });
- }
- /**
- * @api {get} /api/home/couponlist 可领取的优惠券列表
- * @apiDescription 可领取的优惠券列表
- * @apiGroup Coupon
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * ...
- * {
- * "id": 1,
- * "name": "证件照七折优惠", //优惠券名字
- * "type": "1", //优惠券类型 0:固定金额优惠,1:折扣优惠
- * "min_price": 100, //最低使用金额
- * "discount": "7", //折扣
- * "discount_price": null, //优惠金额
- * "product_id": "1,2", //可使用的产品id
- * "product":[ //可使用产品名字
- * "证件照",
- * "履历照"
- * ]
- * "count": 10, //剩余数量
- * "end_time": "2018-07-31", //有效期
- * "created_at": "2018-07-13 07:29:27",
- * "updated_at": "2018-07-18 06:36:38"e
- * }
- * ...
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function couponList(Request $request)
- {
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => '401',
- 'msg' => 'token已过期,请重新登录',
- ];
- return $this->api($data);
- }
- $couponlist = CouponInfoModel::where('end_time', '>', Carbon::now('Asia/Shanghai'))->where('count', '>', 0)->get();
- foreach ($couponlist as $key => $item) {
- $item->product = $item->product();
- $had = UserCouponRelationModel::where('coupon_id', $item->id)->where('user_id', $user->id)->count();
- if ($had) {
- unset($couponlist[$key]);
- }
- }
- return $this->api($couponlist);
- }
- /**
- * @api {get} /api/home/mycoupon 我的优惠券/兑换卡列表
- * @apiDescription 我的优惠券/兑换卡列表
- * @apiGroup Coupon
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "mycoupons":[
- * ...
- * {
- * "id": 1,
- * "coupon_id": 1,
- * "user_id": 1,
- * "coupon": {
- * "id": 1,
- * "name": "证件照七折优惠", //优惠券名字
- * "type": "1", //优惠券类型 0:固定金额优惠,1:折扣优惠
- * "min_price": 100, //最低使用金额
- * "discount": "7", //折扣
- * "discount_price": null, //优惠金额
- * "product_id": "1,2", //可使用的产品id
- * "product":[ //可使用产品名字
- * "证件照",
- * "履历照"
- * ]
- * "count": 10,
- * "end_time": "2018-07-31", //有效期
- * "created_at": "2018-07-13 07:29:27",
- * "updated_at": "2018-07-18 06:36:38"
- * }
- * }
- * ...
- * ],
- * "mycards": [
- * ...
- * {
- * "id": 7,
- * "card_no": "15319090241",
- * "price": 50,
- * "min_price": 100,
- * "status": 1,
- * "user_id": 1,
- * "remark": "梁源源--13407570861",
- * "end_time": "2019-07-31",
- * "qrcode": null,
- * "product_id": "1,2",
- * "product":[],
- * "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
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function myCoupon(Request $request)
- {
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => '401',
- 'msg' => 'token已过期,请重新登录',
- ];
- return $this->api($data);
- }
- $mycoupons = UserCouponRelationModel::where('user_id', $user->id)->with('coupon')->orderBy('created_at', 'desc')->get();
- $mycoupons = $mycoupons->filter(function ($value) {
- if (!$value->coupon) {
- return false;
- }
- if (strtotime($value->coupon->end_time) < strtotime(Carbon::now('Asia/Shanghai'))) {
- return false;
- } else {
- $value->coupon->product = CouponInfoModel::find($value->coupon->id) ? CouponInfoModel::find($value->coupon->id)->product() : '';
- return true;
- }
- });
- $mycoupons = $mycoupons->toArray();
- $mycoupons = array_values($mycoupons);
- $mycards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>', now())->get();
- foreach ($mycards as $card) {
- $card->product = $card->product();
- }
- return $this->api(compact('mycards', 'mycoupons'));
- }
- /**
- * @api {get} /api/home/getcoupon 领取优惠券
- * @apiDescription 领取优惠券
- * @apiGroup Coupon
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} coupon_id 优惠券ID
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "res": 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": 10001,
- * "msg": "你已经领取过改优惠券,不能重复领取!"
- * }
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- * 1001 CLIENT_WRONG_PARAMS 你已经领取过改优惠券,不能重复领取
- */
- public function getCoupon(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'coupon_id' => 'required'
- ],
- [
- 'coupon_id.required' => 'coupon_id不能为空!'
- ]
- );
- 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);
- }
- $had = UserCouponRelationModel::where('coupon_id', request('coupon_id'))->where('user_id', $user->id)->count();
- if ($had) {
- $data = [
- 'code' => 10001,
- 'msg' => '你已经领取过改优惠券,不能重复领取!'
- ];
- return $this->api($data);
- }
- $coupon = CouponInfoModel::find(request('coupon_id'));
- if (!$coupon) {
- $data = [
- 'code' => 10002,
- 'msg' => '改优惠券已被领取完毕!'
- ];
- return $this->api($data);
- }
- if ($coupon->count > 0) {
- $coupon->count = $coupon->count - 1;
- $res = $coupon->save();
- $data = $request->all();
- $data['user_id'] = $user->id;
- UserCouponRelationModel::create($data);
- return $this->api(compact('res'));
- } else {
- $data = [
- 'code' => 10002,
- 'msg' => '改优惠券已被领取完毕!'
- ];
- 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' => 'required',
- ],
- [
- '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 获取订单可用的优惠券/兑换卡
- * @apiGroup Coupon
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} product_id 产品规格ID,订单中获取
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":{
- * "usablecoupons":[ //可用的优惠券
- * ...
- * {
- * "id": 1,
- * "coupon_id": 1,
- * "user_id": 1,
- * "coupon": {
- * "id": 1,
- * "name": "证件照七折优惠",
- * "type": "1",
- * "min_price": 100,
- * "discount": "7",
- * "discount_price": null,
- * "product_id": "1,2",
- * "product":[ //可使用产品名字
- * "证件照",
- * "履历照"
- * ],
- * "count": 7,
- * "end_time": "2018-07-31",
- * "created_at": "2018-07-13 07:29:27",
- * "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",
- * "product":[ //可使用产品名字
- * "证件照",
- * "履历照"
- * ],
- * "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
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function usableCoupon(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'product_id' => 'required'
- ],
- [
- 'product_id.required' => 'product_id不能为空!'
- ]
- );
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => '401',
- 'msg' => 'token已过期,请重新登录',
- ];
- return $this->api($data);
- }
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $mycoupons = UserCouponRelationModel::where('user_id', $user->id)->with('coupon')->orderBy('created_at', 'desc')->get();
- $usablecoupons = $mycoupons->filter(function ($value) {
- $flag = false;
- $product = ProductInfoModel::find(request('product_id'));
- if (!$value->coupon) {
- $flag = false;
- return $flag;
- }
- $products = explode(',', $value->coupon->product_id);
- $price = $product->current_price ? $product->current_price : $product->origin_price;
- if ((strtotime($value->coupon->end_time) > strtotime(Carbon::now('Asia/Shanghai'))) && in_array($product->category_id, $products) && ($price >= $value->coupon->min_price)) {
- $value->coupon->product = CouponInfoModel::find($value->coupon->id) ? CouponInfoModel::find($value->coupon->id)->product() : '';
- $flag = true;
- } else {
- $flag = false;
- }
- return $flag;
- });
- $usablecoupons = $usablecoupons->toArray();
- $usablecoupons = array_values($usablecoupons);
- $current_product = ProductInfoModel::find(request('product_id'));
- $usableCards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>=', now())->where('product_id', 'like', '%' . request('product_id') . '%')->where('min_price','<=',$current_product->origin_price)->get();
- foreach ($usableCards as $card) {
- $card->product = $card->product();
- }
- return $this->api(compact('usablecoupons', 'usableCards'));
- }
- /**
- * @api {get} /api/home/refund 申请退款
- * @apiDescription 申请退款
- * @apiGroup Order
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} order_id 产品规格ID,订单中获取
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "code": 200,
- * "msg": "退款已申请,请等待商家审核!"
- * }
- * }
- * @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": 10003,
- * "msg": "该订单不能退款,如有疑问,请联系商家!"
- * }
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function refund(Request $request)
- {
- $validator = Validator::make($request->all(),
- [
- 'order_id' => 'required'
- ],
- [
- 'order_id.required' => 'order_id不能为空!'
- ]
- );
- $user = Auth('api')->user();
- if (!$user) {
- $data = [
- 'code' => '401',
- 'msg' => 'token已过期,请重新登录',
- ];
- return $this->api($data);
- }
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $order = OrderInfoModel::find(request('order_id'));
- if ($order->status != 1) {
- $data = [
- 'code' => 10003,
- 'msg' => '该订单不能退款,如有疑问,请联系商家!'
- ];
- return $this->api($data);
- }
- $order->status = 3;
- $ok = $order->save();
- if ($ok) {
- $data = [
- 'code' => 200,
- 'msg' => '退款已申请,请等待商家审核!'
- ];
- return $this->api($data);
- }
- }
- //格式化排期
- 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;
- }
- public function options()
- {
- return [
- 'app_id' => $this->setting->app_id,
- 'mch_id' => $this->setting->mch_id,
- 'key' => $this->setting->api_key,
- 'notify_url' => url('/api/home/notify'),
- 'sandbox' => false,
- ];
- }
- }
|