| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace addon\servicer\model;
- use app\model\BaseModel;
- use app\model\member\Member as MemberServices;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- class Member extends BaseModel
- {
- /**
- * 设置会员在线状态
- * @param integer $memberId 会员编号
- * @param boolean $online 是否在线
- * @return int
- * @throws DbException
- */
- public function setMemberOnline($memberId, $online = true)
- {
- return model('servicer_member')->update(['online'=> $online ? 1 : 0], [['member_id', '=', $memberId]]);
- }
- /**
- * 获取会员数据
- * @param $memberId
- * @param $servicerId
- * @param $siteId
- * @return array|\think\Model|null
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getMember($memberId, $servicerId, $siteId = 0)
- {
- $alias = 'sm';
- $condition = [
- ['sm.member_id', '=', $memberId],
- ['sm.servicer_id', '=', $servicerId]
- ];
- $join = [
- ['member m', 'm.member_id = sm.member_id', 'left'],
- ];
- $fields = ['sm.id', 'sm.member_id', 'sm.servicer_id', 'sm.member_name', 'sm.online', 'sm.create_time', 'sm.last_online_time', 'sm.delete_time', 'sm.headimg', 'sm.client_id', 'm.nickname', 'm.username', 'm.headimg'];
- $model = model('servicer_member')->getInfo($condition, $fields, $alias, $join);
- if (empty($model)) {
- return null;
- }
- $dialogs = (new Dialogue)->getDialogueList($memberId, 1, 1, $siteId, $servicerId);
- $dialog = [];
- if (!empty($dialogs) && !empty($dialogs['list']) && count($dialogs['list']) > 0) {
- $dialog = $dialogs['list'][0];
- }
- $model['last_dialog'] = $dialog;
- return $model;
- }
- /**
- * 新建聊天咨询用户
- * @param integer $memberId 会员ID
- * @param integer $servicerId 客服ID
- * @param boolean $online 在线状态
- * @param string $client_id 临时会话ID
- * @return int|string
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function createMember($memberId, $servicerId, $online = true, $client_id = '')
- {
- $memberService = new MemberServices();
- $memberInfo = $memberService->getMemberInfo([['member_id', '=', $memberId]], ['member_id', 'headimg', 'username']);
- if (empty($memberInfo['data'])) {
- return $memberInfo['code'];
- }
- $memberInfo = $memberInfo['data'];
- $memberServicer = model('servicer_member')->getInfo(['servicer_id' => $servicerId, 'member_id' => $memberId]);
- if (!empty($memberServicer)) {
- // 更新在线状态、时间
- $result = model('servicer_member')->update(
- [
- 'online' => $online,
- 'last_online_time' => time(),
- 'client_id' => $client_id,
- 'member_name' => $memberInfo['username'],
- 'headimg' => $memberInfo['headimg']
- ],
- [['member_id', '=', $memberId], ['servicer_id', '=', $servicerId]]
- );
- if($result !== false){
- return $result;
- }else{
- return 0;
- }
- }
- $result = model('servicer_member')->add([
- 'member_id' => $memberId,
- 'servicer_id' => $servicerId,
- 'member_name' => $memberInfo['username'],
- 'online' => $online,
- 'create_time' => time(),
- 'last_online_time' => time(),
- 'delete_time' => 0,
- 'headimg' => $memberInfo['headimg'],
- 'client_id' => $client_id,
- ]);
- return $result;
- }
- /**
- * 获取客服关联会员列表
- * @param array $condition
- * @param bool $field
- * @param string $order
- * @param int $page
- * @param int $list_rows
- * @param string $alias
- * @param array $join
- * @param null $group
- * @param null $limit
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getPageList($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [], $group = null, $limit = null)
- {
- return model('servicer_member')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join, $group, $limit);
- }
- /**
- * 获取数据列表
- * @param $condition
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getList($condition)
- {
- return model('servicer_member')->getList($condition);
- }
- /**
- * 是否已连接会话
- * @param $servicerId
- * @param $memberId
- * @return bool|mixed
- */
- public function isConnect($servicerId, $memberId)
- {
- $result = model('servicer_member')->getInfo([['online', '=', 1], ['servicer_id', '=', $servicerId], ['member_id', '=', $memberId]]);
- return $result ? true : false;
- }
- }
|