Info.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\InfoModel;
  4. use app\common\model\UserFollowModel;
  5. use app\mobile\MobileBaseController;
  6. use app\mobile\validate\InfoValidate;
  7. use think\App;
  8. use think\exception\ValidateException;
  9. class Info extends MobileBaseController
  10. {
  11. private $_user = null;
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->_user = get_user();
  16. }
  17. /**
  18. * 登记列表
  19. */
  20. public function index()
  21. {
  22. $list = InfoModel::where('user_id', $this->_user['id'])
  23. ->append(['type_text'])
  24. ->select();
  25. return view('', ['list' => $list]);
  26. }
  27. /**
  28. * 类型介绍
  29. */
  30. public function type()
  31. {
  32. $list = InfoModel::TYPE;
  33. $describe = InfoModel::TYPE_DESCRIBE;
  34. return view('', ['list' => $list, 'describe' => $describe]);
  35. }
  36. /**
  37. * 登记表单
  38. */
  39. public function form()
  40. {
  41. $id = input('id/d', 0);
  42. if (empty($id)) {
  43. $info = '{}';
  44. } else {
  45. $info = InfoModel::find($id);
  46. $info['sex'] = (string)$info['sex'];
  47. empty($info) && jump('该信息不存在');
  48. }
  49. $type = InfoModel::TYPE;
  50. $type_text = $info == '{}' ? '' : $type[$info['type']];
  51. return view('', [
  52. 'info' => $info,
  53. 'type_text' => $type_text,
  54. 'type_list' => array_to_vue($type),
  55. ]);
  56. }
  57. /**
  58. * 表单提交
  59. */
  60. public function formPost()
  61. {
  62. $data = input('post.');
  63. $data['user_id'] = $this->_user['id'];
  64. try {
  65. validate(InfoValidate::class)->check($data);
  66. } catch (ValidateException $e) {
  67. ajax_return(1, $e->getError());
  68. }
  69. if (empty($data['id'])) {
  70. InfoModel::create($data);
  71. } else {
  72. InfoModel::update($data, ['id' => $data['id']]);
  73. }
  74. ajax_return();
  75. }
  76. /**
  77. * 删除
  78. */
  79. public function delete()
  80. {
  81. $id = input('post.id');
  82. empty($id) && ajax_return(1, '该信息不存在');
  83. $user_id = $this->_user['id'];
  84. $info = InfoModel::where('id', $id)->where('user_id', $user_id)->find();
  85. empty($info) && ajax_return(1, '该信息不存在');
  86. UserFollowModel::destroy(['info_id' => $id]);
  87. $info->delete();
  88. ajax_return();
  89. }
  90. /**
  91. * 跟进
  92. */
  93. public function follow()
  94. {
  95. $id = input('id');
  96. empty($id) && jump('该记录不存在');
  97. $list = UserFollowModel::where('user_id', $this->_user['id'])->where('info_id', $id)->order('id', 'desc')->select();
  98. return view('', ['list' => $list, 'id' => $id]);
  99. }
  100. public function followPost()
  101. {
  102. $id = input('post.id');
  103. empty($id) && ajax_return(1, '数据异常');
  104. $remark = input('post.remark');
  105. empty($remark) && ajax_return(1, '请填写跟进记录');
  106. $data = [
  107. 'user_id' => $this->_user['id'],
  108. 'info_id' => $id,
  109. 'user_type' => UserFollowModel::USER_TYPE_USER,
  110. 'type' => UserFollowModel::TYPE_OTHER,
  111. 'remark' => $remark,
  112. ];
  113. UserFollowModel::create($data);
  114. ajax_return();
  115. }
  116. }