MobileFollow.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\agent\controller;
  3. use app\agent\BaseController;
  4. use app\common\model\MobileFollow as MobileFollowModel;
  5. use app\common\model\MobileFollowLog as MobileFollowLogModel;
  6. class MobileFollow extends BaseController
  7. {
  8. public function followList()
  9. {
  10. $status_list = MobileFollowModel::$statusText;
  11. return view('mobilefollow/followlist', ['status_list' => $status_list]);
  12. }
  13. public function followForm()
  14. {
  15. $id = input('id/d, 0');
  16. $follow = MobileFollowModel::findOrEmpty($id);
  17. $status_list = MobileFollowModel::$statusText;
  18. return view('mobilefollow/followform', [
  19. 'status_list' => $status_list,
  20. 'follow' => $follow,
  21. ]);
  22. }
  23. public function editFollow()
  24. {
  25. $agent = $this->access_agent;
  26. $id = input('id/d', 0);
  27. $data = [
  28. 'agent_id' => $agent['id'],
  29. 'mobile' => input('mobile/s', ""),
  30. 'content' => input('content/s', ""),
  31. 'receive_time' => input('receive_time/s', ""),
  32. 'status' => input('status/d', 1),
  33. ];
  34. if (empty($id)) {
  35. MobileFollowModel::create($data);
  36. } else {
  37. $broker = MobileFollowModel::find($id);
  38. $broker->save($data);
  39. }
  40. exit(json_encode([
  41. 'code' => 0,
  42. ]));
  43. }
  44. public function delFollow()
  45. {
  46. $idarr = input('idarr/a');
  47. $follow_check = MobileFollowLogModel::whereIn('follow_id', $idarr)->find();
  48. if (!empty($follow_check)) {
  49. exit(json_encode([
  50. 'code' => 1,
  51. 'msg' => "该记录下有跟进记录,无法删除",
  52. ]));
  53. }
  54. $follow = MobileFollowModel::whereIn('id', $idarr)->select();
  55. $result = $follow->delete();
  56. if ($result) {
  57. exit(json_encode([
  58. 'code' => 0,
  59. 'msg' => "",
  60. ]));
  61. }
  62. exit(json_encode([
  63. 'code' => 1,
  64. 'msg' => "删除失败,请稍后重试",
  65. ]));
  66. }
  67. public function listFollow()
  68. {
  69. $agentid = $this->access_agent['id'];
  70. $limit = input('limit/d', 20);
  71. $page = input('page/d', 1);
  72. $map = [];
  73. $map[] = ['agent_id', '=', $agentid];
  74. $keywords = input('keywords/s');
  75. if (!empty($keywords)) {
  76. $map[] = ['mobile', 'like', '%' . $keywords . '%'];
  77. }
  78. $status = input('status/d');
  79. if (!empty($status)) {
  80. $map[] = ['status', '=', $status];
  81. }
  82. $list = MobileFollowModel::with(['user'])->where($map)->order('receive_time', 'DESC')->limit($limit)->page($page)->append(['status_text'])->select();
  83. $count = MobileFollowModel::where($map)->count();
  84. foreach ($list as $v) {
  85. $v['is_register'] = empty($v['user']) ? '否' : '是';
  86. }
  87. if ($count == 0) {
  88. exit(json_encode([
  89. 'code' => 1,
  90. 'msg' => "未查询到数据",
  91. ]));
  92. }
  93. exit(json_encode([
  94. 'code' => 0,
  95. 'msg' => "",
  96. 'count' => $count,
  97. 'data' => $list,
  98. ]));
  99. }
  100. public function importView()
  101. {
  102. return view('mobilefollow/importview');
  103. }
  104. public function import()
  105. {
  106. $file_url = input('file_url/s', "");
  107. if (!file_exists($file_url)) {
  108. exit(json_encode([
  109. 'code' => 1,
  110. 'msg' => "文件不存在",
  111. ]));
  112. }
  113. $agentid = $this->access_agent['id'];
  114. $time = time();
  115. $data = ['account', 'mobile', 'content', 'receive_time'];
  116. $list = importExecl($file_url, $data, 1);
  117. $create = [];
  118. foreach ($list as $k => $v) {
  119. $empty_check = [
  120. 'mobile' => '回复手机',
  121. 'content' => '回复内容',
  122. 'receive_time' => '接收时间',
  123. ];
  124. foreach ($empty_check as $key => $value) {
  125. if (empty($v[$key])) {
  126. exit(json_encode([
  127. 'code' => 1,
  128. 'msg' => '第' . ($k + 2) . '行的' . $value . '不能为空',
  129. ]));
  130. }
  131. }
  132. $item = [];
  133. $item['agent_id'] = $agentid;
  134. $item['mobile'] = $v['mobile'];
  135. $item['content'] = $v['content'];
  136. $item['receive_time'] = strtotime($v['receive_time']) ?: $time;
  137. $item['status'] = 1;
  138. $create[] = $item;
  139. }
  140. foreach ($create as $v) {
  141. MobileFollowModel::create($v);
  142. }
  143. exit(json_encode(['code' => 0]));
  144. }
  145. // 用户跟进记录
  146. public function follow()
  147. {
  148. $follow_id = input('follow_id/d');
  149. $follow = MobileFollowModel::findOrEmpty($follow_id);
  150. $followlist = MobileFollowLogModel::where('follow_id', $follow_id)->order('id', 'desc')->limit(100)->select();
  151. $type_list = MobileFollowLogModel::$typeText;
  152. return view('mobilefollow/follow', [
  153. 'follow' => $follow,
  154. 'followlist' => $followlist,
  155. 'type_list' => $type_list,
  156. ]);
  157. }
  158. public function editFollowLog()
  159. {
  160. $follow_id = input('follow_id/d', 0);
  161. $follow = MobileFollowModel::findOrEmpty($follow_id);
  162. if ($follow->isEmpty()) {
  163. exit(json_encode([
  164. 'code' => 1,
  165. 'msg' => "记录不存在。",
  166. ]));
  167. }
  168. MobileFollowLogModel::create([
  169. 'follow_id' => $follow_id,
  170. 'type' => input('type/d', 1),
  171. 'remark' => input('remark/s', ""),
  172. 'createtime' => time(),
  173. ]);
  174. $follow->save([
  175. 'status' => 2,
  176. ]);
  177. exit(json_encode([
  178. 'code' => 0,
  179. ]));
  180. }
  181. }