StoreService.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemAttachment;
  5. use service\FormBuilder as Form;
  6. use service\UtilService as Util;
  7. use service\JsonService as Json;
  8. use service\UploadService as Upload;
  9. use think\Request;
  10. use think\Url;
  11. use app\admin\model\wechat\StoreService as ServiceModel;
  12. use app\admin\model\wechat\StoreServiceLog as StoreServiceLog;
  13. use app\admin\model\wechat\WechatUser as UserModel;
  14. /**
  15. * 客服管理
  16. * Class StoreService
  17. * @package app\admin\controller\store
  18. */
  19. class StoreService extends AuthController
  20. {
  21. /**
  22. * 显示资源列表
  23. *
  24. * @return \think\Response
  25. */
  26. public function index()
  27. {
  28. $this->assign(ServiceModel::getList(0));
  29. return $this->fetch();
  30. }
  31. /**
  32. * 显示创建资源表单页.
  33. *
  34. * @return \think\Response
  35. */
  36. public function create(){
  37. $where = Util::getMore([
  38. ['nickname',''],
  39. ['data',''],
  40. ['tagid_list',''],
  41. ['groupid','-1'],
  42. ['sex',''],
  43. ['export',''],
  44. ['stair',''],
  45. ['second',''],
  46. ['order_stair',''],
  47. ['order_second',''],
  48. ['subscribe',''],
  49. ['now_money',''],
  50. ['is_promoter',''],
  51. ],$this->request);
  52. $this->assign('where',$where);
  53. $this->assign(UserModel::systemPage($where));
  54. $this->assign(['title'=>'添加客服','save'=>Url::build('save')]);
  55. return $this->fetch();
  56. }
  57. /**
  58. * 保存新建的资源
  59. *
  60. * @param \think\Request $request
  61. * @return \think\Response
  62. */
  63. public function save(Request $request){
  64. $params = $request->post();
  65. if(count($params["checked_menus"]) <= 0)return Json::fail('请选择要添加的用户!');
  66. if(ServiceModel::where('mer_id',0)->where(array("uid"=>array("in",$params["checked_menus"])))->count())return Json::fail('添加用户中存在已有的客服!');
  67. foreach ($params["checked_menus"] as $key => $value) {
  68. $now_user = UserModel::get($value);
  69. $data[$key]["mer_id"] = 0;
  70. $data[$key]["uid"] = $now_user["uid"];
  71. $data[$key]["avatar"] = $now_user["headimgurl"];
  72. $data[$key]["nickname"] = $now_user["nickname"];
  73. $data[$key]["add_time"] = time();
  74. }
  75. ServiceModel::setAll($data);
  76. return Json::successful('添加成功!');
  77. }
  78. /**
  79. * 显示编辑资源表单页.
  80. *
  81. * @param int $id
  82. * @return \think\Response
  83. */
  84. public function edit($id)
  85. {
  86. $service = ServiceModel::get($id);
  87. if(!$service) return Json::fail('数据不存在!');
  88. $f = array();
  89. $f[] = Form::formFrameImageOne('avatar','客服头像',$service['avatar']);
  90. $f[] = Form::input('nickname','客服名称',$service["nickname"]);
  91. $f[] = Form::switches('notify','订单通知',$service["notify"])->trueValue(1)->falseValue(0)->openStr('开启')->closeStr('关闭');
  92. $f[] = Form::radio('status','客服状态',$service['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
  93. $form = Form::make_post_form('修改数据',$f,Url::build('update',compact('id')));
  94. $this->assign(compact('form'));
  95. return $this->fetch('public/form-builder');
  96. }
  97. /**
  98. * 保存新建的资源
  99. *
  100. * @param \think\Request $request
  101. * @return \think\Response
  102. */
  103. public function update(Request $request,$id)
  104. {
  105. $params = $request->post();
  106. if(empty($params["nickname"]))return Json::fail("客服名称不能为空!");
  107. // print_r($params);die;
  108. $data = array("avatar"=>$params["avatar"]
  109. ,"nickname"=>$params["nickname"]
  110. ,'status'=>$params['status']
  111. ,'notify'=>$params['notify']
  112. );
  113. ServiceModel::edit($data,$id);
  114. return Json::successful('修改成功!');
  115. }
  116. /**
  117. * 删除指定资源
  118. *
  119. * @param int $id
  120. * @return \think\Response
  121. */
  122. public function delete($id)
  123. {
  124. if(!ServiceModel::del($id))
  125. return Json::fail(ServiceModel::getErrorInfo('删除失败,请稍候再试!'));
  126. else
  127. return Json::successful('删除成功!');
  128. }
  129. /**
  130. * 上传图片
  131. * @return \think\response\Json
  132. */
  133. public function upload()
  134. {
  135. $res = Upload::image('file','store/product/'.date('Ymd'));
  136. if(is_array($res)){
  137. SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
  138. return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
  139. }else
  140. return Json::fail($res);
  141. }
  142. /**
  143. * 显示资源列表
  144. *
  145. * @return \think\Response
  146. */
  147. public function chat_user($id)
  148. {
  149. $now_service = ServiceModel::get($id);
  150. if(!$now_service) return Json::fail('数据不存在!');
  151. $list = ServiceModel::getChatUser($now_service,0);
  152. $this->assign(compact('list','now_service'));
  153. return $this->fetch();
  154. }
  155. /**
  156. * 显示资源列表
  157. *
  158. * @return \think\Response
  159. */
  160. public function chat_list($uid,$to_uid)
  161. {
  162. $this->assign(StoreServiceLog::getChatList($uid,$to_uid,0));
  163. $this->assign('to_uid',$to_uid);
  164. return $this->fetch();
  165. }
  166. }