Company.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // if ($id) {
  85. // $info = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
  86. // if (!$info) return $this->fail('数据不存在!');
  87. // $info['cid'] = intval($info['cid']);
  88. // }
  89. $info = CompanyModel::getOne($id);
  90. return $this->success(compact('info'));
  91. }
  92. }