标签关系
This commit is contained in:
@@ -144,8 +144,8 @@ class CustomerController
|
||||
}
|
||||
|
||||
|
||||
// 执行分页查询
|
||||
$query = Customer::where($where)
|
||||
// 执行分页查询 //关联标签tags //关联标签及分组tags.group
|
||||
$query = Customer::with('tags')->where($where)
|
||||
->orderBy('id', 'desc');
|
||||
if (!Util::isEmpty($keyword)) {
|
||||
$query->where(function ($query) use ($keyword) {
|
||||
@@ -210,7 +210,7 @@ class CustomerController
|
||||
return Util::fail([], 'id' . trans('not_null'));
|
||||
}
|
||||
|
||||
$res = Customer::select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex')
|
||||
$res = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex')
|
||||
->where('id', $id)
|
||||
->first();
|
||||
if ($res) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\CustomerTag;
|
||||
use app\model\TagGroup;
|
||||
use app\util\Util;
|
||||
use support\Request;
|
||||
@@ -17,12 +18,12 @@ class TagGroupController
|
||||
$language = $request->user['language'];
|
||||
foreach ($list as &$item) {
|
||||
$item['names'] = unserialize($item['names']);
|
||||
if(in_array($language, $languageArr)){
|
||||
if (in_array($language, $languageArr)) {
|
||||
$item['name'] = $item['names'][$language];
|
||||
}
|
||||
foreach ($item['tags'] as &$tag) {
|
||||
$tag['names'] = unserialize($tag['names']);
|
||||
if(in_array($language, $languageArr)){
|
||||
if (in_array($language, $languageArr)) {
|
||||
$item['name'] = $item['names'][$language];
|
||||
}
|
||||
}
|
||||
@@ -30,4 +31,35 @@ class TagGroupController
|
||||
|
||||
return Util::success($list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新客户标签关系
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function updatePivot(Request $request)
|
||||
{
|
||||
$customerId = Util::getParam($request, 'customer_id');
|
||||
$groupId = Util::getParam($request, 'group_id');
|
||||
$tagId = Util::getParam($request, 'tag_id');
|
||||
if (Util::isEmpty($customerId)) {
|
||||
return Util::fail([], trans('customer_id') . trans('not_null'));
|
||||
}
|
||||
if (Util::isEmpty($groupId)) {
|
||||
return Util::fail([], trans('tag_group_id') . trans('not_null'));
|
||||
}
|
||||
|
||||
if(empty($tagId)){
|
||||
$res = CustomerTag::where(['customer_id' => $customerId, 'group_id' => $groupId])->delete();
|
||||
}else{
|
||||
$res = CustomerTag::updateOrCreate(['customer_id' => $customerId, 'group_id' => $groupId], ['tag_id' => $tagId]);
|
||||
}
|
||||
|
||||
if($res){
|
||||
return Util::success($res, trans('success'));
|
||||
}else{
|
||||
return Util::fail($res, trans('fail'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user