Merge branch 'develop' into feature/mzl_dev

This commit is contained in:
mzl
2025-09-18 15:04:59 +08:00
23 changed files with 933 additions and 6 deletions
+46
View File
@@ -3,6 +3,7 @@
namespace app\admin\service; namespace app\admin\service;
use app\admin\validate\BrandSeriesValidate; use app\admin\validate\BrandSeriesValidate;
use app\common\model\Brand;
use app\common\traits\crud\CrudServiceTrait; use app\common\traits\crud\CrudServiceTrait;
use app\common\model\BrandSeries; use app\common\model\BrandSeries;
use support\Request; use support\Request;
@@ -77,4 +78,49 @@ class BrandSeriesService
return $config; return $config;
} }
/**
* 生成唯一的7位颜色编码
* 格式:C + (O/I) + 5位字母数字组合
*
* @param int $type 类型
* @return string 7位唯一编码
*/
public function generateUniqueModificationCode($brand_id)
{
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$maxAttempts = 10; // 防止无限循环
$brand_code = Brand::where('id', $brand_id)->value('brand_code');
$brand_code = $brand_code??'BS';
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
// 生成后5位随机字符
$suffix = '';
for ($i = 0; $i < 6; $i++) {
$suffix .= $chars[rand(0, strlen($chars) - 1)];
}
$code = $brand_code . $suffix;
// 检查是否已存在
$existing = BrandSeries::where('series_code', $code)->first();
if (!$existing) {
return $code;
}
}
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
$timestamp = substr(time(), -6);
return $brand_code . $timestamp;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$brand_id = $data['brand_id'] ?? 0;
$data['series_code'] = $this->generateUniqueModificationCode($brand_id);
return $data;
}
} }
+1
View File
@@ -43,6 +43,7 @@ class BrandService
switch ($scene) { switch ($scene) {
case 'index': case 'index':
// ====== ====== 排序 ====== ====== // ====== ====== 排序 ====== ======
$config['order']['hot'] = 'desc';
$config['order']['sort'] = 'desc'; $config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc'; $config['order']['id'] = 'desc';
@@ -0,0 +1,45 @@
<?php
namespace app\admin\targets\controller;
use app\common\controller\BaseController;
use app\common\model\Corp;
use app\common\model\User;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\targets\service\SalesAnnualTargetsService;
class SalesAnnualTargetsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SalesAnnualTargetsService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['corp_id'])){
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
// $data['corp_name'] = $data['corp_name']??'合塑集团';
}
if (isset($data['user_id']))
$data['user_name'] = User::where('id', $data['user_id'])->value('name');
if (empty($data['corp_id']) || empty($data['user_id'])){
$data['user_name'] = '合塑集团';
}
return $data;
}
}
@@ -0,0 +1,40 @@
<?php
namespace app\admin\targets\controller;
use app\common\controller\BaseController;
use app\common\model\Corp;
use app\common\model\User;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\targets\service\SalesMonthlyTargetsService;
class SalesMonthlyTargetsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SalesMonthlyTargetsService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['corp_id']))
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
if (isset($data['user_id']))
$data['user_name'] = User::where('id', $data['user_id'])->value('name');
return $data;
}
}
@@ -0,0 +1,156 @@
<?php
namespace app\admin\targets\controller;
use app\admin\targets\service\SalesAnnualTargetsService;
use app\common\controller\BaseController;
use app\common\model\Corp;
use app\common\model\SalesAnnualTargets;
use app\common\model\SalesMonthlyTargets;
use app\common\model\User;
use app\common\traits\crud\CrudControllerTrait;
use support\Request;
use support\Db;
class StatisticsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SalesAnnualTargetsService();
}
public function total(Request $request)
{
$param = $request->all();
if (empty($param['year'])) {
return $this->error('year不能为空');
}
$data = SalesAnnualTargets::select('annual_target','corp_id')
->whereNull('user_id')
->where('year',$param['year'])
->orderBy('corp_id')
->get()
->toArray();
foreach ($data as &$value) {
$where = [];
$where[] = ['year', '=', $param['year']];
if (!empty($value['corp_id'])) {
$where[] = ['corp_id', '=', $value['corp_id']];
}
$value['achieved'] = SalesMonthlyTargets::where($where)->sum('achieved');
$value['progress'] = empty($value['annual_target'])?'100%':number_format(($value['achieved']/$value['annual_target']*100),2) . '%';
$value['corp_name'] = empty($value['corp_id'])?'集团':Corp::where(['id' => $value['corp_id']])->value('name');
}
return $this->success($data);
}
public function ranking(Request $request){
$param = $request->all();
$year = empty($param['year']) ? date('Y') : $param['year'];
$where = [];
$where[] = ['year', '=', $year];
$ranking = SalesMonthlyTargets::select('corp_id', 'user_id', Db::raw('SUM(achieved) AS achieved'))
->where($where)
->groupBy('corp_id', 'user_id')
->orderBy('achieved', 'desc')
->get();
foreach ($ranking as $key => $value) {
$ranking[$key]['corp_name'] = Corp::where(['id' => $value['corp_id']])->value('name');
$ranking[$key]['user_name'] = User::where(['id' => $value['user_id']])->value('name');
}
return $this->success($ranking);
}
public function achievedUserByMonth(Request $request){
$param = $request->all();
$year = empty($param['year']) ? date('Y') : $param['year'];
$where = [];
$where[] = ['year', '=', $year];
$ranking = SalesMonthlyTargets::select('corp_id', 'user_id', 'month', Db::raw('SUM(achieved) AS achieved'))
->where($where)
->groupBy('corp_id', 'user_id', 'month')
->orderBy('user_id', 'asc')
->orderBy('month', 'asc')
->get();
$result = [];
foreach ($ranking as $key => $value) {
$result[$value['user_id']]['month'][$value['month']] = $value['achieved'];
$result[$value['user_id']]['user_id'] = $value['user_id'];
$result[$value['user_id']]['corp_id'] = $value['corp_id'];
}
foreach ($result as $key => $value) {
for($i = 1; $i <= 12; $i++){
$result[$key]['month'][$i] = $result[$key]['month'][$i]??0;
}
$result[$key]['month'] = array_values($result[$key]['month']);
$result[$key]['corp_name'] = Corp::where(['id' => $value['corp_id']])->value('name');
$result[$key]['user_name'] = User::where(['id' => $value['user_id']])->value('name');
}
$result = array_values($result);
return $this->success($result);
}
/**
* 个人年度目标完成度(百分比)
* @param Request $request
* @return \support\Response
*/
public function userProgressh(Request $request){
$param = $request->all();
$year = empty($param['year']) ? date('Y') : $param['year'];
$where = [];
$where[] = ['year', '=', $year];
$achieved = SalesMonthlyTargets::select('corp_id', 'user_id', Db::raw('SUM(achieved) AS achieved'))
->where($where)
->groupBy('corp_id', 'user_id')
->orderBy('achieved', 'desc')
->get()
->toArray();
$sort = [];
foreach ($achieved as $key => $value) {
$achieved[$key]['corp_name'] = Corp::where(['id' => $value['corp_id']])->value('name');
$achieved[$key]['user_name'] = User::where(['id' => $value['user_id']])->value('name');
$target = SalesAnnualTargets::where(['user_id' => $value['user_id']])->value('annual_target');
$achieved[$key]['progressh'] = empty($target) ? 0 : round(($value['achieved'] / $target) * 100, 2);
$sort[] = $achieved[$key]['progressh'];
}
array_multisort($sort, SORT_DESC, SORT_NUMERIC, $achieved);
foreach ($achieved as $key => $value) {
$achieved[$key]['progressh'] = $value['progressh'];
}
return $this->success($achieved);
}
/**
* 个人累积完成数量(辆)
* @param Request $request
* @return \support\Response
*/
public function userAchieved(Request $request){
$param = $request->all();
$year = empty($param['year']) ? date('Y') : $param['year'];
$where = [];
$where[] = ['year', '=', $year];
$achieved = SalesMonthlyTargets::select('corp_id', 'user_id', Db::raw('SUM(achieved) AS achieved'))
->where($where)
->groupBy('corp_id', 'user_id')
->orderBy('achieved', 'desc')
->get()
->toArray();
foreach ($achieved as $key => $value) {
$achieved[$key]['corp_name'] = Corp::where(['id' => $value['corp_id']])->value('name');
$achieved[$key]['user_name'] = User::where(['id' => $value['user_id']])->value('name');
$target = SalesAnnualTargets::where(['user_id' => $value['user_id']])->value('annual_target');
$achieved[$key]['annual_target'] = empty($target) ? 0 : $target;
$achieved[$key]['total'] = [intval($value['achieved']), $achieved[$key]['annual_target']];
}
return $this->success($achieved);
}
}
@@ -0,0 +1,17 @@
<?php
namespace app\admin\targets\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SalesAnnualTargets;
class SalesAnnualTargetsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SalesAnnualTargets::class;
}
@@ -0,0 +1,17 @@
<?php
namespace app\admin\targets\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SalesMonthlyTargets;
class SalesMonthlyTargetsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SalesMonthlyTargets::class;
}
@@ -0,0 +1,89 @@
<?php
namespace app\admin\targets\service;
use app\admin\targets\validate\SalesAnnualTargetsValidate;
use app\common\model\User;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SalesAnnualTargets;
use support\exception\BusinessException;
use support\Request;
class SalesAnnualTargetsService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SalesAnnualTargets::class;
/**
* 验证器
*/
protected $validator = SalesAnnualTargetsValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
if (isset($p['year']) && $p['year']) {
$config['where']['year'] = $p['year'];
}
$config['order']['id'] = 'desc';
break;
case 'show':
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
}
return $config;
}
// ====== 前置处理 ======
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
if(isset($data['user_id']) && $data['user_id'] && empty($data['corp_id'])){
$data['corp_id'] = User::where('id', $data['user_id'])->value('corp_id');
}
if(isset($data['corp_id']) && empty($data['corp_id'])){
unset($data['corp_id']);
}
if(isset($data['user_id']) && empty($data['user_id'])){
unset($data['user_id']);
}
if(isset($data['user_id']) && isset($data['user_id'])){
$annualTargets = SalesAnnualTargets::where('year',$data['year'])->where('corp_id',$data['corp_id'])->where('user_id', $data['user_id'])->first();
}else{
$annualTargets = SalesAnnualTargets::where('year',$data['year'])->whereNull('corp_id')->whereNull('user_id')->first();
}
if($annualTargets){
throw new BusinessException('目标重复添加');
}
return $data;
}
}
@@ -0,0 +1,75 @@
<?php
namespace app\admin\targets\service;
use app\admin\targets\validate\SalesMonthlyTargetsValidate;
use app\common\model\User;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SalesMonthlyTargets;
use support\Request;
class SalesMonthlyTargetsService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SalesMonthlyTargets::class;
/**
* 验证器
*/
protected $validator = SalesMonthlyTargetsValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
if (isset($p['year']) && $p['year']) {
$config['where']['year'] = $p['year'];
}
$config['order']['year'] = 'desc';
$config['order']['user_id'] = 'desc';
$config['order']['month'] = 'asc';
$config['order']['id'] = 'desc';
break;
case 'show':
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
}
return $config;
}
// ====== 前置处理 ======
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$data['corp_id'] = User::where('id', $data['user_id'])->value('corp_id');
return $data;
}
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\targets\validate;
use think\Validate;
class SalesAnnualTargetsValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\targets\validate;
use think\Validate;
class SalesMonthlyTargetsValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,47 @@
<?php
namespace app\common\controller;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\VehModificationService;
class VehModificationController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehModificationService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ class BrandLogic
public function getList() public function getList()
{ {
return Brand::where('status', 1)->orderBy('sort','desc')->get(['id', 'brand_code', 'brand_name', 'logo', 'description']); return Brand::where('status', 1)->orderBy('hot','desc')->orderBy('sort','desc')->get(['id', 'brand_code', 'brand_name', 'logo', 'description']);
} }
} }
+1 -1
View File
@@ -16,7 +16,7 @@ class SysAccountLogic
public function getList() public function getList()
{ {
return SysAccount::where('status', 1)->orderBy('sort','desc')->get(['id', 'account_name', 'currency_id', 'account_number', 'bank_name', 'bank_branch', 'description']); return SysAccount::where('status', 1)->orderBy('sort','desc')->get(['id', 'account_name', 'currency_id', 'account_number', 'bank_name', 'bank_branch', 'description', 'short_desc']);
} }
} }
+1 -1
View File
@@ -16,7 +16,7 @@ class SysPortLogic
public function getList($where) public function getList($where)
{ {
return SysPort::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'port_code', 'port_name', 'country_id', 'description']); return SysPort::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'port_code', 'port_name', 'port_name_en', 'country_id', 'description']);
} }
} }
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class SalesAnnualTargets extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sales_annual_targets';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'corp_id', 'user_id', 'year', 'annual_target', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class SalesMonthlyTargets extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sales_monthly_targets';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'corp_id', 'user_id', 'year', 'month', 'target', 'achieved', 'amount', 'currency_id', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+1 -1
View File
@@ -40,7 +40,7 @@ class SysAccount extends Model
/** /**
* 允许自动填充模型字段 * 允许自动填充模型字段
*/ */
protected $fillable = ['id', 'corp_id', 'currency_id', 'account_name', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at']; protected $fillable = ['id', 'corp_id', 'currency_id', 'account_name', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'short_desc', 'created_at', 'updated_at'];
/** /**
* 不允许自动填充模型字段 * 不允许自动填充模型字段
+1 -1
View File
@@ -40,7 +40,7 @@ class SysPort extends Model
/** /**
* 允许自动填充模型字段 * 允许自动填充模型字段
*/ */
protected $fillable = ['id', 'port_code', 'port_name', 'country_id', 'lat', 'lng', 'description', 'status', 'sort', 'created_at', 'updated_at']; protected $fillable = ['id', 'port_code', 'port_name', 'port_name_en', 'country_id', 'lat', 'lng', 'description', 'status', 'sort', 'created_at', 'updated_at'];
/** /**
* 不允许自动填充模型字段 * 不允许自动填充模型字段
+1 -1
View File
@@ -346,7 +346,7 @@ class CustomerController extends BaseController
'address' => Util::getParam($request, 'address', ''), 'address' => Util::getParam($request, 'address', ''),
'sex' => Util::getParam($request, 'sex', 0), 'sex' => Util::getParam($request, 'sex', 0),
'obtain' => time(), 'obtain' => time(),
'company' => Util::getParam($request, 'company', 0), 'company' => Util::getParam($request, 'company', ''),
]; ];
if (Util::isEmpty($id)) { if (Util::isEmpty($id)) {
+6
View File
@@ -3,6 +3,7 @@
namespace app\crm\model; namespace app\crm\model;
use app\common\model\Country;
use app\crm\utils\Util; use app\crm\utils\Util;
use config\constants\Constants; use config\constants\Constants;
use DateTimeInterface; use DateTimeInterface;
@@ -106,4 +107,9 @@ class Customer extends Model
return $this->save($options); return $this->save($options);
}); });
} }
public function countryInfo()
{
return $this->hasOne(Country::class, 'id', 'country_id');
}
} }
@@ -0,0 +1,188 @@
<?php
namespace app\crmAdmin\controller;
use app\common\controller\BaseController;
use app\common\model\Country;
use app\common\model\InquiryChannel;
use app\common\model\InquiryLog;
use app\common\traits\crud\CrudControllerTrait;
use app\crm\model\Customer;
use app\inquiry\service\CountryService;
use support\Request;
use support\Db;
use Illuminate\Support\Carbon;
class StatisticsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new CountryService();
}
public function whole()
{
$totals = Customer::count('id');
$channelCount = InquiryChannel::count('id');
$todayCount = Customer::where('created_at', '>=', strtotime(date('Y-m-d')))->count('id');
$releaseCount = Customer::distinct('enter_user_id')->count('id');
$countryCount = Country::count('id');
$trackCount = Customer::distinct('user_id')->count();
$data = [
'totals' => $totals,
'channelCount' => $channelCount,
'todayCount' => $todayCount,
'releaseCount' => $releaseCount,
'countryCount' => $countryCount,
'trackCount' => $trackCount
];
return $this->success($data);
}
// 各渠道计数
public function channelCount()
{
$inquiryChannelList = InquiryChannel::all(['id', 'name']);
$channels = [];
foreach ($inquiryChannelList as $key => $val) {
$channels[$val->id] = $val->name;
}
$list = Customer::select('channel_id', Db::raw('COUNT(*) as totals'))
->groupBy('channel_id')
->get()->toArray();
$channelCounts = [];
foreach ($list as $vo) {
$channelCounts[] = [
"name" => $channels[$vo["channel_id"]],
"value" => $vo["totals"]
];
}
return $this->success($channelCounts);
}
// 各国家计数
public function countryCount()
{
$list = Customer::with("countryInfo")
->select('country_id', Db::raw('COUNT(*) as totals'))
->where('country_id','<>',0)
->groupBy('country_id')
->get();
$arr = [];
foreach ($list as $val) {
$arr[] = [
"value" => $val->totals,
"name" => $val->countryInfo->cn_addr
];
}
return $this->success($arr);
}
// 跟单人计数
public function trackCount()
{
$list = Customer::with(["user"])
->where("user_id", ">", 0)
->whereNotIn('user_id', [1,5,10,11,13,155,16,17,19,74,75,78,141,147])
->select('user_id', Db::raw('COUNT(*) as totals'))
->groupBy('user_id')
->get();
$optionType = [];
$counts = [];
foreach ($list as $val) {
if (isset($val->user) && $val->user) {
$optionType[] = $val->user->name;
$counts[] = $val->totals;
}
}
$arr = [
"optionType" => $optionType,
"counts" => $counts
];
return $this->success($arr);
}
// 每日录单数
public function dayCount()
{
$list = Db::table('crm_customer')
->where('created_at', '>=', Carbon::now()->subDay(7)->timestamp)
->select(
Db::raw('DATE(FROM_UNIXTIME(created_at)) as date'),
Db::raw('COUNT(*) as order_count')
)
->groupBy('date')
->pluck('order_count', 'date')->toArray();
$optionType = [];
$counts = [];
foreach ($list as $key=>$val) {
$optionType[] = $key;
$counts[] = $val;
}
$arr = [
"optionType" => $optionType,
"counts" => $counts
];
return $this->success($arr);
}
public function customerCount(Request $request)
{
$companyId = $request->get('company_id') ?? 0;
// 1. 计算时间范围
$now = Carbon::now();
$sixMonthsAgo = $now->copy()->subMonths(5)->startOfMonth(); // 包含6个月
var_dump($sixMonthsAgo->timestamp);
// 2. 获取关联渠道ID
$channelIds = $this->getChannelIdsByCompany($companyId);
if (empty($channelIds)) {
return collect();
}
// 3. 执行查询
$list = Customer::select([
DB::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m') AS month"),
DB::raw('COUNT(*) AS total_count')
])
->whereIn('channel_id', $channelIds)
->where('created_at', '>', 0)
->where('created_at', '>=', $sixMonthsAgo->timestamp) // 添加时间限制
->groupBy('month')
->orderBy('month')
->get();
$optionType = [];
$counts = [];
foreach ($list as $item) {
$optionType[] = $item->month;
$counts[] = $item->total_count;
}
$arr = [
"optionType" => $optionType,
"counts" => $counts
];
return $this->success($arr);
}
/**
* 获取公司与渠道的映射
*/
private function getChannelIdsByCompany($companyId)
{
$data = [
0 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
1 => [1, 2, 3, 4, 5, 6, 7, 8],
3 => [9, 10, 11]
];
return $data[$companyId] ?? [];
}
}
+44
View File
@@ -194,6 +194,15 @@ Route::group('/admin', function () {
Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']); Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']);
Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']); Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']);
}); });
// 统计
Route::group('/statistics', function () {
Route::any('/whole', [app\crmAdmin\controller\StatisticsController::class, 'whole']);
Route::any('/channel/count', [app\crmAdmin\controller\StatisticsController::class, 'channelCount']);
Route::any('/country/count', [app\crmAdmin\controller\StatisticsController::class, 'countryCount']);
Route::any('/track/count', [app\crmAdmin\controller\StatisticsController::class, 'trackCount']);
Route::any('/day/count', [app\crmAdmin\controller\StatisticsController::class, 'dayCount']);
Route::any('/customer/count', [app\crmAdmin\controller\StatisticsController::class, 'customerCount']);
});
}); });
// 车辆 // 车辆
@@ -244,6 +253,7 @@ Route::group('/admin', function () {
Route::any('/show', [app\admin\controller\BrandController::class, 'show']); Route::any('/show', [app\admin\controller\BrandController::class, 'show']);
Route::any('/store', [app\admin\controller\BrandController::class, 'store']); Route::any('/store', [app\admin\controller\BrandController::class, 'store']);
Route::any('/update', [app\admin\controller\BrandController::class, 'update']); Route::any('/update', [app\admin\controller\BrandController::class, 'update']);
Route::any('/hot', [app\admin\controller\BrandController::class, 'update']);
Route::any('/destroy', [app\admin\controller\BrandController::class, 'destroy']); Route::any('/destroy', [app\admin\controller\BrandController::class, 'destroy']);
// 车系 // 车系
Route::group('/series', function () { Route::group('/series', function () {
@@ -316,6 +326,31 @@ Route::group('/admin', function () {
Route::any('/print', [app\admin\controller\StockOrdersController::class, 'print']); Route::any('/print', [app\admin\controller\StockOrdersController::class, 'print']);
Route::any('/detail', [app\admin\controller\StockOrdersController::class, 'detail']); Route::any('/detail', [app\admin\controller\StockOrdersController::class, 'detail']);
}); });
// crm
Route::group('/targets', function () {
Route::group('/monthly', function () {
Route::any('/list', [app\admin\targets\controller\SalesMonthlyTargetsController::class, 'index']);
Route::any('/store', [app\admin\targets\controller\SalesMonthlyTargetsController::class, 'store']);
Route::any('/update', [app\admin\targets\controller\SalesMonthlyTargetsController::class, 'update']);
Route::any('/destroy', [app\admin\targets\controller\SalesMonthlyTargetsController::class, 'destroy']);
Route::any('/show', [app\admin\targets\controller\SalesMonthlyTargetsController::class, 'show']);
});
Route::group('/annual', function () {
Route::any('/list', [app\admin\targets\controller\SalesAnnualTargetsController::class, 'index']);
Route::any('/store', [app\admin\targets\controller\SalesAnnualTargetsController::class, 'store']);
Route::any('/update', [app\admin\targets\controller\SalesAnnualTargetsController::class, 'update']);
Route::any('/destroy', [app\admin\targets\controller\SalesAnnualTargetsController::class, 'destroy']);
Route::any('/show', [app\admin\targets\controller\SalesAnnualTargetsController::class, 'show']);
});
Route::group('/statistics', function () {
Route::any('/total', [app\admin\targets\controller\StatisticsController::class, 'total']);
Route::any('/ranking', [app\admin\targets\controller\StatisticsController::class, 'ranking']);
Route::any('/user/month', [app\admin\targets\controller\StatisticsController::class, 'achievedUserByMonth']);
Route::any('/user/progressh', [app\admin\targets\controller\StatisticsController::class, 'userProgressh']);
Route::any('/user/achieved', [app\admin\targets\controller\StatisticsController::class, 'userAchieved']);
});
});
}); });
@@ -421,4 +456,13 @@ Route::group('/crm', function () {
Route::any('/destroy', [app\common\controller\VehVehicleSkuController::class, 'destroy']); Route::any('/destroy', [app\common\controller\VehVehicleSkuController::class, 'destroy']);
}); });
}); });
// 汽车改装项目
Route::group('/modification', function () {
Route::any('/list', [app\common\controller\VehModificationController::class, 'index']);
Route::any('/show', [app\common\controller\VehModificationController::class, 'show']);
Route::any('/store', [app\common\controller\VehModificationController::class, 'store']);
Route::any('/update', [app\common\controller\VehModificationController::class, 'update']);
Route::any('/destroy', [app\common\controller\VehModificationController::class, 'destroy']);
});
}); });