Commit 4349eaac authored by 姚书霞's avatar 姚书霞 🐘

电子围栏接口

parent 778b8121
......@@ -9,6 +9,7 @@ use yii\web\BadRequestHttpException;
use yii\web\ServerErrorHttpException;
use yii\data\ActiveDataProvider;
use yidas\phpSpreadsheet\Helper;
use app\models\v1\branch\ShopCityDistributionRegion;
class CityDistributionSettingController extends BaseController
{
......@@ -84,7 +85,7 @@ class CityDistributionSettingController extends BaseController
* @OA\Get(
* path="/backend/web/v1/branch/city-distribution-settings/city-distribution-setting-export",
* tags={"门店&DC"},
* summary="电子围栏列表导出u(姚书侠)",
* summary="电子围栏列表导出(姚书侠)",
* description="电子围栏列表导出接口",
* @OA\Parameter(in = "query",name = "code",description = "门店编码",required = false,@OA\Schema(type="string")),
* @OA\Parameter(in = "query",name = "province",description = "省份",required = false,@OA\Schema(type="string")),
......@@ -140,7 +141,35 @@ class CityDistributionSettingController extends BaseController
* summary="电子围栏详情(姚书侠)",
* description="电子围栏详情接口",
* @OA\Parameter(name="guid",in="query",required=true,description="门店GUID",@OA\Schema(type="string")),
* @OA\Response(response = 200,description = "success"),
* @OA\Response(response = 200,description = "
* GUID:门店GUID,
* NAME:门店名称,
* LAT:门店经纬度,
* LNG:门店经纬度,
* ADDRESS:门店地址,
* O2O:门店O2O电子围栏信息数组,
* GUID:电子围栏设置GUID,
* REGION_TYPE:配送区域类型,
* REGION_DISTR_DISTANCE:不同距离不同配送费**公里内,
* REGION_DISTR_PRICE:不同距离不同配送费*公里内*元,
* INCREASE_DISTANCE:不同距离不同配送费增加*公里,
* INCREASE_PRICE:不同距离不同配送费增加*公里*元,
* STATUS:是否开启同城配送,1:是,
* SETTING_TYPE:电子围栏类型:1:B2C范围,2:O2O范围,
* REGION:O2O设置的下级围栏区域数组(二维),
* GUID:区域GUID,
* ORDEX:区域序号,
* CITY_DISTR_GUID:同城配送设置表,关联CITY_DISTRIBUTION_SETTING表GUID,
* COLORS:区域颜色,
* HF_TYPE:区域划分方式,1半径 2自定义,
* REGION_R:划分方式为半径,存半径的值,
* REGION_RANGE:划分方式自定义时,存数组值,
* QS_PRICE:起送价格,
* PS_PRICE:配送价格,
* WEEK:配送时间周*,
* IS_TYPE:配送时段和区域,QY为区域,SJ为时间,QS_PRICE和PS_PRICE为起始时间字段,
* B2C:门店B2C电子围栏信息数组(字段注释同020),
* "),
* security={{"Authorization": {}}}
* )
*/
......@@ -163,10 +192,30 @@ class CityDistributionSettingController extends BaseController
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="TYPE",description = "保存类型(1:O2O,2:B2C)",type="string"),
* @OA\Property(property="SETTING_TYPE",description = "电子围栏类型(1:B2C,2:O2O)",type="string"),
* @OA\Property(property="BRANCH_GUID",description = "门店GUID",type="string"),
* @OA\Property(property="GUID",description = "O2O或者B2C的GUID",type="string"),
* example={"CODE": 1234567890, "PASSWORD": "123"}
* @OA\Property(property="GUID",description = "电子围栏的GUID(没有不传此字段)",type="string"),
* @OA\Property(property="REGION_TYPE",description = "配送区域类型(1不同区域,2不同距离)",type="string"),
* @OA\Property(property="REGION_DISTR_DISTANCE",description = "不同距离不同配送费**公里内",type="string"),
* @OA\Property(property="REGION_DISTR_PRICE",description = "不同距离不同配送费*公里内*元",type="string"),
* @OA\Property(property="INCREASE_DISTANCE",description = "不同距离不同配送费增加*公里",type="string"),
* @OA\Property(property="INCREASE_PRICE",description = "不同距离不同配送费增加*公里*元",type="string"),
* @OA\Property(property="STATUS",description = "是否开启配送,1:是",type="string"),
* @OA\Property(property="REGION",title = "电子围栏区域数组",
* @OA\Property(
* @OA\Property(property="ORDEX",description = "区域序号",type="string"),
* @OA\Property(property="COLORS",description = "区域颜色",type="string"),
* @OA\Property(property="HF_TYPE",description = "区域划分方式,1半径 2自定义",type="string"),
* @OA\Property(property="REGION_R",description = "划分方式为半径,存半径的值",type="string"),
* @OA\Property(property="REGION_RANGE",description = "划分方式自定义时,存数组值",type="string"),
* @OA\Property(property="QS_PRICE",description = "起送价格",type="string"),
* @OA\Property(property="PS_PRICE",description = "配送价格",type="string"),
* ),
* ),
* example={"SETTING_TYPE": "1", "BRANCH_GUID":"123","GUID":"","REGION_TYPE":"1","REGION_DISTR_DISTANCE":"0",
* "REGION_DISTR_PRICE":"0","INCREASE_DISTANCE":"0","INCREASE_PRICE":"0","STATUS":"1","REGION":{
* {"ORDEX":"1","COLORS":"#123","HF_TYPE":"1","REGION_R":"1000","REGION_RANGE":"21312212","QS_PRICE":"1","PS_PRICE":"1"}}
* }
* )
* )
* ),
......@@ -177,40 +226,72 @@ class CityDistributionSettingController extends BaseController
//编辑用
public function actionCityDistributionSettingSave()
{
$guid = Yii::$app->getRequest()->post('BRANCH_GUID');
$guid = Yii::$app->getRequest()->post('O2O_GUID');
$guid = Yii::$app->getRequest()->post('TYPE');
$model = $this->modelClass::findOne($guid);
if(!$model){
throw new BadRequestHttpException('没有找到记录');
$setting_type = Yii::$app->getRequest()->post('SETTING_TYPE');
$branch_guid = Yii::$app->getRequest()->post('BRANCH_GUID');
$guid = Yii::$app->getRequest()->post('GUID');
$region = Yii::$app->getRequest()->post('REGION');
if(!empty($guid)){
$model = $this->modelClass::findOne($guid);
if(!$model){
throw new BadRequestHttpException('没有找到记录');
}
// $model->scenario = 'update';//创建的场景
}else{
$model = $this->modelClass::findOne(['SETTING_TYPE'=>$setting_type,'BRANCH_GUID'=>$branch_guid]);
if($model){
throw new BadRequestHttpException('请勿重复添加电子围栏设置');
}else{
$model = new $this->modelClass();
}
$other_param = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>'100',//Yii::$app->user->identity->ORG_GUID,
);
$model->setAttributes($other_param,false);
}
$model->scenario = 'update';//创建的场景
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
return $model;
$region_model = new ShopCityDistributionRegion();
$model = new $this->modelClass();
$model->scenario = 'create';//创建的场景
$other_param = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID,
);
$model->setAttributes($other_param);
$model->setAttributes(Yii::$app->getRequest()->post());
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
//开启事务
$trans = $model->getDb()->beginTransaction();
try{
//添加主表
if($model->save()===false){
if(!$model->hasErrors()){
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}else{
return $model;
}
}
//原来有guid的 删除region所有数据
if(!empty($guid)){
ShopCityDistributionRegion::deleteAll(["CITY_DISTR_GUID"=>$guid]);
}
//传过来的数据全部新增
$region_value = [];
foreach($region as $value){
$region_model->setAttributes($value);
$other_param_region = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>'100',//Yii::$app->user->identity->ORG_GUID,
"CITY_DISTR_GUID"=>$model->GUID,
);
$region_model->setAttributes($other_param_region,false);
if ($region_model->validate()) {
$region_value[] = $region_model->getAttributes(["GUID","ORG_GUID","CITY_DISTR_GUID","ORDEX","COLORS","HF_TYPE","REGION_R","REGION_RANGE","QS_PRICE","PS_PRICE"]);
}else{
return $region_model;
}
}
$model->getDb()->createCommand()->batchInsert(ShopCityDistributionRegion::tableName(), ["GUID","ORG_GUID","CITY_DISTR_GUID","ORDEX","COLORS","HF_TYPE","REGION_R","REGION_RANGE","QS_PRICE","PS_PRICE"], $region_value)->execute();
$trans->commit();
return $model;
} catch (\Throwable $e){
$trans->rollBack();
throw new ServerErrorHttpException($e);
}
return $model;
}
}
\ No newline at end of file
......@@ -99,12 +99,11 @@ class ShopUserMembergradeController extends BaseController
public function actionMembergradeAdd()
{
$model = new $this->modelClass();
$model->scenario = 'create';//创建的场景
$other_param = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID,
);
$model->setAttributes($other_param);
$model->setAttributes($other_param,false);
$model->setAttributes(Yii::$app->getRequest()->post());
......
......@@ -81,7 +81,7 @@ use app\models\v1\branch\ShopCityDistributionSetting;
* @property int $IS_B2C 是否B2C门店 1是
* @property int $TOTAL_VOLUME 门店销量
*
* @property ShopCityDistributionSetting[] $shopCityDistributionSettings
* @property CityDistributionSettings[] $CityDistributionSettings
*/
class ShopBranch extends BaseModel
{
......@@ -245,7 +245,7 @@ class ShopBranch extends BaseModel
/**
* @return \yii\db\ActiveQuery
*/
public function getShopCityDistributionSettings()
public function getCityDistributionSettings()
{
return $this->hasMany(ShopCityDistributionSetting::className(), ['BRANCH_GUID' => 'GUID']);
}
......
<?php
namespace app\models\v1\branch;
use Yii;
use app\models\v1\BaseModel;
use app\models\v1\branch\ShopCityDistributionSetting;
/**
* This is the model class for table "shop_city_distribution_region".
*
* @property string $GUID 电子围栏GUID
* @property string $ORG_GUID 组织机构号
* @property string $CITY_DISTR_GUID 同城配送设置表,关联CITY_DISTRIBUTION_SETTING表GUID
* @property string $ORDEX 区域序号
* @property string $COLORS 区域颜色
* @property int $HF_TYPE 区域划分方式,1半径 2自定义
* @property string $REGION_R 划分方式为半径,存半径的值
* @property string $REGION_RANGE 划分方式自定义时,存数组值
* @property string $QS_PRICE 起送价格
* @property string $PS_PRICE 配送价格
* @property string $WEEK 配送时间周*
* @property int $IS_TYPE 配送时段和区域,1为区域,2为时间
*
* @property ShopCityDistributionSetting $CityDistributionSetting
*/
class ShopCityDistributionRegion extends BaseModel
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'shop_city_distribution_region';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['ORDEX', 'COLORS','HF_TYPE','REGION_R','REGION_RANGE','QS_PRICE','PS_PRICE'], 'required'],
[['HF_TYPE'], 'in', 'range' => [1, 2]],
[['REGION_R'], 'integer'],
[['REGION_RANGE'], 'string'],
[['QS_PRICE', 'PS_PRICE'], 'double'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'GUID' => 'Guid',
'ORG_GUID' => 'Org Guid',
'CITY_DISTR_GUID' => 'City Distr Guid',
'ORDEX' => 'Ordex',
'COLORS' => 'Colors',
'HF_TYPE' => 'Hf Type',
'REGION_R' => 'Region R',
'REGION_RANGE' => 'Region Range',
'QS_PRICE' => 'Qs Price',
'PS_PRICE' => 'Ps Price',
'WEEK' => 'Week',
'IS_TYPE' => 'Is Type',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCityDistributionSetting()
{
return $this->hasOne(ShopCityDistributionSetting::className(), ['GUID' => 'CITY_DISTR_GUID']);
}
}
......@@ -4,6 +4,7 @@ namespace app\models\v1\branch;
use Yii;
use app\models\v1\BaseModel;
use app\models\v1\branch\ShopBranch;
use app\models\v1\branch\ShopCityDistributionRegion;
/**
* This is the model class for table "shop_city_distribution_setting".
......@@ -34,7 +35,7 @@ use app\models\v1\branch\ShopBranch;
* @property int $STATUS 是否开启同城配送,1:是
* @property int $SETTING_TYPE 电子围栏类型:1:B2C范围,2:O2O范围
*
* @property CityDistributionRegion[] $cityDistributionRegions
* @property ShopCityDistributionRegion[] $cityDistributionRegions
* @property ShopBranch $bRANCHGU
*/
class ShopCityDistributionSetting extends BaseModel
......@@ -53,14 +54,11 @@ class ShopCityDistributionSetting extends BaseModel
public function rules()
{
return [
[['GUID'], 'required'],
[['IS_OWN_DISTR', 'IS_OTHER_DISTR', 'IS_DADA_DISTR', 'IS_TIMING', 'TIME_SUBDIVISION', 'STATUS', 'SETTING_TYPE'], 'integer'],
[['SIMPLE_DISTR_QS_PRICE', 'SIMPLE_DISTR_PS_PRICE', 'REGION_DISTR_DISTANCE', 'REGION_DISTR_PRICE', 'INCREASE_DISTANCE', 'INCREASE_PRICE'], 'number'],
[['GUID', 'ORG_GUID', 'BRANCH_GUID', 'WORK_TYPE', 'REGION_TYPE', 'ADDRESS', 'BOOKING_ORDER', 'MAX_BOOKING'], 'string', 'max' => 50],
[['SIMPLE_DISTR_NOTES', 'SIMPLE_DISTR_PIC'], 'string', 'max' => 200],
[['LAT', 'LNG'], 'string', 'max' => 20],
[['GUID'], 'unique'],
[['BRANCH_GUID'], 'exist', 'skipOnError' => true, 'targetClass' => ShopBranch::className(), 'targetAttribute' => ['BRANCH_GUID' => 'GUID']],
[['BRANCH_GUID','REGION_TYPE','SETTING_TYPE',], 'required'],
[['REGION_DISTR_DISTANCE', 'REGION_DISTR_PRICE','INCREASE_DISTANCE','INCREASE_PRICE'], 'double'],
[['STATUS'], 'boolean'],
[['REGION_TYPE','SETTING_TYPE'], 'in', 'range' => [1, 2]],
// [['BRANCH_GUID'], 'exist', 'skipOnError' => true, 'targetClass' => ShopBranch::className(), 'targetAttribute' => ['BRANCH_GUID' => 'GUID']],
];
}
......@@ -103,7 +101,7 @@ class ShopCityDistributionSetting extends BaseModel
*/
public function getCityDistributionRegions()
{
return $this->hasMany(CityDistributionRegion::className(), ['CITY_DISTR_GUID' => 'GUID']);
return $this->hasMany(ShopCityDistributionRegion::className(), ['CITY_DISTR_GUID' => 'GUID']);
}
/**
......@@ -177,7 +175,7 @@ class ShopCityDistributionSetting extends BaseModel
//门店下面的O2O和B2C设置,以及对应的区域
$select = "cds.GUID SETTING_GUID,cds.REGION_TYPE,cds.REGION_DISTR_DISTANCE,cds.REGION_DISTR_PRICE,cds.INCREASE_DISTANCE,cds.INCREASE_PRICE,";
$select .= "cds.LAT,cds.LNG,cds.STATUS,cds.SETTING_TYPE,cdr.GUID REGION_GUID,cdr.CITY_DISTR_GUID,cdr.ORDEX,cdr.COLORS,";
$select .= "cds.STATUS,cds.SETTING_TYPE,cdr.GUID REGION_GUID,cdr.CITY_DISTR_GUID,cdr.ORDEX,cdr.COLORS,";
$select .= "cdr.HF_TYPE,cdr.REGION_R,cdr.REGION_RANGE,cdr.QS_PRICE,cdr.PS_PRICE,cdr.WEEK,cdr.IS_TYPE";
$setting_info = $this->find()->alias("cds")
->select($select)
......@@ -198,8 +196,6 @@ class ShopCityDistributionSetting extends BaseModel
$b2c['REGION_DISTR_PRICE'] = $value['REGION_DISTR_PRICE'];
$b2c['INCREASE_DISTANCE'] = $value['INCREASE_DISTANCE'];
$b2c['INCREASE_PRICE'] = $value['INCREASE_PRICE'];
$b2c['LAT'] = $value['LAT'];
$b2c['LNG'] = $value['LNG'];
$b2c['STATUS'] = $value['STATUS'];
$b2c['SETTING_TYPE'] = $value['SETTING_TYPE'];
$b2c['REGION'] = [];
......@@ -243,8 +239,6 @@ class ShopCityDistributionSetting extends BaseModel
$o2o['REGION_DISTR_PRICE'] = $value['REGION_DISTR_PRICE'];
$o2o['INCREASE_DISTANCE'] = $value['INCREASE_DISTANCE'];
$o2o['INCREASE_PRICE'] = $value['INCREASE_PRICE'];
$o2o['LAT'] = $value['LAT'];
$o2o['LNG'] = $value['LNG'];
$o2o['STATUS'] = $value['STATUS'];
$o2o['SETTING_TYPE'] = $value['SETTING_TYPE'];
$o2o['REGION'] = [];
......
......@@ -77,8 +77,6 @@ class ShopUserMembergrade extends BaseModel
[['IS_SETRANGE'], 'in', 'range' => [0, 1, 2]],
[['NAME'], 'string', 'max' => 20],
[['GUID'], 'required','on'=>'update'],
[['GUID'], 'safe','on'=>'create'],
[['ORG_GUID'], 'safe'],
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment