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
<?php
namespace
App\Model
;
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Request
;
use
Request
;
use
Excel
;
use
Excel
;
use
DB
;
use
DB
;
class
KefuModel
extends
Model
class
KefuModel
extends
Model
{
{
protected
$connection
=
'
order'
;
protected
$connection
=
'
web'
;
protected
$table
=
'lie_kefu'
;
protected
$table
=
'lie_kefu'
;
protected
$primaryKey
=
'id'
;
protected
$primaryKey
=
'id'
;
protected
$guarded
=
[
'id'
];
protected
$guarded
=
[
'id'
];
public
$timestamps
=
true
;
public
$timestamps
=
true
;
const
CREATED_AT
=
'create_time'
;
const
CREATED_AT
=
'create_time'
;
const
UPDATED_AT
=
'update_time'
;
const
UPDATED_AT
=
'update_time'
;
/** * @param \DateTime|int $value * @return false|int * @author dividez */
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public
function
fromDateTime
(
$value
)
public
function
fromDateTime
(
$value
)
{
{
return
strtotime
(
parent
::
fromDateTime
(
$value
));
return
strtotime
(
parent
::
fromDateTime
(
$value
));
}
}
// 获取客服
// 获取客服
public
function
lists
(
$request
,
$export
=
''
)
public
function
lists
(
$request
,
$export
=
''
)
{
{
$page
=
$request
->
input
(
'page'
,
1
);
$page
=
$request
->
input
(
'page'
,
1
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$field
=
[
'id'
,
'sale_id'
,
'sale_name'
,
'email'
,
'status'
,
'operator_id'
,
'operator_name'
,
'create_time'
,
'update_time'
];
$field
=
[
'id'
,
'sale_id'
,
'sale_name'
,
'email'
,
'status'
,
'operator_id'
,
'operator_name'
,
'create_time'
,
'update_time'
];
$map
[
'sale_name'
]
=
$request
->
input
(
'sale_name'
,
''
);
// 客服名称
$map
[
'sale_name'
]
=
$request
->
input
(
'sale_name'
,
''
);
// 客服名称
$map
[
'email'
]
=
$request
->
input
(
'email'
,
''
);
// 邮箱
$map
[
'email'
]
=
$request
->
input
(
'email'
,
''
);
// 邮箱
$map
[
'begin_time'
]
=
$request
->
input
(
'begin_time'
,
''
)
?
strtotime
(
$request
->
input
(
'begin_time'
))
:
''
;
$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
:
''
;
$map
[
'end_time'
]
=
$request
->
input
(
'end_time'
,
''
)
?
strtotime
(
$request
->
input
(
'end_time'
))
+
86399
:
''
;
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
// 客服名称
// 客服名称
if
(
$map
[
'sale_name'
])
{
if
(
$map
[
'sale_name'
])
{
$query
->
where
(
'sale_name'
,
'like'
,
$map
[
'sale_name'
]
.
'%'
);
$query
->
where
(
'sale_name'
,
'like'
,
$map
[
'sale_name'
]
.
'%'
);
}
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 邮箱
// 邮箱
if
(
$map
[
'email'
])
{
if
(
$map
[
'email'
])
{
$query
->
where
(
'email'
,
'='
,
$map
[
'email'
]);
$query
->
where
(
'email'
,
'='
,
$map
[
'email'
]);
}
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 创建时间
// 创建时间
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
}
}
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
}
}
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
}
}
})
})
->
select
(
$field
)
->
select
(
$field
)
->
orderBy
(
'status'
,
'desc'
)
->
orderBy
(
'status'
,
'desc'
)
->
orderBy
(
'id'
,
'asc'
);
->
orderBy
(
'id'
,
'asc'
);
if
(
$export
)
{
if
(
$export
)
{
$list
=
$list
->
get
()
->
toArray
();
$list
=
$list
->
get
()
->
toArray
();
if
(
empty
(
$list
))
{
if
(
empty
(
$list
))
{
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
}
}
return
$list
;
return
$list
;
}
else
{
}
else
{
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
}
}
}
}
// 新增客服
// 新增客服
public
function
add
(
$request
)
public
function
add
(
$request
)
{
{
$email
=
$request
->
input
(
'email'
);
$email
=
$request
->
input
(
'email'
);
$CmsModel
=
new
CmsModel
;
$CmsModel
=
new
CmsModel
;
$sales
=
$CmsModel
->
where
(
'email'
,
$email
)
->
select
(
'userId'
,
'name'
,
'status'
)
->
first
();
$sales
=
$CmsModel
->
where
(
'email'
,
$email
)
->
select
(
'userId'
,
'name'
,
'status'
)
->
first
();
if
(
!
$sales
)
return
[
1
,
'客服邮箱不存在'
];
if
(
!
$sales
)
return
[
1
,
'客服邮箱不存在'
];
if
(
$sales
->
status
==
4
)
return
[
1
,
'客服已离职'
];
if
(
$sales
->
status
==
4
)
return
[
1
,
'客服已离职'
];
$exists
=
$this
->
where
(
'email'
,
$email
)
->
first
();
$exists
=
$this
->
where
(
'email'
,
$email
)
->
first
();
if
(
$exists
)
return
[
1
,
'客服已存在'
];
if
(
$exists
)
return
[
1
,
'客服已存在'
];
$sale_id
=
$sales
->
userId
;
$sale_id
=
$sales
->
userId
;
$data
=
[];
$data
=
[];
$data
[
'sale_name'
]
=
$sales
->
name
;
$data
[
'sale_name'
]
=
$sales
->
name
;
$data
[
'email'
]
=
$email
;
$data
[
'email'
]
=
$email
;
$data
[
'operator_id'
]
=
$request
->
user
->
userId
;
$data
[
'operator_id'
]
=
$request
->
user
->
userId
;
$data
[
'operator_name'
]
=
$request
->
user
->
name
;
$data
[
'operator_name'
]
=
$request
->
user
->
name
;
$count
=
$this
->
count
();
// 客服池数量
$count
=
$this
->
count
();
// 客服池数量
if
(
!
$count
)
$data
[
'status'
]
=
1
;
// 待分配
if
(
!
$count
)
$data
[
'status'
]
=
1
;
// 待分配
$res
=
$this
->
updateOrCreate
([
'sale_id'
=>
$sale_id
],
$data
);
$res
=
$this
->
updateOrCreate
([
'sale_id'
=>
$sale_id
],
$data
);
if
(
$res
===
false
)
return
[
1
,
'新增客服失败'
];
if
(
$res
===
false
)
return
[
1
,
'新增客服失败'
];
return
[
0
,
'新增客服成功'
];
return
[
0
,
'新增客服成功'
];
}
}
// 编辑客服
// 编辑客服
public
function
edit
(
$request
)
public
function
edit
(
$request
)
{
{
$id
=
$request
->
input
(
'id'
);
$id
=
$request
->
input
(
'id'
);
$email
=
$request
->
input
(
'email'
);
$email
=
$request
->
input
(
'email'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'email'
=>
$email
]);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'email'
=>
$email
]);
if
(
$res
===
false
)
return
[
1
,
'更新客服失败'
];
if
(
$res
===
false
)
return
[
1
,
'更新客服失败'
];
return
[
0
,
'更新客服成功'
];
return
[
0
,
'更新客服成功'
];
}
}
// 删除客服
// 删除客服
public
function
del
(
$request
)
public
function
del
(
$request
)
{
{
$id
=
$request
->
input
(
'id'
);
$id
=
$request
->
input
(
'id'
);
$status
=
$request
->
input
(
'status'
);
$status
=
$request
->
input
(
'status'
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
if
(
$res
===
false
)
return
[
1
,
'删除客服失败'
];
if
(
$res
===
false
)
return
[
1
,
'删除客服失败'
];
if
(
$status
==
1
)
{
if
(
$status
==
1
)
{
$first
=
$this
->
select
(
'id'
)
->
orderBy
(
'id'
,
'asc'
)
->
first
();
$first
=
$this
->
select
(
'id'
)
->
orderBy
(
'id'
,
'asc'
)
->
first
();
$res
=
$this
->
where
(
'id'
,
$first
[
'id'
])
->
update
([
'status'
=>
1
]);
$res
=
$this
->
where
(
'id'
,
$first
[
'id'
])
->
update
([
'status'
=>
1
]);
if
(
$res
===
false
)
return
[
1
,
'更新第一条客服状态失败'
];
if
(
$res
===
false
)
return
[
1
,
'更新第一条客服状态失败'
];
}
}
return
[
0
,
'删除客服成功'
];
return
[
0
,
'删除客服成功'
];
}
}
// 置顶客服
// 置顶客服
public
function
top
(
$request
)
public
function
top
(
$request
)
{
{
$id
=
$request
->
input
(
'id'
);
$id
=
$request
->
input
(
'id'
);
try
{
try
{
DB
::
connection
(
'order'
)
->
beginTransaction
();
// 开启事务
DB
::
connection
(
'order'
)
->
beginTransaction
();
// 开启事务
DB
::
connection
(
'order'
)
->
update
(
'UPDATE lie_kefu SET status = 0'
);
DB
::
connection
(
'order'
)
->
update
(
'UPDATE lie_kefu SET status = 0'
);
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
1
]);
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
1
]);
DB
::
connection
(
'order'
)
->
commit
();
DB
::
connection
(
'order'
)
->
commit
();
return
[
0
,
'置顶客服成功'
];
return
[
0
,
'置顶客服成功'
];
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
DB
::
connection
(
'order'
)
->
rollback
();
DB
::
connection
(
'order'
)
->
rollback
();
return
[
1
,
'置顶客服失败,'
.
$e
->
getMessage
()];
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