Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
7868a31c
Commit
7868a31c
authored
Jul 09, 2018
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备id绑定表
parent
ea26e994
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
48 deletions
+68
-48
ChatService.php
application/chat/service/ChatService.php
+39
-20
ChatUserExt.php
application/model/ChatUserExt.php
+29
-28
No files found.
application/chat/service/ChatService.php
View file @
7868a31c
...
...
@@ -19,11 +19,8 @@ use app\model\ChatMsgExt;
use
app\model\ChatMsgStatus
;
use
app\model\ChatRelation
;
use
app\model\ChatUser
;
use
app\model\ChatUserExt
;
use
app\model\HouseInfos
;
use
app\model\Users
;
use
http\Exception
;
class
ChatService
{
...
...
@@ -63,53 +60,75 @@ class ChatService
* @param $device_id
* @param $push_id
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
register
(
$user_id
,
$mobile
,
$source
,
$device_id
,
$push_id
)
public
function
register
(
$user_id
,
$mobile
,
$source
,
$device_id
,
$push_id
)
{
$params
[
"type"
]
=
$source
;
$params
[
"user_id"
]
=
$user_id
;
$params
[
"phone"
]
=
$mobile
;
$fields
=
"id,type,phone,only_id,password"
;
$id
=
$only_id
=
0
;
$chatUser
=
$this
->
chatUserModel
->
getChatUser
(
$params
,
$fields
);
if
(
count
(
$chatUser
)
>
0
)
{
return
[
"code"
=>
"200"
,
"only_id"
=>
$chatUser
[
0
][
"only_id"
]
];
$id
=
$chatUser
[
0
][
"id"
];
$only_id
=
$chatUser
[
0
][
"only_id"
];
}
else
{
$only_id
=
$this
->
createOnlyId
(
$user_id
,
$source
);
if
(
!
$only_id
)
{
return
[
"code"
=>
"101"
,
"msg"
=>
"没有找到用户信息"
];
}
else
{
$id
=
$this
->
insertChatUser
(
$source
,
$user_id
,
$mobile
,
$only_id
);
echo
$id
;
}
}
//todo 保存或更新push_id
//todo 1.判断设备id +id 的数据是否存在,存在并且push_id和提交的不同则修改,否者新增
if
(
$id
>
0
)
{
$this
->
savePushId
(
$id
,
$device_id
,
$push_id
);
}
}
return
[
"code"
=>
200
,
"only_id"
=>
$only_id
];
}
}
/**
* @param $chat_user_id
* @param $device_id
* @param $push_id
* @return bool
* @throws \think\Exception
* @throws \think\exception\DbException
*/
private
function
savePushId
(
$chat_user_id
,
$device_id
,
$push_id
){
private
function
savePushId
(
$chat_user_id
,
$device_id
,
$push_id
)
{
$where
[
'ext_id'
]
=
$chat_user_id
;
$where
[
'device_id'
]
=
$device_id
;
$where
[
'push_id'
]
=
$push_id
;
$where
[
'is_forbidden'
]
=
0
;
$info
=
$this
->
chatUserExtModel
->
getChatUserExt
(
$where
,
'id,ext_id,device_id,push_id'
);
$result
=
false
;
if
(
count
(
$info
)
>
0
)
{
if
(
$info
[
0
][
"push_id"
]
!=
$push_id
)
{
//update
$result
=
$this
->
chatUserExtModel
->
addChatUserExt
([
'push_id'
=>
$push_id
],
$info
[
0
][
'id'
]);
}
}
else
{
//todo 保存或更新push_id
$params
[
"ext_id"
]
=
$chat_user_id
;
$params
[
"device_id"
]
=
$device_id
;
$params
[
"push_id"
]
=
$push_id
;
$params
[
"is_forbidden"
]
=
0
;
$params
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
chatUserExtModel
->
addChatUserExt
(
$params
);
$result
=
$this
->
chatUserExtModel
->
addChatUserExt
(
$params
);
}
if
(
!
$result
)
{
return
false
;
}
return
true
;
}
...
...
@@ -226,7 +245,7 @@ class ChatService
$chat_user_arr
=
[];
if
(
$only_id
)
{
$only_id_arr
=
explode
(
","
,
$only_id
);
$where_
[
"only_id"
]
=
array
(
"in"
,
$only_id_arr
)
;
$where_
[
"only_id"
]
=
[
"in"
,
$only_id_arr
]
;
$where_
[
"status"
]
=
0
;
$field
=
"type,user_id,phone,only_id"
;
$chat_user
=
$this
->
chatUserModel
->
getChatUser
(
$where_
,
$field
);
...
...
@@ -254,7 +273,7 @@ class ChatService
$field
=
"a.id,a.name as user_nick,a.phone as user_phone,a.img as user_pic,CONCAT(c.district_name,'-',b.store_name) as shop_name"
;
$where_agent
[
"phone"
]
=
array
(
"in"
,
$agent_phone
)
;
$where_agent
[
"phone"
]
=
[
"in"
,
$agent_phone
]
;
$agentsResult
=
$this
->
agentsV2Model
->
getAgentsInfoByAgentId
(
$field
,
$where_agent
);
foreach
(
$agentsResult
as
$v
)
{
...
...
@@ -272,7 +291,7 @@ class ChatService
$fields
=
"id,user_nick,user_phone,user_pic"
;
$param
[
"status"
]
=
0
;
$param
[
"user_phone"
]
=
array
(
"in"
,
$user_phone
)
;
$param
[
"user_phone"
]
=
[
"in"
,
$user_phone
]
;
$userResult
=
$this
->
userModel
->
getUserByWhere
(
$param
,
$fields
);
foreach
(
$userResult
as
$v
)
{
...
...
@@ -325,7 +344,6 @@ class ChatService
}
/**
* 建立聊天关系
* @param $target
...
...
@@ -355,12 +373,13 @@ class ChatService
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getRelationList
(
$target
){
public
function
getRelationList
(
$target
)
{
$chatRelationModel
=
new
ChatRelation
();
$params
[
"target"
]
=
$target
;
$params
[
"from"
]
=
$target
;
$field
=
"id,to_id,from_id,create_time"
;
return
$chatRelationModel
->
getChatRelation
(
$params
,
$field
);
return
$chatRelationModel
->
getChatRelation
(
$params
,
$field
);
}
/**
...
...
application/model/ChatUserExt.php
View file @
7868a31c
...
...
@@ -52,11 +52,18 @@ class ChatUserExt extends BaseModel
* @param $params
* @return false|int
*/
public
function
addChatUserExt
(
$params
)
public
function
addChatUserExt
(
$params
,
$v
,
$k
=
'id'
)
{
Db
::
startTrans
();
try
{
$res
=
$this
->
save
(
$params
);
$data
=
$this
->
chatUserExtBin
(
$params
);
if
(
$v
)
{
$this
->
db
->
where
(
$k
,
$v
)
->
update
(
$data
);
$res
=
$v
;
}
else
{
$res
=
$this
->
db
->
insertGetId
(
$data
);
}
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
...
...
@@ -70,40 +77,33 @@ class ChatUserExt extends BaseModel
* @param $params
* @return array
*/
private
function
wxInfo
Bin
(
$params
)
private
function
chatUserExt
Bin
(
$params
)
{
$arr
=
[];
$arr
ay
=
[];
if
(
isset
(
$params
[
"id"
]))
{
$arr
[
"id"
]
=
$params
[
"id"
];
$arr
ay
[
"id"
]
=
$params
[
"id"
];
}
else
{
$arr
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
}
if
(
isset
(
$params
[
"wx_open_id"
]))
{
$arr
[
"wx_open_id"
]
=
$params
[
"wx_open_id"
];
}
if
(
isset
(
$params
[
"wx_union_id"
]))
{
$arr
[
"wx_union_id"
]
=
$params
[
"wx_union_id"
];
}
if
(
isset
(
$params
[
"buyer_nick"
]))
{
$arr
[
"buyer_nick"
]
=
$params
[
"buyer_nick"
];
$array
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
}
if
(
isset
(
$params
[
"buyer_img"
]))
{
$arr
[
"buyer_img"
]
=
$params
[
"buyer_img"
];
}
if
(
isset
(
$params
[
"sex"
]))
{
$arr
[
"sex"
]
=
$params
[
"sex"
];
if
(
isset
(
$params
[
"ext_id"
]))
{
$array
[
"ext_id"
]
=
$params
[
"ext_id"
];
}
if
(
isset
(
$params
[
"province"
]))
{
$arr
[
"province"
]
=
$params
[
"province"
];
if
(
isset
(
$params
[
"device_id"
]))
{
$array
[
"device_id"
]
=
$params
[
"device_id"
];
}
if
(
isset
(
$params
[
"city"
]))
{
$arr
[
"city"
]
=
$params
[
"city"
];
if
(
isset
(
$params
[
"push_id"
]))
{
$array
[
"push_id"
]
=
$params
[
"push_id"
];
}
if
(
isset
(
$params
[
"source"
]))
{
$arr
[
"source"
]
=
$params
[
"source"
];
if
(
isset
(
$params
[
"is_forbidden"
]))
{
$array
[
"is_forbidden"
]
=
$params
[
"is_forbidden"
];
}
$arr
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$arr
;
$array
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$array
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment