Explorar el Código

0718-0322-h01

Zory hace 2 semanas
padre
commit
9392a1ac94

+ 9 - 0
app/controller/api/Goods.php

@@ -48,6 +48,15 @@ class Goods extends Base
             }])->findOrEmpty();
             if ($data->isEmpty()) return errorTrans("empty.data");
             if ($data['poi']['status'] <> 1) return error("该店铺已关闭,请联系管理员");
+            $data['content'] = filterHtmlTags($data['content'],[
+                'img' => [
+                    'remove' => ['width', 'height'],
+                    'style'  => ['width' => '100%']
+                ],
+                'p' => [
+                    'style'  => ['margin' => '0']
+                ]
+            ]);
             return $this->encode("success",$data->toArray());
         } catch (\Throwable $th) {
             return error($th->getMessage());

+ 4 - 3
app/controller/merchant/Goods.php

@@ -74,7 +74,10 @@ class Goods extends Base
             if ($detail->isEmpty()) return errorTrans("empty.data");
             if ($detail['poi_id'] <> $request->user['store_id']) return errorTrans("error.param");
             $detail['sold_start_times'] = [(string)$detail['sold_start_time'],(string)$detail['sold_end_time']];
-            $detail['use_times'] = [(string)$detail['use_time_start'],(string)$detail['use_time_end']];
+            $detail['use_times'] = null;
+            if ($detail['use_date_type'] == 2) {
+                $detail['use_times'] = [(string)$detail['use_time_start'],(string)$detail['use_time_end']];
+            }
             return successTrans('success.data',$detail->toArray());
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());
@@ -176,8 +179,6 @@ class Goods extends Base
                 "account"   => sConf("wechat.shop_id"),
             ])->token()->getStoreCategoryTemplate($param['category_id'],$param['product_type']);
             if (empty($valMap['product_attrs'])) return errorTrans("error.data");
-            echo "商品参数信息\n";
-            print_r($param);
             $data = (new BaseData)->config([
                 "appid"     => sConf("wechat.mini_appid"),
                 "secret"    => sConf("wechat.mini_secret"),

+ 7 - 9
app/extra/dyLife/data/BaseData.php

@@ -50,8 +50,8 @@ class BaseData extends BasicLife
                         "poi_id"    => $store['poi_id'], // 门店POI
                     ]
                 ],
-                "sold_end_time" => strtotime($data['sold_start_times'][1]), // 售卖结束时间
-                "sold_start_time"   => strtotime($data['sold_start_times'][0]), // 售卖开始时间
+                "sold_end_time" => strtotime($data['sold_end_time']." 00:00:00"), // 售卖结束时间
+                "sold_start_time"   => strtotime($data['sold_start_time']." 00:00:00"), // 售卖开始时间
                 "spu_id"        => (string)$data['spu_id'], // spuid
                 "account_id"    => $store['store_id'], // 商家id
             ]
@@ -71,8 +71,6 @@ class BaseData extends BasicLife
         } else { // 多sku
 
         }
-        echo "商品提交给API信息\n";
-        print_r($param);
         return $this->curlPostApi("goodlife/v1/goods/product/save/",$param);
     }
 
@@ -181,7 +179,7 @@ class BaseData extends BasicLife
                 if ($data['rec_person_type']==1) {
                     $return = json_encode(["is_limit_use" => false]);
                 } else {
-                    $return = json_encode(['is_limit_use' => true, 'use_num_per_consume' => $data['rec_person_num_max']??0]);
+                    $return = json_encode(['is_limit_use' => true, 'use_num_per_consume' => $data['rec_person_num_max']?intval($data['rec_person_num_max']):0]);
                 }
                 break;
             case "show_channel":
@@ -191,13 +189,13 @@ class BaseData extends BasicLife
                 if ($data['use_date_type'] == 1) { // 指定天数
                     $return = json_encode([
                         "use_date_type" => 2,
-                        "day_duration" => $data['day_duration']
+                        "day_duration" => intval($data['day_duration'])
                     ]);
                 } else { // 指定日期
                     $return = json_encode([
                         "use_date_type" => 1,
-                        "use_start_date" => $data['use_times'][0],
-                        "use_end_date" => $data['use_times'][0]
+                        "use_start_date" => $data['use_time_start'],
+                        "use_end_date" => $data['use_time_end']
                     ]);
                 }
                 break;
@@ -223,7 +221,7 @@ class BaseData extends BasicLife
                 break;
             case "limit_rule": // 限制购买
                 if ($data['limit_rule_type'] == 2) {
-                    $return = json_encode(['is_limit' => true,"total_buy_num" => $data['limit_rule']]);
+                    $return = json_encode(['is_limit' => true,"total_buy_num" => intval($data['limit_rule'])]);
                 } else {
                     $return = json_encode(['is_limit' => false]);
                 }

+ 79 - 0
app/functions.php

@@ -714,4 +714,83 @@ if(! function_exists('str_cut_ellipsis'))
         }
         return mb_substr($str, 0, $len, 'UTF-8') . $dot;
     }
+}
+
+if (! function_exists('filterHtmlTags'))
+{
+    /**
+     * 批量修改 HTML 中指定标签的属性和样式
+     *
+     * @param string $html      原始 HTML 内容
+     * @param array  $rules     规则数组,键为标签名(小写),值为配置:
+     * [
+     *  'remove' => ['width', 'height'], // 要移除的属性名列表
+     *   'style'  => ['width' => '100%', 'margin' => '0'] // 要强制设置/覆盖的样式
+     * ]
+     * @return string 处理后的 HTML
+     */
+    function filterHtmlTags($html, $rules) {
+        // 匹配所有标签的开始部分:<标签名 属性...> 或 <标签名 属性.../> 或 <标签名>
+        $pattern = '/<(\w+)(?:\s+([^>]*?))?\/?>/i';
+        return preg_replace_callback($pattern, function($matches) use ($rules) {
+            $tag = strtolower($matches[1]);
+            // 如果该标签不在规则中,直接返回原匹配
+            if (!isset($rules[$tag])) {
+                return $matches[0];
+            }
+            $rule = $rules[$tag];
+            // 解析属性(如果有)
+            $attrStr = isset($matches[2]) ? $matches[2] : '';
+            $attrArray = [];
+            if ($attrStr) {
+                // 匹配 属性名="值" 或 属性名='值' 或 属性名=值
+                preg_match_all('/([a-zA-Z-]+)\s*=\s*("([^"]*)"|\'([^\']*)\'|([^\s>]+))/', $attrStr, $matchesAttr, PREG_SET_ORDER);
+                foreach ($matchesAttr as $m) {
+                    $name = strtolower($m[1]);
+                    $value = isset($m[3]) ? $m[3] : (isset($m[4]) ? $m[4] : $m[5]);
+                    $attrArray[$name] = $value;
+                }
+            }
+
+            // 1. 移除指定属性
+            if (isset($rule['remove'])) {
+                foreach ($rule['remove'] as $attr) {
+                    unset($attrArray[$attr]);
+                }
+            }
+
+            // 2. 处理样式
+            if (isset($rule['style']) && is_array($rule['style'])) {
+                $oldStyle = isset($attrArray['style']) ? $attrArray['style'] : '';
+                $styles = [];
+                if ($oldStyle) {
+                    // 简单解析,按分号分割
+                    $parts = array_filter(array_map('trim', explode(';', $oldStyle)));
+                    foreach ($parts as $part) {
+                        if (strpos($part, ':') !== false) {
+                            list($key, $value) = array_map('trim', explode(':', $part, 2));
+                            $styles[$key] = $value;
+                        }
+                    }
+                }
+                // 强制覆盖(或添加)样式
+                foreach ($rule['style'] as $key => $value) {
+                    $styles[$key] = $value;
+                }
+                // 重组 style
+                $newStyle = '';
+                foreach ($styles as $k => $v) {
+                    $newStyle .= $k . ':' . $v . ';';
+                }
+                $attrArray['style'] = $newStyle;
+            }
+
+            // 重建属性字符串
+            $newAttr = '';
+            foreach ($attrArray as $k => $v) {
+                $newAttr .= ' ' . $k . '="' . htmlspecialchars($v, ENT_QUOTES, 'UTF-8') . '"';
+            }
+            return '<' . $tag . $newAttr . '>';
+        }, $html);
+    }
 }