BusinessController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace api\business\controller;
  3. use api\applet\model\UserModel;
  4. use api\business\model\BusinessJoinModel;
  5. use api\business\model\BusinessModel;
  6. use cmf\controller\RestBaseController;
  7. class BusinessController extends RestBaseController
  8. {
  9. /**
  10. * 列表
  11. */
  12. public function index()
  13. {
  14. $param = $this->request->param();
  15. $page = empty($param['page']) ? 1 : $param['page'];
  16. $size = empty($param['size']) ? 10 : $param['size'];
  17. //搜索条件
  18. $where = [
  19. ['is_show','=',1]
  20. ];
  21. if (!empty($param['keyword'])) {
  22. $where[] = ['title', 'like', "%{$param['keyword']}%"];
  23. }
  24. $list = BusinessModel::where($where)->page($page, $size)->select();
  25. //数据处理
  26. if (!$list->isEmpty()) {
  27. foreach ($list as $v) {
  28. $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
  29. }
  30. }
  31. $this->success('成功', $list);
  32. }
  33. /**
  34. * 详情
  35. */
  36. public function detail()
  37. {
  38. $id = $this->request->post('id');
  39. $info = BusinessModel::get($id);
  40. //信息处理
  41. if (!empty($info['main_image'])) {
  42. $info['main_image'] = cmf_get_image_preview_url($info['main_image']);
  43. }
  44. if (!empty($info['tags'])) {
  45. $info['tags'] = json_decode($info['tags'], true);
  46. } else {
  47. $info['tags'] = [];
  48. }
  49. $this->success('成功', $info);
  50. }
  51. /**
  52. * 参加活动
  53. */
  54. public function join()
  55. {
  56. $user_id = $this->getUserId();
  57. $user = UserModel::get($user_id);
  58. if (empty($user['user_name']) || empty($user['mobile'])) {
  59. $this->success('', ['code' => 1001, 'msg' => '请完善信息']);
  60. }
  61. $param = $this->request->post();
  62. $param['user_id'] = $user_id;
  63. $param['create_time'] = time();
  64. BusinessJoinModel::create($param);
  65. $this->success('提交成功');
  66. }
  67. }