Prechádzať zdrojové kódy

Wesmiler 校企小程序 更新 6.23

wesmiler 3 rokov pred
rodič
commit
073902e552

+ 0 - 83
app/common/model/School.php

@@ -100,7 +100,6 @@ class School extends BaseModel
         if ($list->isEmpty()) return $list;
         // 遍历商品列表整理数据
         foreach ($list as &$item) {
-            $item['logo_preview'] = $item['logo']? getPreview($item['logo']) : '';
             $data = $this->setData($item, $callback);
         }
         return $list;
@@ -247,86 +246,4 @@ class School extends BaseModel
         return static::get($id, $with);
     }
 
-
-    /**
-     * 添加
-     * @param array $data
-     * @return bool
-     * @throws \cores\exception\BaseException
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public function add(array $data): bool
-    {
-        // 创建数据
-        $data = $this->createData($data);
-        // 事务处理
-        $this->transaction(function () use ($data) {
-            // 添加
-            $this->save($data);
-        });
-        return true;
-    }
-
-    /**
-     * 创建数据
-     * @param array $data
-     * @return array
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \cores\exception\BaseException
-     */
-    private function createData(array $data): array
-    {
-        // 默认数据
-        $data = array_merge($data, []);
-        return $data;
-    }
-
-    /**
-     * 编辑
-     * @param array $data
-     * @return bool
-     * @throws \cores\exception\BaseException
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    public function edit(array $data): bool
-    {
-        // 创建数据
-        $data = $this->createData($data);
-        // 事务处理
-        $this->transaction(function () use ($data) {
-            // 更新
-            $this->save($data);
-        });
-        return true;
-    }
-
-    /**
-     * 修改状态
-     * @param array $ids id集
-     * @param bool $state 为true表示审核通过
-     * @return bool|false
-     */
-    public function setStatus(array $ids, bool $state): bool
-    {
-        // 批量更新记录
-        return static::updateBase(['audit_status' => $state ? 1 : 0], [['id', 'in', $ids]]);
-    }
-
-    /**
-     * 软删除
-     * @param array $ids
-     * @return bool
-     */
-    public function setDelete(array $ids): bool
-    {
-
-        // 批量更新记录
-        return static::updateBase(['audit_status' => 0,'is_delete'=>1], [['id', 'in', $ids]]);
-    }
 }

+ 1 - 2
app/store/controller/Schools.php

@@ -13,8 +13,7 @@ declare (strict_types = 1);
 namespace app\store\controller;
 
 use think\response\Json;
-use app\store\model\Goods as GoodsModel;
-use app\common\model\School as SchoolsModel;
+use app\store\model\School as SchoolsModel;
 use app\common\exception\BaseException;
 
 /**

+ 158 - 0
app/store/model/School.php

@@ -0,0 +1,158 @@
+<?php
+// +----------------------------------------------------------------------
+// | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: thinkphp <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types = 1);
+
+namespace app\store\model;
+
+use app\common\model\School as SchoolModel;
+
+/**
+ * 模型类:学校
+ * Class School
+ * @package app\store\model
+ */
+class School extends SchoolModel
+{
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed|\think\model\Collection|\think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 整理查询参数
+        $params = array_merge($param, []);
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
+     * 设置展示的数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setListDataFromApi($info)
+    {
+        return $this->setListData($info, function ($data) {
+            // 整理数据 api模块
+            $this->setDataFromApi($data);
+
+            // 隐藏冗余的字段
+            $this->hidden(array_merge($this->hidden, ['recruit_phone','post_code','index_url','albums','introduce','recruitment','characteristic','book_fields']));
+        });
+    }
+
+    /**
+     * 整理数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setDataFromApi($info)
+    {
+        return $this->setData($info, function ($data) {
+            // logo封面
+            $data['logo_preview'] = $data['logo']? getPreview($data['logo']) : '';
+            $data['labels'] = $data['labels']? explode(',', $data['labels']) : [];
+        });
+    }
+
+
+    /**
+     * 添加
+     * @param array $data
+     * @return bool
+     * @throws \cores\exception\BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function add(array $data): bool
+    {
+        // 创建数据
+        $data = $this->createData($data);
+        // 事务处理
+        $this->transaction(function () use ($data) {
+            // 添加
+            $this->save($data);
+        });
+        return true;
+    }
+
+    /**
+     * 创建数据
+     * @param array $data
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \cores\exception\BaseException
+     */
+    private function createData(array $data): array
+    {
+        // 默认数据
+        $data = array_merge($data, []);
+        return $data;
+    }
+
+    /**
+     * 编辑
+     * @param array $data
+     * @return bool
+     * @throws \cores\exception\BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function edit(array $data): bool
+    {
+        // 创建数据
+        $data = $this->createData($data);
+        // 事务处理
+        $this->transaction(function () use ($data) {
+            // 更新
+            $this->save($data);
+        });
+        return true;
+    }
+
+    /**
+     * 修改状态
+     * @param array $ids id集
+     * @param bool $state 为true表示审核通过
+     * @return bool|false
+     */
+    public function setStatus(array $ids, bool $state): bool
+    {
+        // 批量更新记录
+        return static::updateBase(['audit_status' => $state ? 1 : 0], [['id', 'in', $ids]]);
+    }
+
+    /**
+     * 软删除
+     * @param array $ids
+     * @return bool
+     */
+    public function setDelete(array $ids): bool
+    {
+
+        // 批量更新记录
+        return static::updateBase(['audit_status' => 0,'is_delete'=>1], [['id', 'in', $ids]]);
+    }
+
+}