Kaynağa Gözat

细节优化

Yahoo 4 yıl önce
ebeveyn
işleme
96041cd19b

+ 5 - 5
app/common/library/helper.php

@@ -23,7 +23,7 @@ class helper
      * @param array $columns
      * @return array
      */
-    public static function pick($source, array $columns)
+    public static function pick($source, array $columns): array
     {
         $dataset = [];
         foreach ($source as $key => $item) {
@@ -53,7 +53,7 @@ class helper
      * @param $columns
      * @return array
      */
-    public static function getArrayColumns($source, $columns)
+    public static function getArrayColumns($source, $columns): array
     {
         $columnArr = [];
         foreach ($source as $item) {
@@ -72,7 +72,7 @@ class helper
      * @param $index
      * @return array
      */
-    public static function arrayColumn2Key($source, $index)
+    public static function arrayColumn2Key($source, $index): array
     {
         $data = [];
         foreach ($source as $item) {
@@ -116,10 +116,10 @@ class helper
      * 在二维数组中查找指定值
      * @param array $array 二维数组
      * @param string $searchIdx 查找的索引
-     * @param string $searchVal 查找的值
+     * @param mixed $searchVal 查找的值
      * @return bool
      */
-    public static function arraySearch($array, $searchIdx, $searchVal)
+    public static function arraySearch(array $array, string $searchIdx, $searchVal): bool
     {
         foreach ($array as $item) {
             if ($item[$searchIdx] == $searchVal) return $item;

+ 15 - 14
app/store/controller/Goods.php

@@ -12,8 +12,9 @@ declare (strict_types = 1);
 
 namespace app\store\controller;
 
-use app\common\exception\BaseException;
+use think\response\Json;
 use app\store\model\Goods as GoodsModel;
+use app\common\exception\BaseException;
 
 /**
  * 商品管理控制器
@@ -24,10 +25,10 @@ class Goods extends Controller
 {
     /**
      * 商品列表
-     * @return array
+     * @return Json
      * @throws \think\db\exception\DbException
      */
-    public function list()
+    public function list(): Json
     {
         // 获取列表记录
         $model = new GoodsModel;
@@ -38,9 +39,9 @@ class Goods extends Controller
     /**
      * 根据商品ID集获取列表记录
      * @param array $goodsIds
-     * @return array
+     * @return Json
      */
-    public function listByIds(array $goodsIds)
+    public function listByIds(array $goodsIds): Json
     {
         // 获取列表记录
         $model = new GoodsModel;
@@ -51,13 +52,13 @@ class Goods extends Controller
     /**
      * 商品详情
      * @param int $goodsId
-     * @return array
+     * @return Json
      * @throws BaseException
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function detail(int $goodsId)
+    public function detail(int $goodsId): Json
     {
         // 获取商品详情
         $model = new GoodsModel;
@@ -67,12 +68,12 @@ class Goods extends Controller
 
     /**
      * 添加商品
-     * @return array
+     * @return Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function add()
+    public function add(): Json
     {
         $model = new GoodsModel;
         if ($model->add($this->postForm())) {
@@ -84,12 +85,12 @@ class Goods extends Controller
     /**
      * 编辑商品
      * @param int $goodsId
-     * @return array
+     * @return Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function edit(int $goodsId)
+    public function edit(int $goodsId): Json
     {
         // 商品详情
         $model = GoodsModel::detail($goodsId);
@@ -104,9 +105,9 @@ class Goods extends Controller
      * 修改商品状态(上下架)
      * @param array $goodsIds 商品id集
      * @param bool $state 为true表示上架
-     * @return array
+     * @return Json
      */
-    public function state(array $goodsIds, bool $state)
+    public function state(array $goodsIds, bool $state): Json
     {
         $model = new GoodsModel;
         if (!$model->setStatus($goodsIds, $state)) {
@@ -120,7 +121,7 @@ class Goods extends Controller
      * @param array $goodsIds
      * @return array
      */
-    public function delete(array $goodsIds)
+    public function delete(array $goodsIds): Json
     {
         $model = new GoodsModel;
         if (!$model->setDelete($goodsIds)) {

+ 1 - 1
app/store/model/Goods.php

@@ -150,7 +150,7 @@ class Goods extends GoodsModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function edit(array $data)
+    public function edit(array $data): bool
     {
         // 创建商品数据
         $data = $this->createData($data);

+ 1 - 1
app/store/model/Spec.php

@@ -32,7 +32,7 @@ class Spec extends SpecModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public static function getNewSpecList(array $specList)
+    public static function getNewSpecList(array $specList): array
     {
         // 规格组名称合集
         $names = helper::getArrayColumn($specList, 'spec_name');