IntegralRecordApi.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\common\api;
  3. use app\common\api\DictApi;
  4. use app\admin\model\Enterprise;
  5. use think\facade\Db;
  6. use app\common\model\IntegralRecord;
  7. use app\common\state\IntegralState;
  8. /**
  9. * Description of IntegralRecordApi
  10. *
  11. * @author sgq
  12. */
  13. class IntegralRecordApi {
  14. public static function getOne($id) {
  15. $result = IntegralRecord::where("id", "=", $id)->find();
  16. $result["enterprise"] = EnterpriseApi::getOne($result["enterprise_id"]);
  17. $result["enterprise"]["streetName"] = DictApi::findDictByCode($result["enterprise"]["street"])["name"];
  18. if ($result) {
  19. $result["items"] = $result->detail;
  20. }
  21. return $result;
  22. }
  23. public static function getList($params) {
  24. $where = [];
  25. $order = $params["order"] ?: "desc";
  26. $offset = $params["offset"] ?: 0;
  27. $limit = $params["limit"] ?: 10;
  28. $where[] = ["e.type", "=", session("user")["type"]];
  29. if (session("user")["usertype"] == 2) {
  30. $where[] = ["enterprise_id", "=", session("user")["uid"]];
  31. }
  32. $where[] = ["delete", "=", 0];
  33. $count = IntegralRecord::alias("ir")->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->count();
  34. $list = IntegralRecord::where($where)->field("ir.*,if(ir.updateTime is not null,ir.updateTime,ir.createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  35. foreach ($list as $key => $item) {
  36. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  37. $tmp_items = [];
  38. foreach ($item["detail"] as $_item) {
  39. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  40. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  41. }
  42. $list[$key]["details"] = implode(",", $tmp_items);
  43. $list[$key]["type"] = session("user")["type"];
  44. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  45. $list[$key]["real_state"] = $last_log["state"];
  46. $list[$key]["last_state"] = $last_log["last_state"];
  47. }
  48. return ["total" => $count, "rows" => $list];
  49. }
  50. public static function getListByProcess($params) {
  51. $process = $params["process"] ?: 1;
  52. $where = [];
  53. switch ($process) {
  54. case 1://初审阶段
  55. $where[] = ["checkState", "in", [IntegralState::SUBMIT]];
  56. break;
  57. case 2://复审阶段
  58. $where[] = ["checkState", "in", [IntegralState::VERIFY_PASS]];
  59. break;
  60. case 3://复审后征信公示等状态
  61. $where[] = ["checkState", "in", [IntegralState::REVERIFY_PASS, IntegralState::ZX_PASS, IntegralState::ZX_FAIL, IntegralState::ANNOUNCED, IntegralState::ANNOUNCED_REVERIFY_PASS, IntegralState::ANNOUNCED_REVERIFY_FAIL, IntegralState::PUBLISH_PASS, IntegralState::PUBLISH_FAIL, IntegralState::SUCCESS]];
  62. break;
  63. }
  64. $order = $params["order"] ?: "desc";
  65. $offset = $params["offset"] ?: 0;
  66. $limit = $params["limit"] ?: 10;
  67. $where[] = ["delete", "=", 0];
  68. $count = IntegralRecord::where($where)->count();
  69. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  70. foreach ($list as $key => $item) {
  71. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  72. $tmp_items = [];
  73. foreach ($item["detail"] as $_item) {
  74. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  75. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  76. }
  77. $list[$key]["details"] = implode(",", $tmp_items);
  78. $list[$key]["type"] = session("user")["type"];
  79. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  80. $list[$key]["real_state"] = $last_log["state"];
  81. $list[$key]["last_state"] = $last_log["last_state"];
  82. }
  83. return ["total" => $count, "rows" => $list];
  84. }
  85. public static function checkIsEditable($id) {
  86. $info = self::getOne($id);
  87. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  88. return false;
  89. return true;
  90. }
  91. static public function chkIsOwner($id, $uid) {
  92. $info = self::getOne($id);
  93. if ($info["enterprise_id"] != $uid)
  94. return null;
  95. return $info;
  96. }
  97. public static function calIntegral($enterprise_id, $cardType, $cardNumber, $itemId) {
  98. $item = getCacheById("IntegralItem", $itemId);
  99. $projectMax = 0; //项目总上限
  100. $itemMax = 0; //标准总上限
  101. if ($item) {
  102. $project = getCacheById("IntegralProject", $item["projectId"]);
  103. if ($project["limit"] == 1) {
  104. //项目下所有规则总上限
  105. $where = [];
  106. $where[] = ["r.enterprise_id", "=", $enterprise_id];
  107. $where[] = ["r.card_type", "=", $cardType];
  108. $where[] = ["r.card_number", "=", $cardNumber];
  109. $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
  110. $where[] = ["i.projectId", "=", $project["id"]];
  111. if ($project["yearly"] == 1) {
  112. //年度重置只算当年度
  113. $startTime = date("Y-01-01 00:00:00");
  114. $endTime = date("Y-12-31 23:59:59");
  115. $where[] = ["r.createTime", "between", [$startTime, $endTime]];
  116. }
  117. $totalPoints = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->leftJoin("new_integral_item i", "i.id=d.item_id")->where($where)->sum("d.point");
  118. }
  119. if ($item["limit"] == 1) {
  120. //规则上限
  121. }
  122. if ($project["limit"] == 2) {
  123. //项目没有设置上限
  124. if ($item["limit"] == 2) {
  125. //标准没有设置上限
  126. } else {
  127. //标准有设置上限,并检查标准有没有年度重置
  128. if ($item["yearly"] == 1) {
  129. //标准有年度重置
  130. } else {
  131. //标准没有重置
  132. }
  133. }
  134. } else {
  135. //有设置上限,并检查有没有年度重置
  136. if ($project["yearly"] == 1) {
  137. //有年度重置
  138. } else {
  139. //没有重置
  140. }
  141. }
  142. }
  143. return 0;
  144. }
  145. }