root
5 years ago
169 changed files with 2105 additions and 1114 deletions
-
1.gitignore
-
18backend/config/main.php
-
149backend/controllers/CategoryController.php
-
0backend/controllers/ConfigController.php
-
149backend/controllers/GoodsController.php
-
0backend/controllers/OrderController.php
-
149backend/controllers/ShopCategoryController.php
-
0backend/controllers/SiteController.php
-
122backend/logic/file/FileManager.php
-
47backend/views/brand/_search.php
-
38backend/views/category/_form.php
-
98backend/views/category/test.php
-
0backend/views/config/index.php
-
82backend/views/goods/_form.php
-
0backend/views/layouts/base.php
-
0backend/views/layouts/breadcrumb.php
-
0backend/views/layouts/footer.php
-
0backend/views/layouts/header.php
-
0backend/views/layouts/main.php
-
16backend/views/layouts/sidebar.php
-
0backend/views/order/_form.php
-
0backend/views/order/_search.php
-
0backend/views/order/create.php
-
0backend/views/order/index.php
-
0backend/views/order/update.php
-
0backend/views/order/view.php
-
44backend/views/shop-category/_form.php
-
0backend/views/site/error.php
-
0backend/views/site/index.php
-
0backend/views/site/login.php
-
0backend/views/site/test.php
-
47backend/views/supplier/_search.php
-
BINbackend/web/uploads/xls/15738696921690.jpg
-
2common/models/ars/Address.php
-
2common/models/ars/AfterSale.php
-
1common/models/ars/Area.php
-
2common/models/ars/Cart.php
-
1common/models/ars/City.php
-
2common/models/ars/Collection.php
-
2common/models/ars/Comment.php
-
0common/models/ars/Config.php
-
2common/models/ars/Delivery.php
-
2common/models/ars/ExpressTemplate.php
-
8common/models/ars/File.php
-
2common/models/ars/Order.php
-
2common/models/ars/OrderGoods.php
-
1common/models/ars/PaymentLog.php
-
1common/models/ars/Province.php
-
1common/models/ars/RefundLog.php
-
2common/models/ars/SearchHistory.php
-
2common/models/ars/TakingSite.php
-
2common/models/ars/TemFile.php
-
0common/models/searchs/OrderSearch.php
-
5composer.json
-
2console/controllers/InitController.php
-
0console/migrations/m130524_201442_init.php
-
0console/migrations/m140506_102106_rbac_init.php
-
0console/migrations/m170907_052038_rbac_add_index_on_auth_assignment_user_id.php
-
0console/migrations/m180523_151638_rbac_updates_indexes_without_prefix.php
-
0console/migrations/m190124_110200_add_verification_token_column_to_user_table.php
-
0console/migrations/m190802_072830_add_category.php
-
0console/migrations/m191111_101658_create_table_area.php
-
0console/migrations/m191111_102644_create_table_province.php
-
0console/migrations/m191111_102730_create_table_city.php
-
8console/migrations/m191111_102925_create_table_cart.php
-
8console/migrations/m191111_112559_create_table_address.php
-
6console/migrations/m191111_113455_create_table_after_sale.php
-
2console/migrations/m191112_005106_create_table_search_history.php
-
4console/migrations/m191112_005545_create_table_collection.php
-
2console/migrations/m191112_005702_create_table_comment.php
-
2console/migrations/m191112_010421_create_table_order.php
-
4console/migrations/m191112_011517_create_table_order_goods.php
-
2console/migrations/m191112_012449_create_table_taking_site.php
-
2console/migrations/m191112_014508_create_table_express_template.php
-
2console/migrations/m191112_015939_create_table_delivery.php
-
0console/migrations/m191112_020830_create_table_payment_log.php
-
0console/migrations/m191112_021528_create_table_refund_log.php
-
0console/migrations/m191112_022131_create_table_file.php
-
0console/migrations/m191112_022532_create_table_tem_file.php
-
0console/migrations/schema-mysql.sql
-
0console/migrations/sql/add_category.sql
-
0console/migrations/sql/area.sql
-
0console/migrations/sql/city.sql
-
0console/migrations/sql/province.sql
-
8environments/skeleton/backend/config/main-local.php
-
0environments/skeleton/backend/config/params-local.php
-
14vendor/antgoods/goods/AutoloadExample.php
-
31vendor/antgoods/goods/README.md
-
21vendor/antgoods/goods/composer.json
-
28vendor/antgoods/goods/src/Module.php
-
12vendor/antgoods/goods/src/controllers/AttributeController.php
-
6vendor/antgoods/goods/src/controllers/BrandController.php
-
276vendor/antgoods/goods/src/controllers/CategoryController.php
-
282vendor/antgoods/goods/src/controllers/GoodsController.php
-
273vendor/antgoods/goods/src/controllers/ShopcategoryController.php
-
6vendor/antgoods/goods/src/controllers/SupplierController.php
-
51vendor/antgoods/goods/src/logic/goods/GoodsManager.php
-
14vendor/antgoods/goods/src/migrations/m191119_021851_create_table_shop_category.php
-
18vendor/antgoods/goods/src/migrations/m191119_022641_create_table_category.php
-
14vendor/antgoods/goods/src/migrations/m191119_022939_create_table_attribute.php
@ -1,149 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\controllers; |
|
||||
|
|
||||
use Yii; |
|
||||
use common\models\ars\Category; |
|
||||
use common\models\searchs\CategorySearch; |
|
||||
use yii\web\Controller; |
|
||||
use yii\web\NotFoundHttpException; |
|
||||
use yii\filters\VerbFilter; |
|
||||
|
|
||||
/** |
|
||||
* CategoryController implements the CRUD actions for Category model. |
|
||||
*/ |
|
||||
class CategoryController extends Controller |
|
||||
{ |
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function behaviors() |
|
||||
{ |
|
||||
return [ |
|
||||
'verbs' => [ |
|
||||
'class' => VerbFilter::className(), |
|
||||
'actions' => [ |
|
||||
'delete' => ['POST'], |
|
||||
], |
|
||||
], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Lists all Category models. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionIndex() |
|
||||
{ |
|
||||
$searchModel = new CategorySearch(); |
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
|
||||
|
|
||||
return $this->render('index', [ |
|
||||
'searchModel' => $searchModel, |
|
||||
'dataProvider' => $dataProvider, |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Displays a single Category model. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionView($id) |
|
||||
{ |
|
||||
return $this->render('view', [ |
|
||||
'model' => $this->findModel($id), |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Creates a new Category model. |
|
||||
* If creation is successful, the browser will be redirected to the 'view' page. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionCreate() |
|
||||
{ |
|
||||
$model = new Category(); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('create', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Updates an existing Category model. |
|
||||
* If update is successful, the browser will be redirected to the 'view' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionUpdate($id) |
|
||||
{ |
|
||||
$model = $this->findModel($id); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('update', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Deletes an existing Category model. |
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionDelete($id) |
|
||||
{ |
|
||||
$this->findModel($id)->delete(); |
|
||||
|
|
||||
return $this->redirect(['index']); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Finds the Category model based on its primary key value. |
|
||||
* If the model is not found, a 404 HTTP exception will be thrown. |
|
||||
* @param integer $id |
|
||||
* @return Category the loaded model |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
protected function findModel($id) |
|
||||
{ |
|
||||
if (($model = Category::findOne($id)) !== null) { |
|
||||
return $model; |
|
||||
} |
|
||||
|
|
||||
throw new NotFoundHttpException('The requested page does not exist.'); |
|
||||
} |
|
||||
/** |
|
||||
* @author iron |
|
||||
* 文件导出 |
|
||||
*/ |
|
||||
public function actionExport() |
|
||||
{ |
|
||||
$searchModel = new CategorySearch(); |
|
||||
$params = Yii::$app->request->queryParams; |
|
||||
if ($params['page-type'] == 'all') { |
|
||||
$dataProvider = $searchModel->allData($params); |
|
||||
} else { |
|
||||
$dataProvider = $searchModel->search($params); |
|
||||
} |
|
||||
\iron\widget\Excel::export([ |
|
||||
'models' => $dataProvider->getModels(), |
|
||||
'format' => 'Xlsx', |
|
||||
'asAttachment' => true, |
|
||||
'fileName' =>'Categories'. "-" .date('Y-m-d H/i/s', time()), |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
} |
|
@ -1,149 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\controllers; |
|
||||
|
|
||||
use Yii; |
|
||||
use common\models\ars\Goods; |
|
||||
use common\models\searchs\GoodsSearch; |
|
||||
use yii\web\Controller; |
|
||||
use yii\web\NotFoundHttpException; |
|
||||
use yii\filters\VerbFilter; |
|
||||
|
|
||||
/** |
|
||||
* GoodsController implements the CRUD actions for Goods model. |
|
||||
*/ |
|
||||
class GoodsController extends Controller |
|
||||
{ |
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function behaviors() |
|
||||
{ |
|
||||
return [ |
|
||||
'verbs' => [ |
|
||||
'class' => VerbFilter::className(), |
|
||||
'actions' => [ |
|
||||
'delete' => ['POST'], |
|
||||
], |
|
||||
], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Lists all Goods models. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionIndex() |
|
||||
{ |
|
||||
$searchModel = new GoodsSearch(); |
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
|
||||
|
|
||||
return $this->render('index', [ |
|
||||
'searchModel' => $searchModel, |
|
||||
'dataProvider' => $dataProvider, |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Displays a single Goods model. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionView($id) |
|
||||
{ |
|
||||
return $this->render('view', [ |
|
||||
'model' => $this->findModel($id), |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Creates a new Goods model. |
|
||||
* If creation is successful, the browser will be redirected to the 'view' page. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionCreate() |
|
||||
{ |
|
||||
$model = new Goods(); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('create', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Updates an existing Goods model. |
|
||||
* If update is successful, the browser will be redirected to the 'view' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionUpdate($id) |
|
||||
{ |
|
||||
$model = $this->findModel($id); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('update', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Deletes an existing Goods model. |
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionDelete($id) |
|
||||
{ |
|
||||
$this->findModel($id)->delete(); |
|
||||
|
|
||||
return $this->redirect(['index']); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Finds the Goods model based on its primary key value. |
|
||||
* If the model is not found, a 404 HTTP exception will be thrown. |
|
||||
* @param integer $id |
|
||||
* @return Goods the loaded model |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
protected function findModel($id) |
|
||||
{ |
|
||||
if (($model = Goods::findOne($id)) !== null) { |
|
||||
return $model; |
|
||||
} |
|
||||
|
|
||||
throw new NotFoundHttpException('The requested page does not exist.'); |
|
||||
} |
|
||||
/** |
|
||||
* @author iron |
|
||||
* 文件导出 |
|
||||
*/ |
|
||||
public function actionExport() |
|
||||
{ |
|
||||
$searchModel = new GoodsSearch(); |
|
||||
$params = Yii::$app->request->queryParams; |
|
||||
if ($params['page-type'] == 'all') { |
|
||||
$dataProvider = $searchModel->allData($params); |
|
||||
} else { |
|
||||
$dataProvider = $searchModel->search($params); |
|
||||
} |
|
||||
\iron\widget\Excel::export([ |
|
||||
'models' => $dataProvider->getModels(), |
|
||||
'format' => 'Xlsx', |
|
||||
'asAttachment' => true, |
|
||||
'fileName' =>'Goods'. "-" .date('Y-m-d H/i/s', time()), |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
} |
|
@ -1,149 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace backend\controllers; |
|
||||
|
|
||||
use Yii; |
|
||||
use common\models\ars\ShopCategory; |
|
||||
use common\models\searchs\ShopCategorySearch; |
|
||||
use yii\web\Controller; |
|
||||
use yii\web\NotFoundHttpException; |
|
||||
use yii\filters\VerbFilter; |
|
||||
|
|
||||
/** |
|
||||
* ShopCategoryController implements the CRUD actions for ShopCategory model. |
|
||||
*/ |
|
||||
class ShopCategoryController extends Controller |
|
||||
{ |
|
||||
/** |
|
||||
* {@inheritdoc} |
|
||||
*/ |
|
||||
public function behaviors() |
|
||||
{ |
|
||||
return [ |
|
||||
'verbs' => [ |
|
||||
'class' => VerbFilter::className(), |
|
||||
'actions' => [ |
|
||||
'delete' => ['POST'], |
|
||||
], |
|
||||
], |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Lists all ShopCategory models. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionIndex() |
|
||||
{ |
|
||||
$searchModel = new ShopCategorySearch(); |
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
|
||||
|
|
||||
return $this->render('index', [ |
|
||||
'searchModel' => $searchModel, |
|
||||
'dataProvider' => $dataProvider, |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Displays a single ShopCategory model. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionView($id) |
|
||||
{ |
|
||||
return $this->render('view', [ |
|
||||
'model' => $this->findModel($id), |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Creates a new ShopCategory model. |
|
||||
* If creation is successful, the browser will be redirected to the 'view' page. |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function actionCreate() |
|
||||
{ |
|
||||
$model = new ShopCategory(); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('create', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Updates an existing ShopCategory model. |
|
||||
* If update is successful, the browser will be redirected to the 'view' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionUpdate($id) |
|
||||
{ |
|
||||
$model = $this->findModel($id); |
|
||||
|
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
||||
return $this->redirect('index'); |
|
||||
} |
|
||||
|
|
||||
return $this->render('update', [ |
|
||||
'model' => $model, |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Deletes an existing ShopCategory model. |
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page. |
|
||||
* @param integer $id |
|
||||
* @return mixed |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
public function actionDelete($id) |
|
||||
{ |
|
||||
$this->findModel($id)->delete(); |
|
||||
|
|
||||
return $this->redirect(['index']); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Finds the ShopCategory model based on its primary key value. |
|
||||
* If the model is not found, a 404 HTTP exception will be thrown. |
|
||||
* @param integer $id |
|
||||
* @return ShopCategory the loaded model |
|
||||
* @throws NotFoundHttpException if the model cannot be found |
|
||||
*/ |
|
||||
protected function findModel($id) |
|
||||
{ |
|
||||
if (($model = ShopCategory::findOne($id)) !== null) { |
|
||||
return $model; |
|
||||
} |
|
||||
|
|
||||
throw new NotFoundHttpException('The requested page does not exist.'); |
|
||||
} |
|
||||
/** |
|
||||
* @author iron |
|
||||
* 文件导出 |
|
||||
*/ |
|
||||
public function actionExport() |
|
||||
{ |
|
||||
$searchModel = new ShopCategorySearch(); |
|
||||
$params = Yii::$app->request->queryParams; |
|
||||
if ($params['page-type'] == 'all') { |
|
||||
$dataProvider = $searchModel->allData($params); |
|
||||
} else { |
|
||||
$dataProvider = $searchModel->search($params); |
|
||||
} |
|
||||
\iron\widget\Excel::export([ |
|
||||
'models' => $dataProvider->getModels(), |
|
||||
'format' => 'Xlsx', |
|
||||
'asAttachment' => true, |
|
||||
'fileName' =>'Shop Categories'. "-" .date('Y-m-d H/i/s', time()), |
|
||||
'columns' => $searchModel->columns() |
|
||||
]); |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,122 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace backend\logic\file; |
||||
|
|
||||
|
use common\models\ars\File; |
||||
|
use common\models\ars\TemFile; |
||||
|
|
||||
|
class FileManager |
||||
|
{ |
||||
|
//数据表ats_file和ats_tem_file的类型字段type
|
||||
|
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 = [ |
||||
|
self::TYPE_IMAGE => ['jpg', 'png', 'jpeg'], |
||||
|
self::TYPE_VIDEO => ['mp4'], |
||||
|
self::TYPE_EXCEL => [], |
||||
|
self::TYPE_WORD => ['docx'], |
||||
|
self::TYPE_TXT => ['txt'], |
||||
|
]; |
||||
|
|
||||
|
/** |
||||
|
* @param $array |
||||
|
* @param $keyword |
||||
|
* @return bool|int|string |
||||
|
* 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false |
||||
|
*/ |
||||
|
public function searchType($array, $keyword) |
||||
|
{ |
||||
|
foreach($array as $key => $value){ |
||||
|
foreach ($value as $k => $v) { |
||||
|
if($v == $keyword){ |
||||
|
return ['status' => true, 'info' => '操作成功', 'type' => $key]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return ['status' => false, 'info' => '操作失败']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $imgIdStr |
||||
|
* @param $ownId |
||||
|
* @param $ownType |
||||
|
* @return array |
||||
|
* 根据临时文件id(字符串)将临时文件保存在文件中 |
||||
|
*/ |
||||
|
public function saveTemFileToFile($temFIleIdArr, $ownId, $ownType) |
||||
|
{ |
||||
|
if(!$temFIleIdArr || !$ownId) { |
||||
|
return ['status' => false, 'info' => '参数错误']; |
||||
|
} |
||||
|
|
||||
|
$i = 1; |
||||
|
$first_file_id = 0; |
||||
|
foreach ($temFIleIdArr as $key => $value) { |
||||
|
$tem_file = TemFile::findOne($value); |
||||
|
|
||||
|
if(!$tem_file) { |
||||
|
return ['status' => false, 'info' => '存在查找不到的文件']; |
||||
|
} |
||||
|
|
||||
|
$res = self::saveNewFile($tem_file, $ownId, $ownType); |
||||
|
if(!$res['status']) { |
||||
|
return ['status' => false, 'info' => '存在文件保存失败']; |
||||
|
} |
||||
|
if($i == 1) { |
||||
|
$first_file_id = $res['file_id']; |
||||
|
} |
||||
|
|
||||
|
$i++; |
||||
|
} |
||||
|
|
||||
|
return ['status' => true, 'info' => '保存成功', 'first_file_id' => $first_file_id]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $temFile |
||||
|
* @param $ownId |
||||
|
* @param $ownType |
||||
|
* @return bool |
||||
|
* 创建新的文件 |
||||
|
*/ |
||||
|
private function saveNewFile($temFile, $ownId, $ownType) |
||||
|
{ |
||||
|
$new_file = new File(); |
||||
|
$new_file->name = $temFile->name; |
||||
|
$new_file->type = $temFile->type; |
||||
|
$new_file->own_id = $ownId; |
||||
|
$new_file->own_type = $ownType; |
||||
|
$new_file->alias = $temFile->alias; |
||||
|
$new_file->path = $temFile->path; |
||||
|
if($new_file->save()) { |
||||
|
return ['status' => true, 'info' => '操作成功', 'file_id' => $new_file->id]; |
||||
|
} else { |
||||
|
return ['status' => false, 'info' => '操作失败']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param $fileIdArr |
||||
|
* 删除file表中的文件 |
||||
|
*/ |
||||
|
public function deleteFile($fileIdArr) |
||||
|
{ |
||||
|
if($fileIdArr){ |
||||
|
foreach ($fileIdArr as $key => $value) { |
||||
|
$file_model = File::findOne($value); |
||||
|
if($file_model){ |
||||
|
$file_model->is_delete = File::IS_DELETE_YES; |
||||
|
if($file_model->save()){ |
||||
|
return ['status' => false, 'info' => '操作失败']; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return ['status' => true, 'info' => '操作成功']; |
||||
|
} |
||||
|
} |
@ -1,47 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use yii\helpers\Html; |
|
||||
use yii\widgets\ActiveForm; |
|
||||
use \blobt\widgets\DateRangePicker; |
|
||||
|
|
||||
/* @var $this yii\web\View */ |
|
||||
/* @var $model common\models\searchs\BrandSearch */ |
|
||||
/* @var $form yii\widgets\ActiveForm */ |
|
||||
?>
|
|
||||
|
|
||||
<?php $form = ActiveForm::begin([ |
|
||||
'action' => ['index'], |
|
||||
'method' => 'get', |
|
||||
'validateOnType' => true, |
|
||||
]); |
|
||||
?>
|
|
||||
<div class="col-sm-12"> |
|
||||
<div class="dataTables_filter"> |
|
||||
<?= $form->field($model, 'id', [ |
|
||||
"template" => "{input}{error}", |
|
||||
"inputOptions" => [ |
|
||||
"placeholder" => "检索ID", |
|
||||
"class" => "form-control", |
|
||||
], |
|
||||
"errorOptions" => [ |
|
||||
"class" => "error-tips" |
|
||||
] |
|
||||
]) |
|
||||
?>
|
|
||||
<?= $form->field($model, "created_at_range", [ |
|
||||
"template" => "{input}{error}", |
|
||||
"inputOptions" => [ |
|
||||
"placeholder" => "创建时间", |
|
||||
], |
|
||||
"errorOptions" => [ |
|
||||
"class" => "error-tips" |
|
||||
] |
|
||||
])->widget(DateRangePicker::className()); |
|
||||
?>
|
|
||||
<div class="form-group"> |
|
||||
<?= Html::submitButton('<i class="fa fa-filter"></i>', ['class' => 'btn btn-default']) ?>
|
|
||||
<?= Html::resetButton('<i class="fa fa-eraser"></i>', ['class' => 'btn btn-default']) ?>
|
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
<?php ActiveForm::end(); ?>
|
|
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use yii\helpers\Html; |
|
||||
use yii\widgets\ActiveForm; |
|
||||
|
|
||||
/* @var $this yii\web\View */ |
|
||||
/* @var $model common\models\ars\Category */ |
|
||||
/* @var $form yii\widgets\ActiveForm */ |
|
||||
?>
|
|
||||
|
|
||||
<div class="category-form"> |
|
||||
|
|
||||
<?php $form = ActiveForm::begin(); ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'pid')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'goods_count')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'sort_order')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'icon_type')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_show')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_delete')->textInput() ?>
|
|
||||
|
|
||||
<div class="form-group"> |
|
||||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|
||||
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
|
|
||||
</div> |
|
||||
|
|
||||
<?php ActiveForm::end(); ?>
|
|
||||
|
|
||||
</div> |
|
@ -1,98 +0,0 @@ |
|||||
<?php |
|
||||
/* |
|
||||
* The MIT License |
|
||||
* |
|
||||
* Copyright 2019 Blobt. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software and associated documentation files (the "Software"), to deal |
|
||||
* in the Software without restriction, including without limitation the rights |
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||
* copies of the Software, and to permit persons to whom the Software is |
|
||||
* furnished to do so, subject to the following conditions: |
|
||||
* |
|
||||
* The above copyright notice and this permission notice shall be included in |
|
||||
* all copies or substantial portions of the Software. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
||||
* THE SOFTWARE. |
|
||||
*/ |
|
||||
?>
|
|
||||
|
|
||||
<header> |
|
||||
<link href="http://hayageek.github.io/jQuery-Upload-File/4.0.11/uploadfile.css" rel="stylesheet"> |
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
|
||||
<script src="http://hayageek.github.io/jQuery-Upload-File/4.0.11/jquery.uploadfile.min.js"></script> |
|
||||
</header> |
|
||||
<body> |
|
||||
<div id="showoldupload"> |
|
||||
<div class="ajax-upload-dragdrop" style="vertical-align: top; width: 600px;"> |
|
||||
<div class="ajax-file-upload" style="position: relative; overflow: hidden; cursor: default;">Upload |
|
||||
<form method="POST" action="upload.php" enctype="multipart/form-data" style="margin: 0px; padding: 0px;"> |
|
||||
<input type="file" id="ajax-upload-id-1573635462220" name="myfile[]" accept="*" multiple="" |
|
||||
style="position: absolute; cursor: pointer; top: 0px; width: 100%; height: 100%; left: 0px; z-index: 100; opacity: 0;"> |
|
||||
</form> |
|
||||
</div> |
|
||||
<span><b>Drag & Drop Files</b></span></div> |
|
||||
<div></div> |
|
||||
</div> |
|
||||
<div class="ajax-file-upload-container"></div> |
|
||||
</body> |
|
||||
<script> |
|
||||
$("#showoldupload").uploadFile( |
|
||||
{ |
|
||||
url: "upload", |
|
||||
dragDrop: true, |
|
||||
fileName: "file", |
|
||||
returnType: "json", |
|
||||
showDelete: true, |
|
||||
showDownload: false, |
|
||||
statusBarWidth: 300, |
|
||||
dragdropWidth: 300, |
|
||||
maxFileSize: 200 * 1024, |
|
||||
dragDropStr: "<span><b>拖动上传</b></span>", |
|
||||
sizeErrorStr: "图片超过最大尺寸限制", |
|
||||
uploadErrorStr: "上传失败", |
|
||||
showPreview: true, |
|
||||
previewHeight: "60px", |
|
||||
previewWidth: "60px", |
|
||||
onSuccess: function (files, data) { |
|
||||
$.ajax({ |
|
||||
url: "save-database", |
|
||||
dataType: "json", |
|
||||
data: {data: data, fileName: files}, |
|
||||
}); |
|
||||
}, |
|
||||
onLoad: function (obj) { |
|
||||
$.ajax({ |
|
||||
cache: false, |
|
||||
url: "previews", |
|
||||
dataType: "json", |
|
||||
success: function (data) { |
|
||||
for (var i = 0; i < data.length; i++) { |
|
||||
obj.createProgress(data[i]["name"], data[i]["path"], data[i]["size"]); |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
}, |
|
||||
deleteCallback: function (data, pd) { |
|
||||
for (var i = 0; i < data.length; i++) { |
|
||||
// alertify.confirm('系统提示', "确定执行批量 '"+act+"' 操作?", function() {
|
|
||||
$.post("image-del", {op: "delete", name: data[i]}, |
|
||||
function (resp, textStatus, jqXHR) { |
|
||||
//Show Message
|
|
||||
alert("File Deleted"); |
|
||||
}); |
|
||||
// },function(){
|
|
||||
// });
|
|
||||
} |
|
||||
pd.statusbar.hide(); //You choice.
|
|
||||
}, |
|
||||
|
|
||||
}); |
|
||||
</script> |
|
@ -1,82 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use yii\helpers\Html; |
|
||||
use yii\widgets\ActiveForm; |
|
||||
|
|
||||
/* @var $this yii\web\View */ |
|
||||
/* @var $model common\models\ars\Goods */ |
|
||||
/* @var $form yii\widgets\ActiveForm */ |
|
||||
?>
|
|
||||
|
|
||||
<div class="goods-form"> |
|
||||
|
|
||||
<?php $form = ActiveForm::begin(); ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'pid')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'cat_id')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'brand_id')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'shop_cat_id')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'sn')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'supplier_id')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'weight')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'length')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'width')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'height')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'diameter')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'unit')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'sold_count')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'limit_count')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'stock')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'stock_warn')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'market_price')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'price')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'brief')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'image')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'model_id')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_sale')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'sort_order')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'bouns_points')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'experience_points')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_delete')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'express_template')->textInput() ?>
|
|
||||
|
|
||||
<div class="form-group"> |
|
||||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|
||||
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
|
|
||||
</div> |
|
||||
|
|
||||
<?php ActiveForm::end(); ?>
|
|
||||
|
|
||||
</div> |
|
@ -1,44 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use yii\helpers\Html; |
|
||||
use yii\widgets\ActiveForm; |
|
||||
|
|
||||
/* @var $this yii\web\View */ |
|
||||
/* @var $model common\models\ars\ShopCategory */ |
|
||||
/* @var $form yii\widgets\ActiveForm */ |
|
||||
?>
|
|
||||
|
|
||||
<div class="shop-category-form"> |
|
||||
|
|
||||
<?php $form = ActiveForm::begin(); ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'pid')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'goods_count')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'keywords')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'desc')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'sort_order')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'icon_type')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'filter_attr')->textarea(['rows' => 6]) ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_show')->textInput() ?>
|
|
||||
|
|
||||
<?= $form->field($model, 'is_delete')->textInput() ?>
|
|
||||
|
|
||||
<div class="form-group"> |
|
||||
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
|
|
||||
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
|
|
||||
</div> |
|
||||
|
|
||||
<?php ActiveForm::end(); ?>
|
|
||||
|
|
||||
</div> |
|
@ -1,47 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use yii\helpers\Html; |
|
||||
use yii\widgets\ActiveForm; |
|
||||
use \blobt\widgets\DateRangePicker; |
|
||||
|
|
||||
/* @var $this yii\web\View */ |
|
||||
/* @var $model common\models\searchs\SupplierSearch */ |
|
||||
/* @var $form yii\widgets\ActiveForm */ |
|
||||
?>
|
|
||||
|
|
||||
<?php $form = ActiveForm::begin([ |
|
||||
'action' => ['index'], |
|
||||
'method' => 'get', |
|
||||
'validateOnType' => true, |
|
||||
]); |
|
||||
?>
|
|
||||
<div class="col-sm-12"> |
|
||||
<div class="dataTables_filter"> |
|
||||
<?= $form->field($model, 'id', [ |
|
||||
"template" => "{input}{error}", |
|
||||
"inputOptions" => [ |
|
||||
"placeholder" => "检索ID", |
|
||||
"class" => "form-control", |
|
||||
], |
|
||||
"errorOptions" => [ |
|
||||
"class" => "error-tips" |
|
||||
] |
|
||||
]) |
|
||||
?>
|
|
||||
<?= $form->field($model, "created_at_range", [ |
|
||||
"template" => "{input}{error}", |
|
||||
"inputOptions" => [ |
|
||||
"placeholder" => "创建时间", |
|
||||
], |
|
||||
"errorOptions" => [ |
|
||||
"class" => "error-tips" |
|
||||
] |
|
||||
])->widget(DateRangePicker::className()); |
|
||||
?>
|
|
||||
<div class="form-group"> |
|
||||
<?= Html::submitButton('<i class="fa fa-filter"></i>', ['class' => 'btn btn-default']) ?>
|
|
||||
<?= Html::resetButton('<i class="fa fa-eraser"></i>', ['class' => 'btn btn-default']) ?>
|
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
<?php ActiveForm::end(); ?>
|
|
Before Width: 1024 | Height: 759 | Size: 159 KiB |
@ -0,0 +1,14 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace antgoods\goods; |
||||
|
|
||||
|
/** |
||||
|
* This is just an example. |
||||
|
*/ |
||||
|
class AutoloadExample extends \yii\base\Widget |
||||
|
{ |
||||
|
public function run() |
||||
|
{ |
||||
|
return "Hello!"; |
||||
|
} |
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
商品模块 |
||||
|
==== |
||||
|
ant基础模块之一 |
||||
|
|
||||
|
Installation |
||||
|
------------ |
||||
|
|
||||
|
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). |
||||
|
|
||||
|
Either run |
||||
|
|
||||
|
``` |
||||
|
php composer.phar require --prefer-dist antgoods/goods "*" |
||||
|
``` |
||||
|
|
||||
|
or add |
||||
|
|
||||
|
``` |
||||
|
"antgoods/goods": "*" |
||||
|
``` |
||||
|
|
||||
|
to the require section of your `composer.json` file. |
||||
|
|
||||
|
|
||||
|
Usage |
||||
|
----- |
||||
|
|
||||
|
Once the extension is installed, simply use it in your code by : |
||||
|
|
||||
|
```php |
||||
|
<?= \antgoods\goods\AutoloadExample::widget(); ?>``` |
@ -0,0 +1,21 @@ |
|||||
|
{ |
||||
|
"name": "antgoods/goods", |
||||
|
"description": "ant基础模块之一", |
||||
|
"type": "yii2-extension", |
||||
|
"keywords": ["goods"], |
||||
|
"license": "MIT", |
||||
|
"authors": [ |
||||
|
{ |
||||
|
"name": "linyao", |
||||
|
"email": "linyaostalker@gmail.com" |
||||
|
} |
||||
|
], |
||||
|
"require": { |
||||
|
"yiisoft/yii2": "~2.0.0" |
||||
|
}, |
||||
|
"autoload": { |
||||
|
"psr-4": { |
||||
|
"antgoods\\goods\\": "" |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2018/9/13 |
||||
|
* Time: 11:47 |
||||
|
*/ |
||||
|
|
||||
|
namespace antgoods\goods; |
||||
|
|
||||
|
|
||||
|
class Module extends \yii\base\Module |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public $controllerNamespace = 'antgoods\goods\controllers'; |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function init() |
||||
|
{ |
||||
|
parent::init(); |
||||
|
|
||||
|
// custom initialization code goes here
|
||||
|
} |
||||
|
} |
@ -0,0 +1,276 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace antgoods\goods\controllers; |
||||
|
|
||||
|
use antgoods\goods\logic\goods\GoodsManager; |
||||
|
use common\models\ars\File; |
||||
|
use Yii; |
||||
|
use antgoods\goods\models\ars\Category; |
||||
|
use antgoods\goods\models\searchs\CategorySearch; |
||||
|
use yii\web\Controller; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\filters\VerbFilter; |
||||
|
|
||||
|
/** |
||||
|
* CategoryController implements the CRUD actions for Category model. |
||||
|
*/ |
||||
|
class CategoryController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
'verbs' => [ |
||||
|
'class' => VerbFilter::className(), |
||||
|
'actions' => [ |
||||
|
'delete' => ['POST'], |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
return [ |
||||
|
'upload' => [ |
||||
|
'class' => 'iron\actions\UploadAction', |
||||
|
'path' => 'xls/', |
||||
|
'maxSize' => 20480, |
||||
|
] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Lists all Category models. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$searchModel = new CategorySearch(); |
||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
||||
|
|
||||
|
return $this->render('index', [ |
||||
|
'searchModel' => $searchModel, |
||||
|
'dataProvider' => $dataProvider, |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Displays a single Category model. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionView($id) |
||||
|
{ |
||||
|
return $this->render('view', [ |
||||
|
'model' => $this->findModel($id), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates a new Category model. |
||||
|
* If creation is successful, the browser will be redirected to the 'view' page. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
$model = new Category(); |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//类目图片上传保存处理
|
||||
|
$icon_image_id_str = $model->iconImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_icon_image_res = $goods_manager->saveFile(explode(',', $icon_image_id_str), $model, [], File::OWN_TYPE_CATEGORY_ICON); |
||||
|
if($save_icon_image_res['status']){ |
||||
|
$model->icon = $save_icon_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('create', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Updates an existing Category model. |
||||
|
* If update is successful, the browser will be redirected to the 'view' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionUpdate($id) |
||||
|
{ |
||||
|
$model = $this->findModel($id); |
||||
|
$model->iconImageId = $model->icon; |
||||
|
//记录已保存的类目图片id,用于修改
|
||||
|
$icon_image_old_id_arr = $model->icon; |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//类目图片上传保存处理
|
||||
|
$icon_image_id_str = $model->iconImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_icon_image_res = $goods_manager->saveFile(explode(',', $icon_image_id_str), $model, explode(',', $icon_image_old_id_arr), File::OWN_TYPE_CATEGORY_ICON); |
||||
|
if($save_icon_image_res['status'] && $save_icon_image_res['first_file_id'] !== 0){ |
||||
|
$model->icon = $save_icon_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('update', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Deletes an existing Category model. |
||||
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionDelete($id) |
||||
|
{ |
||||
|
$model = $this->findModel($id); |
||||
|
|
||||
|
$model->is_delete = Category::IS_DELETE_YES; |
||||
|
$model->save(); |
||||
|
|
||||
|
return $this->redirect(['index']); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds the Category model based on its primary key value. |
||||
|
* If the model is not found, a 404 HTTP exception will be thrown. |
||||
|
* @param integer $id |
||||
|
* @return Category the loaded model |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
protected function findModel($id) |
||||
|
{ |
||||
|
if (($model = Category::findOne($id)) !== null) { |
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
throw new NotFoundHttpException('The requested page does not exist.'); |
||||
|
} |
||||
|
/** |
||||
|
* @author iron |
||||
|
* 文件导出 |
||||
|
*/ |
||||
|
public function actionExport() |
||||
|
{ |
||||
|
$searchModel = new CategorySearch(); |
||||
|
$params = Yii::$app->request->queryParams; |
||||
|
if ($params['page-type'] == 'all') { |
||||
|
$dataProvider = $searchModel->allData($params); |
||||
|
} else { |
||||
|
$dataProvider = $searchModel->search($params); |
||||
|
} |
||||
|
\iron\widget\Excel::export([ |
||||
|
'models' => $dataProvider->getModels(), |
||||
|
'format' => 'Xlsx', |
||||
|
'asAttachment' => true, |
||||
|
'fileName' =>'Categories'. "-" .date('Y-m-d H/i/s', time()), |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id |
||||
|
*/ |
||||
|
public function actionSaveFile() |
||||
|
{ |
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$data = Yii::$app->request->get('data'); |
||||
|
$file_name = Yii::$app->request->get('fileName')[0]; |
||||
|
|
||||
|
if ($data['status'] == true) { |
||||
|
$model = new \common\models\ars\TemFile(); |
||||
|
$model->user_id = Yii::$app->user->identity->id; |
||||
|
$model->name = $file_name; |
||||
|
$file_manager = new \backend\logic\file\FileManager(); |
||||
|
$type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); |
||||
|
if ($type_res['status']) { |
||||
|
$model->type = $type_res['type']; |
||||
|
} |
||||
|
$model->alias = $data['alias']; |
||||
|
$model->path = $data['path']; |
||||
|
$model->save(); |
||||
|
return $model->id; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
* 点击删除按钮时同时删除字符串中的id |
||||
|
*/ |
||||
|
public function actionImgIdDel() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$img_id = Yii::$app->request->get('imgid'); |
||||
|
$img_id_arr = explode(',', $img_id); |
||||
|
if(isset(Yii::$app->request->get('data')['alias'])) { |
||||
|
$alias = Yii::$app->request->get('data')['alias']; |
||||
|
$tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
}else{ |
||||
|
foreach (Yii::$app->request->get() as $key => $value) { |
||||
|
$tem_file = \common\models\ars\File::findOne(['alias' => $value]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$img_id_str = implode(',', $img_id_arr); |
||||
|
return $img_id_str; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool|false|string |
||||
|
* 加载已有的文件 |
||||
|
*/ |
||||
|
public function actionImageFile() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\File')){ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$file_id_str = Yii::$app->request->get('fileidstr'); |
||||
|
$file_id_arr = explode(',', $file_id_str); |
||||
|
$data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); |
||||
|
$res = array(); |
||||
|
if($data) { |
||||
|
$i = 0; |
||||
|
foreach ($data as $key => $value) { |
||||
|
$res[$i]['name'] = $value->alias; |
||||
|
$res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; |
||||
|
$res[$i]['size'] = filesize($value->path); |
||||
|
$i++; |
||||
|
} |
||||
|
} |
||||
|
return json_encode($res); |
||||
|
} |
||||
|
} |
@ -0,0 +1,282 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace antgoods\goods\controllers; |
||||
|
|
||||
|
use common\models\ars\TemFile; |
||||
|
use MongoDB\Driver\Manager; |
||||
|
use Yii; |
||||
|
use antgoods\goods\models\ars\Goods; |
||||
|
use antgoods\goods\models\searchs\GoodsSearch; |
||||
|
use yii\web\Controller; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\filters\VerbFilter; |
||||
|
use antgoods\goods\logic\goods\GoodsManager; |
||||
|
use common\models\ars\File; |
||||
|
|
||||
|
/** |
||||
|
* GoodsController implements the CRUD actions for Goods model. |
||||
|
*/ |
||||
|
class GoodsController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
'verbs' => [ |
||||
|
'class' => VerbFilter::className(), |
||||
|
'actions' => [ |
||||
|
'delete' => ['POST'], |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
return [ |
||||
|
'upload' => [ |
||||
|
'class' => 'iron\actions\UploadAction', |
||||
|
'path' => 'xls/', |
||||
|
'maxSize' => 20480, |
||||
|
] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Lists all Goods models. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$searchModel = new GoodsSearch(); |
||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
||||
|
|
||||
|
return $this->render('index', [ |
||||
|
'searchModel' => $searchModel, |
||||
|
'dataProvider' => $dataProvider, |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Displays a single Goods model. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionView($id) |
||||
|
{ |
||||
|
return $this->render('view', [ |
||||
|
'model' => $this->findModel($id), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates a new Goods model. |
||||
|
* If creation is successful, the browser will be redirected to the 'view' page. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
$model = new Goods(); |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//商品封面图和商品详情图上传保存处理
|
||||
|
$cover_image_id_str = $model->coverImageId; |
||||
|
$detail_image_id_str = $model->detailImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_cover_image_res = $goods_manager->saveFile(explode(',', $cover_image_id_str), $model); |
||||
|
$save_detail_image_res = $goods_manager->saveFile(explode(',', $detail_image_id_str), $model, [], File::OWN_TYPE_GOODS_DETAILS); |
||||
|
if($save_cover_image_res['status'] && $save_detail_image_res['status']){ |
||||
|
$model->image = $save_cover_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('create', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Updates an existing Goods model. |
||||
|
* If update is successful, the browser will be redirected to the 'view' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionUpdate($id) |
||||
|
{ |
||||
|
$model = $this->findModel($id); |
||||
|
$model->coverImageId = $model->image; |
||||
|
$model->detailImageId = implode(',', File::find()->select('id')->where(['is_delete' => File::IS_DELETE_NO, 'own_id' => $model->id, 'own_type' => File::OWN_TYPE_GOODS_DETAILS])->column()); |
||||
|
|
||||
|
//记录已保存的商品图片id,用于修改
|
||||
|
$cover_image_old_id_arr = $model->image; |
||||
|
$detail_image_old_id_arr = $model->detailImageId; |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//商品封面图和商品详情图上传保存处理
|
||||
|
$cover_image_id_str = $model->coverImageId; |
||||
|
$detail_image_id_str = $model->detailImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_cover_image_res = $goods_manager->saveFile(explode(',', $cover_image_id_str), $model, explode(',', $cover_image_old_id_arr)); |
||||
|
$save_detail_image_res = $goods_manager->saveFile(explode(',', $detail_image_id_str), $model, explode(',', $detail_image_old_id_arr), File::OWN_TYPE_GOODS_DETAILS); |
||||
|
if($save_cover_image_res['status'] && $save_detail_image_res['status'] && $save_cover_image_res['first_file_id'] !== 0){ |
||||
|
$model->image = $save_cover_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('update', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Deletes an existing Goods model. |
||||
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionDelete($id) |
||||
|
{ |
||||
|
$this->findModel($id)->delete(); |
||||
|
|
||||
|
return $this->redirect(['index']); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds the Goods model based on its primary key value. |
||||
|
* If the model is not found, a 404 HTTP exception will be thrown. |
||||
|
* @param integer $id |
||||
|
* @return Goods the loaded model |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
protected function findModel($id) |
||||
|
{ |
||||
|
if (($model = Goods::findOne($id)) !== null) { |
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
throw new NotFoundHttpException('The requested page does not exist.'); |
||||
|
} |
||||
|
/** |
||||
|
* @author iron |
||||
|
* 文件导出 |
||||
|
*/ |
||||
|
public function actionExport() |
||||
|
{ |
||||
|
$searchModel = new GoodsSearch(); |
||||
|
$params = Yii::$app->request->queryParams; |
||||
|
if ($params['page-type'] == 'all') { |
||||
|
$dataProvider = $searchModel->allData($params); |
||||
|
} else { |
||||
|
$dataProvider = $searchModel->search($params); |
||||
|
} |
||||
|
\iron\widget\Excel::export([ |
||||
|
'models' => $dataProvider->getModels(), |
||||
|
'format' => 'Xlsx', |
||||
|
'asAttachment' => true, |
||||
|
'fileName' =>'Goods'. "-" .date('Y-m-d H/i/s', time()), |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id |
||||
|
*/ |
||||
|
public function actionSaveFile() |
||||
|
{ |
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$data = Yii::$app->request->get('data'); |
||||
|
$file_name = Yii::$app->request->get('fileName')[0]; |
||||
|
|
||||
|
if ($data['status'] == true) { |
||||
|
$model = new \common\models\ars\TemFile(); |
||||
|
$model->user_id = Yii::$app->user->identity->id; |
||||
|
$model->name = $file_name; |
||||
|
$file_manager = new \backend\logic\file\FileManager(); |
||||
|
$type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); |
||||
|
if ($type_res['status']) { |
||||
|
$model->type = $type_res['type']; |
||||
|
} |
||||
|
$model->alias = $data['alias']; |
||||
|
$model->path = $data['path']; |
||||
|
$model->save(); |
||||
|
return $model->id; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
* 点击删除按钮时同时删除字符串中的id |
||||
|
*/ |
||||
|
public function actionImgIdDel() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$img_id = Yii::$app->request->get('imgid'); |
||||
|
$img_id_arr = explode(',', $img_id); |
||||
|
if(isset(Yii::$app->request->get('data')['alias'])) { |
||||
|
$alias = Yii::$app->request->get('data')['alias']; |
||||
|
$tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
}else{ |
||||
|
foreach (Yii::$app->request->get() as $key => $value) { |
||||
|
$tem_file = \common\models\ars\File::findOne(['alias' => $value]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$img_id_str = implode(',', $img_id_arr); |
||||
|
return $img_id_str; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool|false|string |
||||
|
* 加载已有的文件 |
||||
|
*/ |
||||
|
public function actionImageFile() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\File')){ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$file_id_str = Yii::$app->request->get('fileidstr'); |
||||
|
$file_id_arr = explode(',', $file_id_str); |
||||
|
$data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); |
||||
|
$res = array(); |
||||
|
if($data) { |
||||
|
$i = 0; |
||||
|
foreach ($data as $key => $value) { |
||||
|
$res[$i]['name'] = $value->alias; |
||||
|
$res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; |
||||
|
$res[$i]['size'] = filesize($value->path); |
||||
|
$i++; |
||||
|
} |
||||
|
} |
||||
|
return json_encode($res); |
||||
|
} |
||||
|
} |
@ -0,0 +1,273 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace antgoods\goods\controllers; |
||||
|
|
||||
|
use antgoods\goods\logic\goods\GoodsManager; |
||||
|
use common\models\ars\File; |
||||
|
use Yii; |
||||
|
use antgoods\goods\models\ars\ShopCategory; |
||||
|
use antgoods\goods\models\searchs\ShopCategorySearch; |
||||
|
use yii\web\Controller; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\filters\VerbFilter; |
||||
|
|
||||
|
/** |
||||
|
* ShopcategoryController implements the CRUD actions for ShopCategory model. |
||||
|
*/ |
||||
|
class ShopcategoryController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
'verbs' => [ |
||||
|
'class' => VerbFilter::className(), |
||||
|
'actions' => [ |
||||
|
'delete' => ['POST'], |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function actions() |
||||
|
{ |
||||
|
return [ |
||||
|
'upload' => [ |
||||
|
'class' => 'iron\actions\UploadAction', |
||||
|
'path' => 'xls/', |
||||
|
'maxSize' => 20480, |
||||
|
] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Lists all ShopCategory models. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$searchModel = new ShopCategorySearch(); |
||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
||||
|
|
||||
|
return $this->render('index', [ |
||||
|
'searchModel' => $searchModel, |
||||
|
'dataProvider' => $dataProvider, |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Displays a single ShopCategory model. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionView($id) |
||||
|
{ |
||||
|
return $this->render('view', [ |
||||
|
'model' => $this->findModel($id), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates a new ShopCategory model. |
||||
|
* If creation is successful, the browser will be redirected to the 'view' page. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
$model = new ShopCategory(); |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//类目图片上传保存处理
|
||||
|
$icon_image_id_str = $model->iconImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_icon_image_res = $goods_manager->saveFile(explode(',', $icon_image_id_str), $model, [], File::OWN_TYPE_CATEGORY_ICON); |
||||
|
if($save_icon_image_res['status']){ |
||||
|
$model->icon = $save_icon_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('create', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Updates an existing ShopCategory model. |
||||
|
* If update is successful, the browser will be redirected to the 'view' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionUpdate($id) |
||||
|
{ |
||||
|
$model = $this->findModel($id); |
||||
|
$model->iconImageId = $model->icon; |
||||
|
//记录已保存的类目图片id,用于修改
|
||||
|
$icon_image_old_id_arr = $model->icon; |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post())) { |
||||
|
|
||||
|
//类目图片上传保存处理
|
||||
|
$icon_image_id_str = $model->iconImageId; |
||||
|
$model->save(); |
||||
|
$goods_manager = new GoodsManager(); |
||||
|
$save_icon_image_res = $goods_manager->saveFile(explode(',', $icon_image_id_str), $model, explode(',', $icon_image_old_id_arr), File::OWN_TYPE_CATEGORY_ICON); |
||||
|
if($save_icon_image_res['status'] && $save_icon_image_res['first_file_id'] !== 0){ |
||||
|
$model->icon = $save_icon_image_res['first_file_id']; |
||||
|
$model->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->redirect('index'); |
||||
|
} |
||||
|
|
||||
|
return $this->render('update', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Deletes an existing ShopCategory model. |
||||
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionDelete($id) |
||||
|
{ |
||||
|
$this->findModel($id)->delete(); |
||||
|
|
||||
|
return $this->redirect(['index']); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds the ShopCategory model based on its primary key value. |
||||
|
* If the model is not found, a 404 HTTP exception will be thrown. |
||||
|
* @param integer $id |
||||
|
* @return ShopCategory the loaded model |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
protected function findModel($id) |
||||
|
{ |
||||
|
if (($model = ShopCategory::findOne($id)) !== null) { |
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
throw new NotFoundHttpException('The requested page does not exist.'); |
||||
|
} |
||||
|
/** |
||||
|
* @author iron |
||||
|
* 文件导出 |
||||
|
*/ |
||||
|
public function actionExport() |
||||
|
{ |
||||
|
$searchModel = new ShopCategorySearch(); |
||||
|
$params = Yii::$app->request->queryParams; |
||||
|
if ($params['page-type'] == 'all') { |
||||
|
$dataProvider = $searchModel->allData($params); |
||||
|
} else { |
||||
|
$dataProvider = $searchModel->search($params); |
||||
|
} |
||||
|
\iron\widget\Excel::export([ |
||||
|
'models' => $dataProvider->getModels(), |
||||
|
'format' => 'Xlsx', |
||||
|
'asAttachment' => true, |
||||
|
'fileName' =>'Shop Categories'. "-" .date('Y-m-d H/i/s', time()), |
||||
|
'columns' => $searchModel->columns() |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id |
||||
|
*/ |
||||
|
public function actionSaveFile() |
||||
|
{ |
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$data = Yii::$app->request->get('data'); |
||||
|
$file_name = Yii::$app->request->get('fileName')[0]; |
||||
|
|
||||
|
if ($data['status'] == true) { |
||||
|
$model = new \common\models\ars\TemFile(); |
||||
|
$model->user_id = Yii::$app->user->identity->id; |
||||
|
$model->name = $file_name; |
||||
|
$file_manager = new \backend\logic\file\FileManager(); |
||||
|
$type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); |
||||
|
if ($type_res['status']) { |
||||
|
$model->type = $type_res['type']; |
||||
|
} |
||||
|
$model->alias = $data['alias']; |
||||
|
$model->path = $data['path']; |
||||
|
$model->save(); |
||||
|
return $model->id; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
* 点击删除按钮时同时删除字符串中的id |
||||
|
*/ |
||||
|
public function actionImgIdDel() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
$img_id = Yii::$app->request->get('imgid'); |
||||
|
$img_id_arr = explode(',', $img_id); |
||||
|
if(isset(Yii::$app->request->get('data')['alias'])) { |
||||
|
$alias = Yii::$app->request->get('data')['alias']; |
||||
|
$tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
}else{ |
||||
|
foreach (Yii::$app->request->get() as $key => $value) { |
||||
|
$tem_file = \common\models\ars\File::findOne(['alias' => $value]); |
||||
|
if ($tem_file) { |
||||
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$img_id_str = implode(',', $img_id_arr); |
||||
|
return $img_id_str; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return bool|false|string |
||||
|
* 加载已有的文件 |
||||
|
*/ |
||||
|
public function actionImageFile() |
||||
|
{ |
||||
|
//判断该类是否存在
|
||||
|
if(!class_exists('\common\models\ars\File')){ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$file_id_str = Yii::$app->request->get('fileidstr'); |
||||
|
$file_id_arr = explode(',', $file_id_str); |
||||
|
$data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); |
||||
|
$res = array(); |
||||
|
if($data) { |
||||
|
$i = 0; |
||||
|
foreach ($data as $key => $value) { |
||||
|
$res[$i]['name'] = $value->alias; |
||||
|
$res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; |
||||
|
$res[$i]['size'] = filesize($value->path); |
||||
|
$i++; |
||||
|
} |
||||
|
} |
||||
|
return json_encode($res); |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace antgoods\goods\logic\goods; |
||||
|
|
||||
|
|
||||
|
class GoodsManager |
||||
|
{ |
||||
|
/** |
||||
|
* @param $newFileIdArr |
||||
|
* @param array $oldFileIdArr |
||||
|
* @param $goodsModel |
||||
|
* @param int $filetype |
||||
|
* @return bool |
||||
|
* 保存新文件,删除不需要的文件操作 |
||||
|
*/ |
||||
|
public function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $filetype = 1) |
||||
|
{ |
||||
|
//判断类名是否存在
|
||||
|
if(!class_exists('\backend\logic\file\FileManager') || !class_exists('\common\models\ars\File')) { |
||||
|
return ['status' => false, 'info' => '操作失败']; |
||||
|
} |
||||
|
|
||||
|
//需要新建的文件id
|
||||
|
$create_file_id_arr = array_diff($newFileIdArr, $oldFileIdArr); |
||||
|
|
||||
|
//创建文件
|
||||
|
$class = new \backend\logic\file\FileManager(); |
||||
|
$create_file_res = $class->saveTemFileToFile($create_file_id_arr, $goodsModel->id, $filetype); |
||||
|
|
||||
|
//需要删除的文件id
|
||||
|
$del_file_id_arr = array_diff($oldFileIdArr, $newFileIdArr); |
||||
|
|
||||
|
//删除文件
|
||||
|
$class->deleteFile($del_file_id_arr); |
||||
|
|
||||
|
//记录第一张图片id
|
||||
|
$first_file_id = 0; |
||||
|
|
||||
|
//查看修改数组是否为空
|
||||
|
if (!$newFileIdArr[0]) { |
||||
|
$first_file_id = null; |
||||
|
}else { |
||||
|
if ($create_file_res['status']) { |
||||
|
$first_file_id = $create_file_res['first_file_id']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return ['status' => true, 'info' => '操作成功', 'first_file_id' => $first_file_id]; |
||||
|
} |
||||
|
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue