|
|
@@ -11,10 +11,150 @@ use Exception;
|
|
|
use League\Flysystem\Util;
|
|
|
use think\facade\Cache;
|
|
|
use app\manage\model\{Config};
|
|
|
+use app\admin\model\GuessAskLanguages;
|
|
|
+use app\admin\model\QuestionLanguages;
|
|
|
|
|
|
class Im extends BaseController
|
|
|
{
|
|
|
protected $fileType = ['file', 'image','video','voice','emoji'];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 猜你想问列表
|
|
|
+ */
|
|
|
+ function guessask()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params = $this->request->param();
|
|
|
+ $page = $params['page'] ?? 1;
|
|
|
+ $limit = $params['limit'] ?? 15;
|
|
|
+ $language_code = $this->lang;
|
|
|
+ $query = GuessAskLanguages::where('language_code', $language_code)->where('status', 1);
|
|
|
+ if (!empty($params['name'])) {
|
|
|
+ $query = $query->where('name', 'like', '%'.$params['name'].'%');
|
|
|
+ }
|
|
|
+ if (isset($params['type']) && $params['type'] != '') {
|
|
|
+ $query = $query->where('type', $params['type']);
|
|
|
+ }
|
|
|
+ $count = $query->count();
|
|
|
+ $list = $query->order('is_top','desc')
|
|
|
+ ->order('is_rec','desc')
|
|
|
+ ->order('click_num','desc')
|
|
|
+ ->limit($limit)
|
|
|
+ ->page($page)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success('', [ 'count' => $count, 'list' => $list]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 猜你想问点击使用
|
|
|
+ */
|
|
|
+ function guessaskClick()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $id = $this->request->param('id');
|
|
|
+ $info = GuessAskLanguages::where('id', $id)->where('status', 1)->find();
|
|
|
+ if ($info) {
|
|
|
+ $info->click_num = $info->click_num + 1;
|
|
|
+ $info->save();
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success('');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 问题列表
|
|
|
+ */
|
|
|
+ function question()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params = $this->request->param();
|
|
|
+ $page = $params['page'] ?? 1;
|
|
|
+ $limit = $params['limit'] ?? 15;
|
|
|
+ $language_code = $this->lang;
|
|
|
+ $query = QuestionLanguages::where('language_code', $language_code)->where('status', 1);
|
|
|
+
|
|
|
+ if (isset($params['question_type']) && $params['question_type'] != '') {
|
|
|
+ $query = $query->where('question_type', $params['question_type']);
|
|
|
+ }
|
|
|
+ $count = $query->count();
|
|
|
+ $list = $query->order('weight','desc')
|
|
|
+ ->limit($limit)
|
|
|
+ ->page($page)
|
|
|
+ ->select();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success('', [ 'count' => $count, 'list' => $list]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 问题点赞、点否
|
|
|
+ */
|
|
|
+ function questionClick()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $id = $this->request->param('id');
|
|
|
+ $is_like = $this->request->param('is_like');
|
|
|
+ $question = QuestionLanguages::where('id', $id)->where('status', 1)->find();
|
|
|
+ if ($question) {
|
|
|
+ if ($is_like == 1) {
|
|
|
+ $question->like_count = $question->like_count + 1;
|
|
|
+ } else {
|
|
|
+ $question->dislike_count = $question->dislike_count + 1;
|
|
|
+ }
|
|
|
+ $question->save();
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success('');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转人工客服
|
|
|
+ */
|
|
|
+ function transferHuman()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $user_id = $this->userInfo['user_id'];
|
|
|
+ $user = User::where('user_id', $user_id)->find();
|
|
|
+ if (!$user) {
|
|
|
+ return error('用户不存在');
|
|
|
+ }
|
|
|
+ if ($user->role > 0) {
|
|
|
+ return error('系统管理员无法转人工');
|
|
|
+ }
|
|
|
+ if ($user['service_status'] == -1) {
|
|
|
+ $user->service_status = 0;
|
|
|
+ $user->service->service_start = time();
|
|
|
+ $user->save();
|
|
|
+
|
|
|
+ //机器人客服
|
|
|
+ $autoTask = Config::autoTask();
|
|
|
+ $param = [
|
|
|
+ 'id' => \utils\Str::getUuid(),
|
|
|
+ 'type' => 'text',
|
|
|
+ 'status' => 'going',
|
|
|
+ 'sendTime' => time(),
|
|
|
+ 'toContactId' => !empty($autoTask['user_id']) ? $autoTask['user_id'] : 1,
|
|
|
+ 'content' => $this->globalConfig['transfer_to_human'],
|
|
|
+ 'file_id' => 0,
|
|
|
+ 'is_group' => 0
|
|
|
+ ];
|
|
|
+ Message::sendMsg($param, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success('');
|
|
|
+ }
|
|
|
// 获取联系人列表
|
|
|
public function getContacts()
|
|
|
{
|