Merge pull request 'update custom modules' (#99) from zhangwei into dev
Reviewed-on: #99
This commit is contained in:
commit
2d2caaa57f
@ -52,7 +52,7 @@ class CustomController extends BaseAdminController
|
||||
public function add()
|
||||
{
|
||||
$params = (new CustomValidate())->post()->goCheck('add');
|
||||
$result = CustomLogic::add($params);
|
||||
$result = CustomLogic::add($params,$this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
|
@ -13,13 +13,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\adminapi\controller\custom_follow;
|
||||
namespace app\adminapi\controller\custom;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\custom_follow\CustomFollowLists;
|
||||
use app\adminapi\logic\custom_follow\CustomFollowLogic;
|
||||
use app\adminapi\validate\custom_follow\CustomFollowValidate;
|
||||
use app\adminapi\lists\custom\CustomFollowLists;
|
||||
use app\adminapi\logic\custom\CustomFollowLogic;
|
||||
use app\adminapi\validate\custom\CustomFollowValidate;
|
||||
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ class CustomFollowController extends BaseAdminController
|
||||
public function add()
|
||||
{
|
||||
$params = (new CustomFollowValidate())->post()->goCheck('add');
|
||||
$result = CustomFollowLogic::add($params);
|
||||
$result = CustomFollowLogic::add($params,$this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
@ -69,7 +69,7 @@ class CustomFollowController extends BaseAdminController
|
||||
public function edit()
|
||||
{
|
||||
$params = (new CustomFollowValidate())->post()->goCheck('edit');
|
||||
$result = CustomFollowLogic::edit($params);
|
||||
$result = CustomFollowLogic::edit($params,$this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
@ -16,8 +16,11 @@ namespace app\adminapi\lists\custom;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom\CustomContacts;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
|
||||
|
||||
/**
|
||||
@ -38,7 +41,7 @@ class CustomContactsLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['custom_id', 'name', 'position', 'phone', 'telephone', 'email', 'notes', 'annex'],
|
||||
'%like%' => ['name', 'position', 'phone', 'telephone', 'email'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -54,11 +57,18 @@ class CustomContactsLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return CustomContacts::where($this->searchWhere)
|
||||
->field(['*'])
|
||||
return CustomContacts::field('id,custom_id,name,position,phone,telephone,email,notes,annex')->where($this->searchWhere)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->select()->each(function($item){
|
||||
$custom = Custom::field('org_id,dept_id')->where('id',$item['custom_id'])->findOrEmpty();
|
||||
$org = Orgs::field('name')->where('id',$custom['org_id'])->findOrEmpty();
|
||||
$dept = Dept::field('name')->where('id',$custom['dept_id'])->findOrEmpty();
|
||||
$item['org_name'] = $org['name'];
|
||||
$item['dept_name'] = $dept['name'];
|
||||
unset($item['custom_id']);
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,14 @@
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\lists\custom_follow;
|
||||
namespace app\adminapi\lists\custom;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom_follow\CustomFollow;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom\CustomFollow;
|
||||
|
||||
|
||||
/**
|
||||
@ -39,7 +40,8 @@ class CustomFollowLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['custom_id', 'contacts', 'date', 'types', 'admin_id', 'description', 'annex', 'coordinate', 'next_follow_date', 'status'],
|
||||
'%like%' => ['name', 'contacts', 'executor'],
|
||||
'=' => ['types']
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,13 +57,23 @@ class CustomFollowLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return CustomFollow::where($this->searchWhere)
|
||||
->field(['*'])
|
||||
$params = $this->request->get();
|
||||
$where = [];
|
||||
if(isset($params['custom_name']) && $params['custom_name'] != ''){
|
||||
$custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id');
|
||||
$where[] = ['custom_id','in',$custom_ids];
|
||||
}
|
||||
return CustomFollow::field('id,custom_id,name,contacts,date,types,executor,description,coordinate,next_follow_date,add_user,update_user,create_time,update_time')
|
||||
->where($this->searchWhere)->where($where)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$item['types_text'] = $item->types_text;
|
||||
$custom = Custom::field('name')->where('id',$item['custom_id'])->findOrEmpty();
|
||||
$admin = Admin::where('id','in',[$item['add_user'],$item['update_user']])->column('name','id');
|
||||
$item['custom_name'] = $custom['name'];
|
||||
$item['add_user'] = $admin[$item['add_user']];
|
||||
$item['update_user'] = $admin[$item['update_user']];
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
@ -76,7 +88,13 @@ class CustomFollowLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return CustomFollow::where($this->searchWhere)->count();
|
||||
$params = $this->request->get();
|
||||
$where = [];
|
||||
if(isset($params['custom_name']) && $params['custom_name'] != ''){
|
||||
$custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id');
|
||||
$where[] = ['custom_id','in',$custom_ids];
|
||||
}
|
||||
return CustomFollow::where($this->searchWhere)->where($where)->count();
|
||||
}
|
||||
|
||||
}
|
@ -16,10 +16,10 @@ namespace app\adminapi\lists\custom;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom_follow\CustomFollow;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use think\facade\Db;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\GeoProvince;
|
||||
|
||||
/**
|
||||
* Custom列表
|
||||
@ -39,7 +39,8 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['c.org_id', 'c.dept_id', 'c.name', 'c.custom_type', 'c.phone', 'c.credit_rating', 'c.province', 'c.city', 'c.status'],
|
||||
'=' => ['custom_type', 'phone', 'province'],
|
||||
'%like%' => ['name','master_name']
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,43 +56,56 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('Custom')->alias('c')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('c.delete_time')
|
||||
->leftJoin('orgs o','o.id = c.org_id')
|
||||
->leftJoin('dept d','d.id = c.dept_id')
|
||||
->field('c.*, d.name as dept_name, o.name as org_name')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['c.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
//关联数据后续添加
|
||||
if (!empty($item['other_contacts'])) {
|
||||
$otherContactsArray = json_decode($item['other_contacts'], true);
|
||||
if (is_array($otherContactsArray)) {
|
||||
$item['other_contacts'] = $otherContactsArray;
|
||||
}
|
||||
}
|
||||
$item['last_follow_date'] = '-';
|
||||
$item['next_follow_date'] = '-';
|
||||
$customFollow = CustomFollow::where('custom_id', $item['id'])->order('id', 'desc')->limit(1)->findOrEmpty();
|
||||
if (!$customFollow->isEmpty()) {
|
||||
$interval = date_diff(date_create($customFollow['date']), date_create(date('Y-m-d H:i:s')));
|
||||
if ($interval->days <= 3) {
|
||||
$item['last_follow_date'] = $interval->days . '天内';
|
||||
} else if ($interval->days <= 7) {
|
||||
$item['last_follow_date'] = '1周内';
|
||||
} else if ($interval->days <= 30) {
|
||||
$item['last_follow_date'] = '30天内';
|
||||
} else if ($interval->days <= 60) {
|
||||
$item['last_follow_date'] = '60天内';
|
||||
} else {
|
||||
$item['last_follow_date'] = '超过60天内';
|
||||
}
|
||||
$item['next_follow_date'] = $customFollow['next_follow_date'];
|
||||
}
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
// return Db::name('Custom')->alias('c')
|
||||
// ->where($this->searchWhere)
|
||||
// ->whereNull('c.delete_time')
|
||||
// ->leftJoin('orgs o','o.id = c.org_id')
|
||||
// ->leftJoin('dept d','d.id = c.dept_id')
|
||||
// ->field('c.*, d.name as dept_name, o.name as org_name')
|
||||
// ->limit($this->limitOffset, $this->limitLength)
|
||||
// ->order(['c.id' => 'desc'])
|
||||
// ->select()->each(function($item, $key){
|
||||
// //关联数据后续添加
|
||||
// if (!empty($item['other_contacts'])) {
|
||||
// $otherContactsArray = json_decode($item['other_contacts'], true);
|
||||
// if (is_array($otherContactsArray)) {
|
||||
// $item['other_contacts'] = $otherContactsArray;
|
||||
// }
|
||||
// }
|
||||
// $item['last_follow_date'] = '-';
|
||||
// $item['next_follow_date'] = '-';
|
||||
// $customFollow = CustomFollow::where('custom_id', $item['id'])->order('id', 'desc')->limit(1)->findOrEmpty();
|
||||
// if (!$customFollow->isEmpty()) {
|
||||
// $interval = date_diff(date_create($customFollow['date']), date_create(date('Y-m-d H:i:s')));
|
||||
// if ($interval->days <= 3) {
|
||||
// $item['last_follow_date'] = $interval->days . '天内';
|
||||
// } else if ($interval->days <= 7) {
|
||||
// $item['last_follow_date'] = '1周内';
|
||||
// } else if ($interval->days <= 30) {
|
||||
// $item['last_follow_date'] = '30天内';
|
||||
// } else if ($interval->days <= 60) {
|
||||
// $item['last_follow_date'] = '60天内';
|
||||
// } else {
|
||||
// $item['last_follow_date'] = '超过60天内';
|
||||
// }
|
||||
// $item['next_follow_date'] = $customFollow['next_follow_date'];
|
||||
// }
|
||||
// return $item;
|
||||
// })
|
||||
// ->toArray();
|
||||
return Custom::field('id,name,custom_type,province,master_name,master_position,master_telephone,master_phone,notes,add_user,create_time')
|
||||
->where($this->searchWhere)->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$item['custom_type_text'] = $item->custom_type_text;
|
||||
$admin = Admin::field('id,name')->where('id',$item['add_user'])->findOrEmpty();
|
||||
$province = GeoProvince::field('province_name')->where('province_code',$item['province'])->findOrEmpty();
|
||||
$item['add_user_name'] = $admin['name'];
|
||||
$item['province_name'] = $province['province_name'];
|
||||
unset($item['province'],$item['add_user']);
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@ -103,11 +117,7 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Db::name('Custom')->alias('c')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('c.delete_time')
|
||||
->leftJoin('orgs o','o.id = c.org_id')
|
||||
->leftJoin('dept d','d.id = c.dept_id')->count();
|
||||
return Custom::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
namespace app\adminapi\logic\custom;
|
||||
|
||||
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom\CustomContacts;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
@ -41,16 +42,15 @@ class CustomContactsLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
CustomContacts::create([
|
||||
'custom_id' => $params['custom_id'] ?? 0,
|
||||
'name' => $params['name'] ?? '',
|
||||
'custom_id' => $params['custom_id'],
|
||||
'name' => $params['name'],
|
||||
'position' => $params['position'] ?? '',
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'telephone' => $params['telephone'] ?? '',
|
||||
'email' => $params['email'] ?? '',
|
||||
'notes' => $params['notes'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'annex' => $params['annex'] ?? null,
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -72,17 +72,17 @@ class CustomContactsLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = CustomContacts::field('annex')->where('id',$params['id'])->findOrEmpty();
|
||||
CustomContacts::where('id', $params['id'])->update([
|
||||
'custom_id' => $params['custom_id'] ?? 0,
|
||||
'name' => $params['name'] ?? '',
|
||||
'custom_id' => $params['custom_id'],
|
||||
'name' => $params['name'],
|
||||
'position' => $params['position'] ?? '',
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'telephone' => $params['telephone'] ?? '',
|
||||
'email' => $params['email'] ?? '',
|
||||
'notes' => $params['notes'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'annex' => $params['annex'] ?? $data['annex'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -115,9 +115,9 @@ class CustomContactsLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$customContacts = CustomContacts::findOrEmpty($params['id']);
|
||||
$customContacts->custom = $customContacts->custom;
|
||||
$customContacts->annex = json_decode($customContacts->annex, true);
|
||||
return $customContacts->toArray();
|
||||
$data = CustomContacts::field('id,custom_id,name,position,phone,telephone,email,notes,annex')->findOrEmpty($params['id'])->toArray();
|
||||
$custom = Custom::field('name')->where('id',$data['custom_id'])->findOrEmpty();
|
||||
$data['custom_name'] = $custom['name'];
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -12,11 +12,12 @@
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\logic\custom_follow;
|
||||
namespace app\adminapi\logic\custom;
|
||||
|
||||
|
||||
use app\common\model\custom_follow\CustomFollow;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom\CustomFollow;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -36,23 +37,24 @@ class CustomFollowLogic extends BaseLogic
|
||||
* @author likeadmin
|
||||
* @date 2023/11/12 13:40
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
public static function add(array $params,$admin_id): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
CustomFollow::create([
|
||||
'custom_id' => $params['custom_id'] ?? 0,
|
||||
'custom_id' => $params['custom_id'],
|
||||
'name' => $params['name'],
|
||||
'contacts' => $params['contacts'] ?? '',
|
||||
'date' => strtotime($params['date']),
|
||||
'types' => $params['types'] ?? 0,
|
||||
'admin_id' => $params['admin_id'] ?? 0,
|
||||
'types' => $params['types'],
|
||||
'description' => $params['description'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'coordinate' => $params['coordinate'] ?? 0,
|
||||
'annex' => $params['annex'] ?? null,
|
||||
'coordinate' => $params['coordinate'] ?? '',
|
||||
'executor' => $params['executor'] ?? '',
|
||||
'next_follow_date' => strtotime($params['next_follow_date']),
|
||||
'status' => $params['status'] ?? 0
|
||||
'add_user' => $admin_id,
|
||||
'update_user' => $admin_id
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -70,23 +72,24 @@ class CustomFollowLogic extends BaseLogic
|
||||
* @author likeadmin
|
||||
* @date 2023/11/12 13:40
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
public static function edit(array $params,$admin_id): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
CustomFollow::where('id', $params['id'])->update([
|
||||
'custom_id' => $params['custom_id'] ?? 0,
|
||||
'contacts' => $params['contacts'] ?? '',
|
||||
'date' => strtotime($params['date']),
|
||||
'types' => $params['types'] ?? 0,
|
||||
'admin_id' => $params['admin_id'] ?? 0,
|
||||
'description' => $params['description'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'coordinate' => $params['coordinate'] ?? 0,
|
||||
'next_follow_date' => strtotime($params['next_follow_date']),
|
||||
'status' => $params['status'] ?? 0
|
||||
'custom_id' => $params['custom_id'],
|
||||
'name' => $params['name'],
|
||||
'contacts' => $params['contacts'] ?? '',
|
||||
'date' => strtotime($params['date']),
|
||||
'types' => $params['types'],
|
||||
'description' => $params['description'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] :null,
|
||||
'coordinate' => $params['coordinate'] ?? '',
|
||||
'executor' => $params['executor'] ?? '',
|
||||
'next_follow_date' => strtotime($params['next_follow_date']),
|
||||
'update_user' => $admin_id,
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -119,9 +122,9 @@ class CustomFollowLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$customFollow = CustomFollow::findOrEmpty($params['id']);
|
||||
$customFollow->custom;
|
||||
$customFollow->annex = json_decode($customFollow->annex, true);
|
||||
return $customFollow->toArray();
|
||||
$data = CustomFollow::field('id,custom_id,name,contacts,date,types,description,annex,coordinate,next_follow_date,executor')->findOrEmpty($params['id']);
|
||||
$custom = Custom::field('name')->where('id',$data['custom_id'])->findOrEmpty();
|
||||
$data['custom_name'] = $custom['name'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ namespace app\adminapi\logic\custom;
|
||||
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\custom\CustomContacts;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -36,24 +37,25 @@ class CustomLogic extends BaseLogic
|
||||
* @author likeadmin
|
||||
* @date 2023/11/11 22:10
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
public static function add(array $params,$admin_id): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Custom::create([
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'name' => $params['name'] ?? '',
|
||||
'custom_type' => $params['custom_type'] ?? 0,
|
||||
'parent_company' => $params['parent_company'] ?? 0,
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'credit_rating' => $params['credit_rating'] ?? 0,
|
||||
$other_contacts = json_decode($params['other_contacts'],true);
|
||||
$customRes = Custom::create([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'name' => $params['name'],
|
||||
'custom_type' => $params['custom_type'],
|
||||
'parent_company' => $params['parent_company'] ?? '',
|
||||
'phone' => $params['phone'],
|
||||
'credit_rating' => $params['credit_rating'],
|
||||
'province' => $params['province'] ?? 0,
|
||||
'city' => $params['city'] ?? 0,
|
||||
'area' => $params['area'] ?? 0,
|
||||
'address' => $params['address'] ?? '',
|
||||
'notes' => $params['notes'] ?? '',
|
||||
'master_name' => $params['master_name'] ?? '',
|
||||
'master_name' => $params['master_name'],
|
||||
'master_position' => $params['master_position'] ?? '',
|
||||
'master_phone' => $params['master_phone'] ?? '',
|
||||
'master_email' => $params['master_email'] ?? '',
|
||||
@ -65,10 +67,22 @@ class CustomLogic extends BaseLogic
|
||||
'company_telephone' => $params['company_telephone'] ?? '',
|
||||
'bank_name' => $params['bank_name'] ?? '',
|
||||
'bank_account' => $params['bank_account'] ?? '',
|
||||
'other_contacts' => json_encode($params['other_contacts']),
|
||||
'status' => $params['status'] ?? 0,
|
||||
'add_user' => $admin_id,
|
||||
]);
|
||||
|
||||
if(!empty($other_contacts)){
|
||||
foreach($other_contacts as $v){
|
||||
CustomContacts::create([
|
||||
'custom_id' => $customRes->id,
|
||||
'name' => $v['name'],
|
||||
'position' => $v['position'] ?? '',
|
||||
'phone' => $v['phone'] ?? '',
|
||||
'telephone' => $v['telephone'] ?? '',
|
||||
'email' => $v['email'] ?? '',
|
||||
'notes' => $v['notes'] ?? '',
|
||||
'annex' => !empty($v['annex']) ? json_encode($v['annex']) : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -91,13 +105,13 @@ class CustomLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
Custom::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'name' => $params['name'] ?? '',
|
||||
'custom_type' => $params['custom_type'] ?? 0,
|
||||
'parent_company' => $params['parent_company'] ?? 0,
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'credit_rating' => $params['credit_rating'] ?? 0,
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'name' => $params['name'],
|
||||
'custom_type' => $params['custom_type'],
|
||||
'parent_company' => $params['parent_company'] ?? '',
|
||||
'phone' => $params['phone'],
|
||||
'credit_rating' => $params['credit_rating'],
|
||||
'province' => $params['province'] ?? 0,
|
||||
'city' => $params['city'] ?? 0,
|
||||
'area' => $params['area'] ?? 0,
|
||||
@ -115,10 +129,8 @@ class CustomLogic extends BaseLogic
|
||||
'company_telephone' => $params['company_telephone'] ?? '',
|
||||
'bank_name' => $params['bank_name'] ?? '',
|
||||
'bank_account' => $params['bank_account'] ?? '',
|
||||
'other_contacts' => json_encode($params['other_contacts']),
|
||||
'status' => $params['status'] ?? 0,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -152,11 +164,11 @@ class CustomLogic extends BaseLogic
|
||||
public static function detail($params): array
|
||||
{
|
||||
$custom = Custom::findOrEmpty($params['id']);
|
||||
$parent_company = $custom::field('name')->where('id',$custom['parent_company'])->findOrEmpty();
|
||||
$custom['parent_company_name'] = $parent_company['name'];
|
||||
$custom->org;
|
||||
$custom->dept;
|
||||
$custom->other_contacts = json_decode($custom->other_contacts, true);
|
||||
$custom['org_name'] = $custom->org->name;
|
||||
$custom['dept_name'] = $custom->dept->name;
|
||||
$custom['custom_type_text'] = $custom->custom_type_text;
|
||||
$custom['credit_rating_text'] = $custom->credit_rating_text;
|
||||
unset($custom['org'],$custom['dept']);
|
||||
return $custom->toArray();
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@
|
||||
namespace app\adminapi\validate\custom;
|
||||
|
||||
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\custom\CustomContacts;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -32,18 +34,21 @@ class CustomContactsValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'custom_id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'custom_id' => 'custom_id',
|
||||
'custom_id' => 'require|checkCustom',
|
||||
'name' => 'require',
|
||||
'phone' => 'mobile|unique:'.CustomContacts::class,
|
||||
'email' => 'email',
|
||||
'annex' => 'checkAnnex',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'custom_id.require' => '请选择客户',
|
||||
'name.require' => '请填写姓名',
|
||||
'phone.mobile' => '手机号码格式错误',
|
||||
'phone.unique' => '手机号码已存在',
|
||||
'email.email' => '邮箱格式错误',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
@ -54,7 +59,7 @@ class CustomContactsValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['custom_id']);
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
@ -65,9 +70,7 @@ class CustomContactsValidate extends BaseValidate
|
||||
* @date 2023/11/11 22:56
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','custom_id']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -92,5 +95,25 @@ class CustomContactsValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkCustom($value): bool|string
|
||||
{
|
||||
$custom = Custom::where('id',$value)->findOrEmpty();
|
||||
if($custom->isEmpty()){
|
||||
return '客户不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件数据格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -12,9 +12,11 @@
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\custom_follow;
|
||||
namespace app\adminapi\validate\custom;
|
||||
|
||||
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -32,18 +34,23 @@ class CustomFollowValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'custom_id' => 'require',
|
||||
'name' => 'require',
|
||||
'custom_id' => 'require|checkCustom',
|
||||
'date' => 'require|dateFormat:Y-m-d',
|
||||
'types' => 'require|checkTypes',
|
||||
'next_follow_date' => 'dateFormat:Y-m-d|checkNext',
|
||||
'annex' => 'checkAnnex',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'name.require' => '请填写主题',
|
||||
'custom_id.require' => '请选择客户',
|
||||
'date.require' => '请选择日期',
|
||||
'date.dateFormat' => '日期格式错误',
|
||||
'types.require' => '请选择类型',
|
||||
'next_follow_date.dateFormat' => '下次回访日期格式错误',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
@ -64,9 +71,7 @@ class CustomFollowValidate extends BaseValidate
|
||||
* @date 2023/11/12 13:40
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'custom_id']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -91,5 +96,44 @@ class CustomFollowValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkCustom($value): bool|string
|
||||
{
|
||||
$custom = Custom::where('id',$value)->findOrEmpty();
|
||||
if($custom->isEmpty()){
|
||||
return '客户不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkTypes($value): bool|string
|
||||
{
|
||||
$dictData = DictData::where('type_value','custom_follow_type')->column('value');
|
||||
if(!in_array($value,$dictData)){
|
||||
return '类型无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkNext($value,$rule,$data): bool|string
|
||||
{
|
||||
if(!empty($value)){
|
||||
if(strtotime($value) - strtotime($data['date']) <=0){
|
||||
return '下次回访日期不能小于上面选择的日期';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,9 @@
|
||||
namespace app\adminapi\validate\custom;
|
||||
|
||||
use app\common\model\custom\Custom;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -32,17 +35,31 @@ class CustomValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require|checkName',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'name' => 'require|unique:'.Custom::class,
|
||||
'custom_type' => 'require|checkType',
|
||||
'phone' => 'require',
|
||||
'credit_rating' => 'require|checkRat',
|
||||
'master_name' => 'require',
|
||||
'master_phone' => 'mobile',
|
||||
'master_email' => 'email',
|
||||
'other_contacts' => 'checkContacts'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'name' => '客户名称'
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'name.require' => '请填写客户名称',
|
||||
'name.unique' => '客户名称已存在',
|
||||
'custom_type.require' => '请选择客户属性',
|
||||
'phone.require' => '请填写客户电话',
|
||||
'credit_rating.require' => '请选择信用度',
|
||||
'master_name.require' => '请填写主要负责人姓名',
|
||||
'master_phone.mobile' => '主要负责人手机号格式错误',
|
||||
'master_email.email' => '主要负责人邮箱格式错误',
|
||||
];
|
||||
|
||||
|
||||
@ -65,9 +82,7 @@ class CustomValidate extends BaseValidate
|
||||
* @date 2023/11/11 22:10
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'name']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -92,18 +107,63 @@ class CustomValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkName($value, $rule, $data)
|
||||
{
|
||||
if (!empty($data['id'])) {
|
||||
$custom = Custom::where('name', $value)->where('id', '<>', $data['id'])->findOrEmpty();
|
||||
} else {
|
||||
$custom = Custom::where('name', $value)->findOrEmpty();
|
||||
}
|
||||
if (!$custom->isEmpty()) {
|
||||
return '客户已存在!';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkOrg($value): bool|string
|
||||
{
|
||||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||||
if($org->isEmpty()){
|
||||
return '组织不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkDept($value,$rule,$data): bool|string
|
||||
{
|
||||
$dept = Dept::where('id',$value)->findOrEmpty();
|
||||
if($dept->isEmpty()){
|
||||
return '部门不存在';
|
||||
}
|
||||
if($dept['org_id'] != $data['org_id']){
|
||||
return '部门无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkType($value): bool|string
|
||||
{
|
||||
$dictData = DictData::where('type_value','custom_type')->column('value');
|
||||
if(!in_array($value,$dictData)){
|
||||
return '客户属性无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkRat($value): bool|string
|
||||
{
|
||||
$dictData = DictData::where('type_value','credit_rating')->column('value');
|
||||
if(!in_array($value,$dictData)){
|
||||
return '信用度无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkContacts($value): bool|string
|
||||
{
|
||||
$params = json_decode($value,true);
|
||||
if(empty($params) || !is_array($params)){
|
||||
return '其他联系人数据格式错误';
|
||||
}
|
||||
foreach($params as $v){
|
||||
if(empty($v['name'])){
|
||||
return '请填写联系人姓名';
|
||||
}
|
||||
if(isset($v['annex']) && $v['annex'] != ''){
|
||||
if(!is_array($v['annex'])){
|
||||
return '联系人附件格式错误';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\common\model\custom;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\GeoProvince;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
@ -58,4 +59,14 @@ class Custom extends BaseModel
|
||||
{
|
||||
return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id');
|
||||
}
|
||||
|
||||
public function getCustomTypeTextAttr($value,$data){
|
||||
$dictData = DictData::where('type_value','custom_type')->column('name','value');
|
||||
return $dictData[$data['custom_type']];
|
||||
}
|
||||
|
||||
public function getCreditRatingTextAttr($value,$data){
|
||||
$dictData = DictData::where('type_value','credit_rating')->column('name','value');
|
||||
return $dictData[$data['credit_rating']];
|
||||
}
|
||||
}
|
@ -29,22 +29,8 @@ class CustomContacts extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'custom_contacts';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联关联客户
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author likeadmin
|
||||
* @date 2023/11/11 22:56
|
||||
*/
|
||||
public function customName()
|
||||
{
|
||||
return $this->hasOne(\app\common\model\custom\Custom::class, 'id', 'custom_id')->bind(['custom_name'=>'name']);
|
||||
}
|
||||
|
||||
public function custom()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\custom\Custom::class, 'custom_id');
|
||||
}
|
||||
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value) : null;
|
||||
}
|
||||
}
|
@ -12,10 +12,11 @@
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model\custom_follow;
|
||||
namespace app\common\model\custom;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\dict\DictData;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -30,25 +31,23 @@ class CustomFollow extends BaseModel
|
||||
protected $name = 'custom_follow';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getDateAttr($value)
|
||||
public function getDateAttr($value): string
|
||||
{
|
||||
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||
return empty($value) ? '' : date('Y-m-d', $value);
|
||||
}
|
||||
|
||||
public function getAnnexAttr($value)
|
||||
{
|
||||
return empty($value) ? '' : json_decode($value,true);
|
||||
return empty($value) ? null : json_decode($value,true);
|
||||
}
|
||||
|
||||
public function getNextFollowDateAttr($value)
|
||||
public function getNextFollowDateAttr($value): string
|
||||
{
|
||||
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
|
||||
return empty($value) ? '' : date('Y-m-d', $value);
|
||||
}
|
||||
|
||||
public function custom()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\custom\Custom::class, 'custom_id');
|
||||
public function getTypesTextAttr($value,$data){
|
||||
$dictData = DictData::where('type_value','custom_follow_type')->column('name','value');
|
||||
return $dictData[$data['types']];
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user