Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
namespace shop\manage\goods; use common\constants\log\goods\GoodsLogConstant; use co..
Decoded Output download
<? namespace shop\manage\goods;
use common\constants\log\goods\GoodsLogConstant;
use common\constants\shop\ShopTypeConstant;
use common\exceptions\goods\GoodsException;
use common\helpers\DateTimeHelper;
use common\helpers\LogHelper;
use common\helpers\PluginHelper;
use common\helpers\RequestHelper;
use common\models\goods\category\GoodsCategoryMapModel;
use common\models\goods\category\GoodsCategoryModel;
use common\models\log\LogModel;
use common\models\shop\ShopSettings;
use shopases\ManageApiController;
use yii\helpers\Json;
class CategoryController extends ManageApiController
{
public $postActions = [
'create',
'update',
'forever-delete'
];
public $allowPermActions = [
'get-list',
];
/**
*
* @return \yii\web\Response
* @author
*/
public function actionGetList()
{
$list = GoodsCategoryModel::search($this->shopId, 0);
$list['level'] = ShopSettings::get($this->shopId, 'goods_category')['level'];
return $this->success($list);
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionGetOne()
{
$id = RequestHelper::getInt('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_GET_ONE_PARAMS_ERROR);
}
$category = GoodsCategoryModel::getOne($this->shopId, $id);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_GET_ONE_NOT_FOUND_ERROR);
}
return $this->success($category);
}
// /**
// *
// * @return \yii\web\Response
// * @throws GoodsException
// * @author
// */
// public function actionCreate()
// {
// return $this->actionUpdate();
// }
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionUpdate()
{
$post = RequestHelper::post();
if ($post['id']) {
$category = GoodsCategoryModel::getOne($this->shopId, $post['id']);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_SAVE_NOT_FOUND_ERROR);
}
}
$category = !empty($category) ? $category : new GoodsCategoryModel();
$transaction = \Yii::$app->getDb()->beginTransaction();
try {
unset($post['id']);
if (empty($post['shop_id'])) {
$post['shop_id'] = $this->shopId;
}
$category->setAttributes($post);
if (empty($category->create_time)) {
$category->create_time = DateTimeHelper::now();
}
$dirtyData = $category->getDirtyAttributes2();
if (!$category->save()) {
throw new GoodsException(GoodsException::CATEGORY_SAVE_ERROR);
}
//
// LogModel::write(
// $this->shopId,
// $this->userId,
// GoodsLogConst::getText(GoodsLogConst::GOODS_CATEGORY_ONE_EDIT),
// $category->id,
// $dirtyData
// );
$transaction->commit();
} catch (\Throwable $exception) {
$transaction->rollBack();
throw new GoodsException($exception->getCode());
}
return $this->success();
}
/**
*
* @return \yii\web\Response
* @author
*/
public function actionSave()
{
$post = RequestHelper::post('data');
if (!empty($post)) {
$post = Json::decode($post);
foreach ($post as $oneIndex => $oneLevel) {
$childrens = array_filter($oneLevel['children'] ?? []);
$oneResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $oneLevel, 0, 1);
if (!$oneResult) {
continue;
}
//
if (!empty($childrens) && $this->shopType != ShopTypeConstant::TYPE_MERCHANT) {
foreach ($childrens as $twoIndex => $twoLevel) {
$childrensShildrens = array_filter($twoLevel['children'] ?? []);
$twoResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $twoLevel, $oneResult, 2);
if (!$twoResult) {
continue;
}
//
if (!empty($childrensShildrens)) {
foreach ($childrensShildrens as $threeIndex => $threeLevel) {
$threeResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $threeLevel, $twoResult, 3);
if (!$threeResult) {
continue;
}
}
}
}
}
}
}
return $this->success();
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionForeverDelete()
{
$id = RequestHelper::post('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_DELETE_PARAMS_ERROR);
}
$data = GoodsCategoryModel::findAll(['id' => $id, 'shop_id' => $this->shopId]);
foreach ($data as $item) {
$item->delete();
GoodsCategoryMapModel::deleteAll(['category_id' => $item['id'], 'shop_id' => $this->shopId]);
$logPrimaryData = $item->getLogAttributeRemark([
'id' => $item->id,
'name' => $item->name
]);
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_DELETE,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_DELETE),
[
'log_data' => $item->attributes,
'log_primary' => $logPrimaryData,
'sub_shop_id' => $item->sub_shop_id
]
);
}
return $this->success();
}
/**
*
* @throws GoodsException
* @throws \yii\db\Exception
* @author
*/
public function actionSetSetting()
{
$post = RequestHelper::postArray('data');
if (empty($post)) {
throw new GoodsException(GoodsException::CATEGORY_SET_SETTING_PARAMS_ERROR);
}
ShopSettings::set($this->shopId, 'goods_category', [
'level' => $post['level'] ?: 0, //
'style' => $post['style'] ?: 0, //
'adv_url' => $post['adv_url'] ?: '', //
'template_type' => $post['template_type'], //
'title' => $post['title'] ?: ShopSettings::getDefaultSettings('goods_category.title'), //title
]);
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_SETTING,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_SETTING),
0,
[
'log_data' => $post,
'log_primary' => [
'' => $post['level'] == 1 ? '' : ($post['level'] == 2 ? '' : ''),
// '' => $post['style'] ?: "",
// '' => $post['adv_url'] ?: '',
],
'sub_shop_id' => $this->subShopId
]
);
return $this->success();
}
/**
*
* @author
*/
public function actionGetSetting()
{
$result = ShopSettings::get($this->shopId, 'goods_category');
$result['title'] = $result['title'] ?? ShopSettings::getDefaultSettings('goods_category.title'); //
return $this->success(['data' => $result]);
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionSwitch()
{
$id = RequestHelper::postInt('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_SWITCH_PARAMS_ERROR);
}
$category = GoodsCategoryModel::findOne($id);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_SWITCH_CATEGORY_NOT_FOUND_ERROR);
}
$category->status = $category->status == 1 ? 0 : 1;
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_SWITCH,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_SWITCH),
$id,
[
'log_data' => $category->attributes,
'log_primary' => $category->getLogAttributeRemark([
'status' => $category->status == 1 ? '' : ''
]),
'sub_shop_id' => $this->subShopId
]
);
$category->save();
return $this->success();
}
}
?>
Did this file decode correctly?
Original Code
namespace shop\manage\goods;
use common\constants\log\goods\GoodsLogConstant;
use common\constants\shop\ShopTypeConstant;
use common\exceptions\goods\GoodsException;
use common\helpers\DateTimeHelper;
use common\helpers\LogHelper;
use common\helpers\PluginHelper;
use common\helpers\RequestHelper;
use common\models\goods\category\GoodsCategoryMapModel;
use common\models\goods\category\GoodsCategoryModel;
use common\models\log\LogModel;
use common\models\shop\ShopSettings;
use shop\bases\ManageApiController;
use yii\helpers\Json;
class CategoryController extends ManageApiController
{
public $postActions = [
'create',
'update',
'forever-delete'
];
public $allowPermActions = [
'get-list',
];
/**
*
* @return \yii\web\Response
* @author
*/
public function actionGetList()
{
$list = GoodsCategoryModel::search($this->shopId, 0);
$list['level'] = ShopSettings::get($this->shopId, 'goods_category')['level'];
return $this->success($list);
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionGetOne()
{
$id = RequestHelper::getInt('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_GET_ONE_PARAMS_ERROR);
}
$category = GoodsCategoryModel::getOne($this->shopId, $id);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_GET_ONE_NOT_FOUND_ERROR);
}
return $this->success($category);
}
// /**
// *
// * @return \yii\web\Response
// * @throws GoodsException
// * @author
// */
// public function actionCreate()
// {
// return $this->actionUpdate();
// }
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionUpdate()
{
$post = RequestHelper::post();
if ($post['id']) {
$category = GoodsCategoryModel::getOne($this->shopId, $post['id']);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_SAVE_NOT_FOUND_ERROR);
}
}
$category = !empty($category) ? $category : new GoodsCategoryModel();
$transaction = \Yii::$app->getDb()->beginTransaction();
try {
unset($post['id']);
if (empty($post['shop_id'])) {
$post['shop_id'] = $this->shopId;
}
$category->setAttributes($post);
if (empty($category->create_time)) {
$category->create_time = DateTimeHelper::now();
}
$dirtyData = $category->getDirtyAttributes2();
if (!$category->save()) {
throw new GoodsException(GoodsException::CATEGORY_SAVE_ERROR);
}
//
// LogModel::write(
// $this->shopId,
// $this->userId,
// GoodsLogConst::getText(GoodsLogConst::GOODS_CATEGORY_ONE_EDIT),
// $category->id,
// $dirtyData
// );
$transaction->commit();
} catch (\Throwable $exception) {
$transaction->rollBack();
throw new GoodsException($exception->getCode());
}
return $this->success();
}
/**
*
* @return \yii\web\Response
* @author
*/
public function actionSave()
{
$post = RequestHelper::post('data');
if (!empty($post)) {
$post = Json::decode($post);
foreach ($post as $oneIndex => $oneLevel) {
$childrens = array_filter($oneLevel['children'] ?? []);
$oneResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $oneLevel, 0, 1);
if (!$oneResult) {
continue;
}
//
if (!empty($childrens) && $this->shopType != ShopTypeConstant::TYPE_MERCHANT) {
foreach ($childrens as $twoIndex => $twoLevel) {
$childrensShildrens = array_filter($twoLevel['children'] ?? []);
$twoResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $twoLevel, $oneResult, 2);
if (!$twoResult) {
continue;
}
//
if (!empty($childrensShildrens)) {
foreach ($childrensShildrens as $threeIndex => $threeLevel) {
$threeResult = GoodsCategoryModel::saveData($this->shopId, $this->subShopId, $this->userId, $threeLevel, $twoResult, 3);
if (!$threeResult) {
continue;
}
}
}
}
}
}
}
return $this->success();
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionForeverDelete()
{
$id = RequestHelper::post('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_DELETE_PARAMS_ERROR);
}
$data = GoodsCategoryModel::findAll(['id' => $id, 'shop_id' => $this->shopId]);
foreach ($data as $item) {
$item->delete();
GoodsCategoryMapModel::deleteAll(['category_id' => $item['id'], 'shop_id' => $this->shopId]);
$logPrimaryData = $item->getLogAttributeRemark([
'id' => $item->id,
'name' => $item->name
]);
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_DELETE,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_DELETE),
[
'log_data' => $item->attributes,
'log_primary' => $logPrimaryData,
'sub_shop_id' => $item->sub_shop_id
]
);
}
return $this->success();
}
/**
*
* @throws GoodsException
* @throws \yii\db\Exception
* @author
*/
public function actionSetSetting()
{
$post = RequestHelper::postArray('data');
if (empty($post)) {
throw new GoodsException(GoodsException::CATEGORY_SET_SETTING_PARAMS_ERROR);
}
ShopSettings::set($this->shopId, 'goods_category', [
'level' => $post['level'] ?: 0, //
'style' => $post['style'] ?: 0, //
'adv_url' => $post['adv_url'] ?: '', //
'template_type' => $post['template_type'], //
'title' => $post['title'] ?: ShopSettings::getDefaultSettings('goods_category.title'), //title
]);
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_SETTING,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_SETTING),
0,
[
'log_data' => $post,
'log_primary' => [
'' => $post['level'] == 1 ? '' : ($post['level'] == 2 ? '' : ''),
// '' => $post['style'] ?: "",
// '' => $post['adv_url'] ?: '',
],
'sub_shop_id' => $this->subShopId
]
);
return $this->success();
}
/**
*
* @author
*/
public function actionGetSetting()
{
$result = ShopSettings::get($this->shopId, 'goods_category');
$result['title'] = $result['title'] ?? ShopSettings::getDefaultSettings('goods_category.title'); //
return $this->success(['data' => $result]);
}
/**
*
* @return \yii\web\Response
* @throws GoodsException
* @author
*/
public function actionSwitch()
{
$id = RequestHelper::postInt('id');
if (empty($id)) {
throw new GoodsException(GoodsException::CATEGORY_SWITCH_PARAMS_ERROR);
}
$category = GoodsCategoryModel::findOne($id);
if (empty($category)) {
throw new GoodsException(GoodsException::CATEGORY_SWITCH_CATEGORY_NOT_FOUND_ERROR);
}
$category->status = $category->status == 1 ? 0 : 1;
//
LogModel::write(
$this->shopId,
$this->userId,
GoodsLogConstant::GOODS_CATEGORY_SWITCH,
GoodsLogConstant::getText(GoodsLogConstant::GOODS_CATEGORY_SWITCH),
$id,
[
'log_data' => $category->attributes,
'log_primary' => $category->getLogAttributeRemark([
'status' => $category->status == 1 ? '' : ''
]),
'sub_shop_id' => $this->subShopId
]
);
$category->save();
return $this->success();
}
}
Function Calls
None |
Stats
MD5 | 48e913ddaed12580e6d485d6a0ace8a3 |
Eval Count | 0 |
Decode Time | 65 ms |