更新细节

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\Custom;
use app\common\model\custom_follow\CustomFollow; use app\common\model\custom_follow\CustomFollow;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use think\facade\Db;
/** /**
* Custom列表 * Custom列表
@ -39,7 +39,7 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ 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 public function lists(): array
{ {
return Custom::where($this->searchWhere) return Db::name('Custom')->alias('c')
->with('province') ->where($this->searchWhere)
->field(['*']) ->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) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['c.id' => 'desc'])
->select()->each(function($item, $key){ ->select()->each(function($item, $key){
//关联数据后续添加
if (!empty($item['other_contacts'])) { if (!empty($item['other_contacts'])) {
$otherContactsArray = json_decode($item['other_contacts'], true); $otherContactsArray = json_decode($item['other_contacts'], true);
if (is_array($otherContactsArray)) { if (is_array($otherContactsArray)) {
@ -86,7 +90,8 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
$item['next_follow_date'] = $customFollow['next_follow_date']; $item['next_follow_date'] = $customFollow['next_follow_date'];
} }
return $item; return $item;
})->toArray(); })
->toArray();
} }
@ -98,7 +103,11 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function count(): int 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(); Db::startTrans();
try { try {
Custom::create([ Custom::create([
'org_id' => $params['org_id'] ?? 0,
'dept_id' => $params['dept_id'] ?? 0,
'name' => $params['name'] ?? '', 'name' => $params['name'] ?? '',
'custom_type' => $params['custom_type'] ?? 0, 'custom_type' => $params['custom_type'] ?? 0,
'parent_company' => $params['parent_company'] ?? 0, 'parent_company' => $params['parent_company'] ?? 0,
@ -89,6 +91,8 @@ class CustomLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
Custom::where('id', $params['id'])->update([ Custom::where('id', $params['id'])->update([
'org_id' => $params['org_id'] ?? 0,
'dept_id' => $params['dept_id'] ?? 0,
'name' => $params['name'] ?? '', 'name' => $params['name'] ?? '',
'custom_type' => $params['custom_type'] ?? 0, 'custom_type' => $params['custom_type'] ?? 0,
'parent_company' => $params['parent_company'] ?? 0, 'parent_company' => $params['parent_company'] ?? 0,
@ -147,6 +151,10 @@ class CustomLogic extends BaseLogic
*/ */
public static function detail($params): array 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'); 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');
}
} }