Merge branch 'develop' into feature/mzl_dev
This commit is contained in:
@@ -30,7 +30,8 @@ class SysAccountController extends BaseController
|
|||||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
|
if (isset($data['currency_name']))
|
||||||
|
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@ class SysAccountController extends BaseController
|
|||||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
|
if (isset($data['currency_name']))
|
||||||
|
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
namespace app\admin\controller;
|
namespace app\admin\controller;
|
||||||
|
|
||||||
use app\common\controller\BaseController;
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\model\Country;
|
||||||
use app\common\traits\crud\CrudControllerTrait;
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use app\admin\service\SysCurrencyService;
|
use app\admin\service\SysCurrencyService;
|
||||||
|
|
||||||
@@ -30,6 +31,11 @@ class SysCurrencyController extends BaseController
|
|||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
if (isset($data['last_updated']))
|
if (isset($data['last_updated']))
|
||||||
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
|
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
|
||||||
|
if (isset($data['country_id'])){
|
||||||
|
$data['country_name'] = Country::where('id',$data['country_id'])->value('item_label');
|
||||||
|
} else {
|
||||||
|
$data['country_name'] = '';
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +53,11 @@ class SysCurrencyController extends BaseController
|
|||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
if (isset($data['last_updated']))
|
if (isset($data['last_updated']))
|
||||||
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
|
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
|
||||||
|
if (isset($data['country_id'])){
|
||||||
|
$data['country_name'] = Country::where('id',$data['country_id'])->value('item_label');
|
||||||
|
} else {
|
||||||
|
$data['country_name'] = '';
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
|
use app\admin\service\SysDictCategoryService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
class SysDictCategoryController extends BaseController
|
||||||
|
{
|
||||||
|
use CrudControllerTrait;
|
||||||
|
|
||||||
|
protected $service;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->service = new SysDictCategoryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页数据格式化
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function preset(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$params = $request->all();
|
||||||
|
$result = (new SysDictCategoryService)->getList($params);
|
||||||
|
return $this->success($result, '获取字典项列表');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,11 @@ class SysDictController extends BaseController
|
|||||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
|
if (isset($data['category_id'])){
|
||||||
|
$data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label');
|
||||||
|
} else {
|
||||||
|
$data['category'] = '';
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,4 +79,17 @@ class SysDictController extends BaseController
|
|||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function group(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->group($request);
|
||||||
|
$data = $this->transformData($raw, method_exists($this, 'groupFormat')
|
||||||
|
? [$this, 'groupFormat']
|
||||||
|
: null);
|
||||||
|
return $this->success($data);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,27 @@ class VehColorController extends BaseController
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
// protected function indexFormat($data)
|
protected function indexFormat($data)
|
||||||
// {
|
{
|
||||||
// if (isset($data['created_at']))
|
if (isset($data['created_at']))
|
||||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
// if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
// return $data;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\logic;
|
||||||
|
|
||||||
|
use app\common\traits\crud\CrudLogicTrait;
|
||||||
|
use app\common\model\SysDictCategory;
|
||||||
|
|
||||||
|
class SysDictCategoryLogic
|
||||||
|
{
|
||||||
|
use CrudLogicTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = SysDictCategory::class;
|
||||||
|
|
||||||
|
public function getList()
|
||||||
|
{
|
||||||
|
return SysDictCategory::where('status', 1)->orderBy('sort','desc')->get(['id', 'category_name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\service;
|
||||||
|
|
||||||
|
use app\admin\logic\SysDictCategoryLogic;
|
||||||
|
use app\admin\validate\SysDictCategoryValidate;
|
||||||
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
|
use app\common\model\SysDictCategory;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
class SysDictCategoryService
|
||||||
|
{
|
||||||
|
|
||||||
|
use CrudServiceTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = SysDictCategory::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected $validator = SysDictCategoryValidate::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取验证器
|
||||||
|
*/
|
||||||
|
public function getValidator()
|
||||||
|
{
|
||||||
|
return new $this->validator;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取系统list
|
||||||
|
*/
|
||||||
|
public function getList($params)
|
||||||
|
{
|
||||||
|
return (new SysDictCategoryLogic)->getList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,10 @@ class SysDictService
|
|||||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||||
$config['where']['status'] = $p['status'];
|
$config['where']['status'] = $p['status'];
|
||||||
}
|
}
|
||||||
|
// 分类筛选
|
||||||
|
if (isset($p['category_id']) && !empty($p['category_id'])) {
|
||||||
|
$config['where']['category_id'] = $p['category_id'];
|
||||||
|
}
|
||||||
// 关键字
|
// 关键字
|
||||||
if (isset($p['keyword']) && $p['keyword']) {
|
if (isset($p['keyword']) && $p['keyword']) {
|
||||||
$k = '%' . $p['keyword'] . '%';
|
$k = '%' . $p['keyword'] . '%';
|
||||||
@@ -83,11 +87,25 @@ class SysDictService
|
|||||||
$config['with']['sysDictItem'][] = 'item_label';
|
$config['with']['sysDictItem'][] = 'item_label';
|
||||||
$config['with']['sysDictItem'][] = 'item_value';
|
$config['with']['sysDictItem'][] = 'item_value';
|
||||||
break;
|
break;
|
||||||
|
case 'group':
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
$config['where']['id'] = 1;
|
||||||
|
$config['with']['sysDictItem'][] = 'dict_id';
|
||||||
|
$config['with']['sysDictItem'][] = 'item_label';
|
||||||
|
$config['with']['sysDictItem'][] = 'item_value';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function group(Request $request)
|
||||||
|
{
|
||||||
|
$config = $this->buildQueryConfig($request, 'group');
|
||||||
|
$result = $this->logicShow($config);
|
||||||
|
return $this->postProcess('group', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function serviceListAllScope(Request $request)
|
public function serviceListAllScope(Request $request)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ class SysPortService
|
|||||||
$config['orWhere'][] = [$col, 'like', $k];
|
$config['orWhere'][] = [$col, 'like', $k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 场景
|
||||||
|
if (isset($p['scene']) && $p['scene']) {
|
||||||
|
if($p['country_id'] == 'domestic'){
|
||||||
|
$config['where']['country_id'] = 45;
|
||||||
|
}else{
|
||||||
|
$config['where']['country_id'] = ['<>', 45];
|
||||||
|
}
|
||||||
|
}
|
||||||
//$config['where']['status'] = 1;
|
//$config['where']['status'] = 1;
|
||||||
break;
|
break;
|
||||||
case 'show':
|
case 'show':
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class SysDictCategoryValidate extends Validate
|
||||||
|
{
|
||||||
|
// 规则
|
||||||
|
protected $rule = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 提示
|
||||||
|
protected $message = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 场景
|
||||||
|
protected $scene = [
|
||||||
|
'store' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
'update' => [
|
||||||
|
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -147,10 +147,11 @@ class PresetController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function port()
|
public function port(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = (new SysPortService)->getList();
|
$params = $request->all();
|
||||||
|
$result = (new SysPortService)->getList($params);
|
||||||
return $this->success($result, '获取港口列表');
|
return $this->success($result, '获取港口列表');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ class SysCurrencyLogic
|
|||||||
|
|
||||||
public function getList()
|
public function getList()
|
||||||
{
|
{
|
||||||
return SysCurrency::where('status', 1)->get(['id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'float_percent']);
|
return SysCurrency::where('status', 1)->get(['id', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'float_percent_up', 'float_percent_down']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,9 @@ class SysPortLogic
|
|||||||
*/
|
*/
|
||||||
protected string $modelClass = SysPort::class;
|
protected string $modelClass = SysPort::class;
|
||||||
|
|
||||||
public function getList()
|
public function getList($where)
|
||||||
{
|
{
|
||||||
return SysPort::where('status', 1)->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', 'country_id', 'description']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ class SysAccount extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'account_name', 'account_type', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at'];
|
protected $fillable = ['id', 'currency_id', 'account_name', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class SysCurrency extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'base_currency', 'float_percent', 'status', 'last_updated', 'created_at', 'updated_at'];
|
protected $fillable = ['id', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'base_currency', 'float_percent_up', 'float_percent_down', 'status', 'last_updated', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class SysDict extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at'];
|
protected $fillable = ['id', 'category_id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class SysDictCategory extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'sys_dict_category';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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', 'category_name', 'sort', 'status', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -21,8 +21,16 @@ class SysPortService
|
|||||||
/**
|
/**
|
||||||
* 获取系统list
|
* 获取系统list
|
||||||
*/
|
*/
|
||||||
public function getList()
|
public function getList($params)
|
||||||
{
|
{
|
||||||
return $this->logic->getList();
|
$where = [];
|
||||||
|
if(isset($params['scene']) && $params['scene']) {
|
||||||
|
if($params['scene'] == 'domestic'){
|
||||||
|
$where['country_id'] = 45;
|
||||||
|
}else{
|
||||||
|
$where['country_id'] = ['<>', 45];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->logic->getList($where);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,6 +205,25 @@ class CustomerController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户下拉
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function preset(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$param = $request->all();
|
||||||
|
$param['user_id'] = $request->user->uid;
|
||||||
|
$param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||||
|
$result = (new CustomerService())->preset($param);
|
||||||
|
|
||||||
|
return $this->success($result);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户恢复
|
* 客户恢复
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
|||||||
@@ -164,6 +164,39 @@ class CustomerService
|
|||||||
return $customer;
|
return $customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function preset($params)
|
||||||
|
{
|
||||||
|
$keyword = $params['keyword'] ?? '';
|
||||||
|
$where = [];
|
||||||
|
$user_id =$params['user_id'];
|
||||||
|
|
||||||
|
$where[] = ['status', 1];
|
||||||
|
$where[] = ['user_id', $user_id];
|
||||||
|
|
||||||
|
if (!empty($countryId)){
|
||||||
|
$where[] = ['country_id', $countryId];
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = Customer::select('id','code','sn','corp_id','email','phone','WhatsApp','contacts','company')->where($where);
|
||||||
|
|
||||||
|
if (!Util::isEmpty($keyword)) {
|
||||||
|
$query->where(function ($query) use ($keyword) {
|
||||||
|
$query->where('contacts', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('phone', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('email', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('WhatsApp', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('code', 'like', "%{$keyword}%");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$customer = $query->orderBy('follow_last','desc')->get();
|
||||||
|
|
||||||
|
foreach ($customer as &$item) {
|
||||||
|
}
|
||||||
|
unset($item);
|
||||||
|
|
||||||
|
return $customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** 分页列表 */
|
/** 分页列表 */
|
||||||
public function serviceList(Request $request)
|
public function serviceList(Request $request)
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\queue\redis;
|
||||||
|
|
||||||
|
use app\inquiry\service\InquiryLogService;
|
||||||
|
use app\common\model\CrmCustomer;
|
||||||
|
use app\common\model\InquiryLog;
|
||||||
|
use Webman\RedisQueue\Consumer;
|
||||||
|
use app\common\model\User;
|
||||||
|
use app\common\utils\FeishuMessage;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use support\Log;
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class InquiryToCrmNew implements Consumer
|
||||||
|
{
|
||||||
|
// 要消费的队列名
|
||||||
|
public $queue = 'inquiry-to-crm-new';
|
||||||
|
|
||||||
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
|
public $connection = 'default';
|
||||||
|
|
||||||
|
// 消费
|
||||||
|
public function consume($data)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
询单 与 CRM 之间的同步场景描述
|
||||||
|
|
||||||
|
添加(询单)
|
||||||
|
添加 不发 不分 (不同步)1
|
||||||
|
添加 发了 不分 (要同步)2
|
||||||
|
添加 不发 分了 (要同步)3
|
||||||
|
添加 不发 直分 (要同步)4
|
||||||
|
|
||||||
|
更新(询单)
|
||||||
|
没发 没分 更新 (不同步)5
|
||||||
|
没发 分过 更新 (要同步)6
|
||||||
|
发过 没分 更新 (要同步)7
|
||||||
|
发过 分过 更新 (要同步)8
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取询盘信息
|
||||||
|
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('id', $data['id'])->first();
|
||||||
|
|
||||||
|
// 无论添加 或 更新,询单必然要存在
|
||||||
|
if (!$info) {
|
||||||
|
throw new BusinessException('询盘不存在:' . $data['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 0 && $info->recipient == 0) {
|
||||||
|
// 如果询单未发、未分,则不与crm同步,不做任何处理
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更改库信息
|
||||||
|
$this->syncCustomer($info);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pushWs($title, $content, $recipient = [])
|
||||||
|
{
|
||||||
|
$wsdata = [
|
||||||
|
'sender_id' => 0,
|
||||||
|
'sender_type' => 'system',
|
||||||
|
'title' => $title,
|
||||||
|
'content' => $content,
|
||||||
|
'scene' => 1,
|
||||||
|
'recipient' => $recipient
|
||||||
|
];
|
||||||
|
// 异步推送
|
||||||
|
\Webman\RedisQueue\Redis::send('notice', $wsdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function syncCustomer(Model $info)
|
||||||
|
{
|
||||||
|
$uInfo = $this->recipientInfo($info);
|
||||||
|
$crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first();
|
||||||
|
if ($crmCustomerInfo) {
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 2 && empty($crmCustomerInfo->user_id)) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) {
|
||||||
|
// $notice = '更新';
|
||||||
|
$title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
// $notice = '重新分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$udata = [
|
||||||
|
<<<<<<< HEAD
|
||||||
|
'corp_abbr' => $uInfo['corpId'],
|
||||||
|
=======
|
||||||
|
'corp_id' => $uInfo['corpId'],
|
||||||
|
>>>>>>> feature/distinct
|
||||||
|
'user_id' => $info->recipient,
|
||||||
|
'channel_id' => $info->channel,
|
||||||
|
'country_id' => $info->country,
|
||||||
|
'magnitude' => $info->quality,
|
||||||
|
'email' => $info->email,
|
||||||
|
'phone' => $info->tel,
|
||||||
|
'WhatsApp' => $info->whatsapp,
|
||||||
|
'contacts' => $info->contacts,
|
||||||
|
'desc_collect' => $info->content,
|
||||||
|
];
|
||||||
|
if (!$crmCustomerInfo->update($udata)) {
|
||||||
|
throw new BusinessException('同步失败,更新客户线索失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$crmCustomer = new CrmCustomer();
|
||||||
|
$crmCustomer->sn = $info->order_no;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
$crmCustomer->corp_abbr = $uInfo['corpId'];
|
||||||
|
=======
|
||||||
|
$crmCustomer->corp_id = $uInfo['corpId'];
|
||||||
|
>>>>>>> feature/distinct
|
||||||
|
$crmCustomer->user_id = $uInfo['recipient'];
|
||||||
|
$crmCustomer->type = 1;
|
||||||
|
$crmCustomer->channel_id = $info->channel;
|
||||||
|
$crmCustomer->country_id = $info->country;
|
||||||
|
$crmCustomer->magnitude = $info->quality;
|
||||||
|
$crmCustomer->email = $info->email;
|
||||||
|
$crmCustomer->phone = $info->tel;
|
||||||
|
$crmCustomer->WhatsApp = $info->whatsapp;
|
||||||
|
$crmCustomer->contacts = $info->contacts;
|
||||||
|
$crmCustomer->desc_collect = $info->content;
|
||||||
|
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||||
|
$crmCustomer->obtain = time();
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
if(empty($uInfo['recipient'])){
|
||||||
|
$crmCustomer->deleted_at = time();
|
||||||
|
}
|
||||||
|
>>>>>>> feature/distinct
|
||||||
|
// 修改同步CRM状态
|
||||||
|
$info->sync_crm = 1;
|
||||||
|
// 保存
|
||||||
|
if (!$crmCustomer->save() || !$info->save()) {
|
||||||
|
throw new BusinessException('同步失败,创建客户线索失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 1) {
|
||||||
|
// $notice = '发布';
|
||||||
|
$title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 2) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recipientInfo(Model $info)
|
||||||
|
{
|
||||||
|
$recipient = 0;
|
||||||
|
$corpId = 0;
|
||||||
|
$uinfo = null;
|
||||||
|
if (!empty($info->recipient)) {
|
||||||
|
$recipient = $info->recipient;
|
||||||
|
$uinfo = User::where('id', $info->recipient)->first();
|
||||||
|
if ($uinfo) {
|
||||||
|
$corpId = $uinfo->corp_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'recipient' => $recipient,
|
||||||
|
'corpId' => $corpId,
|
||||||
|
'uinfo' => $uinfo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消费失败回调
|
||||||
|
/*
|
||||||
|
$package = [
|
||||||
|
'id' => 1357277951, // 消息ID
|
||||||
|
'time' => 1709170510, // 消息时间
|
||||||
|
'delay' => 0, // 延迟时间
|
||||||
|
'attempts' => 2, // 消费次数
|
||||||
|
'queue' => 'send-mail', // 队列名
|
||||||
|
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||||
|
'max_attempts' => 5, // 最大重试次数
|
||||||
|
'error' => '错误信息' // 错误信息
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
public function onConsumeFailure(\Throwable $e, $package)
|
||||||
|
{
|
||||||
|
echo "consume failure\n";
|
||||||
|
echo $e->getMessage() . "\n";
|
||||||
|
// 无需反序列化
|
||||||
|
var_export($package);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\queue\redis;
|
||||||
|
|
||||||
|
use app\inquiry\service\InquiryLogService;
|
||||||
|
use app\common\model\CrmCustomer;
|
||||||
|
use app\common\model\InquiryLog;
|
||||||
|
use Webman\RedisQueue\Consumer;
|
||||||
|
use app\common\model\User;
|
||||||
|
use app\common\utils\FeishuMessage;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use support\Log;
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class InquiryToCrmNew implements Consumer
|
||||||
|
{
|
||||||
|
// 要消费的队列名
|
||||||
|
public $queue = 'inquiry-to-crm-new';
|
||||||
|
|
||||||
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
|
public $connection = 'default';
|
||||||
|
|
||||||
|
// 消费
|
||||||
|
public function consume($data)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
询单 与 CRM 之间的同步场景描述
|
||||||
|
|
||||||
|
添加(询单)
|
||||||
|
添加 不发 不分 (不同步)1
|
||||||
|
添加 发了 不分 (要同步)2
|
||||||
|
添加 不发 分了 (要同步)3
|
||||||
|
添加 不发 直分 (要同步)4
|
||||||
|
|
||||||
|
更新(询单)
|
||||||
|
没发 没分 更新 (不同步)5
|
||||||
|
没发 分过 更新 (要同步)6
|
||||||
|
发过 没分 更新 (要同步)7
|
||||||
|
发过 分过 更新 (要同步)8
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取询盘信息
|
||||||
|
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('id', $data['id'])->first();
|
||||||
|
|
||||||
|
// 无论添加 或 更新,询单必然要存在
|
||||||
|
if (!$info) {
|
||||||
|
throw new BusinessException('询盘不存在:' . $data['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 0 && $info->recipient == 0) {
|
||||||
|
// 如果询单未发、未分,则不与crm同步,不做任何处理
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更改库信息
|
||||||
|
$this->syncCustomer($info);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pushWs($title, $content, $recipient = [])
|
||||||
|
{
|
||||||
|
$wsdata = [
|
||||||
|
'sender_id' => 0,
|
||||||
|
'sender_type' => 'system',
|
||||||
|
'title' => $title,
|
||||||
|
'content' => $content,
|
||||||
|
'scene' => 1,
|
||||||
|
'recipient' => $recipient
|
||||||
|
];
|
||||||
|
// 异步推送
|
||||||
|
\Webman\RedisQueue\Redis::send('notice', $wsdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function syncCustomer(Model $info)
|
||||||
|
{
|
||||||
|
$uInfo = $this->recipientInfo($info);
|
||||||
|
$crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first();
|
||||||
|
if ($crmCustomerInfo) {
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 2 && empty($crmCustomerInfo->user_id)) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) {
|
||||||
|
// $notice = '更新';
|
||||||
|
$title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
// $notice = '重新分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$udata = [
|
||||||
|
'corp_abbr' => $uInfo['corpId'],
|
||||||
|
'user_id' => $info->recipient,
|
||||||
|
'channel_id' => $info->channel,
|
||||||
|
'country_id' => $info->country,
|
||||||
|
'magnitude' => $info->quality,
|
||||||
|
'email' => $info->email,
|
||||||
|
'phone' => $info->tel,
|
||||||
|
'WhatsApp' => $info->whatsapp,
|
||||||
|
'contacts' => $info->contacts,
|
||||||
|
'desc_collect' => $info->content,
|
||||||
|
];
|
||||||
|
if (!$crmCustomerInfo->update($udata)) {
|
||||||
|
throw new BusinessException('同步失败,更新客户线索失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$crmCustomer = new CrmCustomer();
|
||||||
|
$crmCustomer->sn = $info->order_no;
|
||||||
|
$crmCustomer->corp_abbr = $uInfo['corpId'];
|
||||||
|
$crmCustomer->user_id = $uInfo['recipient'];
|
||||||
|
$crmCustomer->type = 1;
|
||||||
|
$crmCustomer->channel_id = $info->channel;
|
||||||
|
$crmCustomer->country_id = $info->country;
|
||||||
|
$crmCustomer->magnitude = $info->quality;
|
||||||
|
$crmCustomer->email = $info->email;
|
||||||
|
$crmCustomer->phone = $info->tel;
|
||||||
|
$crmCustomer->WhatsApp = $info->whatsapp;
|
||||||
|
$crmCustomer->contacts = $info->contacts;
|
||||||
|
$crmCustomer->desc_collect = $info->content;
|
||||||
|
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||||
|
$crmCustomer->obtain = time();
|
||||||
|
// 修改同步CRM状态
|
||||||
|
$info->sync_crm = 1;
|
||||||
|
// 保存
|
||||||
|
if (!$crmCustomer->save() || !$info->save()) {
|
||||||
|
throw new BusinessException('同步失败,创建客户线索失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 1) {
|
||||||
|
// $notice = '发布';
|
||||||
|
$title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 2) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recipientInfo(Model $info)
|
||||||
|
{
|
||||||
|
$recipient = 0;
|
||||||
|
$corpId = 0;
|
||||||
|
$uinfo = null;
|
||||||
|
if (!empty($info->recipient)) {
|
||||||
|
$recipient = $info->recipient;
|
||||||
|
$uinfo = User::where('id', $info->recipient)->first();
|
||||||
|
if ($uinfo) {
|
||||||
|
$corpId = $uinfo->corp_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'recipient' => $recipient,
|
||||||
|
'corpId' => $corpId,
|
||||||
|
'uinfo' => $uinfo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消费失败回调
|
||||||
|
/*
|
||||||
|
$package = [
|
||||||
|
'id' => 1357277951, // 消息ID
|
||||||
|
'time' => 1709170510, // 消息时间
|
||||||
|
'delay' => 0, // 延迟时间
|
||||||
|
'attempts' => 2, // 消费次数
|
||||||
|
'queue' => 'send-mail', // 队列名
|
||||||
|
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||||
|
'max_attempts' => 5, // 最大重试次数
|
||||||
|
'error' => '错误信息' // 错误信息
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
public function onConsumeFailure(\Throwable $e, $package)
|
||||||
|
{
|
||||||
|
echo "consume failure\n";
|
||||||
|
echo $e->getMessage() . "\n";
|
||||||
|
// 无需反序列化
|
||||||
|
var_export($package);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\queue\redis;
|
||||||
|
|
||||||
|
use app\inquiry\service\InquiryLogService;
|
||||||
|
use app\common\model\CrmCustomer;
|
||||||
|
use app\common\model\InquiryLog;
|
||||||
|
use Webman\RedisQueue\Consumer;
|
||||||
|
use app\common\model\User;
|
||||||
|
use app\common\utils\FeishuMessage;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use support\Log;
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class InquiryToCrmNew implements Consumer
|
||||||
|
{
|
||||||
|
// 要消费的队列名
|
||||||
|
public $queue = 'inquiry-to-crm-new';
|
||||||
|
|
||||||
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
|
public $connection = 'default';
|
||||||
|
|
||||||
|
// 消费
|
||||||
|
public function consume($data)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
询单 与 CRM 之间的同步场景描述
|
||||||
|
|
||||||
|
添加(询单)
|
||||||
|
添加 不发 不分 (不同步)1
|
||||||
|
添加 发了 不分 (要同步)2
|
||||||
|
添加 不发 分了 (要同步)3
|
||||||
|
添加 不发 直分 (要同步)4
|
||||||
|
|
||||||
|
更新(询单)
|
||||||
|
没发 没分 更新 (不同步)5
|
||||||
|
没发 分过 更新 (要同步)6
|
||||||
|
发过 没分 更新 (要同步)7
|
||||||
|
发过 分过 更新 (要同步)8
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取询盘信息
|
||||||
|
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->where('id', $data['id'])->first();
|
||||||
|
|
||||||
|
// 无论添加 或 更新,询单必然要存在
|
||||||
|
if (!$info) {
|
||||||
|
throw new BusinessException('询盘不存在:' . $data['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 0 && $info->recipient == 0) {
|
||||||
|
// 如果询单未发、未分,则不与crm同步,不做任何处理
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更改库信息
|
||||||
|
$this->syncCustomer($info);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pushWs($title, $content, $recipient = [])
|
||||||
|
{
|
||||||
|
$wsdata = [
|
||||||
|
'sender_id' => 0,
|
||||||
|
'sender_type' => 'system',
|
||||||
|
'title' => $title,
|
||||||
|
'content' => $content,
|
||||||
|
'scene' => 1,
|
||||||
|
'recipient' => $recipient
|
||||||
|
];
|
||||||
|
// 异步推送
|
||||||
|
\Webman\RedisQueue\Redis::send('notice', $wsdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function syncCustomer(Model $info)
|
||||||
|
{
|
||||||
|
$uInfo = $this->recipientInfo($info);
|
||||||
|
$crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first();
|
||||||
|
if ($crmCustomerInfo) {
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 2 && empty($crmCustomerInfo->user_id)) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) {
|
||||||
|
// $notice = '更新';
|
||||||
|
$title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
} else {
|
||||||
|
// $notice = '重新分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$udata = [
|
||||||
|
'corp_id' => $uInfo['corpId'],
|
||||||
|
'user_id' => $info->recipient,
|
||||||
|
'channel_id' => $info->channel,
|
||||||
|
'country_id' => $info->country,
|
||||||
|
'magnitude' => $info->quality,
|
||||||
|
'email' => $info->email,
|
||||||
|
'phone' => $info->tel,
|
||||||
|
'WhatsApp' => $info->whatsapp,
|
||||||
|
'contacts' => $info->contacts,
|
||||||
|
'desc_collect' => $info->content,
|
||||||
|
];
|
||||||
|
if (!$crmCustomerInfo->update($udata)) {
|
||||||
|
throw new BusinessException('同步失败,更新客户线索失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$crmCustomer = new CrmCustomer();
|
||||||
|
$crmCustomer->sn = $info->order_no;
|
||||||
|
$crmCustomer->corp_id = $uInfo['corpId'];
|
||||||
|
$crmCustomer->user_id = $uInfo['recipient'];
|
||||||
|
$crmCustomer->type = 1;
|
||||||
|
$crmCustomer->channel_id = $info->channel;
|
||||||
|
$crmCustomer->country_id = $info->country;
|
||||||
|
$crmCustomer->magnitude = $info->quality;
|
||||||
|
$crmCustomer->email = $info->email;
|
||||||
|
$crmCustomer->phone = $info->tel;
|
||||||
|
$crmCustomer->WhatsApp = $info->whatsapp;
|
||||||
|
$crmCustomer->contacts = $info->contacts;
|
||||||
|
$crmCustomer->desc_collect = $info->content;
|
||||||
|
$crmCustomer->enter_user_id = $info->enter_user_id;
|
||||||
|
$crmCustomer->obtain = time();
|
||||||
|
if(empty($uInfo['recipient'])){
|
||||||
|
$crmCustomer->deleted_at = time();
|
||||||
|
}
|
||||||
|
// 修改同步CRM状态
|
||||||
|
$info->sync_crm = 1;
|
||||||
|
// 保存
|
||||||
|
if (!$crmCustomer->save() || !$info->save()) {
|
||||||
|
throw new BusinessException('同步失败,创建客户线索失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消息推送
|
||||||
|
if ($info->status == 1) {
|
||||||
|
// $notice = '发布';
|
||||||
|
$title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($info->status == 2) {
|
||||||
|
// $notice = '分配';
|
||||||
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
|
$recipient = [$info->recipient];
|
||||||
|
$this->pushWs($title, $content, $recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recipientInfo(Model $info)
|
||||||
|
{
|
||||||
|
$recipient = 0;
|
||||||
|
$corpId = 0;
|
||||||
|
$uinfo = null;
|
||||||
|
if (!empty($info->recipient)) {
|
||||||
|
$recipient = $info->recipient;
|
||||||
|
$uinfo = User::where('id', $info->recipient)->first();
|
||||||
|
if ($uinfo) {
|
||||||
|
$corpId = $uinfo->corp_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'recipient' => $recipient,
|
||||||
|
'corpId' => $corpId,
|
||||||
|
'uinfo' => $uinfo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消费失败回调
|
||||||
|
/*
|
||||||
|
$package = [
|
||||||
|
'id' => 1357277951, // 消息ID
|
||||||
|
'time' => 1709170510, // 消息时间
|
||||||
|
'delay' => 0, // 延迟时间
|
||||||
|
'attempts' => 2, // 消费次数
|
||||||
|
'queue' => 'send-mail', // 队列名
|
||||||
|
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||||
|
'max_attempts' => 5, // 最大重试次数
|
||||||
|
'error' => '错误信息' // 错误信息
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
public function onConsumeFailure(\Throwable $e, $package)
|
||||||
|
{
|
||||||
|
echo "consume failure\n";
|
||||||
|
echo $e->getMessage() . "\n";
|
||||||
|
// 无需反序列化
|
||||||
|
var_export($package);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -212,6 +212,8 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/update', [app\admin\controller\SysDictController::class, 'update']);
|
Route::any('/update', [app\admin\controller\SysDictController::class, 'update']);
|
||||||
Route::any('/destroy', [app\admin\controller\SysDictController::class, 'destroy']);
|
Route::any('/destroy', [app\admin\controller\SysDictController::class, 'destroy']);
|
||||||
Route::any('/scope', [app\admin\controller\SysDictController::class, 'listScope']);
|
Route::any('/scope', [app\admin\controller\SysDictController::class, 'listScope']);
|
||||||
|
// 字典分类
|
||||||
|
Route::any('/group', [app\admin\controller\SysDictController::class, 'group']);
|
||||||
|
|
||||||
Route::group('/item', function () {
|
Route::group('/item', function () {
|
||||||
Route::any('/list', [app\admin\controller\SysDictItemController::class, 'index']);
|
Route::any('/list', [app\admin\controller\SysDictItemController::class, 'index']);
|
||||||
@@ -220,6 +222,7 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/update', [app\admin\controller\SysDictItemController::class, 'update']);
|
Route::any('/update', [app\admin\controller\SysDictItemController::class, 'update']);
|
||||||
Route::any('/destroy', [app\admin\controller\SysDictItemController::class, 'destroy']);
|
Route::any('/destroy', [app\admin\controller\SysDictItemController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 货币
|
// 货币
|
||||||
@@ -337,6 +340,7 @@ Route::group('/crm', function () {
|
|||||||
Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']);
|
Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']);
|
||||||
Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']);
|
Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']);
|
||||||
Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']);
|
Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']);
|
||||||
|
Route::any('/customer/preset', [app\crm\controller\CustomerController::class, 'preset']);
|
||||||
|
|
||||||
Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']);
|
Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']);
|
||||||
Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);
|
Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);
|
||||||
|
|||||||
Reference in New Issue
Block a user