Company.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\adminapi\controller\v1\company;
  3. use app\adminapi\controller\AuthController;
  4. use crmeb\services\{UtilService as Util};
  5. use app\models\section\SectionModel;
  6. use app\models\company\CompanyModel;
  7. use app\models\company\ExampleModel;
  8. use app\models\company\DesignerModel;
  9. use think\Request;
  10. class Company extends AuthController
  11. {
  12. /**
  13. * 显示资源列表
  14. *
  15. * @return \think\Response
  16. */
  17. public function index()
  18. {
  19. $where = Util::getMore([
  20. ['title', ''],
  21. ['sid', ''],
  22. ['page', 1],
  23. ['limit', 10]
  24. ], $this->request);
  25. $list = CompanyModel::systemPage($where);
  26. return $this->success($list);
  27. }
  28. /**
  29. * 保存新建的资源
  30. *
  31. * @param \think\Request $request
  32. * @return \think\Response
  33. */
  34. public function save(Request $request)
  35. {
  36. $data = Util::postMore([
  37. ['id', 0],
  38. ['sid', ''],
  39. ['title', ''],
  40. ['logo', ''],
  41. ['intro', ''],
  42. ['contact', ''],
  43. ['phone', ''],
  44. ['project', ''],
  45. ['slider_image', ''],
  46. ['sort', 0],
  47. ['status', 1],
  48. ['example', []],
  49. ['designer', []],
  50. ]);
  51. if (!$data['title']) return $this->fail('缺少参数');
  52. $example = $data['example'];
  53. $designer = $data['designer'];
  54. unset($data['example'], $data['designer']);
  55. if ($data['id']) {
  56. $id = $data['id'];
  57. unset($data['id']);
  58. $res = CompanyModel::edit($data, $id, 'id');
  59. ExampleModel::saveExample($example, $id);
  60. DesignerModel::saveDesigner($designer, $id);
  61. return $this->success('修改成功!', ['id' => $id]);
  62. } else {
  63. $data['add_time'] = time();
  64. $res = CompanyModel::create($data);
  65. foreach($example as $key => $value){
  66. $example[$key]['cid'] = (int)($res['id']);
  67. }
  68. foreach($designer as $key => $value){
  69. $designer[$key]['cid'] = (int)($res['id']);
  70. }
  71. ExampleModel::saveExample($example, $res['id']);
  72. DesignerModel::saveDesigner($designer, $res['id']);
  73. return $this->success('添加成功!', ['id' => $res->id]);
  74. }
  75. }
  76. /**
  77. * 显示指定的资源
  78. *
  79. * @param int $id
  80. * @return \think\Response
  81. */
  82. public function read($id)
  83. {
  84. $info = CompanyModel::getOne($id);
  85. return $this->success(compact('info'));
  86. }
  87. /**
  88. * 删除指定资源
  89. *
  90. * @param int $id
  91. * @return \think\Response
  92. */
  93. public function delete($id)
  94. {
  95. if (!$id) return $this->fail('数据不存在');
  96. $res = CompanyModel::get($id);
  97. if (!$res) return $this->fail('数据不存在!');
  98. if ($res['is_del']) return $this->fail('已删除!');
  99. $data['is_del'] = 1;
  100. if (!CompanyModel::edit($data, $id))
  101. return $this->fail(CompanyModel::getErrorInfo('删除失败,请稍候再试!'));
  102. else
  103. return $this->success('删除成功!');
  104. }
  105. /**
  106. * 修改状态
  107. * @param $id
  108. * @param $status
  109. * @return mixed
  110. */
  111. public function set_status($id, $status)
  112. {
  113. if ($status == '' || $id == 0) return $this->fail('参数错误');
  114. CompanyModel::where(['id' => $id])->update(['status' => $status]);
  115. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  116. }
  117. }