iron
5 years ago
35 changed files with 1595 additions and 493 deletions
-
6api/config/main.php
-
1api/logic/AddressLogic.php
-
1api/logic/CartLogic.php
-
1api/logic/CollectionLogic.php
-
1api/logic/CommentLogic.php
-
203api/logic/ExpressLogic.php
-
1api/logic/OrderLogic.php
-
63backend/modules/file/logic/file/FileManager.php
-
5backend/modules/goods/controllers/CategoryController.php
-
16backend/modules/goods/controllers/GoodsController.php
-
5backend/modules/goods/controllers/ShopCategoryController.php
-
114backend/modules/goods/logic/goods/GoodsManager.php
-
26backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php
-
40backend/modules/goods/models/ars/Goods.php
-
2backend/modules/goods/models/ars/GoodsSku.php
-
6backend/modules/goods/views/goods/create.php
-
60backend/modules/goods/views/goods/express.php
-
6backend/modules/goods/views/goods/picture.php
-
6backend/modules/goods/views/goods/update.php
-
263backend/modules/shop/controllers/ExpressTemplateController.php
-
32backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php
-
36backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php
-
101backend/modules/shop/models/ars/ExpressArea.php
-
27backend/modules/shop/models/ars/ExpressTemplate.php
-
187backend/modules/shop/models/searchs/ExpressAreaSearch.php
-
37backend/modules/shop/models/searchs/ExpressTemplateSearch.php
-
143backend/modules/shop/views/express-template/_form.php
-
34backend/modules/shop/views/express-template/create.php
-
51backend/modules/shop/views/express-template/express_area_create.php
-
156backend/modules/shop/views/express-template/express_area_form.php
-
33backend/modules/shop/views/express-template/express_area_list.php
-
52backend/modules/shop/views/express-template/express_area_update.php
-
94backend/modules/shop/views/express-template/express_area_view.php
-
34backend/modules/shop/views/express-template/update.php
-
67vendor/iron/grid/GridView.php
@ -0,0 +1,203 @@ |
|||
<?php |
|||
|
|||
namespace api\logic; |
|||
|
|||
|
|||
use backend\modules\goods\models\ars\Goods; |
|||
use backend\modules\shop\models\ars\ExpressArea; |
|||
use backend\modules\shop\models\ars\ExpressTemplate; |
|||
use backend\modules\shop\models\ars\Order; |
|||
use backend\modules\shop\models\ars\OrderGoods; |
|||
use Yii; |
|||
use yii\base\BaseObject; |
|||
use yii\web\NotFoundHttpException; |
|||
|
|||
/** |
|||
* @author iron |
|||
* @email weiriron@gmail.com |
|||
* @package api\logic |
|||
*/ |
|||
class ExpressLogic extends BaseObject |
|||
{ |
|||
public $viewAction = 'view'; |
|||
/** |
|||
* @var Order |
|||
* 订单 |
|||
*/ |
|||
public $order; |
|||
|
|||
/** |
|||
* @param $order |
|||
* @return float|int |
|||
* @throws NotFoundHttpException |
|||
* 计算运费 |
|||
*/ |
|||
public function countShippingAmount($order) |
|||
{ |
|||
if ($order->shipping_type == Order::SHIPPING_TYPE_PICKED_UP) { |
|||
return 0; |
|||
} |
|||
$this->order = $order; |
|||
$allGoods = $this->findDifferentExpressTypeGoods($order);/*获取不同运费计算模式的商品*/ |
|||
$uniformPostage = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTAGE);/*计算统一运费模式下所有商品运费*/ |
|||
$expressTemplate = $this->countGoodsExpress($allGoods['uniformPostageGoods'], Goods::EXPRESS_TYPE_UNIFORM_POSTATE);/*计算运费模板模式下所有商品的运费*/ |
|||
return $uniformPostage > $expressTemplate ? $uniformPostage : $expressTemplate;/*比较两种不同运费计算模式下,取金额大的值为最终收取运费*/ |
|||
} |
|||
|
|||
/*--------------------------------------------------------------------------------------*/ |
|||
/** |
|||
* @param $order |
|||
* @return array |
|||
* @throws NotFoundHttpException |
|||
* |
|||
*/ |
|||
private function findDifferentExpressTypeGoods($order) |
|||
{ |
|||
$uniformPostage = $useTemplate = []; |
|||
$allGoods = OrderGoods::findAll(['order_id' => $order->id, 'user_id' => Yii::$app->user->getId()]); |
|||
foreach ($allGoods as $orderGoods) { |
|||
$goods = Goods::findOne(['id' => $orderGoods->goods_id, 'is_sale' => Goods::IS_SALE_YES, 'is_delete' => Goods::IS_DELETE_NO]); |
|||
if (!$goods) { |
|||
throw new NotFoundHttpException('商品未找到'); |
|||
} |
|||
$goodsArr['object'] = $goods; |
|||
$goodsArr['count'] = $orderGoods->goods_count; |
|||
$goodsArr['weight'] = $orderGoods->weight; |
|||
if ($goods->is_express && $goods->express_type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE) { |
|||
$uniformPostage[] = $goodsArr; |
|||
} |
|||
if ($goods->is_express && $goods->express_type == Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE) { |
|||
$useTemplate[] = $goodsArr; |
|||
} |
|||
} |
|||
return ['uniformPostageGoods' => $uniformPostage, 'useTemplateGoods' => $useTemplate]; |
|||
} |
|||
|
|||
/** |
|||
* @param $allGoods |
|||
* @param $type |
|||
* @return float|int |
|||
* @throws NotFoundHttpException |
|||
*/ |
|||
private function countGoodsExpress($allGoods, $type) |
|||
{ |
|||
if (!$type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE) { |
|||
$amount = 0; |
|||
foreach ($allGoods['object'] as $goods) { |
|||
$amount = $goods->uniform_postage > $amount ? $goods->uniform_postage : $amount; |
|||
} |
|||
return $amount; |
|||
} else { |
|||
$extraPrice = 0; |
|||
$areasIds = []; |
|||
foreach ($allGoods['object'] as $k => $goods) { |
|||
$extraPrice += $this->countExtraAmount($allGoods['count'][$k], $allGoods['weight'][$k], $goods->express_template); |
|||
$areasIds[] = $this->getAreaId($goods->express_template); |
|||
} |
|||
$basic = $this->getBasicPriceAndAreaId($areasIds); |
|||
return $basic['price'] + $extraPrice - $this->countSurplusPrice($basic['id']); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param $areaId |
|||
* @return float|int |
|||
* @throws NotFoundHttpException |
|||
* 计算多余(多算的)运费 |
|||
* 选定的作为基础运费的计费规则的对应商品基础数量内的扩展费用 |
|||
*/ |
|||
private function countSurplusPrice($areaId) |
|||
{ |
|||
$area = $this->findArea($areaId); |
|||
return $area->extra_price * ceil($area->basic_count / $area->extra_count); |
|||
} |
|||
|
|||
/** |
|||
* @param $areaIds |
|||
* @return array |
|||
* @throws NotFoundHttpException |
|||
* 获取基础运费 |
|||
*/ |
|||
private function getBasicPriceAndAreaId($areaIds) |
|||
{ |
|||
$basePrice = $id = 0; |
|||
foreach ($areaIds as $areasId) { |
|||
$area = $this->findArea($areasId); |
|||
if (!$area->basic_price > $basePrice) { |
|||
continue; |
|||
} |
|||
$basePrice = $area->basic_price; |
|||
$id = $areasId; |
|||
} |
|||
return ['price' => $basePrice, 'id' => $id]; |
|||
} |
|||
|
|||
/** |
|||
* @param $count |
|||
* @param $weight |
|||
* @param $templateId |
|||
* @return float|int |
|||
* @throws NotFoundHttpException |
|||
* 计算扩展运费 |
|||
*/ |
|||
private function countExtraAmount($count, $weight, $templateId) |
|||
{ |
|||
$area = $this->findArea($this->getAreaId($templateId)); |
|||
$template = $this->findTemplate($templateId); |
|||
if ($template->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|||
$amount = $area->extra_price * ceil($weight / $area->extra_count); |
|||
} else { |
|||
$amount = $area->extra_price * ceil($count / $area->extra_count); |
|||
} |
|||
return $amount; |
|||
} |
|||
|
|||
/** |
|||
* @param $templateId |
|||
* @return int |
|||
* @throws NotFoundHttpException |
|||
* 根据运费模板和收货地址获取区域 |
|||
*/ |
|||
private function getAreaId($templateId) |
|||
{ |
|||
$areas = ExpressArea::findALl(['express_template' => $templateId]); |
|||
$city = $this->order->city; |
|||
foreach ($areas as $area) { |
|||
$allCity = explode(',', $area->city); |
|||
if (in_array($city, $allCity)) { |
|||
return $area->id; |
|||
} |
|||
} |
|||
throw new NotFoundHttpException('超出配送范围(无对应地区运费计算规则)'); |
|||
} |
|||
|
|||
/** |
|||
* @param $areaId |
|||
* @return ExpressArea|null |
|||
* @throws NotFoundHttpException |
|||
* 获取对应区域 |
|||
*/ |
|||
private function findArea($areaId) |
|||
{ |
|||
$area = ExpressArea::findOne($areaId); |
|||
if (!$area) { |
|||
throw new NotFoundHttpException('模板地区未找到'); |
|||
} |
|||
return $area; |
|||
} |
|||
|
|||
/** |
|||
* @param $templateId |
|||
* @return ExpressTemplate|null |
|||
* @throws NotFoundHttpException |
|||
* 获取运费模板 |
|||
*/ |
|||
private function findTemplate($templateId) |
|||
{ |
|||
$template = ExpressTemplate::findOne($templateId); |
|||
if (!$template) { |
|||
throw new NotFoundHttpException('运费模板未找到'); |
|||
} |
|||
return $template; |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
<?php |
|||
|
|||
use yii\db\Migration; |
|||
|
|||
/** |
|||
* Class m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods |
|||
*/ |
|||
class m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods extends Migration |
|||
{ |
|||
public function up() |
|||
{ |
|||
$this->addColumn('atg_goods', 'is_taking', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否自提')); |
|||
$this->addColumn('atg_goods', 'is_express', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否快递发货')); |
|||
$this->addColumn('atg_goods', 'express_type', $this->tinyInteger(2)->defaultValue(0)->comment('快递运费方式')); |
|||
$this->addColumn('atg_goods', 'uniform_postage', $this->integer(20)->defaultValue(0)->comment('统一邮费')); |
|||
} |
|||
|
|||
public function down() |
|||
{ |
|||
$this->dropColumn('atg_goods', 'is_taking'); |
|||
$this->dropColumn('atg_goods', 'is_express'); |
|||
$this->dropColumn('atg_goods', 'express_type'); |
|||
$this->dropColumn('atg_goods', 'uniform_postage'); |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Url; |
|||
use blobt\widgets\Icheck; |
|||
use backend\modules\goods\models\ars\Goods; |
|||
use linyao\widgets\Select2; |
|||
use backend\modules\shop\models\ars\ExpressTemplate; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\goods\models\ars\Goods */ |
|||
/* @var $form yii\widgets\ActiveForm */ |
|||
?>
|
|||
<?= $form->field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?>
|
|||
|
|||
<?= $form->field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?>
|
|||
|
|||
<fieldset id="isExpress" style="display: <?= $model->is_express == Goods::IS_EXPRESS_NO ? 'none' : 'block' ?>"> |
|||
<?= $form->field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?>
|
|||
|
|||
<fieldset id="uniformPostage" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE ? 'block' : 'none' ?>"> |
|||
<?= $form->field($model, 'uniform_postage')->textInput() ?>
|
|||
</fieldset> |
|||
|
|||
<fieldset id="expressTemplate" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_EXPRESS_TEMPLAGE ? 'block' : 'none' ?>"> |
|||
<?= $form->field($model, 'express_template')->widget(Select2::className(), ["items" => ExpressTemplate::modelColumn()]) ?>
|
|||
</fieldset> |
|||
</fieldset> |
|||
|
|||
<?php |
|||
$js =<<<JS |
|||
$("input:radio[name='Goods[is_express]']").on('ifChecked', function(event){ |
|||
if ($(this).val() === '1') { |
|||
$("#isExpress").show(); |
|||
} else { |
|||
$("#isExpress").hide(); |
|||
} |
|||
}) |
|||
$("input:radio[name='Goods[express_type]']").on('ifChecked', function(event){ |
|||
if ($(this).val() === '1') { |
|||
$("#uniformPostage").show(); |
|||
$("#expressTemplate").hide(); |
|||
} else { |
|||
$("#expressTemplate").show(); |
|||
$("#uniformPostage").hide(); |
|||
} |
|||
}) |
|||
$("#goods-uniform_postage").blur(function(){ |
|||
if(isNaN($(this).val())){ |
|||
$(this).val("0.00") |
|||
} |
|||
if($(this).val().indexOf('-') != -1){ |
|||
$(this).val("0.00") |
|||
} |
|||
var basicPrice = $(this).val(); |
|||
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); |
|||
}) |
|||
JS; |
|||
$this->registerJs($js); |
|||
|
|||
?>
|
@ -0,0 +1,32 @@ |
|||
<?php |
|||
|
|||
use yii\db\Migration; |
|||
|
|||
/** |
|||
* Class m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template |
|||
*/ |
|||
class m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template extends Migration |
|||
{ |
|||
public function up() |
|||
{ |
|||
$this->dropColumn('ats_express_template', 'province'); |
|||
$this->dropColumn('ats_express_template', 'city'); |
|||
$this->dropColumn('ats_express_template', 'area'); |
|||
$this->dropColumn('ats_express_template', 'extra_price'); |
|||
$this->dropColumn('ats_express_template', 'basic_price'); |
|||
$this->dropColumn('ats_express_template', 'basic_count'); |
|||
$this->dropColumn('ats_express_template', 'extra_count'); |
|||
} |
|||
|
|||
public function down() |
|||
{ |
|||
$this->addColumn('ats_express_template', 'province', $this->text()->comment('省份')); |
|||
$this->addColumn('ats_express_template', 'city', $this->text()->comment('城市')); |
|||
$this->addColumn('ats_express_template', 'area', $this->text()->comment('区域')); |
|||
$this->addColumn('ats_express_template', 'extra_price', $this->integer(20)->defaultValue(null)->comment('续重运费')); |
|||
$this->addColumn('ats_express_template', 'basic_price', $this->integer(20)->defaultValue(null)->comment('基本运费')); |
|||
$this->addColumn('ats_express_template', 'basic_count', $this->integer(20)->defaultValue(null)->comment('基本数量')); |
|||
$this->addColumn('ats_express_template', 'extra_count', $this->integer(20)->defaultValue(null)->comment('续重数量')); |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
use yii\db\Migration; |
|||
|
|||
/** |
|||
* Class m191205_092942_create_table_ats_express_area |
|||
*/ |
|||
class m191205_092942_create_table_ats_express_area extends Migration |
|||
{ |
|||
public function up() |
|||
{ |
|||
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT="快递区域价格表"'; |
|||
$this->createTable('ats_express_area', [ |
|||
'id' => $this->primaryKey(), |
|||
'province' => $this->text()->comment('省份'), |
|||
'city' => $this->text()->comment('城市'), |
|||
'area' => $this->text()->comment('区域'), |
|||
'express_template' => $this->integer(11)->defaultValue(null)->comment('运费模板id'), |
|||
'extra_price' => $this->integer(20)->defaultValue(null)->comment('续重运费'), |
|||
'basic_price' => $this->integer(20)->defaultValue(null)->comment('基本运费'), |
|||
'basic_count' => $this->integer(20)->defaultValue(null)->comment('基本数量'), |
|||
'extra_count' => $this->integer(20)->defaultValue(null)->comment('续重数量'), |
|||
'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), |
|||
'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), |
|||
],$tableOptions); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function down() |
|||
{ |
|||
$this->dropTable('ats_express_area'); |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,101 @@ |
|||
<?php |
|||
|
|||
namespace backend\modules\shop\models\ars; |
|||
|
|||
use Yii; |
|||
use yii\behaviors\TimestampBehavior; |
|||
|
|||
/** |
|||
* This is the model class for table "ats_express_area". |
|||
* |
|||
* @property int $id |
|||
* @property string $province 省份 |
|||
* @property string $city 城市 |
|||
* @property string $area 区域 |
|||
* @property int $express_template 运费模板id |
|||
* @property int $extra_price 续重运费 |
|||
* @property int $basic_price 基本运费 |
|||
* @property int $basic_count 基本数量 |
|||
* @property int $extra_count 续重数量 |
|||
* @property int $updated_at 更新时间 |
|||
* @property int $created_at 创建时间 |
|||
*/ |
|||
class ExpressArea extends \yii\db\ActiveRecord |
|||
{ |
|||
public static $formList = [ |
|||
1 => [ |
|||
"basic_count"=>"基本重量(KG)", |
|||
"basic_price"=>"基本运费(元)", |
|||
"extra_count"=>"续重重量(KG)", |
|||
"extra_price"=>"续重运费(元)" |
|||
], |
|||
2 => [ |
|||
"basic_count"=>"基本数量(件)", |
|||
"basic_price"=>"基本运费(元)", |
|||
"extra_count"=>"续重数量(件)", |
|||
"extra_price"=>"续重运费(元)" |
|||
] |
|||
]; |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public static function tableName() |
|||
{ |
|||
return 'ats_express_area'; |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
[['province', 'city', 'area'], 'string'], |
|||
[['express_template'], 'integer'], |
|||
[['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'], |
|||
[['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'number'], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function attributeLabels() |
|||
{ |
|||
return [ |
|||
'id' => 'id', |
|||
'province' => '省份', |
|||
'city' => '城市', |
|||
'area' => '区域', |
|||
'express_template' => '运费模板id', |
|||
'extra_price' => '续重运费', |
|||
'basic_price' => '基本运费', |
|||
'basic_count' => '基本数量', |
|||
'extra_count' => '续重数量', |
|||
'updated_at' => '更新时间', |
|||
'created_at' => '创建时间', |
|||
]; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* @author linyao |
|||
* @email 602604991@qq.com |
|||
* @created Nov 8, 2019 |
|||
* |
|||
* 行为存储创建时间和更新时间 |
|||
*/ |
|||
public function behaviors() |
|||
{ |
|||
return [ |
|||
[ |
|||
'class' => TimestampBehavior::className(), |
|||
'createdAtAttribute' => 'created_at', |
|||
'updatedAtAttribute' => 'updated_at', |
|||
'value' => function() { |
|||
return time(); |
|||
}, |
|||
], |
|||
]; |
|||
} |
|||
} |
@ -0,0 +1,187 @@ |
|||
<?php |
|||
|
|||
namespace backend\modules\shop\models\searchs; |
|||
|
|||
use backend\modules\shop\models\ars\City; |
|||
use backend\modules\shop\models\ars\Province; |
|||
use yii\base\Model; |
|||
use yii\data\ActiveDataProvider; |
|||
use yii\helpers\ArrayHelper; |
|||
use backend\modules\shop\models\ars\ExpressArea; |
|||
use yii; |
|||
use yii\bootstrap4\Html; |
|||
|
|||
/** |
|||
* ExpressAreaSearch represents the model behind the search form of `backend\modules\shop\models\ars\ExpressArea`. |
|||
*/ |
|||
class ExpressAreaSearch extends ExpressArea |
|||
{ |
|||
/** |
|||
* @return array |
|||
* 增加创建时间查询字段 |
|||
*/ |
|||
public function attributes() |
|||
{ |
|||
return ArrayHelper::merge(['created_at_range'], parent::attributes()); |
|||
} |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
[['id', 'express_template', 'extra_price', 'basic_price', 'basic_count', 'extra_count', 'updated_at', 'created_at'], 'integer'], |
|||
[['province', 'city', 'area'], 'safe'], |
|||
['created_at_range','safe'], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function scenarios() |
|||
{ |
|||
// bypass scenarios() implementation in the parent class
|
|||
return Model::scenarios(); |
|||
} |
|||
/** |
|||
* @return array |
|||
* 列格式 |
|||
*/ |
|||
public function columns() |
|||
{ |
|||
return [ |
|||
[ |
|||
'class' => 'blobt\grid\CheckboxColumn', |
|||
'width' => '2%', |
|||
'align' => 'center' |
|||
], |
|||
'id', |
|||
['attribute' => 'city', |
|||
'value' => function ($model) { |
|||
$expressAreas = ExpressArea::findOne($model->id); |
|||
$expressAresCityIdArr = explode(',', $expressAreas->city); |
|||
$cities = []; |
|||
$provinces = Province::find()->cache(0)->all(); |
|||
foreach ($provinces as $k => $v) { |
|||
$cityId = City::find() |
|||
->select(['city_id']) |
|||
->where(['province_id' => $v->province_id]) |
|||
->column(); |
|||
if (empty(array_diff($cityId, $expressAresCityIdArr))) { |
|||
$cities[] = $v->name; |
|||
}else{ |
|||
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { |
|||
$cities[] = $city->name; |
|||
} |
|||
} |
|||
} |
|||
return implode(' , ', $cities); |
|||
}, |
|||
], |
|||
[ |
|||
'class' => 'iron\grid\ActionColumn', |
|||
'align' => 'center', |
|||
'config' => [ |
|||
[ |
|||
'name' => 'express-area-view', |
|||
'icon' => 'list', |
|||
'title' => '详情', |
|||
], |
|||
[ |
|||
'name' => 'express-area-update', |
|||
'icon' => 'pencil', |
|||
'title' => '修改' |
|||
], |
|||
[ |
|||
'name' => 'express-area-delete', |
|||
'icon' => 'trash', |
|||
'title' => '删除', |
|||
'contents' => '确定删除?' |
|||
] |
|||
], |
|||
], |
|||
]; |
|||
} |
|||
/** |
|||
* @param $params |
|||
* @return ActiveDataProvider |
|||
* 不分页的所有数据 |
|||
*/ |
|||
public function allData($params) |
|||
{ |
|||
$query = ExpressArea::find(); |
|||
$dataProvider = new ActiveDataProvider([ |
|||
'query' => $query, |
|||
'pagination' => false, |
|||
'sort' => false |
|||
]); |
|||
$this->load($params); |
|||
return $this->filter($query, $dataProvider); |
|||
} |
|||
|
|||
/** |
|||
* Creates data provider instance with search query applied |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return ActiveDataProvider |
|||
*/ |
|||
public function search($params, $expressTemplateId) |
|||
{ |
|||
$query = ExpressArea::find()->where(['express_template' => $expressTemplateId]); |
|||
|
|||
// add conditions that should always apply here
|
|||
|
|||
$dataProvider = new ActiveDataProvider([ |
|||
'query' => $query, |
|||
'pagination' => [ |
|||
'pageSizeLimit' => [1, 200] |
|||
], |
|||
'sort' => [ |
|||
'defaultOrder' => [ |
|||
'id' => SORT_DESC, |
|||
] |
|||
], |
|||
]); |
|||
|
|||
$this->load($params); |
|||
return $this->filter($query, $dataProvider); |
|||
} |
|||
/** |
|||
* @param $query |
|||
* @param $dataProvider |
|||
* @return ActiveDataProvider |
|||
* 条件筛选 |
|||
*/ |
|||
private function filter($query, $dataProvider){ |
|||
if (!$this->validate()) { |
|||
// uncomment the following line if you do not want to return any records when validation fails
|
|||
// $query->where('0=1');
|
|||
return $dataProvider; |
|||
} |
|||
|
|||
// grid filtering conditions
|
|||
$query->andFilterWhere([ |
|||
'id' => $this->id, |
|||
'express_template' => $this->express_template, |
|||
'extra_price' => $this->extra_price, |
|||
'basic_price' => $this->basic_price, |
|||
'basic_count' => $this->basic_count, |
|||
'extra_count' => $this->extra_count, |
|||
'updated_at' => $this->updated_at, |
|||
'created_at' => $this->created_at, |
|||
]); |
|||
|
|||
$query->andFilterWhere(['like', 'province', $this->province]) |
|||
->andFilterWhere(['like', 'city', $this->city]) |
|||
->andFilterWhere(['like', 'area', $this->area]); |
|||
if ($this->created_at_range) { |
|||
$arr = explode(' ~ ', $this->created_at_range); |
|||
$start = strtotime($arr[0]); |
|||
$end = strtotime($arr[1]) + 3600 * 24; |
|||
$query->andFilterWhere(['between', 'created_at', $start, $end]); |
|||
} |
|||
return $dataProvider; |
|||
} |
|||
} |
@ -0,0 +1,51 @@ |
|||
<?php |
|||
|
|||
use yii\bootstrap4\Html; |
|||
use yii\bootstrap4\ActiveForm; |
|||
use kartik\tabs\TabsX; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
|||
|
|||
$this->title = '创建区域运费模板'; |
|||
$this->params['breadcrumbs'][] = ['label' => '运费区域模板', 'url' => ['express_area_list', ['id' => $expressTemplateModel->id]]]; |
|||
$this->params['breadcrumbs'][] = $this->title; |
|||
Yii::$app->params['bsVersion'] = '4.x'; |
|||
?>
|
|||
<div class="express-template-create"> |
|||
<div class="express-template-form"> |
|||
|
|||
<?php |
|||
$form = ActiveForm::begin(['options' => ['class' => 'container-fluid']]); |
|||
|
|||
echo TabsX::widget([ |
|||
'bordered' => true, |
|||
'items' => [ |
|||
[ |
|||
'label' => '<i class="fas fa-user"></i> 基本信息', |
|||
'content' => $this->render('express_area_form', [ |
|||
'model' => $model, |
|||
'form' => $form, |
|||
'expressTemplateModel' => $expressTemplateModel |
|||
]), |
|||
], |
|||
[ |
|||
'label' => '<i class="fas fa-globe"></i> 选择配送区域', |
|||
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] |
|||
]), |
|||
], |
|||
], |
|||
'position' => TabsX::POS_ABOVE, |
|||
'encodeLabels' => false |
|||
]); |
|||
?>
|
|||
|
|||
<div class="form-group"> |
|||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|||
<?= Html::a('返回', ['express-area-list', 'id' => $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
|
|||
</div> |
|||
|
|||
<?php ActiveForm::end(); ?>
|
|||
|
|||
</div> |
|||
</div> |
@ -0,0 +1,156 @@ |
|||
<?php |
|||
|
|||
use blobt\widgets\Icheck; |
|||
use backend\modules\shop\models\ars\ExpressTemplate; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
|||
/* @var $form yii\widgets\ActiveForm */ |
|||
?>
|
|||
|
|||
<?php |
|||
$status = Yii::$app->request->get('status'); |
|||
if ($status == 1) { |
|||
?>
|
|||
<div class="alert alert-warning alert-dismissible" role="alert"> |
|||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span |
|||
aria-hidden="true">×</span></button> |
|||
<p style="color: #2e2e2e">必须至少选择一个城市为配送区域</p> |
|||
</div> |
|||
<?php } ?>
|
|||
|
|||
<?= $form->field($model, 'express_template')->textInput(['maxlength' => true]) ?>
|
|||
|
|||
<?= $form->field($model, 'basic_count')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'basic_price')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'extra_count')->textInput() ?>
|
|||
|
|||
<?= $form->field($model, 'extra_price')->textInput() ?>
|
|||
|
|||
<?php |
|||
$js=<<<JS |
|||
const formList = [//切换时,class对应的标题
|
|||
{ |
|||
"field-expressarea-basic_count":"基本重量(KG)", |
|||
"field-expressarea-basic_price":"基本运费(元)", |
|||
"field-expressarea-extra_count":"续重重量(KG)", |
|||
"field-expressarea-extra_price":"续重运费(元)" |
|||
|
|||
}, |
|||
|
|||
{ |
|||
"field-expressarea-basic_count":"基本数量(件)", |
|||
"field-expressarea-basic_price":"基本运费(元)", |
|||
"field-expressarea-extra_count":"续重数量(件)", |
|||
"field-expressarea-extra_price":"续重运费(元)" |
|||
|
|||
} |
|||
] |
|||
const udfVal = [//初始值
|
|||
[0.1,"0.00"], |
|||
[1,"0.00"] |
|||
] |
|||
var calType = {$expressTemplateModel->calculation_type}-1;//初始的计算方式0:计重 1:计件
|
|||
|
|||
function updateTypeChangeCalType(type){//当切换计算方式
|
|||
|
|||
$.each(formList[type],function(index,value){ //更改文字标题
|
|||
$("." + index).children("label").html(value) |
|||
}); |
|||
|
|||
$("#expressarea-basic_count").val(udfVal[type][0])//重置初始值
|
|||
$("#expressarea-basic_price").val(udfVal[type][1]) |
|||
$("#expressarea-extra_count").val(0) |
|||
$("#expressarea-extra_price").val(udfVal[type][1]) |
|||
calType = type; |
|||
} |
|||
function changeCalType(type){//当切换计算方式
|
|||
|
|||
$.each(formList[type],function(index,value){ //更改文字标题
|
|||
$("." + index).children("label").html(value) |
|||
}); |
|||
|
|||
if(!$("#expressarea-basic_count").val()){ |
|||
$("#expressarea-basic_count").val(udfVal[type][0])//重置初始值
|
|||
} |
|||
if(!$("#expressarea-basic_price").val()){ |
|||
$("#expressarea-basic_price").val(udfVal[type][1]) |
|||
} |
|||
if(!$("#expressarea-extra_count").val()){ |
|||
$("#expressarea-extra_count").val(0) |
|||
} |
|||
if(!$("#expressarea-extra_price").val()){ |
|||
$("#expressarea-extra_price").val(udfVal[type][1]) |
|||
} |
|||
calType = type; |
|||
} |
|||
$(document).ready(function(){ |
|||
$("#expressarea-basic_count").blur(function(){ |
|||
if(isNaN($(this).val())){ |
|||
$(this).val(1) |
|||
} |
|||
if (calType == 0) { |
|||
if($(this).val() < 0.1){ |
|||
$(this).val(1) |
|||
} |
|||
var basiccount = $(this).val(); |
|||
// $(this).val(Math.floor(basiccount * 10) / 10);
|
|||
$(this).val(basiccount.toString().match(/^\d+(?:\.\d{0,1})?/)); |
|||
} else{ |
|||
if($(this).val() < 1){ |
|||
$(this).val(1) |
|||
} |
|||
var basiccount = $(this).val(); |
|||
$(this).val(Math.floor(basiccount * 1) / 1); |
|||
} |
|||
}) |
|||
$("#expressarea-basic_price").blur(function(){ |
|||
if(isNaN($(this).val())){ |
|||
$(this).val("0.00") |
|||
} |
|||
if($(this).val().indexOf('-') != -1){ |
|||
$(this).val("0.00") |
|||
} |
|||
var basicPrice = $(this).val(); |
|||
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); |
|||
}) |
|||
$("#expressarea-extra_count").blur(function(){ |
|||
if(isNaN($(this).val())){ |
|||
$(this).val(0) |
|||
} |
|||
if (calType == 0) { |
|||
if($(this).val() < 0){ |
|||
$(this).val(0) |
|||
} |
|||
var basiccount = $(this).val(); |
|||
$(this).val(Math.floor(basiccount * 10) / 10); |
|||
} else{ |
|||
if($(this).val() < 0){ |
|||
$(this).val(0) |
|||
} |
|||
var basiccount = $(this).val(); |
|||
$(this).val(Math.floor(basiccount * 1) / 1); |
|||
} |
|||
}) |
|||
$("#expressarea-extra_price").blur(function(){ |
|||
if(isNaN($(this).val())){ |
|||
$(this).val("0.00") |
|||
} |
|||
if($(this).val().indexOf('-') != -1){ |
|||
$(this).val("0.00") |
|||
} |
|||
var basicPrice = $(this).val(); |
|||
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); |
|||
}) |
|||
|
|||
$("input:radio[name='ExpressArea[calculation_type]']").on('ifChecked', function(event){ |
|||
updateTypeChangeCalType($(this).val()-1) |
|||
}) |
|||
changeCalType(calType) |
|||
}) |
|||
JS; |
|||
$this->registerJs($js) |
|||
|
|||
?>
|
@ -0,0 +1,33 @@ |
|||
<?php |
|||
|
|||
use yii\helpers\Html; |
|||
use iron\grid\GridView; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $searchModel backend\modules\shop\models\searchs\ExpressAreaSearch */ |
|||
/* @var $dataProvider yii\data\ActiveDataProvider */ |
|||
|
|||
$this->title = '运费区域模板:'.$expressTemplate->name; |
|||
$this->params['breadcrumbs'][] = $this->title; |
|||
?>
|
|||
<div class="row"> |
|||
<div class="col-12"> |
|||
<?= GridView::widget([ |
|||
'dataProvider' => $dataProvider, |
|||
'filter' => $this->render("_search", ['model' => $searchModel]), |
|||
'batch' => [ |
|||
[ |
|||
"label" => "删除", |
|||
"url" => "express-area/deletes" |
|||
], |
|||
], |
|||
'columns' => $columns, |
|||
'batchTemplate' => '', |
|||
'create' => '', |
|||
'export' => '', |
|||
'content' => Html::a('创建', ['express-area-create', 'expressTemplateId' => $expressTemplate->id], ['class' => 'btn btn-default']). |
|||
Html::a('返回', ['index'], ['class' => 'btn btn-default']) |
|||
]); |
|||
?>
|
|||
</div> |
|||
</div> |
@ -0,0 +1,52 @@ |
|||
<?php |
|||
|
|||
use yii\bootstrap4\Html; |
|||
use yii\bootstrap4\ActiveForm; |
|||
use kartik\tabs\TabsX; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
|||
|
|||
$this->title = '编辑区域运费模板'; |
|||
$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; |
|||
$this->params['breadcrumbs'][] = ['label' => '区域运费模板:'.$expressTemplateModel->name, 'url' => ['express-area-list', 'id' => $expressTemplateModel->id]]; |
|||
$this->params['breadcrumbs'][] = '编辑区域运费模板'; |
|||
Yii::$app->params['bsVersion'] = '4.x'; |
|||
?>
|
|||
<div class="express-template-update"> |
|||
<div class="express-template-form"> |
|||
|
|||
<?php |
|||
$form = ActiveForm::begin(['options' => ['class' => 'container-fluid']]); |
|||
|
|||
echo TabsX::widget([ |
|||
'bordered' => true, |
|||
'items' => [ |
|||
[ |
|||
'label' => '<i class="fas fa-user"></i> 基本信息', |
|||
'content' => $this->render('express_area_form', [ |
|||
'model' => $model, |
|||
'form' => $form, |
|||
'expressTemplateModel' => $expressTemplateModel |
|||
]), |
|||
], |
|||
[ |
|||
'label' => '<i class="fas fa-globe"></i> 选择配送区域', |
|||
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities |
|||
]), |
|||
], |
|||
], |
|||
'position' => TabsX::POS_ABOVE, |
|||
'encodeLabels' => false |
|||
]); |
|||
?>
|
|||
|
|||
<div class="form-group"> |
|||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|||
<?= Html::a('返回', ['express-area-list', 'id' => $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
|
|||
</div> |
|||
|
|||
<?php ActiveForm::end(); ?>
|
|||
|
|||
</div> |
|||
</div> |
@ -0,0 +1,94 @@ |
|||
<?php |
|||
|
|||
use backend\modules\shop\models\ars\City; |
|||
use backend\modules\shop\models\ars\ExpressArea; |
|||
use backend\modules\shop\models\ars\Province; |
|||
use yii\helpers\Html; |
|||
use yii\widgets\DetailView; |
|||
use backend\modules\shop\models\ars\ExpressTemplate; |
|||
|
|||
/* @var $this yii\web\View */ |
|||
/* @var $model backend\modules\shop\models\ars\ExpressTemplate */ |
|||
|
|||
$this->title = $model->id; |
|||
$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; |
|||
$this->params['breadcrumbs'][] = ['label' => '运费区域模板:'.$expressTemplateModel->name, 'url' => ['express-area-list?id='.$expressTemplateModel->id]]; |
|||
$this->params['breadcrumbs'][] = $this->title; |
|||
\yii\web\YiiAsset::register($this); |
|||
?>
|
|||
<div class="express-template-view"> |
|||
|
|||
<p> |
|||
<?= Html::a('返回列表', ['express-area-list?id='.$expressTemplateModel->id], ['class' => 'btn btn-success']) ?>
|
|||
</p> |
|||
|
|||
<?= DetailView::widget([ |
|||
'model' => $model, |
|||
'attributes' => [ |
|||
'id', |
|||
[ |
|||
'attribute' => 'basic_count', |
|||
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_count'], |
|||
'value' => function ($model) { |
|||
$expressTemplateModel = ExpressTemplate::findOne($model->express_template); |
|||
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|||
return $model->basic_count /= 10; |
|||
} else { |
|||
return $model->basic_count; |
|||
} |
|||
} |
|||
], |
|||
[ |
|||
'attribute' => 'basic_price', |
|||
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_price'], |
|||
'value' => function ($model) { |
|||
return $model->basic_price /= 100; |
|||
} |
|||
], |
|||
[ |
|||
'attribute' => 'extra_count', |
|||
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_count'], |
|||
'value' => function ($model) { |
|||
$expressTemplateModel = ExpressTemplate::findOne($model->express_template); |
|||
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|||
return $model->extra_count /= 10; |
|||
} else { |
|||
return $model->extra_count; |
|||
} |
|||
} |
|||
], |
|||
[ |
|||
'attribute' => 'extra_price', |
|||
'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_price'], |
|||
'value' => function ($model) { |
|||
return $model->extra_price /= 100; |
|||
} |
|||
], |
|||
'updated_at:datetime', |
|||
'created_at:datetime', |
|||
['attribute' => 'city', |
|||
'value' => function ($model) { |
|||
$expressAreas = ExpressArea::findOne($model->id); |
|||
$expressAresCityIdArr = explode(',', $expressAreas->city); |
|||
$cities = []; |
|||
$provinces = Province::find()->cache(0)->all(); |
|||
foreach ($provinces as $k => $v) { |
|||
$cityId = City::find() |
|||
->select(['city_id']) |
|||
->where(['province_id' => $v->province_id]) |
|||
->column(); |
|||
if (empty(array_diff($cityId, $expressAresCityIdArr))) { |
|||
$cities[] = $v->name; |
|||
}else{ |
|||
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { |
|||
$cities[] = $city->name; |
|||
} |
|||
} |
|||
} |
|||
return implode(' , ', $cities); |
|||
}, |
|||
], |
|||
], |
|||
]) ?>
|
|||
|
|||
</div> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue