公海,转让,名片
This commit is contained in:
@@ -4,7 +4,9 @@ namespace app\controller;
|
||||
|
||||
use app\model\Channel;
|
||||
use app\model\Customer;
|
||||
use app\model\CustomerHis;
|
||||
use app\model\Follow;
|
||||
use app\model\User;
|
||||
use app\service\UserService;
|
||||
use app\util\Util;
|
||||
use config\constants\Constants;
|
||||
@@ -129,6 +131,8 @@ class CustomerController
|
||||
$follow = $request->input('follow', ''); //跟进状态
|
||||
$keyword = $request->input('keyword', ''); //follow_last
|
||||
$follow_last = $request->input('follow_last', ''); //最后跟进:1:当天跟进客户,2:近三天跟进客户,3:近七天跟进客户
|
||||
$tagId = $request->input('tag_id', ''); //打有某个标签的客户
|
||||
$seas = $request->input('seas', ''); //公海客户
|
||||
|
||||
$where = [];
|
||||
|
||||
@@ -136,7 +140,11 @@ class CustomerController
|
||||
if (Util::isEmpty($userId)) {
|
||||
return Util::fail(['user_id' => $userId], trans('user_none'));
|
||||
}
|
||||
$where[] = ['user_id', $userId];
|
||||
if($seas == 'seas'){
|
||||
$where[] = ['user_id', 0];
|
||||
}else{
|
||||
$where[] = ['user_id', $userId];
|
||||
}
|
||||
//验证权限
|
||||
// if ($request->user['role'] != 1) {
|
||||
// $where[] =['user_id',$userId] ;
|
||||
@@ -160,18 +168,21 @@ class CustomerController
|
||||
|
||||
|
||||
// 执行分页查询 //关联标签tags //关联标签及分组tags.group
|
||||
$query = Customer::where($where)
|
||||
$query = Customer::with('tags')->where($where)
|
||||
->orderBy('id', 'desc');
|
||||
if(!empty($tagId)){
|
||||
$query->with(['tags' => function($query) use ($tagId){
|
||||
$query->where('id', $tagId);
|
||||
}]);
|
||||
}
|
||||
if (!Util::isEmpty($keyword)) {
|
||||
$query->where(function ($query) use ($keyword) {
|
||||
$query->where('contacts', 'like', "%{$keyword}%")
|
||||
->orWhere('phone', 'like', "%{$keyword}%");
|
||||
});
|
||||
|
||||
}
|
||||
if (!Util::isEmpty($grade)) {
|
||||
$query->whereIn('grade', $grade);
|
||||
|
||||
}
|
||||
|
||||
$recycle = Util::getParam($request,'recycle', '');
|
||||
@@ -301,6 +312,92 @@ class CustomerController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取公海客户
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function claim(Request $request)
|
||||
{
|
||||
$customerId = Util::getParam($request, 'customer_id');
|
||||
$userId = $request->user['id'];
|
||||
if (Util::isEmpty($customerId)) {
|
||||
return Util::fail([], trans('customer_id').trans('not_null'));
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $request->user['id']
|
||||
];
|
||||
$customer= Customer::find($customerId);
|
||||
|
||||
if($customer->user_id != 0){
|
||||
return Util::fail('', trans('claim_fail'));
|
||||
}
|
||||
|
||||
$customer->restore();
|
||||
$res = $customer->update($data);
|
||||
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $customerId,
|
||||
'user_his' => 0,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
|
||||
if ($res) {
|
||||
return Util::success($res, trans('success'));
|
||||
} else {
|
||||
return Util::fail($res, trans('fail'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量转让
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function cede(Request $request)
|
||||
{
|
||||
$customerId = Util::getParam($request, 'customer_id');
|
||||
$user_sn = Util::getParam($request, 'user_sn');
|
||||
$userId = $request->user['id'];
|
||||
if (Util::isEmpty($user_sn)) {
|
||||
return Util::fail([], 'ID'.trans('not_null'));
|
||||
}
|
||||
|
||||
$user = User::where(['sn' => $user_sn])->first();
|
||||
if (Util::isEmpty($user)) {
|
||||
return Util::fail(null, trans('user_none'));
|
||||
}
|
||||
|
||||
if(Util::isEmpty($customerId)){
|
||||
$data = [
|
||||
'user_id' => $userId
|
||||
];
|
||||
$query= Customer::where($data);
|
||||
}else{
|
||||
$query= Customer::whereIn('id',explode(',',$customerId));
|
||||
}
|
||||
$customer = $query->get();
|
||||
|
||||
foreach ($customer as $item) {
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $item->id,
|
||||
'user_his' => $item->user_id,
|
||||
'user_id' => $user['id'],
|
||||
]);
|
||||
}
|
||||
$res = $query->update(['user_id' => $user->id]);
|
||||
|
||||
|
||||
if ($res) {
|
||||
return Util::success($res, trans('success'));
|
||||
} else {
|
||||
return Util::fail($res, trans('fail'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跟进状态
|
||||
* @param Request $request
|
||||
|
||||
@@ -197,7 +197,7 @@ class UserController
|
||||
$user['avatar_url'] = $user['avatar'];
|
||||
$ossservice = new \app\service\OssService();
|
||||
$user['avatar'] = $user['avatar'] ? $ossservice->generatePrivateUrl($user['avatar']) : '';
|
||||
return Util::success($user, trans('save_success'));
|
||||
return Util::success($user, trans('success'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,27 +208,18 @@ class UserController
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$name = Util::getParam($request, 'name');
|
||||
$sex = Util::getParam($request, 'sex');
|
||||
$position = Util::getParam($request, 'position');
|
||||
$country_id = Util::getParam($request, 'country_id');
|
||||
$sign = Util::getParam($request, 'sign');
|
||||
$id = $request->user['id'];
|
||||
$avatar = Util::getParam($request, 'avatar_url');
|
||||
$mobile = Util::getParam($request, 'mobile');
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'sex' => $sex,
|
||||
'position' => $position,
|
||||
'country_id' => $country_id,
|
||||
'sign' => $sign,
|
||||
'avatar' => $avatar,
|
||||
'mobile' => $mobile
|
||||
];
|
||||
$user = User::where('id', $id)->first();
|
||||
// 只填充前端传递的字段
|
||||
$user->fill($request->only(['name', 'sex', 'position', 'country_id', 'sign', 'mobile', 'address']));
|
||||
|
||||
$res = User::where('id', $id)
|
||||
->update($data);
|
||||
if(!Util::isEmpty($avatar)){
|
||||
$user->avatar = $avatar;
|
||||
}
|
||||
|
||||
$res = $user->save();
|
||||
|
||||
if ($res) {
|
||||
return Util::success($res, trans('save_success'));
|
||||
|
||||
@@ -121,4 +121,11 @@ class Customer extends Model
|
||||
return $this->belongsToMany(Tag::class, 'customer_tag', 'customer_id', 'tag_id')
|
||||
->withTimestamps(); // 如果需要记录关联时间
|
||||
}
|
||||
|
||||
|
||||
// 定义与 变更历史 的一对多关系
|
||||
public function his()
|
||||
{
|
||||
return $this->hasMany(CustomerHis::class, 'customer_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
|
||||
use app\util\Util;
|
||||
use config\constants\Constants;
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Support\Carbon;
|
||||
use support\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CustomerHis extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'customer_his';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
//设置黑名单
|
||||
protected $guarded = ['id','created_at'];
|
||||
|
||||
// 指定日期字段存储格式为时间戳
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
|
||||
// 'created_at' => 'timestamp', // 指定序列化格式
|
||||
];
|
||||
|
||||
/**
|
||||
* 重新格式化时间
|
||||
* @param DateTimeInterface $date
|
||||
* @return string
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date): string
|
||||
{
|
||||
return $date->format(Carbon::parse($date)->toDateTimeString());
|
||||
}
|
||||
|
||||
// 定义反向多对一关联
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class, 'customer_id', 'id');
|
||||
}
|
||||
|
||||
// 禁用 updated_at 的自动更新
|
||||
public function setUpdatedAt($value)
|
||||
{
|
||||
return $this; // 不做任何操作
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\process;
|
||||
|
||||
use app\controller\FeishuController;
|
||||
use app\model\Customer;
|
||||
use app\model\CustomerHis;
|
||||
use app\model\FeishuUser;
|
||||
use app\model\User;
|
||||
use support\Log;
|
||||
@@ -71,6 +72,29 @@ class Task
|
||||
Log::info('send follow start',[time()]);
|
||||
});
|
||||
|
||||
|
||||
// 每小时执行一次
|
||||
new Crontab('0 10 * * * *', function(){
|
||||
echo date('Y-m-d H:i:s') . "\n";
|
||||
Log::info('send high seas start',[time()]);
|
||||
|
||||
$where = [
|
||||
['deleted_at', '<=', time() - 3600],
|
||||
['user_id', '<>', 0],
|
||||
];
|
||||
$customer = Customer::where($where)->onlyTrashed()->get();
|
||||
foreach ($customer as $item) {
|
||||
$item->update(['user_id' => 0]);
|
||||
CustomerHis::create([
|
||||
'customer_id' => $item->_id,
|
||||
'user_his' => $item->user_id,
|
||||
'user_id' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
Log::info('send high seas start',[time()]);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user