1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- use think\response\Json;
- class BudgetDepTotal extends Model
- {
- public function lists($page,$size,$budgetId,$companyId,$orgId){
- $map[] = ['org_id','=',$orgId];
- if($budgetId > 0){
- $map[] = ['budget_id','=',$budgetId];
- }
- if($companyId > 0){
- $map[] = ['company_id','=',$companyId];
- }
- $lists = Db::name('budget_dep_total')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['budgetName'] = Db::name('budget')->where('id',$v['budget_id'])->value('title');
- $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name');
- $lists[$k]['companyName'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $total = Db::name('budget_dep_total')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function info($id){
- $info = Db::name('budget_dep_total')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- $budget = Db::name('budget')->where('id',$info['budget_id'])->find();
- if(!$budget){
- HelpHander::error('记录 不存在');
- }
- $company = Db::name('company')->where('id',$info['company_id'])->value('title');
- $items = Db::name('budget_dep')
- ->alias('bd')
- ->join('budget_items b','b.id = bd.items_id')
- ->where('bd.dep_id',$info['dep_id'])
- ->where('bd.budget_id',$info['budget_id'])
- ->where('bd.company_id',$info['company_id'])
- ->where('bd.org_id',$info['org_id'])
- ->field('bd.money,bd.money2,bd.money3,bd.org_id,b.title,bd.budget_id,b.id,bd.intro,b.remark,b.sorts')
- ->order('b.sorts asc,id asc')
- ->select();
- return [
- 'year' => $budget['year'],
- 'title' => $budget['title'],
- 'company' => $company,
- 'items' => $items?$items:[]
- ];
- }
- }
|