StoreService.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemAttachment;
  5. use crmeb\services\CacheService;
  6. use crmeb\services\FormBuilder as Form;
  7. use crmeb\services\UtilService as Util;
  8. use crmeb\services\JsonService as Json;
  9. use crmeb\services\UploadService as Upload;
  10. use think\facade\Route as 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::buildUrl('save')]);
  55. return $this->fetch();
  56. }
  57. /**
  58. * 保存新建的资源
  59. */
  60. public function save(){
  61. $params = request()->post();
  62. if(count($params["checked_menus"]) <= 0)return Json::fail('请选择要添加的用户!');
  63. if(ServiceModel::where('mer_id',0)->where(array("uid"=>array("in",implode(',',$params["checked_menus"]))))->count())return Json::fail('添加用户中存在已有的客服!');
  64. foreach ($params["checked_menus"] as $key => $value) {
  65. $now_user = UserModel::get($value);
  66. $data[$key]["mer_id"] = 0;
  67. $data[$key]["uid"] = $now_user["uid"];
  68. $data[$key]["avatar"] = $now_user["headimgurl"];
  69. $data[$key]["nickname"] = $now_user["nickname"];
  70. $data[$key]["add_time"] = time();
  71. }
  72. ServiceModel::setAll($data);
  73. return Json::successful('添加成功!');
  74. }
  75. /**
  76. * 显示编辑资源表单页.
  77. *
  78. * @param int $id
  79. * @return \think\Response
  80. */
  81. public function edit($id)
  82. {
  83. $service = ServiceModel::get($id);
  84. if(!$service) return Json::fail('数据不存在!');
  85. $f = array();
  86. $f[] = Form::frameImageOne('avatar','客服头像',Url::buildUrl('admin/widget.images/index',array('fodder'=>'avatar')),$service['avatar'])->icon('image')->width('100%')->height('500px');
  87. $f[] = Form::input('nickname','客服名称',$service["nickname"]);
  88. $f[] = Form::radio('customer','统计管理',$service['customer'])->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
  89. $f[] = Form::radio('notify','订单通知',$service['notify'])->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
  90. $f[] = Form::radio('status','客服状态',$service['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
  91. $form = Form::make_post_form('修改数据',$f,Url::buildUrl('update',compact('id')));
  92. $this->assign(compact('form'));
  93. return $this->fetch('public/form-builder');
  94. }
  95. /**
  96. * 保存新建的资源
  97. *
  98. * @param \think\Request $request
  99. * @return \think\Response
  100. */
  101. public function update($id)
  102. {
  103. $params = request()->post();
  104. if(empty($params["nickname"]))return Json::fail("客服名称不能为空!");
  105. $data = array("avatar"=>$params["avatar"]
  106. ,"nickname"=>$params["nickname"]
  107. ,'status'=>$params['status']
  108. ,'notify'=>$params['notify']
  109. ,'customer'=>$params['customer']
  110. );
  111. ServiceModel::edit($data,$id);
  112. return Json::successful('修改成功!');
  113. }
  114. /**
  115. * 删除指定资源
  116. *
  117. * @param int $id
  118. * @return \think\Response
  119. */
  120. public function delete($id)
  121. {
  122. if(!ServiceModel::del($id))
  123. return Json::fail(ServiceModel::getErrorInfo('删除失败,请稍候再试!'));
  124. else
  125. return Json::successful('删除成功!');
  126. }
  127. /**
  128. * 上传图片
  129. * @return \think\response\Json
  130. */
  131. public function upload()
  132. {
  133. $res = Upload::getInstance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
  134. if(is_array($res)){
  135. SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
  136. return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
  137. }else
  138. return Json::fail($res);
  139. }
  140. /**
  141. * 显示资源列表
  142. *
  143. * @return \think\Response
  144. */
  145. public function chat_user($id)
  146. {
  147. $now_service = ServiceModel::get($id);
  148. if(!$now_service) return Json::fail('数据不存在!');
  149. $list = ServiceModel::getChatUser($now_service->toArray(),0);
  150. $this->assign(compact('list','now_service'));
  151. return $this->fetch();
  152. }
  153. /**
  154. * @param int $uid
  155. * @param int $to_uid
  156. * @return string
  157. */
  158. public function chat_list()
  159. {
  160. $where = Util::getMore([['uid',0], ['to_uid', 0], ['id', 0]]);
  161. if($where['uid'])
  162. CacheService::set('admin_chat_list'.$this->adminId, $where);
  163. $where = CacheService::get('admin_chat_list'.$this->adminId);
  164. $this->assign(StoreServiceLog::getChatList($where, 0));
  165. $this->assign('where',$where);
  166. return $this->fetch();
  167. }
  168. }