Company.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. $data['slider_image'] = json_encode($data['slider_image']);
  53. $example = $data['example'];
  54. $designer = $data['designer'];
  55. unset($data['example'], $data['designer']);
  56. if ($data['id']) {
  57. $id = $data['id'];
  58. unset($data['id']);
  59. $res = CompanyModel::edit($data, $id, 'id');
  60. ExampleModel::saveExample($example, $id);
  61. DesignerModel::saveDesigner($designer, $id);
  62. return $this->success('修改成功!', ['id' => $id]);
  63. } else {
  64. $data['add_time'] = time();
  65. $res = CompanyModel::create($data);
  66. foreach($example as $key => $value){
  67. $example[$key]['cid'] = (int)($res['id']);
  68. }
  69. foreach($designer as $key => $value){
  70. $designer[$key]['cid'] = (int)($res['id']);
  71. }
  72. ExampleModel::saveExample($example, $res['id']);
  73. DesignerModel::saveDesigner($designer, $res['id']);
  74. return $this->success('添加成功!', ['id' => $res->id]);
  75. }
  76. }
  77. /**
  78. * 显示指定的资源
  79. *
  80. * @param int $id
  81. * @return \think\Response
  82. */
  83. public function read($id)
  84. {
  85. $info = CompanyModel::getOne($id);
  86. return $this->success(compact('info'));
  87. }
  88. /**
  89. * 删除指定资源
  90. *
  91. * @param int $id
  92. * @return \think\Response
  93. */
  94. public function delete($id)
  95. {
  96. if (!$id) return $this->fail('数据不存在');
  97. $res = CompanyModel::get($id);
  98. if (!$res) return $this->fail('数据不存在!');
  99. if ($res['is_del']) return $this->fail('已删除!');
  100. $data['is_del'] = 1;
  101. if (!CompanyModel::edit($data, $id))
  102. return $this->fail(CompanyModel::getErrorInfo('删除失败,请稍候再试!'));
  103. else
  104. return $this->success('删除成功!');
  105. }
  106. /**
  107. * 修改状态
  108. * @param $id
  109. * @param $status
  110. * @return mixed
  111. */
  112. public function set_status($id, $status)
  113. {
  114. if ($status == '' || $id == 0) return $this->fail('参数错误');
  115. CompanyModel::where(['id' => $id])->update(['status' => $status]);
  116. return $this->success($status == 0 ? '隐藏成功' : '显示成功');
  117. }
  118. }