Skip to content

Commit

Permalink
admin productinfoController
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Sep 30, 2020
1 parent feb48ce commit a4a8145
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions app/appadmin/modules/Catalog/controllers/ProductinfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,12 @@ public function actionManagerdelete()
$data = $this->getBlock('manageredit')->delete();
}

/**
* 检查spu的唯一性
*/

public function actionSpucode()
{
// 产品原来的id,新建产品为空
$product_id = Yii::$app->request->get('product_id');
// 产品原来的spu,新建产品为空
$product_spu = Yii::$app->request->get('product_spu');
// 编辑产品的spu。
$spu = Yii::$app->request->get('spu');
// 编辑产品的spu为空,或,和原来的spu相同,则。
$spu = Yii::$app->request->get('spu');//
if (!$spu || ($spu == $product_spu)) {
echo json_encode([
'statusCode' => '200',
Expand All @@ -190,9 +184,11 @@ public function actionSpucode()
];
$data = Yii::$service->product->coll($filter);
if ($data['count'] < 1 ) {
$randomSku = $spu.'-'.$this->getRandom();
echo json_encode([
'statusCode' => '200',
'message' => 'spu is unique',
'randomSku' => $randomSku,
]);
exit;
} else {
Expand All @@ -204,4 +200,19 @@ public function actionSpucode()
}

}

/**
* generate random string.
*/
protected function getRandom($length = 6)
{
$str = null;
$strPol = '123456789';
$max = strlen($strPol) - 1;
for ($i = 0; $i < $length; $i++) {
$str .= $strPol[rand(0, $max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数
}

return $str;
}
}

0 comments on commit a4a8145

Please sign in to comment.