| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?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, []);
- // 验证数据
- $validate = new \app\store\validate\schools\School();
- if(!$validate->check($data)){
- throwError($validate->getError());
- }
- $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]]);
- }
- }
|