递归查询下属公司的文章和充值记录

This commit is contained in:
luofei 2023-07-21 10:46:00 +08:00
parent a814c6a977
commit eb86ede96b
4 changed files with 31 additions and 2 deletions

View File

@ -15,9 +15,11 @@
namespace app\adminapi\lists\article;
use app\adminapi\lists\BaseAdminDataLists;
use app\adminapi\logic\CompanyLogic;
use app\common\lists\ListsSearchInterface;
use app\common\lists\ListsSortInterface;
use app\common\model\article\Article;
use app\common\model\Company;
/**
* 资讯列表
@ -71,7 +73,12 @@ class ArticleLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function lists(): array
{
$ArticleLists = Article::where($this->searchWhere)
$query = Article::where($this->searchWhere);
$companyIds = CompanyLogic::getAllCompanyIds();
if (!empty($companyIds)) {
$query->whereIn('company_id', $companyIds);
}
$ArticleLists = $query->with(['company'])
->append(['cate_name', 'click'])
->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder)

View File

@ -15,6 +15,7 @@
namespace app\adminapi\lists\recharge;
use app\adminapi\lists\BaseAdminDataLists;
use app\adminapi\logic\CompanyLogic;
use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSearchInterface;
use app\common\model\recharge\RechargeOrder;
@ -103,13 +104,17 @@ class RechargeLists extends BaseAdminDataLists implements ListsSearchInterface,
*/
public function lists(): array
{
$companyIds = CompanyLogic::getAllCompanyIds();
$field = 'ro.id,ro.sn,ro.order_amount,ro.pay_way,ro.pay_time,ro.pay_status,ro.create_time,ro.refund_status';
$field .= ',u.avatar,u.nickname';
$field .= ',u.avatar,u.nickname,a.company_id';
$lists = RechargeOrder::alias('ro')
->join('user u', 'u.id = ro.user_id')
->join('admin a', 'u.admin_id = a.id')
->join('company c', 'a.company_id = c.id')
->field($field)
->where($this->queryWhere())
->where($this->searchWhere)
->where('c.id', 'in', $companyIds)
->order('ro.id', 'desc')
->limit($this->limitOffset, $this->limitLength)
->append(['pay_status_text', 'pay_way_text'])

View File

@ -187,4 +187,15 @@ class CompanyLogic extends BaseLogic
$model->save();
}
public static function getAllCompanyIds()
{
$companyId = request()->adminInfo['company_id'] ?? 0;
$companyIds[] = $companyId;
$companies = loopGetChild(Company::class, $companyId, 'level_one', 'id,level_one');
if (!empty($companies)) {
$companyIds = array_merge(array_column($companies, 'id'), $companyIds);
}
return array_filter($companyIds);
}
}

View File

@ -16,6 +16,7 @@ namespace app\common\model\article;
use app\common\enum\YesNoEnum;
use app\common\model\BaseModel;
use app\common\model\Company;
use think\model\concern\SoftDelete;
/**
@ -109,4 +110,9 @@ class Article extends BaseModel
->toArray();
}
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id')->field('id,company_name');
}
}