Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
朱继来
/
后台订单管理
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
aecbf32a
authored
Oct 20, 2021
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调整
parent
6fbcddcf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
166 additions
and
165 deletions
app/Model/KefuModel.php
app/Model/KefuModel.php
View file @
aecbf32a
<?php
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Request
;
use
Excel
;
use
DB
;
class
KefuModel
extends
Model
{
protected
$connection
=
'
order'
;
protected
$table
=
'lie_kefu'
;
protected
$primaryKey
=
'id'
;
protected
$guarded
=
[
'id'
];
public
$timestamps
=
true
;
const
CREATED_AT
=
'create_time'
;
const
UPDATED_AT
=
'update_time'
;
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public
function
fromDateTime
(
$value
)
{
return
strtotime
(
parent
::
fromDateTime
(
$value
));
}
// 获取客服
public
function
lists
(
$request
,
$export
=
''
)
{
$page
=
$request
->
input
(
'page'
,
1
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$field
=
[
'id'
,
'sale_id'
,
'sale_name'
,
'email'
,
'status'
,
'operator_id'
,
'operator_name'
,
'create_time'
,
'update_time'
];
$map
[
'sale_name'
]
=
$request
->
input
(
'sale_name'
,
''
);
// 客服名称
$map
[
'email'
]
=
$request
->
input
(
'email'
,
''
);
// 邮箱
$map
[
'begin_time'
]
=
$request
->
input
(
'begin_time'
,
''
)
?
strtotime
(
$request
->
input
(
'begin_time'
))
:
''
;
$map
[
'end_time'
]
=
$request
->
input
(
'end_time'
,
''
)
?
strtotime
(
$request
->
input
(
'end_time'
))
+
86399
:
''
;
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
// 客服名称
if
(
$map
[
'sale_name'
])
{
$query
->
where
(
'sale_name'
,
'like'
,
$map
[
'sale_name'
]
.
'%'
);
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 邮箱
if
(
$map
[
'email'
])
{
$query
->
where
(
'email'
,
'='
,
$map
[
'email'
]);
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 创建时间
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
}
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
}
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
}
})
->
select
(
$field
)
->
orderBy
(
'status'
,
'desc'
)
->
orderBy
(
'id'
,
'asc'
);
if
(
$export
)
{
$list
=
$list
->
get
()
->
toArray
();
if
(
empty
(
$list
))
{
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
}
return
$list
;
}
else
{
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
}
}
// 新增客服
public
function
add
(
$request
)
{
$email
=
$request
->
input
(
'email'
);
$CmsModel
=
new
CmsModel
;
$sales
=
$CmsModel
->
where
(
'email'
,
$email
)
->
select
(
'userId'
,
'name'
,
'status'
)
->
first
();
if
(
!
$sales
)
return
[
1
,
'客服邮箱不存在'
];
if
(
$sales
->
status
==
4
)
return
[
1
,
'客服已离职'
];
$exists
=
$this
->
where
(
'email'
,
$email
)
->
first
();
if
(
$exists
)
return
[
1
,
'客服已存在'
];
$sale_id
=
$sales
->
userId
;
$data
=
[];
$data
[
'sale_name'
]
=
$sales
->
name
;
$data
[
'email'
]
=
$email
;
$data
[
'operator_id'
]
=
$request
->
user
->
userId
;
$data
[
'operator_name'
]
=
$request
->
user
->
name
;
$count
=
$this
->
count
();
// 客服池数量
if
(
!
$count
)
$data
[
'status'
]
=
1
;
// 待分配
$res
=
$this
->
updateOrCreate
([
'sale_id'
=>
$sale_id
],
$data
);
if
(
$res
===
false
)
return
[
1
,
'新增客服失败'
];
return
[
0
,
'新增客服成功'
];
}
// 编辑客服
public
function
edit
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
$email
=
$request
->
input
(
'email'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'email'
=>
$email
]);
if
(
$res
===
false
)
return
[
1
,
'更新客服失败'
];
return
[
0
,
'更新客服成功'
];
}
// 删除客服
public
function
del
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
$status
=
$request
->
input
(
'status'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
if
(
$res
===
false
)
return
[
1
,
'删除客服失败'
];
if
(
$status
==
1
)
{
$first
=
$this
->
select
(
'id'
)
->
orderBy
(
'id'
,
'asc'
)
->
first
();
$res
=
$this
->
where
(
'id'
,
$first
[
'id'
])
->
update
([
'status'
=>
1
]);
if
(
$res
===
false
)
return
[
1
,
'更新第一条客服状态失败'
];
}
return
[
0
,
'删除客服成功'
];
}
// 置顶客服
public
function
top
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
try
{
DB
::
connection
(
'order'
)
->
beginTransaction
();
// 开启事务
DB
::
connection
(
'order'
)
->
update
(
'UPDATE lie_kefu SET status = 0'
);
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
1
]);
DB
::
connection
(
'order'
)
->
commit
();
return
[
0
,
'置顶客服成功'
];
}
catch
(
Exception
$e
)
{
DB
::
connection
(
'order'
)
->
rollback
();
return
[
1
,
'置顶客服失败,'
.
$e
->
getMessage
()];
}
}
<?php
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Request
;
use
Excel
;
use
DB
;
class
KefuModel
extends
Model
{
protected
$connection
=
'
web'
;
protected
$table
=
'lie_kefu'
;
protected
$primaryKey
=
'id'
;
protected
$guarded
=
[
'id'
];
public
$timestamps
=
true
;
const
CREATED_AT
=
'create_time'
;
const
UPDATED_AT
=
'update_time'
;
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public
function
fromDateTime
(
$value
)
{
return
strtotime
(
parent
::
fromDateTime
(
$value
));
}
// 获取客服
public
function
lists
(
$request
,
$export
=
''
)
{
$page
=
$request
->
input
(
'page'
,
1
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$field
=
[
'id'
,
'sale_id'
,
'sale_name'
,
'email'
,
'status'
,
'operator_id'
,
'operator_name'
,
'create_time'
,
'update_time'
];
$map
[
'sale_name'
]
=
$request
->
input
(
'sale_name'
,
''
);
// 客服名称
$map
[
'email'
]
=
$request
->
input
(
'email'
,
''
);
// 邮箱
$map
[
'begin_time'
]
=
$request
->
input
(
'begin_time'
,
''
)
?
strtotime
(
$request
->
input
(
'begin_time'
))
:
''
;
$map
[
'end_time'
]
=
$request
->
input
(
'end_time'
,
''
)
?
strtotime
(
$request
->
input
(
'end_time'
))
+
86399
:
''
;
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
// 客服名称
if
(
$map
[
'sale_name'
])
{
$query
->
where
(
'sale_name'
,
'like'
,
$map
[
'sale_name'
]
.
'%'
);
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 邮箱
if
(
$map
[
'email'
])
{
$query
->
where
(
'email'
,
'='
,
$map
[
'email'
]);
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 创建时间
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
}
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
}
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
}
})
->
select
(
$field
)
->
orderBy
(
'status'
,
'desc'
)
->
orderBy
(
'id'
,
'asc'
);
if
(
$export
)
{
$list
=
$list
->
get
()
->
toArray
();
if
(
empty
(
$list
))
{
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
}
return
$list
;
}
else
{
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
}
}
// 新增客服
public
function
add
(
$request
)
{
$email
=
$request
->
input
(
'email'
);
$CmsModel
=
new
CmsModel
;
$sales
=
$CmsModel
->
where
(
'email'
,
$email
)
->
select
(
'userId'
,
'name'
,
'status'
)
->
first
();
if
(
!
$sales
)
return
[
1
,
'客服邮箱不存在'
];
if
(
$sales
->
status
==
4
)
return
[
1
,
'客服已离职'
];
$exists
=
$this
->
where
(
'email'
,
$email
)
->
first
();
if
(
$exists
)
return
[
1
,
'客服已存在'
];
$sale_id
=
$sales
->
userId
;
$data
=
[];
$data
[
'sale_name'
]
=
$sales
->
name
;
$data
[
'email'
]
=
$email
;
$data
[
'operator_id'
]
=
$request
->
user
->
userId
;
$data
[
'operator_name'
]
=
$request
->
user
->
name
;
$count
=
$this
->
count
();
// 客服池数量
if
(
!
$count
)
$data
[
'status'
]
=
1
;
// 待分配
$res
=
$this
->
updateOrCreate
([
'sale_id'
=>
$sale_id
],
$data
);
if
(
$res
===
false
)
return
[
1
,
'新增客服失败'
];
return
[
0
,
'新增客服成功'
];
}
// 编辑客服
public
function
edit
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
$email
=
$request
->
input
(
'email'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'email'
=>
$email
]);
if
(
$res
===
false
)
return
[
1
,
'更新客服失败'
];
return
[
0
,
'更新客服成功'
];
}
// 删除客服
public
function
del
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
$status
=
$request
->
input
(
'status'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
if
(
$res
===
false
)
return
[
1
,
'删除客服失败'
];
if
(
$status
==
1
)
{
$first
=
$this
->
select
(
'id'
)
->
orderBy
(
'id'
,
'asc'
)
->
first
();
$res
=
$this
->
where
(
'id'
,
$first
[
'id'
])
->
update
([
'status'
=>
1
]);
if
(
$res
===
false
)
return
[
1
,
'更新第一条客服状态失败'
];
}
return
[
0
,
'删除客服成功'
];
}
// 置顶客服
public
function
top
(
$request
)
{
$id
=
$request
->
input
(
'id'
);
try
{
DB
::
connection
(
'order'
)
->
beginTransaction
();
// 开启事务
DB
::
connection
(
'order'
)
->
update
(
'UPDATE lie_kefu SET status = 0'
);
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
1
]);
DB
::
connection
(
'order'
)
->
commit
();
return
[
0
,
'置顶客服成功'
];
}
catch
(
Exception
$e
)
{
DB
::
connection
(
'order'
)
->
rollback
();
return
[
1
,
'置顶客服失败,'
.
$e
->
getMessage
()];
}
}
}
\ 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