diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index 4d23710..3354e88 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -75,6 +75,9 @@ class UserService $k = '%' . $p['keyword'] . '%'; $config['where']['name'] = ['like', $k]; } + if (isset($p['status']) && $p['status']) { + $config['where']['status'] = $p['status']; + } if (isset($p['user_id']) && $p['user_id']) { $config['where']['user_id'] = $p['user_id']; } diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index f391abd..3d03c9e 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -50,6 +50,7 @@ class CustomerController extends BaseController : null); foreach ($data['records'] as &$item) { $item = $this->service->getCustomer($item); + $item = Util::formatDate($item,['created_at','updated_at']); } return $this->success($data); } catch (\Throwable $e) { @@ -162,7 +163,7 @@ class CustomerController extends BaseController $perPage = $request->input('size', 10); $where = [ ['user_id', '=', $userId], - ['corp_abbr', '=', $request->basic_data['corp_abbr']], +// ['corp_abbr', '=', $request->basic_data['corp_abbr']], ['follow_next', '<>', 0], ]; @@ -329,6 +330,7 @@ class CustomerController extends BaseController 'address' => Util::getParam($request, 'address', ''), 'sex' => Util::getParam($request, 'sex', 0), 'obtain' => time(), + 'company' => Util::getParam($request, 'company', 0), ]; if (Util::isEmpty($id)) { diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index b7654f0..a3559d5 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -10,12 +10,16 @@ use app\crm\logic\CustomerLogic; use app\crm\model\Channel; use app\crm\model\Country; use app\crm\model\Customer; +use app\crm\model\Tag; use app\crm\model\CustomerHis; use app\crm\model\Follow; use app\crm\utils\Util; use config\constants\Constants; use support\Request; +/** + * @method mixed complexQuery(array $params) + */ class CustomerService { @@ -37,6 +41,8 @@ class CustomerService $follow = $params['follow'] ?? ''; $follow_last = $params['follow_last'] ?? ''; $tagId = $params['tag_id'] ?? []; + $sort = $params['sort'] ?? null; + $sortId = $params['sort_id'] ?? null; $countryId = $params['country_id'] ?? ''; $where = []; $user_id =$params['user_id']; @@ -72,7 +78,7 @@ class CustomerService $where[] = ['follow_last', '>', strtotime('-7 day')]; } - $query = Customer::where($where); + $query = Customer::select('crm_customer.*')->where($where); if(!empty($tagId)){ //查询有$tagId 里任意一个标签的客户 @@ -115,7 +121,33 @@ class CustomerService $query->withTrashed(); } - $customer = $query->orderBy('id','desc')->paginate($perPage, ['*'], 'page', $page); + if ($sort == 'tag_group') { + // 排序:按关联的 crm_tag.sort 最小值升序,其次按客户ID倒序 + $minSortSub = Tag::selectRaw('MIN(crm_tag.sort) AS min_sort, crm_customer_tag.customer_id') + ->join('crm_customer_tag', 'crm_customer_tag.tag_id', '=', 'crm_tag.id') + ->whereNull('crm_tag.deleted_at') + ->when(!empty($sortId), function ($q) use ($sortId) { + $q->where('crm_tag.group_id', $sortId); + }) + ->groupBy('crm_customer_tag.customer_id'); + + $query->leftJoinSub($minSortSub, 'tag_min', function ($join) { + $join->on('crm_customer.id', '=', 'tag_min.customer_id'); + }); + + $query = $query->orderByRaw('tag_min.min_sort IS NULL') + ->orderBy('tag_min.min_sort', 'asc') + ->orderBy('crm_customer.id', 'desc'); + }elseif ($sort == 'follow_last') { + $query = $query->orderBy('crm_customer.follow_last', 'desc'); + }elseif ($sort == 'follow_next') { + $query = $query->orderByRaw('crm_customer.follow_next IS NULL, crm_customer.follow_next ASC'); + }elseif ($sort == 'id' || empty($sort)) { + $query = $query->orderBy('crm_customer.id', 'desc'); + } + + $customer = $query->paginate($perPage, ['*'], 'page', $page); + foreach ($customer as &$item) { $item = $this->getCustomer($item); if($seas == 'seas'){ @@ -256,7 +288,7 @@ class CustomerService // $customer['created_at'] = Util::timeTotDate($customer['created_at']); // $customer['updated_at'] = Util::timeTotDate($customer['updated_at']); - $customer = Util::formatDate($customer,['follow_last']); + $customer = Util::formatDate($customer,['follow_next','follow_last']); $nameLang = $language=='en'?'name_en':($language=='ru'?'name_ru':'name'); $countryLang = $language=='en'?'en_addr':'cn_addr'; // $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang); @@ -281,7 +313,7 @@ class CustomerService public function detail($params) { $id =$params['id']; - $customer = 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') + $customer = 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', 'company') ->where('id', $id) ->first(); diff --git a/app/crm/utils/Util.php b/app/crm/utils/Util.php index e6ac4d0..586ee45 100644 --- a/app/crm/utils/Util.php +++ b/app/crm/utils/Util.php @@ -100,7 +100,13 @@ class Util public static function formatDate($value,$key = ['created_at','updated_at']) { foreach ($key as $k){ - $value[$k]= self::timeTotDate($value[$k]); + // 如果是整数,可能是 UNIX 时间戳 + if (is_numeric($value[$k]) && $value[$k] > 0) { + // 检查是否是合理的时间戳范围(1970-2100年) + if ($value[$k] >= 0 && $value[$k] <= 4102444800) { + $value[$k]= self::timeTotDate($value[$k]); + } + } } return $value; } diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index a3ee935..038a5e0 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -135,7 +135,6 @@ class CustomerService foreach ($customer as &$item) { $item = $this->getCustomer($item); $item['desc_collect'] = $item['desc_collect'] ?? ''; - $item['follow_next'] = empty($item['follow_next'])?'':date('Y-m-d H:i:s', $item['follow_next']); if ($seas == 'seas' || $scene == 'seas') { $item['seas_time'] = time() - (empty($item['deleted_at'])?strtotime($item['updated_at']):strtotime($item['deleted_at'])); } @@ -427,7 +426,7 @@ class CustomerService // $customer['created_at'] = Util::timeTotDate($customer['created_at']); // $customer['updated_at'] = Util::timeTotDate($customer['updated_at']); - $customer = Util::formatDate($customer, ['follow_last']); + $customer = Util::formatDate($customer, ['follow_next','follow_last']); $nameLang = $language == 'en' ? 'name_en' : ($language == 'ru' ? 'name_ru' : 'name'); $countryLang = $language == 'en' ? 'en_addr' : 'cn_addr'; // $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang); diff --git a/app/ticket/model/Conversation.php b/app/ticket/model/Conversation.php index f275f2b..641ff35 100644 --- a/app/ticket/model/Conversation.php +++ b/app/ticket/model/Conversation.php @@ -20,11 +20,7 @@ class Conversation extends Model protected $primaryKey = 'id'; public $timestamps = true; protected $dateFormat = 'U'; - protected $dates = ['created_at', 'updated_at']; - protected $casts = [ - 'updated_at' => 'datetime:Y-m-d H:i:s', - 'created_at' => 'datetime:Y-m-d H:i:s', - ]; + protected $fillable = [ 'ticket_id', 'user_id', diff --git a/app/ticket/model/Ticket.php b/app/ticket/model/Ticket.php index cf71b2a..d1bbe9e 100644 --- a/app/ticket/model/Ticket.php +++ b/app/ticket/model/Ticket.php @@ -47,16 +47,34 @@ class Ticket extends Model * * @var bool */ - public $timestamps = true; + public $timestamps = false; protected $dateFormat = 'U'; - protected $dates = ['created_at', 'updated_at']; + /** + * 在保存时手动设置时间戳 + */ + protected static function boot() + { + parent::boot(); - protected $casts = [ - 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式 - 'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式 - ]; + static::creating(function ($model) { + $model->created_at = time(); + $model->updated_at = time(); + }); + + static::updating(function ($model) { + $model->updated_at = time(); + }); + } + + /** + * 指定哪些字段自动转换为 Carbon 实例 + */ + public function getDates() + { + return []; + } protected $fillable = [ 'code', diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index e80704a..ea97cef 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -35,6 +35,8 @@ class ConversationService $user = User::where('id', $value['user_id'])->first(); $value['user_name'] = $user?->name; $value['user_avatar'] = $user?->avatar; + $value['created_at'] = date('Y-m-d H:i:s', strtotime($value['created_at'])); + $value['updated_at'] = date('Y-m-d H:i:s', strtotime($value['updated_at'])); $result[$key] = $value; } return $result; @@ -60,7 +62,8 @@ class ConversationService 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - $emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤 + //$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱 + $emailDefault = env('TICKET_EMAIL_DEFAULT'); if (empty($conversation)) { $email = $emailDefault; }else{ @@ -84,7 +87,9 @@ class ConversationService $notice['reply'] = '