123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\adminapi\controller\v1\company;
- use app\adminapi\controller\AuthController;
- use crmeb\services\{UtilService as Util};
- use app\models\section\SectionModel;
- use app\models\company\CompanyModel;
- use app\models\company\ExampleModel;
- use app\models\company\DesignerModel;
- use think\Request;
- class Company extends AuthController
- {
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = Util::getMore([
- ['title', ''],
- ['sid', ''],
- ['page', 1],
- ['limit', 10]
- ], $this->request);
- $list = CompanyModel::systemPage($where);
- return $this->success($list);
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save(Request $request)
- {
- $data = Util::postMore([
- ['id', 0],
- ['sid', ''],
- ['title', ''],
- ['logo', ''],
- ['intro', ''],
- ['contact', ''],
- ['phone', ''],
- ['project', ''],
- ['slider_image', ''],
- ['sort', 0],
- ['status', 1],
- ['example', []],
- ['designer', []],
- ]);
- if (!$data['title']) return $this->fail('缺少参数');
- $data['slider_image'] = json_encode($data['slider_image']);
- $example = $data['example'];
- $designer = $data['designer'];
- unset($data['example'], $data['designer']);
- if ($data['id']) {
- $id = $data['id'];
- unset($data['id']);
- $res = CompanyModel::edit($data, $id, 'id');
- ExampleModel::saveExample($example, $id);
- DesignerModel::saveDesigner($designer, $id);
- return $this->success('修改成功!', ['id' => $id]);
- } else {
- $data['add_time'] = time();
- $res = CompanyModel::create($data);
- foreach($example as $key => $value){
- $example[$key]['cid'] = (int)($res['id']);
- }
- foreach($designer as $key => $value){
- $designer[$key]['cid'] = (int)($res['id']);
- }
- ExampleModel::saveExample($example, $res['id']);
- DesignerModel::saveDesigner($designer, $res['id']);
- return $this->success('添加成功!', ['id' => $res->id]);
- }
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- $info = CompanyModel::getOne($id);
- return $this->success(compact('info'));
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$id) return $this->fail('数据不存在');
- $res = CompanyModel::get($id);
- if (!$res) return $this->fail('数据不存在!');
- if ($res['is_del']) return $this->fail('已删除!');
- $data['is_del'] = 1;
- if (!CompanyModel::edit($data, $id))
- return $this->fail(CompanyModel::getErrorInfo('删除失败,请稍候再试!'));
- else
- return $this->success('删除成功!');
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function set_status($id, $status)
- {
- if ($status == '' || $id == 0) return $this->fail('参数错误');
- CompanyModel::where(['id' => $id])->update(['status' => $status]);
- return $this->success($status == 0 ? '隐藏成功' : '显示成功');
- }
- }
|