소스 검색

Wesmiler 校企小程序 更新 6.23

wesmiler 3 년 전
부모
커밋
124859f3e2
2개의 변경된 파일218개의 추가작업 그리고 0개의 파일을 삭제
  1. 94 0
      app/common/model/School.php
  2. 124 0
      app/store/controller/Schools.php

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

@@ -234,4 +234,98 @@ class School extends BaseModel
     public static function setIncViews($id){
         (new static())->setInc(['id'=> $id], 'views', 1);
     }
+
+    /**
+     * 获取详情
+     * @param int $id
+     * @param array $with
+     * @return static
+     */
+    public static function detail(int $id, array $with = [])
+    {
+        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]]);
+    }
 }

+ 124 - 0
app/store/controller/Schools.php

@@ -0,0 +1,124 @@
+<?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\controller;
+
+use think\response\Json;
+use app\store\model\Goods as GoodsModel;
+use app\common\model\School as SchoolsModel;
+use app\common\exception\BaseException;
+
+/**
+ * 学校管理控制器
+ * Class Schools
+ * @package app\store\controller
+ */
+class Schools extends Controller
+{
+    /**
+     * 列表
+     * @return Json
+     * @throws \think\db\exception\DbException
+     */
+    public function list(): Json
+    {
+        // 获取列表记录
+        $model = new SchoolsModel();
+        $list = $model->getList($this->request->param());
+        return $this->renderSuccess(compact('list'));
+    }
+
+
+    /**
+     * 商品详情
+     * @param int $goodsId
+     * @return Json
+     * @throws BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \cores\exception\BaseException
+     */
+    public function detail(int $id): Json
+    {
+        // 获取详情
+        $model = new SchoolsModel();
+        $info = $model->detail($id);
+        return $this->renderSuccess(compact('info'));
+    }
+
+    /**
+     * 添加
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \cores\exception\BaseException
+     */
+    public function add(): Json
+    {
+        $model = new SchoolsModel();
+        if ($model->add($this->postForm())) {
+            return $this->renderSuccess('添加成功');
+        }
+        return $this->renderError($model->getError() ?: '添加失败');
+    }
+
+    /**
+     * 编辑
+     * @param int $id
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \cores\exception\BaseException
+     */
+    public function edit(int $id): Json
+    {
+        // 详情
+        $model = SchoolsModel::detail($id);
+        // 更新记录
+        if ($model->edit($this->postForm())) {
+            return $this->renderSuccess('更新成功');
+        }
+        return $this->renderError($model->getError() ?: '更新失败');
+    }
+
+    /**
+     * 修改状态(审核通过)
+     * @param array $ids id集
+     * @param bool $state 为true表示通过
+     * @return Json
+     */
+    public function state(array $ids, bool $state): Json
+    {
+        $model = new SchoolsModel();
+        if (!$model->setStatus($ids, $state)) {
+            return $this->renderError($model->getError() ?: '操作失败');
+        }
+        return $this->renderSuccess('操作成功');
+    }
+
+    /**
+     * 删除
+     * @param array $ids
+     * @return Json
+     */
+    public function delete(array $ids): Json
+    {
+        $model = new SchoolsModel();
+        if (!$model->setDelete($ids)) {
+            return $this->renderError($model->getError() ?: '删除失败');
+        }
+        return $this->renderSuccess('删除成功');
+    }
+}