StoreService.php 6.2 KB

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