Browse Source

Merge branch 'antshop' into kernel

wechat_public_accounts
root 5 years ago
parent
commit
3f53377e2e
  1. 8
      backend/modules/goods/controllers/GoodsController.php
  2. 8
      backend/modules/goods/logic/goods/GoodsManager.php
  3. 23
      backend/modules/goods/migrations/m191209_091129_update_columns_in_table_atg_goods.php
  4. 20
      backend/modules/goods/migrations/m191209_091524_add_column_weight_in_table_atg_goods_sku.php
  5. 17
      backend/modules/goods/migrations/sql/update_goods.sql
  6. 5
      backend/modules/goods/models/ars/GoodsSku.php
  7. 10
      backend/modules/goods/views/goods/express.php
  8. 20
      backend/modules/goods/views/goods/goods.php
  9. 8
      backend/modules/shop/controllers/ExpressTemplateController.php

8
backend/modules/goods/controllers/GoodsController.php

@ -101,9 +101,6 @@ class GoodsController extends Controller
$model->is_express = Goods::IS_EXPRESS_YES; $model->is_express = Goods::IS_EXPRESS_YES;
$model->express_type = Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE; $model->express_type = Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE;
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->uniform_postage) {
$model->uniform_postage *= 100;
}
//商品封面图和商品详情图上传保存处理 //商品封面图和商品详情图上传保存处理
$res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model);
if ($res['status']) { if ($res['status']) {
@ -133,9 +130,6 @@ class GoodsController extends Controller
$cover_image_old_id_str = $model->image; $cover_image_old_id_str = $model->image;
$detail_image_old_id_str = $model->detailImageId; $detail_image_old_id_str = $model->detailImageId;
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->uniform_postage) {
$model->uniform_postage *= 100;
}
//商品封面图和商品详情图上传保存处理 //商品封面图和商品详情图上传保存处理
$res = GoodsManager::updateGoods(Yii::$app->request->post(), $model, $cover_image_old_id_str, $detail_image_old_id_str); $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model, $cover_image_old_id_str, $detail_image_old_id_str);
if ($res['status']) { if ($res['status']) {
@ -143,6 +137,8 @@ class GoodsController extends Controller
} }
} }
$model->uniform_postage /= 100; $model->uniform_postage /= 100;
$model->market_price /= 100;
$model->price /= 100;
$attributeModel = GoodsManager::getAttribute($id); $attributeModel = GoodsManager::getAttribute($id);
$checkAttr = GoodsManager::getSkuInfo($id); $checkAttr = GoodsManager::getSkuInfo($id);
$filterAttributeModel = GoodsManager::getFilterAttribute($id); $filterAttributeModel = GoodsManager::getFilterAttribute($id);

8
backend/modules/goods/logic/goods/GoodsManager.php

@ -73,6 +73,9 @@ class GoodsManager
{ {
$attribute = $data['attribute']; $attribute = $data['attribute'];
$filterAttribute = $data['filterattribute']; $filterAttribute = $data['filterattribute'];
$model->uniform_postage *= 100;
$model->market_price *= 100;
$model->price *= 100;
$tra = Yii::$app->db->beginTransaction(); $tra = Yii::$app->db->beginTransaction();
try { try {
if (!$model->save()) { if (!$model->save()) {
@ -300,7 +303,7 @@ class GoodsManager
$data['id'] = $sku->id; $data['id'] = $sku->id;
$data['price'] = $sku->price; $data['price'] = $sku->price;
$data['stock'] = $sku->stock; $data['stock'] = $sku->stock;
$data['weight'] = $sku->weight;
$data['weight'] = $sku->weight/1000;
return $data; return $data;
} }
@ -395,7 +398,7 @@ class GoodsManager
$goodsSku->goods_id = $goodsId; $goodsSku->goods_id = $goodsId;
$goodsSku->price = $sku['price']; $goodsSku->price = $sku['price'];
$goodsSku->stock = $sku['stock']; $goodsSku->stock = $sku['stock'];
$goodsSku->weight = $sku['weight'];
$goodsSku->weight = $sku['weight']*1000;
$goodsSku->goods_sn = $goodsModel->sn; $goodsSku->goods_sn = $goodsModel->sn;
if (!$goodsSku->save()) { if (!$goodsSku->save()) {
throw new \Exception('保存失败,请检查是否有重复规格'); throw new \Exception('保存失败,请检查是否有重复规格');
@ -405,6 +408,7 @@ class GoodsManager
if (!$goods->save()) { if (!$goods->save()) {
throw new \Exception('商品sku类型修改失败'); throw new \Exception('商品sku类型修改失败');
} }
$tra->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
$tra->rollBack(); $tra->rollBack();
throw new \Exception($e->getMessage()); throw new \Exception($e->getMessage());

23
backend/modules/goods/migrations/m191209_091129_update_columns_in_table_atg_goods.php

@ -0,0 +1,23 @@
<?php
use yii\db\Migration;
/**
* Class m191209_091129_update_columns_in_table_atg_goods
*/
class m191209_091129_update_columns_in_table_atg_goods extends Migration
{
public function up()
{
$sql = file_get_contents(__DIR__."/sql/update_goods.sql");
$this->execute($sql);
}
/**
* {@inheritdoc}
*/
public function down()
{
return true;
}
}

20
backend/modules/goods/migrations/m191209_091524_add_column_weight_in_table_atg_goods_sku.php

@ -0,0 +1,20 @@
<?php
use yii\db\Migration;
/**
* Class m191209_091524_add_column_weight_in_table_atg_goods_sku
*/
class m191209_091524_add_column_weight_in_table_atg_goods_sku extends Migration
{
public function up()
{
$this->addColumn('atg_goods_sku', 'weight', $this->integer(8)->defaultValue("0")->unsigned()->comment('重量'));
}
public function down()
{
$this->dropColumn('atg_goods_sku', 'weight');
return true;
}
}

17
backend/modules/goods/migrations/sql/update_goods.sql

@ -0,0 +1,17 @@
ALTER TABLE `atg_goods` DROP `weight`;
ALTER TABLE `atg_goods` DROP `length`;
ALTER TABLE `atg_goods` DROP `width`;
ALTER TABLE `atg_goods` DROP `height`;
ALTER TABLE `atg_goods` DROP `diameter`;
ALTER TABLE `atg_goods` DROP `sold_count`;
ALTER TABLE `atg_goods` DROP `market_price`;
ALTER TABLE `atg_goods` DROP `price`;
ALTER TABLE `atg_goods` ADD COLUMN `weight` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '重量';
ALTER TABLE `atg_goods` ADD COLUMN `length` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '长度';
ALTER TABLE `atg_goods` ADD COLUMN `width` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '宽度';
ALTER TABLE `atg_goods` ADD COLUMN `height` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '高度';
ALTER TABLE `atg_goods` ADD COLUMN `diameter` mediumint(8) UNSIGNED DEFAULT NULL COMMENT '直径';
ALTER TABLE `atg_goods` ADD COLUMN `sold_count` int(10) UNSIGNED DEFAULT NULL COMMENT '已售数量';
ALTER TABLE `atg_goods` ADD COLUMN `market_price` int(20) UNSIGNED DEFAULT NULL COMMENT '市场价';
ALTER TABLE `atg_goods` ADD COLUMN `price` int(20) UNSIGNED DEFAULT NULL COMMENT '销售价';

5
backend/modules/goods/models/ars/GoodsSku.php

@ -24,6 +24,7 @@ use yii\behaviors\TimestampBehavior;
* @property int $created_at 创建时间 * @property int $created_at 创建时间
* @property int $updated_at 更新时间 * @property int $updated_at 更新时间
* @property int $is_manaul 是否手动 * @property int $is_manaul 是否手动
* @property int $weight 重量
*/ */
class GoodsSku extends \yii\db\ActiveRecord class GoodsSku extends \yii\db\ActiveRecord
{ {
@ -48,9 +49,10 @@ class GoodsSku extends \yii\db\ActiveRecord
{ {
return [ return [
[['goods_id', 'goods_sn'], 'required'], [['goods_id', 'goods_sn'], 'required'],
[['goods_id', 'diameter', 'sold_count', 'stock', 'market_price', 'price', 'model_id', 'is_sale', 'sort_order', 'is_delete', 'is_manaul'], 'integer'],
[['goods_id', 'sold_count', 'stock', 'market_price', 'price', 'model_id', 'is_sale', 'sort_order', 'is_delete', 'is_manaul'], 'integer'],
[['goods_code'], 'string', 'max' => 50], [['goods_code'], 'string', 'max' => 50],
[['goods_sn', 'goods_attr'], 'string', 'max' => 60], [['goods_sn', 'goods_attr'], 'string', 'max' => 60],
[['weight'], 'safe']
]; ];
} }
@ -75,6 +77,7 @@ class GoodsSku extends \yii\db\ActiveRecord
'is_delete' => '是否删除,1为已删除', 'is_delete' => '是否删除,1为已删除',
'created_at' => '创建时间', 'created_at' => '创建时间',
'updated_at' => '更新时间', 'updated_at' => '更新时间',
'weight' => '重量',
]; ];
} }

10
backend/modules/goods/views/goods/express.php

@ -28,6 +28,12 @@ use backend\modules\shop\models\ars\ExpressTemplate;
<?php <?php
$js =<<<JS $js =<<<JS
$(document).ready(function(){
if(!$("#goods-uniform_postage").val()){
$("#goods-uniform_postage").val("0.00")
}else{
$("#goods-uniform_postage").val(toFixeds($("#goods-uniform_postage").val(), 2));
}
$("input:radio[name='Goods[is_express]']").on('ifChecked', function(event){ $("input:radio[name='Goods[is_express]']").on('ifChecked', function(event){
if ($(this).val() === '1') { if ($(this).val() === '1') {
$("#isExpress").show(); $("#isExpress").show();
@ -45,6 +51,9 @@ use backend\modules\shop\models\ars\ExpressTemplate;
} }
}) })
$("#goods-uniform_postage").blur(function(){ $("#goods-uniform_postage").blur(function(){
if(!$(this).val()){
$(this).val("0.00")
}
if(isNaN($(this).val())){ if(isNaN($(this).val())){
$(this).val("0.00") $(this).val("0.00")
} }
@ -74,6 +83,7 @@ use backend\modules\shop\models\ars\ExpressTemplate;
} }
return f; return f;
} }
})
JS; JS;
$this->registerJs($js); $this->registerJs($js);

20
backend/modules/goods/views/goods/goods.php

@ -64,24 +64,39 @@ use backend\modules\goods\models\ars\Goods;
</div> </div>
<?php <?php
$js =<<<JS $js =<<<JS
$(document).ready(function(){
if(!$("#goods-market_price").val()){
$("#goods-market_price").val("0.00")
}else{
$("#goods-market_price").val(toFixeds($("#goods-market_price").val(), 2));
}
if(!$("#goods-price").val()){
$("#goods-price").val("0.00")
}else{
$("#goods-price").val(toFixeds($("#goods-price").val(), 2));
}
$("#goods-market_price").blur(function(){ $("#goods-market_price").blur(function(){
if(!$(this).val()){
$(this).val("0.00")
}
if(isNaN($(this).val())){ if(isNaN($(this).val())){
$(this).val("0.00") $(this).val("0.00")
} }
if($(this).val().indexOf('-') != -1){ if($(this).val().indexOf('-') != -1){
$(this).val("0.00") $(this).val("0.00")
} }
var basicPrice = $(this).val();
$(this).val(toFixeds($(this).val(), 2)); $(this).val(toFixeds($(this).val(), 2));
}) })
$("#goods-price").blur(function(){ $("#goods-price").blur(function(){
if(!$(this).val()){
$(this).val("0.00")
}
if(isNaN($(this).val())){ if(isNaN($(this).val())){
$(this).val("0.00") $(this).val("0.00")
} }
if($(this).val().indexOf('-') != -1){ if($(this).val().indexOf('-') != -1){
$(this).val("0.00") $(this).val("0.00")
} }
var basicPrice = $(this).val();
$(this).val(toFixeds($(this).val(), 2)); $(this).val(toFixeds($(this).val(), 2));
}) })
//金额补全 //金额补全
@ -104,6 +119,7 @@ $js =<<<JS
} }
return f; return f;
} }
})
JS; JS;
$this->registerJs($js); $this->registerJs($js);

8
backend/modules/shop/controllers/ExpressTemplateController.php

@ -210,8 +210,8 @@ class ExpressTemplateController extends Controller
$model->basic_price *= 100; $model->basic_price *= 100;
$model->extra_price *= 100; $model->extra_price *= 100;
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) {
$model->basic_count *= 10;
$model->extra_count *= 10;
$model->basic_count *= 1000;
$model->extra_count *= 1000;
} else { } else {
$model->basic_count *= 1; $model->basic_count *= 1;
$model->extra_count *= 1; $model->extra_count *= 1;
@ -279,8 +279,8 @@ class ExpressTemplateController extends Controller
$model->basic_price *= 100; $model->basic_price *= 100;
$model->extra_price *= 100; $model->extra_price *= 100;
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) {
$model->basic_count *= 10;
$model->extra_count *= 10;
$model->basic_count *= 1000;
$model->extra_count *= 1000;
} else { } else {
$model->basic_count *= 1; $model->basic_count *= 1;
$model->extra_count *= 1; $model->extra_count *= 1;

Loading…
Cancel
Save