Browse Source

细节优化 array_merge

萤火科技 1 năm trước cách đây
mục cha
commit
46c7c9c7cd

+ 3 - 3
app/api/controller/Checkout.php

@@ -160,7 +160,7 @@ class Checkout extends Controller
      */
     private function getValidate(): CheckoutValidate
     {
-        if (is_null($this->validate)) {
+        if (\is_null($this->validate)) {
             $this->validate = new CheckoutValidate;
         }
         return $this->validate;
@@ -173,7 +173,7 @@ class Checkout extends Controller
     private function getCartIds()
     {
         $cartIds = $this->request->param('cartIds');
-        return explode(',', $cartIds);
+        return \explode(',', $cartIds);
     }
 
     /**
@@ -183,6 +183,6 @@ class Checkout extends Controller
      */
     private function getParam(array $define = []): array
     {
-        return array_merge($define, $this->request->param());
+        return \array_merge($define, $this->request->param());
     }
 }

+ 1 - 1
app/api/model/Category.php

@@ -41,6 +41,6 @@ class Category extends CategoryModel
      */
     public function getListPublic(array $param = []): array
     {
-        return parent::getList(array_merge($param, ['status' => 1]));
+        return parent::getList(\array_merge($param, ['status' => 1]));
     }
 }

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

@@ -96,7 +96,7 @@ class Goods extends GoodsModel
     public function getList(array $param = [], int $listRows = 15)
     {
         // 整理查询参数
-        $params = array_merge($param, ['status' => GoodsStatusEnum::ON_SALE]);
+        $params = \array_merge($param, ['status' => GoodsStatusEnum::ON_SALE]);
         // 获取商品列表
         $list = parent::getList($params, $listRows);
         if ($list->isEmpty()) {

+ 2 - 2
app/api/service/order/Checkout.php

@@ -123,7 +123,7 @@ class Checkout extends BaseService
      */
     public function setParam($param): array
     {
-        $this->param = array_merge($this->param, $param);
+        $this->param = \array_merge($this->param, $param);
         return $this->getParam();
     }
 
@@ -154,7 +154,7 @@ class Checkout extends BaseService
      */
     public function setOrderSource($data): Checkout
     {
-        $this->orderSource = array_merge($this->orderSource, $data);
+        $this->orderSource = \array_merge($this->orderSource, $data);
         return $this;
     }
 

+ 3 - 3
app/common/library/Log.php

@@ -52,9 +52,9 @@ class Log
      */
     public static function append(string $name, array $data)
     {
-        $merge = array_merge(compact('name'), $data);
+        $merge = \array_merge(compact('name'), $data);
         if (isset(static::$data[$name])) {
-            $merge = array_merge(static::$data[$name], $merge);
+            $merge = \array_merge(static::$data[$name], $merge);
         }
         static::$data[$name] = $merge;
     }
@@ -65,7 +65,7 @@ class Log
     public static function end()
     {
         foreach (static::$data as $name => $item) {
-            static::record(array_merge(['name' => $name], $item));
+            static::record(\array_merge(['name' => $name], $item));
         }
     }
 }

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

@@ -388,7 +388,7 @@ class helper
      */
     public static function setQueryDefaultValue(array $query, array $default = []): array
     {
-        $data = array_merge($default, $query);
+        $data = \array_merge($default, $query);
 
         foreach ($query as $field => $value) {
             // 不存在默认值跳出循环

+ 1 - 1
app/common/library/payment/gateway/driver/wechat/V3.php

@@ -558,7 +558,7 @@ class V3
             'noncestr' => Formatter::nonce(),
             'prepayid' => $prepayId,
         ];
-        return array_merge($params, [
+        return \array_merge($params, [
             'sign' => Rsa::sign(
                 Formatter::joinedByLineFeed(...array_values($params)),
                 $this->getMerchantPrivateKeyInstance()

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

@@ -211,7 +211,7 @@ class Goods extends BaseModel
         } elseif ($params['sortType'] === 'price') {
             $sort = $params['sortPrice'] ? ['goods_price_max' => 'desc'] : ['goods_price_min' => 'asc'];
         }
-        return array_merge($sort, [$this->getPk() => 'desc']);
+        return \array_merge($sort, [$this->getPk() => 'desc']);
     }
 
     /**

+ 2 - 2
app/common/model/GoodsSku.php

@@ -172,7 +172,7 @@ class GoodsSku extends BaseModel
     {
         // 单规格模式
         if ($specType === SpecTypeEnum::SINGLE) {
-            return (new static)->save(array_merge($newSkuList, [
+            return (new static)->save(\array_merge($newSkuList, [
                 'goods_id' => $goodsId,
                 'goods_sku_id' => 0,
                 'store_id' => $storeId ?: self::$storeId
@@ -196,7 +196,7 @@ class GoodsSku extends BaseModel
     {
         $dataset = [];
         foreach ($skuList as $skuItem) {
-            $dataset[] = array_merge($skuItem, [
+            $dataset[] = \array_merge($skuItem, [
                 'id' => null,   // 此处的id必须是数据库自增
                 'goods_sku_id' => $skuItem['goods_sku_id'],
                 'goods_price' => $skuItem['goods_price'] ?: 0.01,

+ 1 - 1
app/common/model/Payment.php

@@ -239,7 +239,7 @@ class Payment extends BaseModel
         ];
         $defaultMethods = [];
         foreach ($designated as $key => $method) {
-            $defaultMethods["{$client}-{$method}"] = array_merge($record, [
+            $defaultMethods["{$client}-{$method}"] = \array_merge($record, [
                 'key' => $key + 1,
                 'method' => $method,
                 'is_must_template' => !\in_array($method, [PaymentMethodEnum::BALANCE]),

+ 1 - 1
app/common/model/PaymentTemplate.php

@@ -140,7 +140,7 @@ class PaymentTemplate extends BaseModel
         $info = $template->toArray();
         // 记录证书文件名
         $methodConfig = $info['config'][$info['method']];
-        $info['config'] = [$info['method'] => array_merge(
+        $info['config'] = [$info['method'] => \array_merge(
             $methodConfig,
             $this->certFileName($info['method'], $methodConfig, $template['store_id'])
         )];

+ 1 - 1
app/common/model/User.php

@@ -92,7 +92,7 @@ class User extends BaseModel
     {
         $filter = ['is_delete' => 0];
         if (is_array($where)) {
-            $filter = array_merge($filter, $where);
+            $filter = \array_merge($filter, $where);
         } else {
             $filter['user_id'] = (int)$where;
         }

+ 1 - 1
app/common/model/user/BalanceLog.php

@@ -51,7 +51,7 @@ class BalanceLog extends BaseModel
     public static function add(int $scene, array $data, array $describeParam, ?int $storeId = null)
     {
         $model = new static;
-        $model->save(array_merge([
+        $model->save(\array_merge([
             'scene' => $scene,
             'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
             'store_id' => $storeId ?: $model::$storeId

+ 1 - 1
app/common/model/user/GradeLog.php

@@ -39,7 +39,7 @@ class GradeLog extends BaseModel
     {
         $saveData = [];
         foreach ($data as $item) {
-            $saveData[] = array_merge([
+            $saveData[] = \array_merge([
                 'change_type' => ChangeTypeEnum::ADMIN_USER,
                 'store_id' => static::$storeId
             ], $item);

+ 1 - 1
app/common/service/Goods.php

@@ -39,7 +39,7 @@ class Goods extends BaseService
         $model = new GoodsModel;
         $goodsData = $model->getListByIds(helper::getArrayColumn($dataSource, $goodsIndex));
         // 设置隐藏的属性
-        $goodsData->hidden(array_merge(['images'], $hidden));
+        $goodsData->hidden(\array_merge(['images'], $hidden));
         // 整理列表数据
         $goodsList = helper::arrayColumn2Key($goodsData, 'goods_id');
         foreach ($dataSource as &$item) {

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

@@ -199,7 +199,7 @@ class Goods extends GoodsModel
     private function createData(array $data): array
     {
         // 默认数据
-        $data = array_merge($data, [
+        $data = \array_merge($data, [
             'line_price' => $data['line_price'] ?? 0,
             'content' => $data['content'] ?? '',
             'newSpecList' => [],

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

@@ -73,7 +73,7 @@ class PaymentTemplate extends PaymentTemplateModel
         $data['store_id'] = self::$storeId;
         // 记录证书文件名
         $data['config'] = [
-            $data['method'] => array_merge($methodConfig, $this->certFileName($data['method'], $methodConfig))
+            $data['method'] => \array_merge($methodConfig, $this->certFileName($data['method'], $methodConfig))
         ];
         // 记录微信支付v3平台证书序号或微信支付公钥ID
         $data['wechatpay_serial'] = $this->wechatpaySerial($data);

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

@@ -74,7 +74,7 @@ class UploadGroup extends UploadGroupModel
      */
     public function add(array $data): bool
     {
-        return $this->save(array_merge([
+        return $this->save(\array_merge([
             'store_id' => self::$storeId,
             'sort' => 100
         ], $data));

+ 1 - 1
app/store/service/store/Role.php

@@ -69,7 +69,7 @@ class Role extends BaseService
                 // 页面操作项 例如: 新增 编辑 删除
                 'actionEntitySet' => static::getActionEntitySet($menu)
             ];
-            !empty($menu['children']) && $data = array_merge($data, static::buildPermissions($menu['children']));
+            !empty($menu['children']) && $data = \array_merge($data, static::buildPermissions($menu['children']));
         }
         return $data;
     }