ContactWay.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\Work\State as Model;
  3. use App\Facades\Servers\WechatWork\ContactWay as Work;
  4. use App\Facades\Servers\WechatWork\User as WorkUser;
  5. use App\Facades\Servers\WechatWork\CorpTag as WorkTag;
  6. use App\Http\Requests\Admin\ContactWay as Request;
  7. use App\Models\Custom;
  8. /**
  9. * 联系方式-联系我
  10. *
  11. * @author 刘相欣
  12. *
  13. */
  14. class ContactWay extends Auth{
  15. protected function _initialize(){
  16. parent::_initialize();
  17. $this->assign('breadcrumb1','联系方式');
  18. $this->assign('breadcrumb2','渠道活码');
  19. }
  20. /**
  21. * 列表页
  22. *
  23. * */
  24. public function index(Model $Model,Custom $Custom){
  25. // 接受参数
  26. $user = request('user','');
  27. $remark = request('remark','');
  28. $customUid = request('customUid','');
  29. // 查询条件
  30. $map = [];
  31. // 组合条件
  32. if( $remark ) $map[] = ['remark','LIKE','%'.$remark.'%'];
  33. if( $user ) $map[] = ['user','LIKE','%'.$user.'%'];
  34. if( $customUid ) $map[] = ['custom_uid','=',$customUid];
  35. // 查询数据
  36. $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
  37. // 循环处理数据
  38. foreach ($list as $key => $value) {
  39. // 接待成员
  40. $value['user'] = explode(',',$value['user']);
  41. // 标签信息
  42. $value['tags'] = explode(',',$value['tags']);
  43. // 使用对象
  44. $value['custom_name'] = $Custom->getValue($value['custom_uid'],'username');
  45. // 重组
  46. $list[$key] = $value;
  47. }
  48. // 获取部门数据
  49. $partUserList = WorkUser::getListDepart();
  50. // 获取标签数据
  51. $corpTagList = WorkTag::getList();
  52. // 获取商业与地区代表
  53. $customList = $Custom->getListUserType();
  54. // 分配数据
  55. $this->assign('list',$list);
  56. $this->assign('partUserList',$partUserList);
  57. $this->assign('customList',$customList);
  58. $this->assign('corpTagList',$corpTagList);
  59. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  60. // 加载模板
  61. return $this->fetch();
  62. }
  63. /**
  64. * 添加
  65. *
  66. * */
  67. public function add(Request $request,Model $Model,Custom $Custom){
  68. if( request()->isMethod('post') ){
  69. // 验证参数
  70. $request->scene('add')->validate();
  71. // 状态
  72. $state['remark'] = request('remark','');
  73. $state['user_type'] = request('user_type','');
  74. $state['custom_uid'] = request('custom_uid',0);
  75. $state['tags'] = request('tags',[]);
  76. $state['user'] = request('user',[]);
  77. // 数据处理
  78. $state['tags'] = implode(',',$state['tags']);
  79. $state['user'] = implode(',',$state['user']);
  80. // 获取ID
  81. $id = $Model->add($state);
  82. // 如果操作失败
  83. if( !$id ) return json_send(['code'=>'error','msg'=>'参数创建失败','path'=>'']);
  84. // 接收数据
  85. $data['user'] = request('user',[]);
  86. $data['remark'] = request('remark','');
  87. $data['state'] = http_build_query(['state_id'=>$id]);
  88. // 写入数据表
  89. $data = Work::add($data,2,2);
  90. // 如果操作失败
  91. if( !$data ) return json_send(['code'=>'error','msg'=>'活码创建失败','path'=>'']);
  92. // 写入数据表
  93. $result = $Model->edit($id,$data);
  94. // 如果操作失败
  95. if( !$result ) return json_send(['code'=>'error','msg'=>'活码创建失败','path'=>'']);
  96. // 告知结果
  97. return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
  98. }
  99. // 获取部门数据
  100. $partUserList = WorkUser::getListDepart();
  101. // 获取标签数据
  102. $corpTagList = WorkTag::getList();
  103. // 获取商业与地区代表
  104. $customList = $Custom->getListUserType();
  105. // 分配数据
  106. $this->assign('crumbs','新增');
  107. $this->assign('partUserList',$partUserList);
  108. $this->assign('corpTagList',$corpTagList);
  109. $this->assign('customList',$customList);
  110. // 加载模板
  111. return $this->fetch();
  112. }
  113. /**
  114. * 添加
  115. *
  116. * */
  117. public function edit(Request $request,Model $Model,Custom $Custom){
  118. // 接收数据
  119. $id = request('id','');
  120. // 获取旧数据
  121. $oldData = $Model->getOne($id);
  122. // 修改
  123. if( request()->isMethod('post') ){
  124. // 验证参数
  125. $request->scene('edit')->validate();
  126. // 如果操作失败
  127. if( !$oldData ) return json_send(['code'=>'error','msg'=>'数据不存在','path'=>'']);
  128. // 状态
  129. $state['remark'] = request('remark','');
  130. $state['user_type'] = request('user_type','');
  131. $state['custom_uid'] = request('custom_uid',0);
  132. $state['tags'] = request('tags',[]);
  133. $state['user'] = request('user',[]);
  134. // 数据处理
  135. $state['tags'] = implode(',',$state['tags']);
  136. $state['user'] = implode(',',$state['user']);
  137. // 接收数据
  138. $data['user'] = request('user',[]);
  139. $data['remark'] = request('remark','');
  140. // 写入数据表
  141. $result = Work::edit($oldData['config_id'],$data);
  142. // 如果操作失败
  143. if( !$result ) return json_send(['code'=>'error','msg'=>'活码编辑失败','path'=>'']);
  144. // 写入数据表
  145. $result = $Model->edit($id,$state);
  146. // 如果操作失败
  147. if( !$result ) return json_send(['code'=>'error','msg'=>'活码编辑失败','path'=>'']);
  148. // 告知结果
  149. return json_send(['code'=>'success','msg'=>'编辑成功','action'=>'edit']);
  150. }
  151. // 如果不存在的话
  152. if( !$oldData ) return $this->error('数据未查到');
  153. // 标签切割
  154. $oldData['tags'] = explode(',',$oldData['tags']);
  155. // 接待人员切割
  156. $oldData['user'] = explode(',',$oldData['user']);
  157. // 获取部门数据
  158. $partUserList = WorkUser::getListDepart();
  159. // 获取标签数据
  160. $corpTagList = WorkTag::getList();
  161. // 获取商业与地区代表
  162. $customList = $Custom->getListUserType();
  163. // 分配数据
  164. $this->assign('crumbs','修改');
  165. $this->assign('oldData',$oldData);
  166. $this->assign('customList',$customList);
  167. $this->assign('corpTagList',$corpTagList);
  168. $this->assign('partUserList',$partUserList);
  169. // 加载模板
  170. return $this->fetch();
  171. }
  172. /**
  173. * 设置为客服推送
  174. * @param string $code 授权码
  175. *
  176. * */
  177. public function set_follow(Request $request,Model $Model){
  178. // 验证参数
  179. $request->scene('set_follow')->validate();
  180. // 接收参数
  181. $id = request('id',0);
  182. // 如果需要默认当前的话
  183. $Model->query()->where([])->update(['is_follow'=>0]);
  184. // 查询是否已经提交过
  185. $result = $Model->edit($id,['is_follow'=>1]);
  186. // 提示
  187. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败,请重试','data'=>['error'=>'写入失败']]);
  188. // 二维码
  189. $Model->getFollowQrcode(true);
  190. // 记录行为
  191. // $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['is_follow'=>1]);
  192. // 返回结果
  193. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  194. }
  195. }