diff --git a/backend/modules/file/logic/file/FileManager.php b/backend/modules/file/logic/file/FileManager.php index 80d2f26..35edc15 100755 --- a/backend/modules/file/logic/file/FileManager.php +++ b/backend/modules/file/logic/file/FileManager.php @@ -5,17 +5,20 @@ namespace backend\modules\file\logic\file; use backend\modules\file\models\ars\File; use backend\modules\file\models\ars\TemFile; +use yii\web\HttpException; +use yii; class FileManager { //数据表ats_file和ats_tem_file的类型字段type + const TYPE_NONE = 0;//不存在 const TYPE_IMAGE = 1;//图片 const TYPE_VIDEO = 2;//影视 const TYPE_EXCEL = 3;//excel表单 const TYPE_WORD = 4;//word文本 const TYPE_TXT = 5;//txt文本 - public static $extension = [ + private $extension = [ self::TYPE_IMAGE => ['jpg', 'png', 'jpeg'], self::TYPE_VIDEO => ['mp4'], self::TYPE_EXCEL => [], @@ -24,54 +27,56 @@ class FileManager ]; /** - * @param $array * @param $keyword - * @return array - * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false + * @return int|string + * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回self::TYPE_NONE */ - public function searchType($array, $keyword) + public function searchType($keyword) { - foreach($array as $key => $value){ - foreach ($value as $k => $v) { - if($v == $keyword){ - return ['status' => true, 'info' => '操作成功', 'type' => $key]; - } + foreach($this->extension as $key => $type){ + if (in_array($keyword, $type)) { + return $key; } } - return ['status' => false, 'info' => '操作失败']; + return self::TYPE_NONE; } /** - * @param $temFIleIdArr + * @param $temFileIdArr * @param $ownId * @param $ownType - * @return array + * @return array|bool + * @throws \Exception * 根据临时文件id将临时文件保存在文件中 */ - public function saveTemFileToFile($temFIleIdArr, $ownId, $ownType) + public function saveTemFileToFile($temFileIdArr, $ownId, $ownType) { - if(!$temFIleIdArr || !$ownId) { - return ['status' => false, 'info' => '参数错误']; + if(empty($temFileIdArr) || !$ownId) { + return false; } - $firstFileId = 0; - foreach ($temFIleIdArr as $key => $value) { - $temFile = TemFile::findOne($value); + $tra = Yii::$app->db->beginTransaction(); + try { + $firstFileId = 0; + foreach ($temFileIdArr as $key => $value) { + $temFile = TemFile::findOne($value); - if(!$temFile) { - return ['status' => false, 'info' => '存在查找不到的文件']; - } + if (!$temFile) { + throw new \Exception('存在查找不到的文件'); + } - $res = self::saveNewFile($temFile, $ownId, $ownType); - if(!$res['status']) { - return ['status' => false, 'info' => '存在文件保存失败']; - } - if($key == 0) { - $firstFileId = $res['file_id']; + $res = self::saveNewFile($temFile, $ownId, $ownType); + if ($key == 0) { + $firstFileId = $res['file_id']; + } } - } - return ['status' => true, 'info' => '保存成功', 'first_file_id' => $firstFileId]; + $tra->commit(); + return ['status' => true, 'info' => '保存成功', 'first_file_id' => $firstFileId]; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); + } } /** @@ -79,6 +84,7 @@ class FileManager * @param $ownId * @param $ownType * @return array + * @throws HttpException * 创建新的文件 */ private function saveNewFile($temFile, $ownId, $ownType) @@ -93,13 +99,14 @@ class FileManager if($newFile->save()) { return ['status' => true, 'info' => '操作成功', 'file_id' => $newFile->id]; } else { - return ['status' => false, 'info' => '操作失败']; + throw new HttpException('500', 'File保存失败'); } } /** * @param $fileIdArr - * @return array + * @return bool + * @throws HttpException * 删除file表中的文件 */ public function deleteFile($fileIdArr) @@ -109,12 +116,12 @@ class FileManager $fileModel = File::findOne($value); if($fileModel){ $fileModel->is_delete = File::IS_DELETE_YES; - if($fileModel->save()){ - return ['status' => false, 'info' => '操作失败']; + if(!$fileModel->save()){ + throw new HttpException('500', '文件删除失败'); } } } } - return ['status' => true, 'info' => '操作成功']; + return true; } } \ No newline at end of file diff --git a/backend/modules/goods/controllers/CategoryController.php b/backend/modules/goods/controllers/CategoryController.php index 7cf5a09..305db28 100755 --- a/backend/modules/goods/controllers/CategoryController.php +++ b/backend/modules/goods/controllers/CategoryController.php @@ -201,10 +201,7 @@ class CategoryController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); diff --git a/backend/modules/goods/controllers/GoodsController.php b/backend/modules/goods/controllers/GoodsController.php index e0d4833..9284c30 100755 --- a/backend/modules/goods/controllers/GoodsController.php +++ b/backend/modules/goods/controllers/GoodsController.php @@ -11,6 +11,7 @@ use Yii; use backend\modules\goods\models\ars\Goods; use backend\modules\goods\models\searchs\GoodsSearch; use yii\web\Controller; +use yii\web\HttpException; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use backend\modules\goods\logic\goods\GoodsManager; @@ -96,7 +97,13 @@ class GoodsController extends Controller $model = new Goods(); $model->is_sale = Goods::IS_SALE_YES; $model->stock = -1; + $model->is_taking = Goods::IS_TAKING_NO; + $model->is_express = Goods::IS_EXPRESS_YES; + $model->express_type = Goods::EXPRESS_TYPE_EXPRESS_TEMPLAGE; 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); if ($res['status']) { @@ -126,12 +133,16 @@ class GoodsController extends Controller $cover_image_old_id_str = $model->image; $detail_image_old_id_str = $model->detailImageId; 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); if ($res['status']) { return $this->redirect('index'); } } + $model->uniform_postage /= 100; $attributeModel = GoodsManager::getAttribute($id); $checkAttr = GoodsManager::getSkuInfo($id); $filterAttributeModel = GoodsManager::getFilterAttribute($id); @@ -211,10 +222,7 @@ class GoodsController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); diff --git a/backend/modules/goods/controllers/ShopCategoryController.php b/backend/modules/goods/controllers/ShopCategoryController.php index 70d1515..c0feeec 100755 --- a/backend/modules/goods/controllers/ShopCategoryController.php +++ b/backend/modules/goods/controllers/ShopCategoryController.php @@ -212,10 +212,7 @@ class ShopCategoryController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); diff --git a/backend/modules/goods/logic/goods/GoodsManager.php b/backend/modules/goods/logic/goods/GoodsManager.php index ce534c8..eb0de2f 100755 --- a/backend/modules/goods/logic/goods/GoodsManager.php +++ b/backend/modules/goods/logic/goods/GoodsManager.php @@ -10,6 +10,7 @@ use backend\modules\goods\models\ars\GoodsSku; use backend\modules\goods\models\ars\Goods; use backend\modules\goods\models\ars\FilterAttr; use backend\modules\goods\models\ars\Category; +use yii\web\HttpException; class GoodsManager { @@ -19,36 +20,44 @@ class GoodsManager * @param array $oldFileIdArr * @param int $fileType * @return array + * @throws \Exception * 保存新文件,删除不需要的文件操作 */ public static function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $fileType = 1) { - //需要新建的文件id - $createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); + $tra = Yii::$app->db->beginTransaction(); + try { + //需要新建的文件id + $createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); - //创建文件 - $class = new \backend\modules\file\logic\file\FileManager(); - $createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); + //创建文件 + $class = new \backend\modules\file\logic\file\FileManager(); + $createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); - //需要删除的文件id - $delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); + //需要删除的文件id + $delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); - //删除文件 - $class->deleteFile($delFileIdArr); + //删除文件 + $class->deleteFile($delFileIdArr); - //记录第一张图片id - $firstFileId = 0; + //记录第一张图片id + $firstFileId = 0; - //查看修改数组是否为空 - if (!$newFileIdArr[0]) { - $firstFileId = null; - }else { - if ($createFileRes['status']) { - $firstFileId = $createFileRes['first_file_id']; + //查看修改数组是否为空 + if (!$newFileIdArr[0]) { + $firstFileId = null; + } else { + if ($createFileRes['status']) { + $firstFileId = $createFileRes['first_file_id']; + } } - } - return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; + $tra->commit(); + return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); + } } /** @@ -57,7 +66,7 @@ class GoodsManager * @param null $coverImageOldIdStr * @param null $detailImageOldIdStr * @return array - * @throws \Throwable + * @throws \Exception * 创建修改商品操作 */ public static function updateGoods($data, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) @@ -67,19 +76,15 @@ class GoodsManager $tra = Yii::$app->db->beginTransaction(); try { if (!$model->save()) { - throw new Exception(''); + throw new \Exception('商品保存失败'); } $saveCoverImageRes = self::saveFile(explode(',', $model->coverImageId), $model, explode(',', $coverImageOldIdStr)); $saveDetailImageRes = self::saveFile(explode(',', $model->detailImageId), $model, explode(',', $detailImageOldIdStr), File::OWN_TYPE_GOODS_DETAILS); - if ($saveCoverImageRes['status'] && $saveDetailImageRes['status']) { - if($saveCoverImageRes['first_file_id'] !== 0) { - $model->image = $saveCoverImageRes['first_file_id']; - if (!$model->save()) { - throw new Exception('图片保存失败'); - } + if($saveCoverImageRes['first_file_id'] !== 0) { + $model->image = $saveCoverImageRes['first_file_id']; + if (!$model->save()) { + throw new \Exception('图片保存失败'); } - } else { - throw new Exception('图片保存失败'); } self::addAttributeOperating(['id' => $model->id, 'attribute' => $attribute]); self::addFilterAttributeOperating(['id' => $model->id, 'filterAttribute' => $filterAttribute]); @@ -87,60 +92,71 @@ class GoodsManager return ['status' => true]; } catch (\yii\base\Exception $e) { $tra->rollBack(); - return ['status' => false, 'info' => $e->getMessage()]; + throw new \Exception($e->getMessage()); } } /** * @param $data * @return bool - * @throws Exception + * @throws \Exception * 创建修改商品属性操作 */ - public static function addAttributeOperating($data) + private static function addAttributeOperating($data) { - if (!$data['attribute']) { - return true; - } - $data['attribute'] = json_decode($data['attribute'], true); - $oldAttr = []; - $goodsAttr = GoodsAttr::find()->where(['goods_id' => $data['id'], 'is_delete' => GoodsAttr::IS_DELETE_NO])->all(); - if ($goodsAttr) { //如果商品有旧的属性 - if(count($data['attribute']) == 0 && is_array($data['attribute'])) { //如果传上来的是空数组,删除该商品下的全部属性 - self::delAttribute($goodsAttr); + $tra = Yii::$app->db->beginTransaction(); + try { + if (!$data['attribute']) { + $tra->commit(); return true; } - foreach ($goodsAttr as $key => $value) { //把旧的商品属性保存到一个数组 - $oldAttr[$value->id] = $value->attr_value; + $data['attribute'] = json_decode($data['attribute'], true); + $oldAttr = []; + $goodsAttr = GoodsAttr::find()->where(['goods_id' => $data['id'], 'is_delete' => GoodsAttr::IS_DELETE_NO])->all(); + if ($goodsAttr) { //如果商品有旧的属性 + if (count($data['attribute']) == 0 && is_array($data['attribute'])) { //如果传上来的是空数组,删除该商品下的全部属性 + self::delAttribute($goodsAttr); + $tra->commit(); + return true; + } + foreach ($goodsAttr as $key => $value) { //把旧的商品属性保存到一个数组 + $oldAttr[$value->id] = $value->attr_value; + } } - } - $newAttr = self::addAttribute($data['attribute'], $data['id']); //添加新的商品属性 - $delAttr = array_diff(array_keys($oldAttr), array_keys($newAttr)); //找出需要删除的goodsAttrId - if (!$delAttr) { - return true; - } - foreach ($delAttr as $value) { - $model = GoodsAttr::find()->where(['id' => $value, 'is_delete' => GoodsAttr::IS_DELETE_NO])->One(); - if ($model) { - $model->is_delete = GoodsAttr::IS_DELETE_YES; - if (!$model->save()) { - throw new Exception('goodsAttribute delete false'); + $newAttr = self::addAttribute($data['attribute'], $data['id']); //添加新的商品属性 + $delAttr = array_diff(array_keys($oldAttr), array_keys($newAttr)); //找出需要删除的goodsAttrId + if (!$delAttr) { + $tra->commit(); + return true; + } + foreach ($delAttr as $value) { + $model = GoodsAttr::find()->where(['id' => $value, 'is_delete' => GoodsAttr::IS_DELETE_NO])->One(); + if ($model) { + $model->is_delete = GoodsAttr::IS_DELETE_YES; + if (!$model->save()) { + throw new \Exception('goodsAttribute delete false'); + } } } + $tra->commit(); + return true; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); } } /** * @param $goodsAttr - * @throws Exception + * @throws \Exception * 删除商品属性 */ - public static function delAttribute($goodsAttr) + private static function delAttribute($goodsAttr) { foreach ($goodsAttr as $key => $value) { $value->is_delete = GoodsAttr::IS_DELETE_YES; if (!$value->save()) { - throw new Exception('goods attribute delete false'); + throw new \Exception('goods attribute delete false'); } } } @@ -149,10 +165,10 @@ class GoodsManager * @param $attribute * @param $goodsId * @return array - * @throws Exception + * @throws \Exception * 保存商品属性 */ - public static function addAttribute($attribute, $goodsId) + private static function addAttribute($attribute, $goodsId) { $newAttr = []; if (!$attribute) { @@ -169,7 +185,7 @@ class GoodsManager $goodsAttrModel->goods_id = $goodsId; $goodsAttrModel->attr_value = $v; if (!$goodsAttrModel->save()) { - throw new Exception('goodsAttribute save false'); + throw new \Exception('goodsAttribute save false'); } $newAttr[$goodsAttrModel->id] = $goodsAttrModel->attr_value; //新增的数据 } @@ -306,29 +322,18 @@ class GoodsManager if ($attribute && $attribute->type == Attribute::TYPE_ATTR) { $ret['name'] = $attribute->name; $ret['id'] = $attribute->id; - $ret['attrValue'] = self::getAttrValue($attribute->id, $id); + $ret['attrValue'] = GoodsAttr::find() + ->select(['id', 'attr_value']) + ->where(['goods_id' => $id]) + ->andWhere(['attr_id' => $attribute->id]) + ->asArray() + ->all(); $attributes[] = $ret; } } return $attributes; } - /** - * @param $attrId - * @param $goodsId - * @return GoodsAttr[]|GoodsSku[]|array|File[]|\backend\modules\file\models\ars\TemFile[]|\yii\db\ActiveRecord[] - * 获取属性值 - */ - public static function getAttrValue($attrId, $goodsId) - { - return GoodsAttr::find() - ->select(['id', 'attr_value']) - ->where(['goods_id' => $goodsId]) - ->andWhere(['attr_id' => $attrId]) - ->asArray() - ->all(); - } - /** * @param $type * @param $goodsId @@ -356,45 +361,53 @@ class GoodsManager /** * @param $sku - * @throws \yii\db\Exception + * @param $type + * @param $goodsId + * @throws \Exception * 添加或更新sku数据 */ public static function AddOrUpdateData($sku, $type, $goodsId) { - $goodsModel = Goods::findOne($goodsId); - if ($sku['id'] > 0) { - $goodsSku = GoodsSku::findOne($sku['id']); - $attrId = array_filter(explode(',', $goodsSku->goods_attr)); - $attr = GoodsAttr::findOne($attrId[0]); - } else { - $goodsSku = new GoodsSku(); - $attr = new GoodsAttr(); - } - if (!$attr || !$goodsSku || !$goodsModel) { - throw new \yii\db\Exception('系统异常'); - } - if ($type == Goods::SKU_MODE_MANUAL) { - $attr->attr_value = $sku['value']; - if (!$attr->save()) { - throw new \yii\db\Exception('手动属性修改失败'); + $tra = Yii::$app->db->beginTransaction(); + try { + $goodsModel = Goods::findOne($goodsId); + if ($sku['id'] > 0) { + $goodsSku = GoodsSku::findOne($sku['id']); + $attrId = array_filter(explode(',', $goodsSku->goods_attr)); + $attr = GoodsAttr::findOne($attrId[0]); + } else { + $goodsSku = new GoodsSku(); + $attr = new GoodsAttr(); } - $goodsSku->goods_attr = (string)$attr->id; - $goodsSku->is_manaul = 1; - } else { - $goodsSku->goods_attr = implode(',', array_filter($sku['value'])); - } - $goodsSku->goods_id = $goodsId; - $goodsSku->price = $sku['price']; - $goodsSku->stock = $sku['stock']; - $goodsSku->weight = $sku['weight']; - $goodsSku->goods_sn = $goodsModel->sn; - if (!$goodsSku->save()) { - throw new \yii\db\Exception('保存失败,请检查是否有重复规格'); - } - $goods = Goods::findOne($goodsId); - $goods->sku_mode = $type; - if (!$goods->save()) { - throw new \yii\db\Exception('商品sku类型修改失败'); + if (!$attr || !$goodsSku || !$goodsModel) { + throw new \Exception('参数错误'); + } + if ($type == Goods::SKU_MODE_MANUAL) { + $attr->attr_value = $sku['value']; + if (!$attr->save()) { + throw new \Exception('手动属性修改失败'); + } + $goodsSku->goods_attr = (string)$attr->id; + $goodsSku->is_manaul = 1; + } else { + $goodsSku->goods_attr = implode(',', array_filter($sku['value'])); + } + $goodsSku->goods_id = $goodsId; + $goodsSku->price = $sku['price']; + $goodsSku->stock = $sku['stock']; + $goodsSku->weight = $sku['weight']; + $goodsSku->goods_sn = $goodsModel->sn; + if (!$goodsSku->save()) { + throw new \Exception('保存失败,请检查是否有重复规格'); + } + $goods = Goods::findOne($goodsId); + $goods->sku_mode = $type; + if (!$goods->save()) { + throw new \Exception('商品sku类型修改失败'); + } + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); } } @@ -433,9 +446,10 @@ class GoodsManager * @param $data * @return bool * @throws Exception + * @throws HttpException * 创建修改商品筛选属性操作 */ - public static function addFilterAttributeOperating($data) + private static function addFilterAttributeOperating($data) { if (!$data['filterAttribute']) { return true; @@ -462,7 +476,7 @@ class GoodsManager if ($model) { $model->is_delete = FilterAttr::IS_DELETE_YES; if (!$model->save()) { - throw new Exception('goodsAttribute delete false'); + throw new \Exception('goodsAttribute delete false'); } } } @@ -470,15 +484,15 @@ class GoodsManager /** * @param $goodsFilterAttr - * @throws Exception + * @throws HttpException * 删除商品筛选属性 */ - public static function delFilterAttribute($goodsFilterAttr) + private static function delFilterAttribute($goodsFilterAttr) { foreach ($goodsFilterAttr as $key => $value) { $value->is_delete = FilterAttr::IS_DELETE_YES; if (!$value->save()) { - throw new Exception('goods attribute delete false'); + throw new \Exception('goods attribute delete false'); } } } @@ -487,10 +501,10 @@ class GoodsManager * @param $attribute * @param $goodsId * @return array - * @throws Exception + * @throws \Exception * 保存商品筛选属性 */ - public static function addFilterAttribute($attribute, $goodsId) + private static function addFilterAttribute($attribute, $goodsId) { $newAttr = []; if (!$attribute) { @@ -507,7 +521,7 @@ class GoodsManager $goodsFilterAttrModel->goods_id = $goodsId; $goodsFilterAttrModel->attr_value = $v; if (!$goodsFilterAttrModel->save()) { - throw new Exception('goodsAttribute save false'); + throw new \Exception('goodsAttribute save false'); } $newAttr[$goodsFilterAttrModel->id] = $goodsFilterAttrModel->attr_value; //新增的数据 } @@ -549,7 +563,7 @@ class GoodsManager /** * @param $goodsModel * @return bool - * + * 判断该商品的sku是否存在已选属性,存在则返回true,表示不得删除 */ public static function judgeGoodsCategory($goodsModel) { diff --git a/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php b/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php new file mode 100644 index 0000000..4f06e33 --- /dev/null +++ b/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php @@ -0,0 +1,26 @@ +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; + } +} diff --git a/backend/modules/goods/models/ars/Goods.php b/backend/modules/goods/models/ars/Goods.php index beaa058..7ec96dc 100755 --- a/backend/modules/goods/models/ars/Goods.php +++ b/backend/modules/goods/models/ars/Goods.php @@ -47,6 +47,10 @@ use backend\modules\goods\models\ars\Supplier; * @property int $created_at 创建时间 * @property int $updated_at 更新时间 * @property int $sku_mode sku类型 + * @property int $is_taking 是否自提 + * @property int $is_express 是否快递发货 + * @property int $express_type 快递运费方式 + * @property int $uniform_postage 统一邮费 */ class Goods extends \yii\db\ActiveRecord { @@ -62,9 +66,31 @@ class Goods extends \yii\db\ActiveRecord //该商品是否开放销售is_sale const IS_SALE_NO = 0;//否 const IS_SALE_YES = 1;//是 - //sku类型 + //类型sku const SKU_MODE_ATTR = 1;//SKU类型属性 const SKU_MODE_MANUAL = 2;//SKU类型手写 + //是否自提is_taking + const IS_TAKING_NO = 0; //否 + const IS_TAKING_YES = 1; //是 + //是否快递发货is_express + const IS_EXPRESS_NO = 0; //否 + const IS_EXPRESS_YES = 1; //是 + //快递运费计算方式express_type + const EXPRESS_TYPE_UNIFORM_POSTAGE = 1; //统一邮费 + const EXPRESS_TYPE_EXPRESS_TEMPLAGE = 2; //运费模板 + + public static $isTaking = [ + self::IS_TAKING_NO => '否', + self::IS_TAKING_YES => '是' + ]; + public static $isExpress = [ + self::IS_EXPRESS_NO => '否', + self::IS_EXPRESS_YES => '是' + ]; + public static $expressType = [ + self::EXPRESS_TYPE_UNIFORM_POSTAGE => '统一邮费', + self::EXPRESS_TYPE_EXPRESS_TEMPLAGE => '运费模板' + ]; public static $isSale = [ self::IS_SALE_NO => '不在售', self::IS_SALE_YES => '在售' @@ -84,7 +110,7 @@ class Goods extends \yii\db\ActiveRecord public function rules() { return [ - [['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template', 'sku_mode'], 'integer'], + [['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template', 'sku_mode', 'is_taking', 'is_express', 'express_type'], 'integer'], [['cat_id', 'brand_id', 'shop_cat_id', 'name'], 'required'], [['sn'], 'checkExist'], [['description', 'coverImageId', 'detailImageId'], 'string'], @@ -93,7 +119,8 @@ class Goods extends \yii\db\ActiveRecord [['code'], 'string', 'max' => 50], [['unit'], 'string', 'max' => 16], [['brief'], 'string', 'max' => 255], - [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price'], 'checkNegative'], + [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price', 'uniform_postage'], 'checkNegative'], + [['uniform_postage'], 'safe'] ]; } @@ -164,9 +191,14 @@ class Goods extends \yii\db\ActiveRecord 'bouns_points' => '奖励积分', 'experience_points' => '经验值', 'is_delete' => '是否删除,1为已删除', - 'express_template' => '配送详情id', + 'express_template' => '配送详情', 'created_at' => '创建时间', 'updated_at' => '更新时间', + 'sku_mode' => 'sku类型', + 'is_taking' => '是否自提', + 'is_express' => '是否快递发货', + 'express_type' => '快递运费方式', + 'uniform_postage' => '统一邮费', ]; } diff --git a/backend/modules/goods/models/ars/GoodsSku.php b/backend/modules/goods/models/ars/GoodsSku.php index 053394a..ab0b17d 100755 --- a/backend/modules/goods/models/ars/GoodsSku.php +++ b/backend/modules/goods/models/ars/GoodsSku.php @@ -6,7 +6,7 @@ use Yii; use yii\behaviors\TimestampBehavior; /** - * This is the model class for table "goods_goods_sku". + * This is the model class for table "atg_goods_sku". * * @property int $id * @property int $goods_id 商品id @@ -38,7 +38,7 @@ class GoodsSku extends \yii\db\ActiveRecord */ public static function tableName() { - return 'goods_goods_sku'; + return 'atg_goods_sku'; } /** diff --git a/backend/modules/goods/views/goods/create.php b/backend/modules/goods/views/goods/create.php index a2f1131..1d87807 100755 --- a/backend/modules/goods/views/goods/create.php +++ b/backend/modules/goods/views/goods/create.php @@ -42,6 +42,12 @@ Yii::$app->params['bsVersion'] = '4.x'; 'attrValue' => [], ]), ], + [ + 'label' => ' 物流信息', + 'content' => $this->render('express', ['model' => $model, + 'form' => $form, + ]), + ], [ 'label' => ' 详情上传', 'content' => $this->render('new_editor', ['model' => $model, diff --git a/backend/modules/goods/views/goods/express.php b/backend/modules/goods/views/goods/express.php new file mode 100755 index 0000000..c97839e --- /dev/null +++ b/backend/modules/goods/views/goods/express.php @@ -0,0 +1,60 @@ + +field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?> + +field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?> + +
+ field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?> + +
+ field($model, 'uniform_postage')->textInput() ?> +
+ +
+ field($model, 'express_template')->widget(Select2::className(), ["items" => ExpressTemplate::modelColumn()]) ?> +
+
+ +registerJs($js); + +?> \ No newline at end of file diff --git a/backend/modules/goods/views/goods/picture.php b/backend/modules/goods/views/goods/picture.php index eb0cec4..022f640 100755 --- a/backend/modules/goods/views/goods/picture.php +++ b/backend/modules/goods/views/goods/picture.php @@ -15,9 +15,8 @@ use yii\helpers\Url; 'maxCount' => 1, 'fillInAttribute' => 'coverImageId', 'model' => $model, - 'ruleVerify' => $model->ruleVerify, 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId]), + 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId, 'ruleverify' => $model->ruleVerify]), ], ])->label('商品封面图') ?> @@ -30,8 +29,7 @@ use yii\helpers\Url; 'maxCount' => 5, 'fillInAttribute' => 'detailImageId', 'model' => $model, - 'ruleVerify' => $model->ruleVerify, 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId]), + 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId, 'ruleverify' => $model->ruleVerify]), ], ])->label('商品详情图') ?> diff --git a/backend/modules/goods/views/goods/update.php b/backend/modules/goods/views/goods/update.php index da346ef..25ac202 100755 --- a/backend/modules/goods/views/goods/update.php +++ b/backend/modules/goods/views/goods/update.php @@ -44,6 +44,12 @@ Yii::$app->params['bsVersion'] = '4.x'; 'goodsModel' => $model, ]), ], + [ + 'label' => ' 物流信息', + 'content' => $this->render('express', ['model' => $model, + 'form' => $form, + ]), + ], [ 'label' => ' 详情上传', 'content' => $this->render('new_editor', ['model' => $model, diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 460be98..7b712cb 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -2,17 +2,20 @@ namespace backend\modules\shop\controllers; -use backend\modules\shop\models\ars\City; -use backend\modules\shop\models\ars\Province; +use backend\modules\shop\models\ars\City; +use backend\modules\shop\models\ars\Province; +use backend\modules\shop\models\searchs\ExpressAreaSearch; use Yii; -use backend\modules\shop\models\ars\ExpressTemplate; -use backend\modules\shop\models\searchs\ExpressTemplateSearch; -use yii\caching\Cache; +use backend\modules\shop\models\ars\ExpressTemplate; +use backend\modules\shop\models\searchs\ExpressTemplateSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\web\Response; use yii\widgets\ActiveForm; +use backend\modules\shop\models\ars\ExpressArea; +use backend\modules\goods\models\ars\Goods; + /** * ExpressTemplateController implements the CRUD actions for ExpressTemplate model. @@ -71,52 +74,13 @@ class ExpressTemplateController extends Controller public function actionCreate() { $model = new ExpressTemplate(); - $model->calculation_type = ExpressTemplate::CALCULATION_TYPE_NUMBER; - $model->basic_count = 1; - $model->basic_price = '0.00'; - if (Yii::$app->request->isPost) { - $data = Yii::$app->request->post('ExpressTemplate'); - if (Yii::$app->request->isAjax) { - $model->load($data, ''); - Yii::$app->response->format = Response::FORMAT_JSON; - $data = ActiveForm::validate($model); - $data['status'] = 2; - return $data; - } - if (Yii::$app->request->post('area') == null) { - return $this->redirect(Yii::$app->request->referrer . '?status=1'); - } - $cityIds = array_keys(Yii::$app->request->post('area')); - $data['city'] = implode(',', $cityIds); - $model->load($data, ''); - $model->basic_price *= 100; - $model->extra_price *= 100; - if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { - $model->basic_count *= 10; - $model->extra_count *= 10; - } else { - $model->basic_count *= 1; - $model->extra_count *= 1; - } - $model->save(); + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } - $data = []; - $provinces = Province::find()->cache(0)->all(); - foreach ($provinces as $k => $v) { - $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) - ->where(['province_id' => $v->province_id]) - ->all(); - foreach ($cities as $city) { - $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; - } - } return $this->render('create', [ 'model' => $model, - 'data' => $data ]); } @@ -130,36 +94,13 @@ class ExpressTemplateController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - $model->basic_price /= 100; - $model->extra_price /= 100; - if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { - $model->basic_count /= 10; - $model->extra_count /= 10; - } - $data = Yii::$app->request->post('ExpressTemplate'); - if ($data) { - if (Yii::$app->request->post('area') == null) { - return $this->redirect(Yii::$app->request->referrer . '&status=1'); - } - $cityIds = array_keys(Yii::$app->request->post('area')); - $data['city'] = implode(',', $cityIds); - $model->load($data, ''); - $model->save(); - return $this->render('view', ['model' => ExpressTemplate::findOne($model->id)]); - } - $data = []; - $provinces = Province::find()->cache(0)->all(); - foreach ($provinces as $k => $v) { - $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) - ->where(['province_id' => $v->province_id]) - ->all(); - foreach ($cities as $city) { - $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; - } + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); } + return $this->render('update', [ - 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city) + 'model' => $model, ]); } @@ -172,7 +113,13 @@ class ExpressTemplateController extends Controller */ public function actionDelete($id) { - $this->findModel($id)->delete(); + if (Goods::find()->where(['express_template' => $id])->count() == 0) { + $expressTemplateModel = $this->findModel($id); + ExpressArea::deleteAll(['express_template' => $expressTemplateModel->id]); + $expressTemplateModel->delete(); + } else { + Yii::$app->session->setFlash('error', '该模板已被使用'); + } return $this->redirect(['index']); } @@ -213,4 +160,184 @@ class ExpressTemplateController extends Controller 'columns' => $searchModel->columns() ]); } + + /** + * @return string + * 运费区域列表 + */ + public function actionExpressAreaList($id) + { + $expressTemplate = ExpressTemplate::findOne($id); + $searchModel = new ExpressAreaSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id); + + return $this->render('express_area_list', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns(), + 'expressTemplate' => $expressTemplate + ]); + } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域创建方法 + */ + public function actionExpressAreaCreate() + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $model = new ExpressArea(); + $model->basic_count = 1; + $model->basic_price = '0.00'; + $model->express_template = $expressTemplateModel->id; + + if (Yii::$app->request->isPost) { + $data = Yii::$app->request->post('ExpressArea'); + if (Yii::$app->request->isAjax) { + $model->load($data, ''); + Yii::$app->response->format = Response::FORMAT_JSON; + $data = ActiveForm::validate($model); + $data['status'] = 2; + return $data; + } + if (Yii::$app->request->post('area') == null) { + return $this->redirect(Yii::$app->request->referrer . '?status=1'); + } + $cityIds = array_keys(Yii::$app->request->post('area')); + $data['city'] = implode(',', $cityIds); + $model->load($data, ''); + $model->basic_price *= 100; + $model->extra_price *= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count *= 10; + $model->extra_count *= 10; + } else { + $model->basic_count *= 1; + $model->extra_count *= 1; + } + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->all(); + $expressAresCityIdArr = []; + if ($expressAreas) { + foreach ($expressAreas as $expressAreaCity) { + $cityIdArr = explode(',', $expressAreaCity->city); + $expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); + } + } + $provinces = Province::find()->cache(0)->all(); + $j = 0; + foreach ($provinces as $k => $v) { + $cities = City::find() + ->where(['province_id' => $v->province_id]) + ->andWhere(['not in', 'city_id', $expressAresCityIdArr]) + ->all(); + if ($cities) { + $data[$j]['province'] = $v->name; + foreach ($cities as $city) { + $data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + $j++; + } + } + if (empty($data)) { + Yii::$app->session->setFlash('error', '已无地区选择'); + return $this->redirect('express-area-list?id='.$expressTemplateModel->id); + } + return $this->render('express_area_create', [ + 'model' => $model, + 'data' => $data, + 'expressTemplateModel' => $expressTemplateModel + ]); + } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域更新方法 + */ + public function actionExpressAreaUpdate($id) + { + $model = ExpressArea::findOne($id); + $expressTemplateModel = ExpressTemplate::findOne($model->express_template); + $model->basic_price /= 100; + $model->extra_price /= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count /= 10; + $model->extra_count /= 10; + } + $data = Yii::$app->request->post('ExpressArea'); + if ($data) { + if (Yii::$app->request->post('area') == null) { + return $this->redirect(Yii::$app->request->referrer . '&status=1'); + } + $cityIds = array_keys(Yii::$app->request->post('area')); + $data['city'] = implode(',', $cityIds); + $model->load($data, ''); + $model->basic_price *= 100; + $model->extra_price *= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count *= 10; + $model->extra_count *= 10; + } else { + $model->basic_count *= 1; + $model->extra_count *= 1; + } + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->andWhere(['!=', 'id', $id])->all(); + $expressAresCityIdArr = []; + if ($expressAreas) { + foreach ($expressAreas as $expressAreaCity) { + $cityIdArr = explode(',', $expressAreaCity->city); + $expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); + } + } + $provinces = Province::find()->cache(0)->all(); + $j = 0; + foreach ($provinces as $k => $v) { + $cities = City::find() + ->where(['province_id' => $v->province_id]) + ->andWhere(['not in', 'city_id', $expressAresCityIdArr]) + ->all(); + if ($cities) { + $data[$j]['province'] = $v->name; + foreach ($cities as $city) { + $data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + $j++; + } + } + + return $this->render('express_area_update', [ + 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel + ]); + } + + /** + * @param $id + * @return string + * 运费区域模板区域查看方法 + */ + public function actionExpressAreaView($id) + { + $expressAreaModel = ExpressArea::findOne($id); + $expressTemplateModel = ExpressTemplate::findOne($expressAreaModel->express_template); + return $this->render('express_area_view', [ + 'model' => $expressAreaModel, + 'expressTemplateModel' => $expressTemplateModel + ]); + } + + public function actionExpressAreaDelete($id) + { + $expressAreaModel = ExpressArea::findOne($id); + $expressTemplateId = $expressAreaModel->express_template; + $expressAreaModel->delete(); + return $this->redirect('express-area-list?id='.$expressTemplateId); + } } diff --git a/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php b/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php new file mode 100644 index 0000000..a0859df --- /dev/null +++ b/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php b/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php new file mode 100644 index 0000000..bd50a85 --- /dev/null +++ b/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/backend/modules/shop/models/ars/ExpressArea.php b/backend/modules/shop/models/ars/ExpressArea.php new file mode 100644 index 0000000..259201a --- /dev/null +++ b/backend/modules/shop/models/ars/ExpressArea.php @@ -0,0 +1,101 @@ + [ + "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(); + }, + ], + ]; + } +} diff --git a/backend/modules/shop/models/ars/ExpressTemplate.php b/backend/modules/shop/models/ars/ExpressTemplate.php index ce4fd07..b0ef8b7 100644 --- a/backend/modules/shop/models/ars/ExpressTemplate.php +++ b/backend/modules/shop/models/ars/ExpressTemplate.php @@ -10,15 +10,8 @@ use yii\behaviors\TimestampBehavior; * * @property int $id * @property string $name 名称 - * @property string $province 省份 - * @property string $city 城市 - * @property string $area 区域 - * @property int $extra_price 续重运费 * @property int $updated_at 更新时间 * @property int $created_at 创建时间 - * @property int $basic_price 基本运费 - * @property int $basic_count 基本数量 - * @property int $extra_count 续重数量 * @property int $calculation_type 计算方式 */ class ExpressTemplate extends \yii\db\ActiveRecord @@ -46,10 +39,8 @@ class ExpressTemplate extends \yii\db\ActiveRecord { return [ [['name'], 'required'], - [['province', 'city', 'area'], 'string'], [['calculation_type'], 'integer'], - [['name'], 'string', 'max' => 255], - [['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'] + [['name'], 'string', 'max' => 255] ]; } @@ -61,15 +52,8 @@ class ExpressTemplate extends \yii\db\ActiveRecord return [ 'id' => 'id', 'name' => '名称', - 'province' => '省份', - 'city' => '城市', - 'area' => '区域', - 'extra_price' => '续重运费', 'updated_at' => '更新时间', 'created_at' => '创建时间', - 'basic_price' => '基本运费', - 'basic_count' => '基本数量', - 'extra_count' => '续重数量', 'calculation_type' => '计算方式', ]; } @@ -95,4 +79,13 @@ class ExpressTemplate extends \yii\db\ActiveRecord ], ]; } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->indexBy('id')->column(); + } } diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php new file mode 100644 index 0000000..0893957 --- /dev/null +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -0,0 +1,187 @@ + '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; + } +} diff --git a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php index 8cee01c..09beeed 100755 --- a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php +++ b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php @@ -26,8 +26,8 @@ class ExpressTemplateSearch extends ExpressTemplate public function rules() { return [ - [['id', 'calculation_type', 'basic_price', 'basic_count', 'extra_price', 'extra_count', 'updated_at', 'created_at'], 'integer'], - [['name', 'province', 'city', 'area'], 'safe'], + [['id', 'calculation_type', 'updated_at', 'created_at'], 'integer'], + [['name'], 'safe'], ['created_at_range','safe'], ]; } @@ -52,11 +52,35 @@ class ExpressTemplateSearch extends ExpressTemplate 'width' => '2%', 'align' => 'center' ], - 'id', - 'name', + 'id', + 'name', + [ + 'attribute' => 'calculation_type', + 'value' => function ($model) { + return ExpressTemplate::$calculationType[$model->calculation_type]; + } + ], [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', + 'config' => [ + [ + 'name' => 'update', + 'icon' => 'pencil', + 'title' => '修改' + ], + [ + 'name' => 'express-area-list', + 'icon' => 'hard-drive', + 'title' => '配送区域' + ], + [ + 'name' => 'delete', + 'icon' => 'trash', + 'title' => '删除', + 'contents' => '确定删除?' + ] + ], ], ]; } @@ -122,18 +146,11 @@ class ExpressTemplateSearch extends ExpressTemplate $query->andFilterWhere([ 'id' => $this->id, 'calculation_type' => $this->calculation_type, - 'basic_price' => $this->basic_price, - 'basic_count' => $this->basic_count, - 'extra_price' => $this->extra_price, - 'extra_count' => $this->extra_count, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, ]); - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'province', $this->province]) - ->andFilterWhere(['like', 'city', $this->city]) - ->andFilterWhere(['like', 'area', $this->area]); + $query->andFilterWhere(['like', 'name', $this->name]); if ($this->created_at_range) { $arr = explode(' ~ ', $this->created_at_range); $start = strtotime($arr[0]); diff --git a/backend/modules/shop/views/express-template/_form.php b/backend/modules/shop/views/express-template/_form.php index 940b46f..c919f92 100755 --- a/backend/modules/shop/views/express-template/_form.php +++ b/backend/modules/shop/views/express-template/_form.php @@ -2,144 +2,31 @@ use blobt\widgets\Icheck; use backend\modules\shop\models\ars\ExpressTemplate; +use yii\bootstrap4\ActiveForm; +use yii\bootstrap4\Html; /* @var $this yii\web\View */ /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ /* @var $form yii\widgets\ActiveForm */ ?> -request->get('status'); -if ($status == 1) { - ?> - - - -field($model, 'name')->textInput(['maxlength' => true]) ?> - -field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> - -field($model, 'basic_count')->textInput() ?> +
-field($model, 'basic_price')->textInput() ?> + -field($model, 'extra_count')->textInput() ?> + field($model, 'name')->textInput(['maxlength' => true]) ?> -field($model, 'extra_price')->textInput() ?> - -field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]); + } + ?> - $.each(formList[type],function(index,value){ //更改文字标题 - $("." + index).children("label").html(value) - }); - - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 - $("#expresstemplate-basic_price").val(udfVal[type][1]) - $("#expresstemplate-extra_count").val(0) - $("#expresstemplate-extra_price").val(udfVal[type][1]) - calType = type; -} -function changeCalType(type){//当切换计算方式 +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
- $.each(formList[type],function(index,value){ //更改文字标题 - $("." + index).children("label").html(value) - }); - - if(!$("#expresstemplate-basic_count").val()){ - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 - } - if(!$("#expresstemplate-basic_price").val()){ - $("#expresstemplate-basic_price").val(udfVal[type][1]) - } - if(!$("#expresstemplate-extra_count").val()){ - $("#expresstemplate-extra_count").val(0) - } - if(!$("#expresstemplate-extra_price").val()){ - $("#expresstemplate-extra_price").val(udfVal[type][1]) - } - calType = type; -} -$(document).ready(function(){ - $("#expresstemplate-basic_count").blur(function(){ - if (calType == 0) { - if($(this).val() < 0.1){ - $(this).val(0.1) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 10) / 10); - } else{ - if($(this).val() < 1){ - $(this).val(1) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 1) / 1); - } - }) - $("#expresstemplate-basic_price").blur(function(){ - if($(this).val().indexOf('-') != -1){ - $(this).val("0.00") - } - var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); - }) - $("#expresstemplate-extra_count").blur(function(){ - 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); - } - }) - $("#expresstemplate-extra_price").blur(function(){ - 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='ExpressTemplate[calculation_type]']").on('ifChecked', function(event){ - updateTypeChangeCalType($(this).val()-1) - }) - changeCalType(calType) -}) -JS; -$this->registerJs($js) + -?> \ No newline at end of file +
\ No newline at end of file diff --git a/backend/modules/shop/views/express-template/create.php b/backend/modules/shop/views/express-template/create.php index fb35a2e..14ec692 100755 --- a/backend/modules/shop/views/express-template/create.php +++ b/backend/modules/shop/views/express-template/create.php @@ -13,38 +13,10 @@ $this->params['breadcrumbs'][] = $this->title; Yii::$app->params['bsVersion'] = '4.x'; ?>
-
- ['class' => 'container-fluid']]); + render('_form', [ + 'model' => $model, + 'isCreate' => true + ]) ?> - echo TabsX::widget([ - 'bordered' => true, - 'items' => [ - [ - 'label' => ' 基本信息', - 'content' => $this->render('_form', [ - 'model' => $model, - 'form' => $form, - ]), - ], - [ - 'label' => ' 选择配送区域', - 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] - ]), - ], - ], - 'position' => TabsX::POS_ABOVE, - 'encodeLabels' => false - ]); - ?> - -
- 'btn btn-success']) ?> - 'btn btn-info']) ?> -
- - - -
diff --git a/backend/modules/shop/views/express-template/express_area_create.php b/backend/modules/shop/views/express-template/express_area_create.php new file mode 100755 index 0000000..d9068a5 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_create.php @@ -0,0 +1,51 @@ +title = '创建区域运费模板'; +$this->params['breadcrumbs'][] = ['label' => '运费区域模板', 'url' => ['express_area_list', ['id' => $expressTemplateModel->id]]]; +$this->params['breadcrumbs'][] = $this->title; +Yii::$app->params['bsVersion'] = '4.x'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('express_area_form', [ + 'model' => $model, + 'form' => $form, + 'expressTemplateModel' => $expressTemplateModel + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + $expressTemplateModel->id], ['class' => 'btn btn-info']) ?> +
+ + + +
+
diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php new file mode 100755 index 0000000..74b97d9 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -0,0 +1,156 @@ + + +request->get('status'); +if ($status == 1) { + ?> + + + +field($model, 'express_template')->textInput(['maxlength' => true]) ?> + +field($model, 'basic_count')->textInput() ?> + +field($model, 'basic_price')->textInput() ?> + +field($model, 'extra_count')->textInput() ?> + +field($model, 'extra_price')->textInput() ?> + +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) + +?> \ No newline at end of file diff --git a/backend/modules/shop/views/express-template/express_area_list.php b/backend/modules/shop/views/express-template/express_area_list.php new file mode 100644 index 0000000..1f59fb9 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_list.php @@ -0,0 +1,33 @@ +title = '运费区域模板:'.$expressTemplate->name; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $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']) + ]); + ?> +
+
\ No newline at end of file diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php new file mode 100755 index 0000000..60c0704 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -0,0 +1,52 @@ +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'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('express_area_form', [ + 'model' => $model, + 'form' => $form, + 'expressTemplateModel' => $expressTemplateModel + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + $expressTemplateModel->id], ['class' => 'btn btn-info']) ?> +
+ + + +
+
diff --git a/backend/modules/shop/views/express-template/express_area_view.php b/backend/modules/shop/views/express-template/express_area_view.php new file mode 100755 index 0000000..31d353e --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_view.php @@ -0,0 +1,94 @@ +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); +?> +
+ +

+ id], ['class' => 'btn btn-success']) ?> +

+ + $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); + }, + ], + ], + ]) ?> + +
diff --git a/backend/modules/shop/views/express-template/update.php b/backend/modules/shop/views/express-template/update.php index 13c0193..8e086e9 100755 --- a/backend/modules/shop/views/express-template/update.php +++ b/backend/modules/shop/views/express-template/update.php @@ -14,38 +14,10 @@ $this->params['breadcrumbs'][] = 'Update '; Yii::$app->params['bsVersion'] = '4.x'; ?>
-
- ['class' => 'container-fluid']]); + render('_form', [ + 'model' => $model, + 'isCreate' => false + ]) ?> - echo TabsX::widget([ - 'bordered' => true, - 'items' => [ - [ - 'label' => ' 基本信息', - 'content' => $this->render('_form', [ - 'model' => $model, - 'form' => $form, - ]), - ], - [ - 'label' => ' 选择配送区域', - 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities - ]), - ], - ], - 'position' => TabsX::POS_ABOVE, - 'encodeLabels' => false - ]); - ?> - -
- 'btn btn-success']) ?> - 'btn btn-info']) ?> -
- - - -
diff --git a/vendor/iron/grid/GridView.php b/vendor/iron/grid/GridView.php index 4f83b4a..c2f2ca9 100644 --- a/vendor/iron/grid/GridView.php +++ b/vendor/iron/grid/GridView.php @@ -219,16 +219,12 @@ class GridView extends BaseListView
{batch} - 添加 + + {create} -
- - -
+ {export} + {content}
{filter} @@ -263,6 +259,26 @@ HTML;
HTML; + public $export =<< + + +
+HTML; + public $create =<<添加 + +HTML; + /** + * @var + * 表单头部内容 + */ + public $content; + + /** * 初始化 grid view. @@ -447,6 +463,12 @@ SCRIPT; return $this->renderBatch(); case '{url}': return Yii::$app->request->url; + case '{export}': + return $this->renderExport(); + case '{create}': + return $this->renderCreate(); + case '{content}': + return $this->renderContent(); default: return false; } @@ -696,4 +718,31 @@ SCRIPT; ]); } + /** + * 渲染导出部分 + * @return string + */ + protected function renderExport() + { + return $this->export; + } + + /** + * 渲染创建部分 + * @return string + */ + protected function renderCreate() + { + return $this->create; + } + + /** + * 渲染表单头部内容 + * @return string + */ + protected function renderContent() + { + return Html::tag('div', $this->content, ['class' => 'btn-group']); + } + }