BudgetDepTotal.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. use think\response\Json;
  7. class BudgetDepTotal extends Model
  8. {
  9. public function lists($page,$size,$budgetId,$companyId,$orgId){
  10. $map[] = ['org_id','=',$orgId];
  11. if($budgetId > 0){
  12. $map[] = ['budget_id','=',$budgetId];
  13. }
  14. if($companyId > 0){
  15. $map[] = ['company_id','=',$companyId];
  16. }
  17. $lists = Db::name('budget_dep_total')
  18. ->where($map)
  19. ->page($page,$size)
  20. ->order('id desc')
  21. ->select();
  22. $lists = $lists?$lists:[];
  23. foreach ($lists as $k=>$v){
  24. // $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  25. $lists[$k]['budgetName'] = Db::name('budget')->where('id',$v['budget_id'])->value('title');
  26. $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name');
  27. $lists[$k]['companyName'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  28. }
  29. $total = Db::name('budget_dep_total')->where($map)->count();
  30. $data = [
  31. 'total' => $total,
  32. 'list' => $lists?$lists:[]
  33. ];
  34. return $data;
  35. }
  36. public function info($id){
  37. $info = Db::name('budget_dep_total')->where('id',$id)->find();
  38. if(!$info){
  39. HelpHander::error('记录不存在');
  40. }
  41. $budget = Db::name('budget')->where('id',$info['budget_id'])->find();
  42. if(!$budget){
  43. HelpHander::error('记录 不存在');
  44. }
  45. $company = Db::name('company')->where('id',$info['company_id'])->value('title');
  46. $items = Db::name('budget_dep')
  47. ->alias('bd')
  48. ->join('budget_items b','b.id = bd.items_id')
  49. ->where('bd.dep_id',$info['dep_id'])
  50. ->where('bd.budget_id',$info['budget_id'])
  51. ->where('bd.company_id',$info['company_id'])
  52. ->where('bd.org_id',$info['org_id'])
  53. ->field('bd.money,bd.money2,bd.money3,bd.org_id,b.title,bd.budget_id,b.id,bd.intro,b.remark,b.sorts')
  54. ->order('b.sorts asc,id asc')
  55. ->select();
  56. return [
  57. 'year' => $budget['year'],
  58. 'title' => $budget['title'],
  59. 'company' => $company,
  60. 'items' => $items?$items:[]
  61. ];
  62. }
  63. }