Commit ea2ca1e2 authored by 侯贺政's avatar 侯贺政

运费模板列表

Signed-off-by: 侯贺政's avatarhouhezheng <houhezheng@romens.cn>
parent f4529efb
......@@ -6,3 +6,4 @@ defined('DEFAULT_DB_PREFIX') or define('DEFAULT_DB_PREFIX', 'db');//默认db
defined('ADMIN_ACTIVE_STATUS') or define('ADMIN_ACTIVE_STATUS', '1');//管理员活动状态
defined('UPLOAD_FILE_PATH') or define('UPLOAD_FILE_PATH', dirname(__FILE__).'../../../uploadtempfiles/');//上传文件路径
defined('TEMPLATE_FILE_PATH') or define('TEMPLATE_FILE_PATH', dirname(__FILE__).'../../../template/');//模板文件路径
defined('PAGE_SIZE') or define('PAGE_SIZE',10);//分页,默认每页提供数据条数
......@@ -202,6 +202,16 @@ return [
'GET,OPTIONS template-file' => 'template-file',
],
],
//运费模板
[
'class'=>'yii\rest\UrlRule',
'controller'=>[
'v1/transport/transport-setting',
],
'extraPatterns'=>[
'GET,OPTIONS transport-templates' => 'transport-templates',
]
],
],
],
]
......
<?php
namespace backend\controllers\v1\transport;
use backend\controllers\v1\BaseController;
use Yii;
use yii\web\BadRequestHttpException;
class TransportSettingController extends BaseController
{
public $modelClass = 'app\models\v1\transport\TransportSetting';
/**
* @OA\GET(
* path="/backend/web/v1/transport/transport-settings/transport-templates",
* tags={"配送管理"},
* summary="配送价格列表(侯贺政)",
* description="
* 运费模板列表:
* 运费模板所属平台,如果不填默认取微商城的运费模板",
* @OA\Parameter(name="page",in="query",description="分页页码",@OA\Schema(type="int")),
* @OA\Parameter(name="PLATFORM_TYPE",in="query",description="运费模板所属平台(微商城:shop,积分商城:points)",@OA\Schema(type="int")),
* @OA\Response(response="200",description="
* GUID:运费模板GUID,
* TRANSPOR_TTYPE:配送方式,
* BASE_FEE:统一费用,
* BASE_WEIGHT:首重,
* BASE_WEIGHT_FEE:首重费用,
* INCREASE_WEIGHT:续重,
* INCREASE_WEIGHT_FEE:续重费用,
* IS_USED:是否启用,
* SELECT_AREA:配送城市"),
* security={{"Authorization":{}}}
* )
*/
public function actionTransportTemplates()
{
$platform_type = Yii::$app->request->get('PLATFORM_TYPE');
if (empty($platform_type)) {
$platform_type = 'shop'; //默认取微商城的运费模板
}
$model = new $this->modelClass();
$model->PLATFORM_TYPE = $platform_type;
if (!$model->validate()) {
Yii::$app->response->statusCode = 422;
return $model->errors;
}
$list = $model->templates($platform_type);
if (!$list) {
throw new BadRequestHttpException('未找到符合条件的数据');
}
return $list;
}
}
<?php
namespace app\models\v1\transport;
use app\models\v1\common\ShopTransportArea;
use Yii;
use yii\data\ActiveDataProvider;
use yii\debug\models\timeline\DataProvider;
/**
* This is the model class for table "shop_transport_setting".
*
* @property string $GUID
* @property string $ORG_GUID 组织机构号
* @property string|null $TRANSPOR_TTYPE 配送方式
* @property string|null $TRANSPORT_COMPANY 配送公司
* @property float|null $BASE_FEE 统一费用
* @property string|null $BASE_WEIGHT 首重
* @property float|null $BASE_WEIGHT_FEE 首重费用
* @property string|null $INCREASE_WEIGHT 续重
* @property float|null $INCREASE_WEIGHT_FEE 续重费用
* @property string|null $DESCRIPTION 简介
* @property string|null $SELECT_AREA 配送城市
* @property int|null $IS_DEFAULT 是否默认
* @property int|null $IS_USED 是否启用
* @property string $PLATFORM_TYPE 运费模板所属平台(shop,points)默认shop
* @property string|null $LIMIT_MEMBER_GROUP_GUID 限制人群
* @property string|null $GROUP_GUID 权限
*/
class TransportSetting extends \app\models\v1\BaseModel
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'shop_transport_setting';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['GUID', 'ORG_GUID'], 'required', 'on' => ['creation']],
[['BASE_FEE', 'BASE_WEIGHT_FEE', 'INCREASE_WEIGHT_FEE'], 'number'],
[['SELECT_AREA', 'LIMIT_MEMBER_GROUP_GUID'], 'string'],
[['IS_DEFAULT', 'IS_USED'], 'integer'],
[['GUID', 'ORG_GUID', 'TRANSPOR_TTYPE', 'TRANSPORT_COMPANY', 'BASE_WEIGHT', 'INCREASE_WEIGHT', 'PLATFORM_TYPE', 'GROUP_GUID'], 'string', 'max' => 50],
[['DESCRIPTION'], 'string', 'max' => 300],
[['GUID'], 'unique', 'on' => ['creation']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'GUID' => 'Guid',
'ORG_GUID' => '组织机构号',
'TRANSPOR_TTYPE' => '配送方式',
'TRANSPORT_COMPANY' => '配送公司',
'BASE_FEE' => '统一费用',
'BASE_WEIGHT' => '首重',
'BASE_WEIGHT_FEE' => '首重费用',
'INCREASE_WEIGHT' => '续重',
'INCREASE_WEIGHT_FEE' => '续重费用',
'DESCRIPTION' => '简介',
'SELECT_AREA' => '配送城市',
'IS_DEFAULT' => '是否默认',
'IS_USED' => '是否启用',
'PLATFORM_TYPE' => '运费模板所属平台',
'LIMIT_MEMBER_GROUP_GUID' => '限制人群',
'GROUP_GUID' => '权限',
];
}
/**
* 运费模板列表
*
* @params string $platform_type 运费模板所属平台
* @return array|null 返回运费模板列表
*/
public function templates($platform_type)
{
$query = static::find()->alias('ts')
->select(['ts.GUID', 'stt.NAME as TRANSPORT_NAME', 'ts.BASE_FEE', 'ts.BASE_WEIGHT', 'ts.BASE_WEIGHT_FEE', 'ts.IS_USED', 'ts.SELECT_AREA'])
->leftJoin('shop_transport_type stt', 'ts.TRANSPOR_TTYPE=stt.GUID')
->where(['ts.PLATFORM_TYPE' => $platform_type]);
$dataProvider = new ActiveDataProvider([
'query' => $query->asArray(),
'pagination' => [
'pageSize' => PAGE_SIZE
],
'sort' => [
'attributes' => ['TRANSPOR_TTYPE']
]
]);
$temp = $dataProvider->getModels();
foreach ($temp as $key => $value) {
$citys = explode(',', $value['SELECT_AREA']);
$area = ShopTransportArea::findAll(["GUID" => $citys]);
$area_name = [];
foreach ($area as $v) {
$area_name[]= $v['NAME'];
}
$temp[$key]['SELECT_AREA'] = implode(',',$area_name);
}
$dataProvider->setModels($temp);
return $dataProvider;
}
}
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