CostProject.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\model;
  3. use think\facade\Db;
  4. use think\model;
  5. class CostProject extends Model
  6. {
  7. /**
  8. * 获取分页列表
  9. * @param $where
  10. * @param $param
  11. */
  12. public function getCostProjectList($where, $param)
  13. {
  14. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  15. $order = empty($param['order']) ? 'id desc' : $param['order'];
  16. $list = self::where($where)->field('id,status,project_name,project_num,project_time,review_unit,review_head,review_head_phone,sent_review_unit,sent_review_head,sent_review_phone,construction_unit,construction_head,construction_phone,project_scale,engineering_category,engineering_type,project_region,fiscal_nature,sent_review_cost,preparation_amount,sent_review_amount,authorize_amount,review_add_amount,review_reduce_amount,report_time,charge_standard,invoicing__amount,invoicing__num,operate_head,operate_team,project_end_time')
  17. ->order($order)->paginate($rows, false, ['query' => $param]);
  18. return $list;
  19. }
  20. /**
  21. * 添加数据
  22. * @param $param
  23. */
  24. public function addCostProject($param)
  25. {
  26. $insertId = 0;
  27. try {
  28. $param['create_time'] = time();
  29. $insertId = self::strict(false)->field(true)->insertGetId($param);
  30. // halt($insertId);
  31. add_log('add', $insertId, $param);
  32. add_project_log("创建项目", $insertId);
  33. add_project_log('新增', $insertId);
  34. } catch (\Exception $e) {
  35. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  36. }
  37. return to_assign(0, '操作成功', ['aid' => $insertId]);
  38. }
  39. /**
  40. * 添加数据
  41. * @param $param
  42. */
  43. public function addConstructionPeople($param)
  44. {
  45. try {
  46. $param['create_time'] = time();
  47. self::where('id', $param['id'])->save($param);
  48. } catch (\Exception $e) {
  49. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  50. }
  51. return to_assign(0, '操作成功');
  52. }
  53. /**
  54. * 编辑信息
  55. * @param $param
  56. */
  57. public function editCostProject($param)
  58. {
  59. try {
  60. $param['update_time'] = time();
  61. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  62. add_log('edit', $param['id'], $param);
  63. } catch (\Exception $e) {
  64. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  65. }
  66. return to_assign(0, '操作成功');
  67. }
  68. /**
  69. * 根据id获取信息
  70. * @param $id
  71. */
  72. public function getCostProjectById($id)
  73. {
  74. $info = self::where('id', $id)->find();
  75. if(!empty($info["operate_team"])){
  76. $operate_team = explode(",", $info["operate_team"]);
  77. $name = Db::name("admin")->whereIn("id", $operate_team)->column("nickname");
  78. $names = implode(",",$name);
  79. $info["operate_team_names"] = $names;
  80. }
  81. if(!empty($info)){
  82. $unit_type = Db::name("department")->where("id",get_login_admin("unit_name"))->value("type");
  83. $info["unit_type"] = $unit_type;
  84. }
  85. return $info;
  86. }
  87. /**
  88. * 删除信息
  89. * @param $id
  90. * @return array
  91. */
  92. public function delCostProjectById($id, $type = 0)
  93. {
  94. if ($type == 0) {
  95. //逻辑删除
  96. try {
  97. $param['delete_time'] = time();
  98. self::where('id', $id)->update(['delete_time' => time()]);
  99. add_log('delete', $id);
  100. add_project_log('删除', $id);
  101. } catch (\Exception $e) {
  102. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  103. }
  104. } else {
  105. //物理删除
  106. try {
  107. self::where('id', $id)->delete();
  108. add_log('delete', $id);
  109. add_project_log('删除', $id);
  110. } catch (\Exception $e) {
  111. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  112. }
  113. }
  114. return to_assign();
  115. }
  116. }