StoreService.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\{
  6. CacheService,
  7. FormBuilder as Form,
  8. UtilService as Util,
  9. JsonService as Json
  10. };
  11. use think\facade\Route as Url;
  12. use app\admin\model\wechat\{
  13. StoreService as ServiceModel, StoreServiceLog as StoreServiceLog, WechatUser as UserModel
  14. };
  15. /**
  16. * 客服管理
  17. * Class StoreService
  18. * @package app\admin\controller\store
  19. */
  20. class StoreService extends AuthController
  21. {
  22. /**
  23. * 显示资源列表
  24. *
  25. * @return \think\Response
  26. */
  27. public function index()
  28. {
  29. $this->assign(ServiceModel::getList(0));
  30. return $this->fetch();
  31. }
  32. /**
  33. * 显示创建资源表单页.
  34. *
  35. * @return \think\Response
  36. */
  37. public function create()
  38. {
  39. $where = Util::getMore([
  40. ['nickname', ''],
  41. ['data', ''],
  42. ['tagid_list', ''],
  43. ['groupid', '-1'],
  44. ['sex', ''],
  45. ['export', ''],
  46. ['stair', ''],
  47. ['second', ''],
  48. ['order_stair', ''],
  49. ['order_second', ''],
  50. ['subscribe', ''],
  51. ['now_money', ''],
  52. ['is_promoter', ''],
  53. ], $this->request);
  54. $this->assign('where', $where);
  55. $this->assign(UserModel::systemPage($where));
  56. $this->assign(['title' => '添加客服', 'save' => Url::buildUrl('save')]);
  57. return $this->fetch();
  58. }
  59. /**
  60. * 保存新建的资源
  61. */
  62. public function save()
  63. {
  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", implode(',', $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::frameImageOne('avatar', '客服头像', Url::buildUrl('admin/widget.images/index', array('fodder' => 'avatar')), $service['avatar'])->icon('image')->width('100%')->height('500px');
  90. $f[] = Form::input('nickname', '客服名称', $service["nickname"]);
  91. $f[] = Form::radio('customer', '统计管理', $service['customer'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
  92. $f[] = Form::radio('notify', '订单通知', $service['notify'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
  93. $f[] = Form::radio('status', '客服状态', $service['status'])->options([['value' => 1, 'label' => '在线'], ['value' => 0, 'label' => '离线']]);
  94. $form = Form::make_post_form('修改数据', $f, Url::buildUrl('update', compact('id')));
  95. $this->assign(compact('form'));
  96. return $this->fetch('public/form-builder');
  97. }
  98. /**
  99. * 保存新建的资源
  100. *
  101. * @param \think\Request $request
  102. * @return \think\Response
  103. */
  104. public function update($id)
  105. {
  106. $params = request()->post();
  107. if (empty($params["nickname"])) return Json::fail("客服名称不能为空!");
  108. $data = array("avatar" => $params["avatar"]
  109. , "nickname" => $params["nickname"]
  110. , 'status' => $params['status']
  111. , 'notify' => $params['notify']
  112. , 'customer' => $params['customer']
  113. );
  114. ServiceModel::edit($data, $id);
  115. return Json::successful('修改成功!');
  116. }
  117. /**
  118. * 删除指定资源
  119. *
  120. * @param int $id
  121. * @return \think\Response
  122. */
  123. public function delete($id)
  124. {
  125. if (!ServiceModel::del($id))
  126. return Json::fail(ServiceModel::getErrorInfo('删除失败,请稍候再试!'));
  127. else
  128. return Json::successful('删除成功!');
  129. }
  130. /**
  131. * 显示资源列表
  132. *
  133. * @return \think\Response
  134. */
  135. public function chat_user($id)
  136. {
  137. $now_service = ServiceModel::get($id);
  138. if (!$now_service) return Json::fail('数据不存在!');
  139. $list = ServiceModel::getChatUser($now_service->toArray(), 0);
  140. $this->assign(compact('list', 'now_service'));
  141. return $this->fetch();
  142. }
  143. /**
  144. * @param int $uid
  145. * @param int $to_uid
  146. * @return string
  147. */
  148. public function chat_list()
  149. {
  150. $where = Util::getMore([['uid', 0], ['to_uid', 0], ['id', 0]]);
  151. if ($where['uid'])
  152. CacheService::set('admin_chat_list' . $this->adminId, $where);
  153. $where = CacheService::get('admin_chat_list' . $this->adminId);
  154. $this->assign(StoreServiceLog::getChatList($where, 0));
  155. $this->assign('where', $where);
  156. return $this->fetch();
  157. }
  158. }