_valid([ "shop.require" => "", "print.require" => "", "code.require" => "", "card.default" => "" ],$request->method()); if (!is_array($param)) return error($param); $userinfo = (new Crypt([ "appid" => sConf("wechat.mini_appid"), "appsecret" => sConf("wechat.mini_secret") ]))->session($param['code']); if (!isset($userinfo['openid'])) return error("获取数据失败"); $map = ['is_deleted' => 0, 'openid' => $userinfo['openid']]; $user = (new SaasUserOpen)->where($map)->findOrEmpty(); if ($user->isEmpty()) { $user->insertGetId(['openid' => $userinfo['openid'],"create_ip" => $request->getRealIp(),"nickname" => "微信用户","headimg" => "https://inmei-print.oss-cn-guangzhou.aliyuncs.com/logo.png"]); $user = (new SaasUserOpen)->where($map)->findOrEmpty(); } $userAuth = get_object_vars(AuthMode::guard("member")->login($user->toArray())); $shopData = []; $cardState = 0; if (!empty($param['shop'])) { $shop = (new SaasShop)->where("shop_id", $param['shop'])->field("shop_name,start_at,end_at,vip_end,shop_status,shop_notice,line_time,status,shop_address")->findOrEmpty(); if ($shop->isEmpty()) return error("店铺已被关闭"); $currentTime = time(); $vipEndTime = strtotime($shop['vip_end'] ?? ''); $lineEndTime = strtotime("+10020000 min", strtotime($shop['line_time'] ?? '')); $today = date('Y-m-d'); $startTime = strtotime("{$today} {$shop['start_at']}"); $endTime = strtotime("{$today} {$shop['end_at']}"); if ($currentTime > $vipEndTime){ $status = ['text' => '已过期', 'val' => 0]; } else if ($shop['status'] == 2) { $status = ['text' => '已冻结', 'val' => 0]; } else if ($currentTime > $lineEndTime) { $status = ['text' => '已离线', 'val' => 0]; } else if ($currentTime > $endTime || $currentTime < $startTime) // 过了营业时间 { $status = ['text' => '休息中', 'val' => 0]; } else { $status = ['text' => '营业中', 'val' => 1]; } $shop['status_text'] = $status['text']; $shop['status_val'] = $status['val']; $shop['time'] = ($shop['start_at'] == '00:00' && $shop['end_at'] == '23:59') ? '24小时营业' : date('H:i', $startTime) . '-' . date('H:i', $endTime); if ($param['card'] == 1) { // 领取会员卡 $cardInfo = (new SaasUser)->where("shop_id",$param['shop'])->where("openid",$userinfo['openid'])->findOrEmpty(); if ($cardInfo->isEmpty()) { $cardInfo->insertGetId([ "shop_id" => $param['shop'], "openid" => $userinfo['openid'], "card_no" => CodeExtend::uniqidDate(16,"1088") ]); $cardState = 1; } } $shopData = $shop->toArray(); } $share = sConf("wechat.share"); return success("ok",["shop" => $shopData,'user' => ['nickname' => $user['nickname']??'','avatar' => $user['avatar']??''],"token" => $userAuth,"card" => $cardState,"share" => $share]); }catch (\Throwable $e){ echo $e->getMessage()."\n"; echo $e->getFile()."\n"; echo $e->getLine()."\n"; return error($e->getMessage()); } } }