Index_company.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types=1);
  8. namespace app\mobile\controller;
  9. use app\admin\BaseController;
  10. use app\admin\model\Admin;
  11. use app\admin\model\CostProject as CostProjectModel;
  12. use app\admin\model\ProjectAudit as AuditModel;
  13. use think\App;
  14. use think\facade\Db;
  15. use think\facade\View;
  16. class Index_company extends BaseController
  17. {
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct(App $app)
  22. {
  23. parent::__construct($app);
  24. $this->model = new CostProjectModel();
  25. $this->Adminmodel = new Admin();
  26. $this->Auditmodel = new AuditModel();
  27. $this->uid = get_login_admin('id');
  28. $this->unit = get_login_admin('unit_name');
  29. }
  30. /**
  31. * 公司首页
  32. */
  33. public function main_company()
  34. {
  35. $sent_review_amount = Db::name("cost_project")->where([
  36. ["review_unit", "=", get_login_admin("unit_name")],
  37. ['delete_time', '=', 0],
  38. ['project_status', '>', 3],
  39. ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select();
  40. //engineering_type1=1是预算,2是结算
  41. $amount = [
  42. //送审总额
  43. 'sent_review_amount' => 0,
  44. //评审服务费
  45. 'sent_review_cost' => 0,
  46. //审定总额
  47. 'authorize_amount' => 0,
  48. //总审减率
  49. 'review_add_reduce_rate' => 0
  50. ];
  51. $sent_review_amount_tol = [
  52. "sent_review_amount_type1" => 0,
  53. "sent_review_amount_type2" => 0,
  54. "authorize_amount_type1" => 0,
  55. "authorize_amount_type2" => 0,
  56. "review_add_reduce_rate_type1" => 0,
  57. "review_add_reduce_rate_type2" => 0
  58. ];
  59. for ($i = 0; $i < count($sent_review_amount); $i++) {
  60. $a = $sent_review_amount[$i];
  61. if ($a['engineering_type1'] == 1) {
  62. if ($a["sent_review_amount"] && $a["authorize_amount"]) {
  63. //预算总额
  64. $sent_review_amount_tol["sent_review_amount_type1"] += $a["sent_review_amount"];
  65. //审定
  66. $sent_review_amount_tol["authorize_amount_type1"] += $a["authorize_amount"];
  67. }
  68. } elseif ($a['engineering_type1'] == 2) {
  69. if ($a["sent_review_amount"] && $a["authorize_amount"]) {
  70. //结算总额
  71. $sent_review_amount_tol["sent_review_amount_type2"] += $a["sent_review_amount"];
  72. //审定
  73. $sent_review_amount_tol["authorize_amount_type2"] += $a["authorize_amount"];
  74. }
  75. }
  76. }
  77. if ($sent_review_amount_tol["sent_review_amount_type1"] && $sent_review_amount_tol["authorize_amount_type1"]) {
  78. //预算核增减率
  79. $sent_review_amount_tol["review_add_reduce_rate_type1"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type1"] - $sent_review_amount_tol["sent_review_amount_type1"]) / $sent_review_amount_tol["sent_review_amount_type1"])) * 100;
  80. }
  81. if ($sent_review_amount_tol["sent_review_amount_type2"] && $sent_review_amount_tol["authorize_amount_type2"]) {
  82. //结算核增减率
  83. $sent_review_amount_tol["review_add_reduce_rate_type2"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type2"] - $sent_review_amount_tol["sent_review_amount_type2"]) / $sent_review_amount_tol["sent_review_amount_type2"])) * 100;
  84. }
  85. for ($i = 0; $i < count($sent_review_amount); $i++) {
  86. $a = $sent_review_amount[$i];
  87. if ($a['sent_review_amount'] && $a['sent_review_cost'] && $a['authorize_amount']) {
  88. $amount["sent_review_amount"] += $a['sent_review_amount'];
  89. $amount["sent_review_cost"] += $a['sent_review_cost'];
  90. $amount["authorize_amount"] += $a['authorize_amount'];
  91. }
  92. }
  93. if ($amount['sent_review_amount'] && $amount["authorize_amount"]) {
  94. $amount['review_add_reduce_rate'] = (sprintf("%.4f", ($amount["authorize_amount"] - $amount["sent_review_amount"]) / $amount["sent_review_amount"])) * 100;
  95. }
  96. //评审服务费,上半年服务费用,下半年服务费用 start
  97. $currentTime = time();
  98. $year = date('Y', $currentTime);
  99. // 计算上半年时间范围
  100. $firstHalfStart = strtotime($year . '-01-01');
  101. $firstHalfEnd = strtotime($year . '-06-30 23:59:59');
  102. // 计算下半年时间范围
  103. $secondHalfStart = strtotime($year . '-07-01');
  104. $secondHalfEnd = strtotime($year . '-12-31 23:59:59');
  105. $first_sent_review_cost = Db::name("cost_project")->where([
  106. ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")]
  107. ])->
  108. whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select()->toArray();
  109. $second_sent_review_cost = Db::name("cost_project")->where([
  110. ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")]
  111. ])->
  112. whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select()->toArray();
  113. $sent_review_cost = [
  114. 'first_sent_review_cost' => 0,
  115. 'second_sent_review_cost' => 0
  116. ];
  117. for ($i = 0; $i < count($first_sent_review_cost); $i++) {
  118. $a = $first_sent_review_cost[$i];
  119. $sent_review_cost["first_sent_review_cost"] += $a['sent_review_cost'];
  120. }
  121. for ($i = 0; $i < count($second_sent_review_cost); $i++) {
  122. $a = $second_sent_review_cost[$i];
  123. $sent_review_cost["second_sent_review_cost"] += $a['sent_review_cost'];
  124. }
  125. //评审服务费,上半年服务费用,下半年服务费用 end
  126. //项目数量,正在作业,已归档
  127. $num = Db::name("cost_project")->where([
  128. ["review_unit", "=", get_login_admin("unit_name")],
  129. ['delete_time', '=', 0],
  130. ["project_status", '>', 3],
  131. ])->count();
  132. $where = [
  133. ["review_unit", "=", get_login_admin("unit_name")],
  134. ['delete_time', '=', 0],
  135. ["project_status", ">", 3]
  136. ];
  137. $data = Db::name("cost_project")->where($where)->select();
  138. $num_project = [
  139. 'num' => 0,
  140. "yu" => 0,
  141. "jie" => 0,
  142. "zuo" => 0,
  143. "gui" => 0,
  144. "tui" => 0,
  145. ];
  146. foreach ($data as $key => $value) {
  147. $num_project["num"] += 1;
  148. if ($value["project_status"] < 6 && $value["project_status"] > 3) {
  149. $num_project["zuo"] += 1;
  150. }
  151. if ($value["engineering_type1"] == 1) {
  152. $num_project["yu"] += 1;
  153. }
  154. if ($value["engineering_type1"] == 2) {
  155. $num_project["jie"] += 1;
  156. }
  157. if ($value["project_status"] == 8) {
  158. $num_project["gui"] += 1;
  159. }
  160. if ($value["project_status"] == 9) {
  161. $num_project["tui"] += 1;
  162. }
  163. }
  164. //项目数量,正在作业,已归档
  165. View::assign("sent_review_cost", $sent_review_cost);
  166. View::assign("amount", $amount);
  167. View::assign("num", $num);
  168. View::assign("num_project", $num_project);
  169. View::assign("sent_review_amount_tol", $sent_review_amount_tol);
  170. return View();
  171. }
  172. }