更新细节

This commit is contained in:
yaooo 2023-12-23 14:36:53 +08:00
parent 0fe251ad2a
commit 490bde6bb4
3 changed files with 49 additions and 10 deletions

View File

@ -19,7 +19,7 @@ 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;
/**
* Custom列表
@ -39,7 +39,7 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['name', 'custom_type', 'phone', 'credit_rating', 'province', 'city', 'status'],
'=' => ['c.name', 'c.custom_type', 'c.phone', 'c.credit_rating', 'c.province', 'c.city', 'c.status'],
];
}
@ -55,12 +55,16 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
return Custom::where($this->searchWhere)
->with('province')
->field(['*'])
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(['id' => 'desc'])
->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)) {
@ -84,9 +88,10 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
$item['last_follow_date'] = '超过60天内';
}
$item['next_follow_date'] = $customFollow['next_follow_date'];
}
}
return $item;
})->toArray();
})
->toArray();
}
@ -98,7 +103,11 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
return Custom::where($this->searchWhere)->count();
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();
}
}

View File

@ -41,6 +41,8 @@ class CustomLogic extends BaseLogic
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,
@ -89,6 +91,8 @@ 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,
@ -147,6 +151,10 @@ class CustomLogic extends BaseLogic
*/
public static function detail($params): array
{
return Custom::findOrEmpty($params['id'])->toArray();
$custom = Custom::findOrEmpty($params['id']);
$custom->org;
$custom->dept;
$custom->other_contacts = json_decode($custom->other_contacts, true);
return $custom->toArray();
}
}

View File

@ -36,4 +36,26 @@ class Custom extends BaseModel
{
return $this->hasOne(GeoProvince::class, 'province_code','province');
}
/**
* @notes 关联org
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/12/20 11:01
*/
public function org()
{
return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id');
}
/**
* @notes 关联dept
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/12/20 11:01
*/
public function dept()
{
return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id');
}
}