find(); $result["enterprise"] = EnterpriseApi::getOne($result["enterprise_id"]); $result["enterprise"]["streetName"] = DictApi::findDictByCode($result["enterprise"]["street"])["name"]; if ($result) { $result["items"] = $result->detail; } return $result; } public static function getList($params) { $where = []; $order = $params["order"] ?: "desc"; $offset = $params["offset"] ?: 0; $limit = $params["limit"] ?: 10; $where[] = ["e.type", "=", session("user")["type"]]; if (session("user")["usertype"] == 2) { $where[] = ["enterprise_id", "=", session("user")["uid"]]; } $where[] = ["ir.delete", "=", 0]; $count = IntegralRecord::alias("ir")->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->count(); $list = IntegralRecord::alias("ir")->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->field("ir.*,if(ir.updateTime is not null,ir.updateTime,ir.createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select(); foreach ($list as $key => $item) { $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"]; $tmp_items = []; foreach ($item["detail"] as $_item) { $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]); $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]); } $list[$key]["details"] = implode(",", $tmp_items); $list[$key]["type"] = session("user")["type"]; $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL); $list[$key]["real_state"] = $last_log["state"]; $list[$key]["last_state"] = $last_log["last_state"]; } return ["total" => $count, "rows" => $list]; } public static function getListByProcess($params) { $process = $params["process"] ?: 1; $where = []; switch ($process) { case 1://初审阶段 $where[] = ["checkState", "in", [IntegralState::SUBMIT, IntegralState::VERIFY_FAIL]]; break; case 2://复审阶段 $where[] = ["checkState", "in", [IntegralState::VERIFY_PASS, IntegralState::REVERIFY_FAIL]]; break; case 3://复审后征信公示等状态 $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]]; break; } $order = $params["order"] ?: "desc"; $offset = $params["offset"] ?: 0; $limit = $params["limit"] ?: 10; $where[] = ["delete", "=", 0]; $count = IntegralRecord::where($where)->count(); $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select(); foreach ($list as $key => $item) { $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"]; $tmp_items = []; foreach ($item["detail"] as $_item) { $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]); $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]); } $list[$key]["details"] = implode(",", $tmp_items); $list[$key]["type"] = session("user")["type"]; $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL); $list[$key]["real_state"] = $last_log["state"]; $list[$key]["last_state"] = $last_log["last_state"]; } return ["total" => $count, "rows" => $list]; } public static function checkIsEditable($id) { $info = self::getOne($id); if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE])) return false; return true; } static public function chkIsOwner($id, $uid) { $info = self::getOne($id); if ($info["enterprise_id"] != $uid) return null; return $info; } /** * 计算积分 * @param type $enterpriseId 企业id * @param type $cardType 证件类型 * @param type $cardNumber 证件号码 * @param type $itemId 标准id * @param type $amount 达成数额 * @return \stdClass 完整积分记录对象 */ public static function calIntegral($enterpriseId, $cardType, $cardNumber, $itemId, $amount) { $returnObj = new \stdClass(); $returnObj->amount = $amount; $item = getCacheById("IntegralItem", $itemId); $projectRemainderPoints = 0; //项目剩余总上限 $itemRemainderPoints = 0; //标准剩余总上限 $points = 0; //当前可获得积分 if ($item) { $project = getCacheById("IntegralProject", $item["projectId"]); $projectRemainderPoints = $project["max"]; //初始化项目可获得剩余积分 $itemRemainderPoints = $item["max"]; //初始化标准可获得剩余积分 if ($project["limit"] == 1) { //项目下所有规则总上限 $where = []; $where[] = ["r.enterprise_id", "=", $enterprise_id]; $where[] = ["r.card_type", "=", $cardType]; $where[] = ["r.card_number", "=", $cardNumber]; $where[] = ["r.checkState", ">=", IntegralState::SUCCESS]; $where[] = ["i.projectId", "=", $project["id"]]; if ($project["yearly"] == 1) { //年度重置只算当年度 $startTime = date("Y-01-01 00:00:00"); $endTime = date("Y-12-31 23:59:59"); $where[] = ["r.createTime", "between", [$startTime, $endTime]]; $returnObj->projectYearly = 1; } $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"); $projectRemainderPoints -= $totalPoints; $returnObj->projectMaxPoints = $project["max"]; $returnObj->projectRemainderPoints = $projectRemainderPoints; } if ($item["limit"] == 1) { //规则上限 $where = []; $where[] = ["r.enterprise_id", "=", $enterprise_id]; $where[] = ["r.card_type", "=", $cardType]; $where[] = ["r.card_number", "=", $cardNumber]; $where[] = ["r.checkState", ">=", IntegralState::SUCCESS]; $where[] = ["d.item_id", "=", $itemId]; if ($item["yearly"] == 1) { //年度重置只算当年度 $startTime = date("Y-01-01 00:00:00"); $endTime = date("Y-12-31 23:59:59"); $where[] = ["r.createTime", "between", [$startTime, $endTime]]; $returnObj->itemYearly = 1; } $totalPoints = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->where($where)->sum("d.point"); $itemRemainderPoints -= $totalPoints; $returnObj->itemMaxPoints = $item["max"]; $returnObj->itemRemainderPoints = $itemRemainderPoints; } $where = []; $where[] = ["r.enterprise_id", "=", $enterprise_id]; $where[] = ["r.card_type", "=", $cardType]; $where[] = ["r.card_number", "=", $cardNumber]; $where[] = ["r.checkState", ">=", IntegralState::SUCCESS]; $where[] = ["d.item_id", "=", $itemId]; $fstGain = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->where($where)->field("d.*")->order("createTime asc")->find(); if ($item["stepNeedAmount"] && $item["stepGainPoints"]) { $returnObj->stepNeedAmount = $item["stepNeedAmount"]; $returnObj->stepGainPoints = $item["stepGainPoints"]; if ($fstGain) { $returnObj->fstGainRecordId = $fstGain["record_id"]; $returnObj->fstGainDetailId = $fstGain["id"]; //有配置增量积分 if ($item["stepIsYear"] == 1) { //较上年度增量 $where = []; $where[] = ["r.enterprise_id", "=", $enterprise_id]; $where[] = ["r.card_type", "=", $cardType]; $where[] = ["r.card_number", "=", $cardNumber]; $where[] = ["r.checkState", ">=", IntegralState::SUCCESS]; $where[] = ["d.item_id", "=", $itemId]; $startTime = date("Y-m-d 00:00:00", strtotime("first day of last year")); $endTime = date("Y-12-31 23:59:59", strtotime("last day of last year")); $where[] = ["r.createTime", "between", [$startTime, $endTime]]; $lastYearTotalAmount = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->where($where)->sum("d.amount"); $newGainAmount = $amount - $lastYearTotalAmount; $times = floor($newGainAmount / $item["stepNeedAmount"]); $returnObj->stepIsYear = 1; $returnObj->lastYearTotalAmount = $lastYearTotalAmount; $returnObj->newGainAmount = $newGainAmount; } else { $times = floor($amount / $item["stepNeedAmount"]); $returnObj->stepAmount = $amount; } $points = $item["stepGainPoints"] * $times; $returnObj->times = $times; $returnObj->points = $returnObj->stepPoints = $points; } else { //首次 $returnObj->fstNeedAmount = $item["fstNeedAmount"]; $returnObj->fstGainPoints = $item["fstGainPoints"]; $returnObj->fstAmount = $amount >= $item["fstNeedAmount"] ? $item["fstNeedAmount"] : $amount; $returnObj->fstPoints = $amount >= $item["fstNeedAmount"] ? $item["fstGainPoints"] : 0; if ($item["stepIsYear"] != 1) { //未设置较上年度增量时,首次还需计算增量部分 $stepAmount = $amount - $item["fstNeedAmount"]; if ($stepAmount > 0) { $times = floor($stepAmount / $item["stepNeedAmount"]); $returnObj->stepAmount = $stepAmount; $returnObj->times = $times; $returnObj->stepPoints = $item["stepGainPoints"] * $times; } } else { $returnObj->stepIsYear = 1; } $returnObj->points = $returnObj->stepPoints ? $returnObj->fstPoints + $returnObj->stepPoints : $returnObj->fstPoints; } } else { //仅首次可得积分 if ($fstGain) { $returnObj->points = 0; $returnObj->msg = "仅首次能获得积分"; } else { $returnObj->fstNeedAmount = $item["fstNeedAmount"]; $returnObj->fstGainPoints = $item["fstGainPoints"]; $returnObj->fstAmount = $amount >= $item["fstNeedAmount"] ? $item["fstNeedAmount"] : $amount; $returnObj->points = $returnObj->fstPoints = $amount >= $item["fstNeedAmount"] ? $item["fstGainPoints"] : 0; } } $point1 = $project["limit"] == 1 ? ($returnObj->projectRemainderPoints > $returnObj->points ? $returnObj->points : $returnObj->projectRemainderPoints) : $returnObj->points; $point2 = $item["limit"] == 1 ? ($returnObj->itemRemainderPoints > $returnObj->points ? $returnObj->points : $returnObj->itemRemainderPoints) : $returnObj->points; $returnObj->theoretical = $returnObj->points; //理论值 $returnObj->points = $point1 > $point2 ? $point2 : $point1; //实际值,当有限额时,会与理论值有偏差 } return $returnObj; } }