xieruidong пре 2 година
родитељ
комит
82172daaad

+ 1 - 1
application/admin/controller/Category.php

@@ -113,7 +113,7 @@ class Category extends Backend
             if ($params) {
                 $params = $this->preExcludeFields($params);
 
-                if ($params['pid'] != $row['pid']) {
+                if (!empty($params['pid']) && $params['pid'] != $row['pid']) {
                     $childrenIds = Tree::instance()->init(collection(\app\common\model\Category::select())->toArray())->getChildrenIds($row['id'], true);
                     if (in_array($params['pid'], $childrenIds)) {
                         $this->error(__('Can not change the parent to child or itself'));

+ 2 - 2
application/admin/view/category/add.html

@@ -84,12 +84,12 @@
             <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="0">
         </div>
     </div>
-    <!--<div class="form-group">
+    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">
             {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])}
         </div>
-    </div>-->
+    </div>
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 2 - 2
application/admin/view/category/edit.html

@@ -80,12 +80,12 @@
             <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh}">
         </div>
     </div>
-    <!--<div class="form-group">
+    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">
             {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')], $row['status'])}
         </div>
-    </div>-->
+    </div>
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 24 - 0
application/api/controller/mall/Index.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\api\controller\mall;
+
+use app\common\controller\Api;
+use app\common\model\Category;
+
+/**
+ * 商城首页接口
+ * @inheritdoc
+ */
+class Index extends Api
+{
+    protected $noNeedLogin = '*';
+    protected $noNeedRight = '*';
+
+    /**
+     * 首页分类和商品
+     */
+    public function category(){
+        $category=Category::mall(['goods']);
+        $this->success('',$category);
+    }
+}

+ 8 - 4
application/common/model/Category.php

@@ -31,6 +31,10 @@ class Category extends Model
         return is_array($value) ? implode(',', $value) : $value;
     }
 
+    public function goods(){
+        return $this->hasMany(Goods::class)->where('status',1);
+    }
+
     /**
      * 读取分类类型
      * @return array
@@ -70,7 +74,7 @@ class Category extends Model
      * @param string $status 指定状态
      * @return array
      */
-    public static function getCategoryArray($type = null, $status = null)
+    public static function getCategoryArray($type = null, $status = null,$with=[])
     {
         $list = collection(self::where(function ($query) use ($type, $status) {
             if (!is_null($type)) {
@@ -79,11 +83,11 @@ class Category extends Model
             if (!is_null($status)) {
                 $query->where('status', '=', $status);
             }
-        })->order('weigh', 'desc')->select())->toArray();
+        })->order('weigh', 'desc')->with($with)->select())->toArray();
         return $list;
     }
 
-    public static function mall(){
-        return self::getCategoryArray('mall');
+    public static function mall($with=[]){
+        return self::getCategoryArray('mall','normal',$with);
     }
 }

+ 0 - 1
application/index/controller/Index.php

@@ -20,7 +20,6 @@ class Index extends Frontend
 
     public function index()
     {
-        $this->redirect('/build');
     }
     public function payment($a=null){
         if(!$a){

Разлика између датотеке није приказан због своје велике величине
+ 283 - 162
public/api.html


Неке датотеке нису приказане због велике количине промена