diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index da39f6e..179aa41 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -167,7 +167,7 @@ class CustomerController $data = $query->paginate($perPage, ['*'], 'page', $page); foreach ($data->items() as &$value) { - $value = Customer::getCustomer($value); + $value = Customer::getCustomer($value, $request); } return Util::page($data); @@ -219,7 +219,7 @@ class CustomerController return Util::fail([], '记录不存在'); } - $res = Customer::getCustomer($res,$request); + $res = Customer::getCustomer($res, $request, true); return Util::success($res); } diff --git a/app/model/Customer.php b/app/model/Customer.php index 54cf548..86adea5 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -59,11 +59,18 @@ class Customer extends Model return $date->format(Carbon::parse($date)->toDateTimeString()); } - public static function getCustomer($customer,$request = null) + /** + * @param $customer + * @param $request + * @param $tag 是否返回客户标签 + * @return mixed + */ + public static function getCustomer($customer, $request, $tag = false) { $customer['grade_txt'] = Constants::GRADE[$customer['grade']]; $customer['magnitude_txt'] = Constants::MAGNITUDE[$customer['magnitude']]; $customer['sex_txt'] = Constants::SEX[$customer['sex']]; + $language = $request->user['language'] ?: 'en'; if ($customer['grade']<=2) { $customer['follow'] = 0; @@ -94,8 +101,7 @@ class Customer extends Model $customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value('name'); // $customer['last_follow'] = $last_follow; - if (!empty($request)) { - $language = $request->user['language'] ?: 'en'; + if ($tag) { foreach ($customer['tags'] as &$tag) { $tag['names'] = unserialize($tag['names']); $tag['name'] = $tag['names'][$language];