96 lines
3.5 KiB
PHP
96 lines
3.5 KiB
PHP
<?php
|
|
namespace app\models\common;
|
|
use Yii;
|
|
use yii\db\ActiveRecord;
|
|
use yii\web\Controller;
|
|
use app\models\common\Config;
|
|
class Store extends ActiveRecord{
|
|
//获取系统设置
|
|
public static function getMainStore($uniacid) {
|
|
$res=(new \yii\db\Query())
|
|
->select(['id','name','storeNumber'])
|
|
->from('{{%ybwm_store}}')
|
|
->where('uniacid=:uniacid AND isMain=1',[':uniacid'=>$uniacid])
|
|
->one();
|
|
return $res?:[];
|
|
}
|
|
|
|
//获取门店信息
|
|
public static function getStoreInfo($uniacid,$storeId){
|
|
$res=(new \yii\db\Query())
|
|
->select(['goodsModel','isMain'])
|
|
->from('{{%ybwm_store}}')
|
|
->where('uniacid=:uniacid AND id=:id',[':uniacid'=>$uniacid,'id'=>$storeId])
|
|
->one();
|
|
return $res?:[];
|
|
}
|
|
//查看商家外卖是否营业
|
|
public static function getStoreOutBusiness($storeId,$type=1) {
|
|
if($type==1){
|
|
$storeSet = Config::getStoreSet('takeOutSet', $storeId);
|
|
}else{
|
|
$storeSet = Config::getStoreSet('instoreSet', $storeId);
|
|
}
|
|
|
|
$storeSet['timeType']=$storeSet['timeType']?:1;
|
|
$storeId=(new \yii\db\Query())
|
|
->select(['storeOpen'])
|
|
->from('{{%ybwm_store}}')
|
|
->where('id=:id',[':id'=>$storeId])->one();
|
|
if($storeId['storeOpen']==2){
|
|
return 3;//关店
|
|
}
|
|
date_default_timezone_set('PRC');
|
|
$timeOpen = 1;
|
|
if ($storeSet['timeType'] == 2) {
|
|
$timeOpen = 2;//不在营业时间
|
|
$times=$storeSet['timeArr'];
|
|
for($m = 0; $m < count($times); $m++){
|
|
$startTime=strtotime(date("Y-m-d ".$times[$m]['startTime']));
|
|
if($times[$m]['ciri']===true){
|
|
$endTime=strtotime(date("Y-m-d ".$times[$m]['endTime']))+86400;
|
|
}else{
|
|
$endTime=strtotime(date("Y-m-d ".$times[$m]['endTime']));
|
|
}
|
|
//如果是次日 当前时间小于开始时间并且当前时间小于结束时间
|
|
if($times[$m]['ciri']===true&&time()<$startTime&&time()<strtotime(date("Y-m-d ".$times[$m]['endTime']))){
|
|
return 1;//营业
|
|
}
|
|
if ($startTime <= time() AND $endTime >= time()){
|
|
return 1;//营业
|
|
}
|
|
}
|
|
}
|
|
return $timeOpen;
|
|
}
|
|
|
|
static function location($uniacid){
|
|
//获取客户端ip
|
|
$ip=Yii::$app->request->userIP;
|
|
$system=Config::getSystemSet('system',$uniacid);
|
|
$key=$system['txKey']?:'EOJBZ-HSBW6-G2VSM-EE3KV-4OAAK-RXFWT';
|
|
$url="https://apis.map.qq.com/ws/location/v1/ip?ip=".$ip."&key=".$key;
|
|
$res=httpRequest($url);
|
|
$result=json_decode($res,true);
|
|
if($result['status']==0){
|
|
$data['ip']=$ip;
|
|
$data['lat']=$result['result']['location']['lat'];
|
|
$data['lng']=$result['result']['location']['lng'];
|
|
$data['address']=$result['result']['ad_info']['province'].$result['result']['ad_info']['city'].$result['result']['ad_info']['district'];
|
|
return $data;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
//查看门店是否是主门店
|
|
static function isMain($storeId){
|
|
$res=(new \yii\db\Query())
|
|
->select(['isMain'])
|
|
->from('{{%ybwm_store}}')
|
|
->where('id=:id',[':id'=>$storeId])
|
|
->one();
|
|
return $res['isMain'];
|
|
}
|
|
|
|
}
|