123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\admin\controller\marketing;
- use app\admin\service\sys_manage\DeptService;
- use app\admin\validate\sys_manage\DeptValidate;
- use app\controller\Curd;
- use app\model\SysDept;
- use support\Db;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- class DeptPremisesController extends Curd
- {
- public function __construct()
- {
- $this->model = new SysDept();
- $this->validate = true;
- $this->validateClass = new DeptValidate();
- }
- /**
- * @Desc 营业场所列表
- * @Author Gorden
- * @Date 2024/3/7 13:17
- *
- * @param Request $request
- * @return Response
- * @throws BusinessException
- */
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $order = $request->get('order', 'desc');
- $field = $request->get('field','dept_addtimes');
- $where['dept_super_id'] = 0;
- $where['dept_category'] = '营业场所';
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- /**
- * @Desc 添加营业场所
- * @Author Gorden
- * @Date 2024/3/7 11:48
- *
- * @param Request $request
- * @return Response
- */
- public function insert(Request $request): Response
- {
- if ($this->validate && !$this->validateClass->scene('add_premises')->check($request->post())) {
- return json_fail($this->validateClass->getError());
- }
- // 验证编号是否存在
- if (SysDept::checkExist('营业场所','dept_code',$request->post('dept_code'))){
- return json_fail('编号重复,请重新输入');
- }
- Db::beginTransaction();
- try {
- $data = $this->insertInput($request);
- $data['dept_super_id'] = 0;
- $deptId = $this->doInsert($data);
- if (!$deptId) {
- throw new BusinessException('创建营业场所失败');
- }
- // 更新部门path
- $path = '/0/' . $deptId . '/';
- if (!SysDept::where('dept_id', $deptId)->update(['dept_super_path' => $path])) {
- throw new BusinessException('创建营业场所失败');
- }
- Db::commit();
- } catch (BusinessException $customException) {
- Db::rollBack();
- return json_fail($customException->getMessage());
- } catch (\Exception $exception) {
- Db::rollBack();
- return json_fail('创建营业场所失败');
- }
- return json_success('success');
- }
- /**
- * @Desc 更新
- * @Author Gorden
- * @Date 2024/3/7 13:14
- *
- * @param Request $request
- * @return Response
- */
- public function update(Request $request): Response
- {
- if ($this->validate && !$this->validateClass->scene('update_premises')->check($request->post())) {
- return json_fail($this->validateClass->getError());
- }
- try {
- [$id, $data] = $this->updateInput($request);
- $this->doUpdate($id, $data);
- } catch (BusinessException $customException) {
- return json_fail($customException->getMessage());
- } catch (\Exception $e) {
- return json_fail('数据更新失败');
- }
- return json_success('success');
- }
- }
|