IntegralRecordApi.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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["apply_year"] = BatchApi::getOne($result["batch_id"])["batch"];
  18. $result["enterprise"]["streetName"] = DictApi::findDictByCode($result["enterprise"]["street"])["name"];
  19. if ($result) {
  20. $result["items"] = $result->detail;
  21. }
  22. return $result;
  23. }
  24. public static function getList($params) {
  25. $order = $params["order"] ?: "desc";
  26. $offset = $params["offset"] ?: 0;
  27. $limit = $params["limit"] ?: 10;
  28. $where = [];
  29. $where[] = ["e.type", "=", session("user")["type"]];
  30. if (session("user")["usertype"] == 2) {
  31. $where[] = ["enterprise_id", "=", session("user")["uid"]];
  32. }
  33. $where[] = ["ir.delete", "=", 0];
  34. if ($params["apply_year"]) {
  35. $where[] = ["b.batch", "like", "%{$params['apply_year']}%"];
  36. }
  37. if ($params["name"]) {
  38. $where[] = ["ir.name", "like", "%{$params['name']}%"];
  39. }
  40. if ($params["card_number"]) {
  41. $where[] = ["ir.card_number", "like", "%{$params['card_number']}%"];
  42. }
  43. if ($params["phone"]) {
  44. $where[] = ["ir.phone", "like", "%{$params['phone']}%"];
  45. }
  46. if ($params["email"]) {
  47. $where[] = ["ir.email", "like", "%{$params['email']}%"];
  48. }
  49. if ($params["shareholder"]) {
  50. $where[] = ["ir.shareholder", "=", $params['shareholder']];
  51. }
  52. switch ($params["checkState"]) {
  53. case -1:
  54. $where[] = ["tl.state", "in", [IntegralState::VERIFY_FAIL, IntegralState::REVERIFY_FAIL, IntegralState::ZX_FAIL, IntegralState::ANNOUNCED_REVERIFY_FAIL, IntegralState::PUBLISH_FAIL]];
  55. break;
  56. case 1:
  57. $where[] = ["tl.state", "=", IntegralState::SAVE];
  58. break;
  59. case 2:
  60. $where[] = ["tl.state", "in", [IntegralState::VERIFY_REJECT, IntegralState::REVERIFY_REJECT]];
  61. break;
  62. case 3:
  63. $where[] = ["tl.state", "in", [IntegralState::SUBMIT, IntegralState::VERIFY_PASS]];
  64. break;
  65. case 4:
  66. $where[] = ["tl.state", ">=", IntegralState::REVERIFY_PASS];
  67. $where[] = ["tl.state", "not in", [IntegralState::REVERIFY_REJECT, IntegralState::REVERIFY_FAIL]];
  68. break;
  69. case 5:
  70. $where[] = ["tl.state", "=", IntegralState::SUCCESS];
  71. break;
  72. }
  73. $count = IntegralRecord::alias("ir")
  74. ->leftJoin("sys_batch b", "b.id=ir.batch_id")
  75. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=20 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ir.id")
  76. ->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->count();
  77. $list = IntegralRecord::alias("ir")
  78. ->leftJoin("sys_batch b", "b.id=ir.batch_id")
  79. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=20 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ir.id")
  80. ->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->field("ir.*,b.batch as apply_year,tl.state,tl.new_state,if(ir.updateTime is not null,ir.updateTime,ir.createTime) as orderTime")
  81. ->limit($offset, $limit)
  82. ->order("orderTime " . $order)
  83. ->select();
  84. foreach ($list as $key => $item) {
  85. $tmp_items = [];
  86. foreach ($item["detail"] as $_item) {
  87. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  88. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  89. }
  90. $list[$key]["details"] = implode(",", $tmp_items);
  91. $list[$key]["type"] = session("user")["type"];
  92. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  93. $list[$key]["real_state"] = $last_log["state"];
  94. $list[$key]["last_state"] = $last_log["last_state"];
  95. }
  96. return ["total" => $count, "rows" => $list];
  97. }
  98. public static function getPublicList($params) {
  99. $order = $params["order"];
  100. $offset = $params["offset"];
  101. $limit = $params["limit"];
  102. $where = [];
  103. $where[] = ["e.type", "=", session("user")["type"]];
  104. if ($params["name"]) {
  105. $where[] = ["ir.name", "like", "%" . $params["name"] . "%"];
  106. }
  107. switch ($params["checkState"]) {
  108. case 1:
  109. $where[] = ["ir.checkState", "in", [IntegralState::REVERIFY_PASS, IntegralState::ZX_PASS, IntegralState::ANNOUNCED, IntegralState::ANNOUNCED_REVERIFY_PASS, IntegralState::PUBLISH_PASS]];
  110. break;
  111. case 2:
  112. $where[] = ["ir.checkState", "in", [IntegralState::REVERIFY_FAIL, IntegralState::ZX_FAIL, IntegralState::ANNOUNCED_REVERIFY_FAIL, IntegralState::PUBLISH_FAIL]];
  113. break;
  114. }
  115. $type = $params["type"];
  116. switch ($type) {
  117. case 1:
  118. case 2:
  119. $where[] = ["ir.checkState", "=", IntegralState::REVERIFY_PASS];
  120. break;
  121. case 3: //公示
  122. case 7: //公示预览
  123. $where[] = ["ir.checkState", "=", IntegralState::ZX_PASS];
  124. break;
  125. case 4: //公示通过
  126. $where[] = ["ir.checkState", "=", IntegralState::ANNOUNCED];
  127. break;
  128. case 5:
  129. case 8: //公布预览
  130. $where[] = ["ir.checkState", "=", IntegralState::ANNOUNCED_REVERIFY_PASS];
  131. break;
  132. case 6:
  133. $where[] = ["ir.checkState", "=", IntegralState::PUBLISH_PASS];
  134. break;
  135. }
  136. $count = IntegralRecord::alias("ir")->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")->where($where)->count();
  137. $list = IntegralRecord::alias("ir")->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")
  138. ->where($where)
  139. ->limit($offset, $limit)
  140. ->order("ir.createTime " . $order)->field("ir.*,e.name as enterpriseName,e.type as enterprise_type,enterpriseTag")->select()->toArray();
  141. foreach ($list as &$item) {
  142. $item["talent_type"] = $item["enterprise_type"] == 1 ? "晋江市现代产业体系人才" : "集成电路优秀人才";
  143. }unset($item);
  144. return ["total" => $count, "rows" => $list];
  145. }
  146. public static function getListByProcess($params) {
  147. $order = $params["order"] ?: "desc";
  148. $offset = $params["offset"] ?: 0;
  149. $limit = $params["limit"] ?: 10;
  150. $process = $params["process"] ?: 1;
  151. $where = [];
  152. $where[] = ["e.type", "=", session("user")["type"]];
  153. switch ($process) {
  154. case 1://初审阶段
  155. switch ($params["checkState"]) {
  156. case 1://待审核
  157. $where[] = ["ir.checkState", "=", IntegralState::SUBMIT];
  158. $where[] = ["tl.state", "=", IntegralState::SUBMIT];
  159. break;
  160. case 2://驳回
  161. $where[] = ["tl.new_state", "in", [IntegralState::SAVE]];
  162. $where[] = ["tl.state", "in", [IntegralState::VERIFY_REJECT]];
  163. break;
  164. case 3:
  165. //审核失败
  166. $where[] = ["ir.checkState", "in", [IntegralState::VERIFY_FAIL]];
  167. break;
  168. default:
  169. $where[] = ["tl.state", "in", [IntegralState::SUBMIT, IntegralState::VERIFY_REJECT, IntegralState::VERIFY_FAIL]];
  170. }
  171. break;
  172. case 2://复审阶段
  173. switch ($params["checkState"]) {
  174. case 1://待审核
  175. $where[] = ["tl.state", "=", IntegralState::VERIFY_PASS];
  176. break;
  177. case 3:
  178. //审核失败
  179. $where[] = ["tl.state", "in", [IntegralState::VERIFY_FAIL]];
  180. break;
  181. default:
  182. $where[] = ["tl.state", "in", [IntegralState::VERIFY_PASS, IntegralState::REVERIFY_FAIL]];
  183. }
  184. break;
  185. case 3://复审后征信公示等状态
  186. if ($params["checkState"]) {
  187. $where[] = ["ir.checkState", "=", $params["checkState"]];
  188. } else {
  189. $where[] = ["ir.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]];
  190. }
  191. break;
  192. }
  193. $where[] = ["ir.delete", "=", 0];
  194. if ($params["apply_year"]) {
  195. $where[] = ["b.batch", "like", "%{$params['apply_year']}%"];
  196. }
  197. if ($params["name"]) {
  198. $where[] = ["ir.name", "like", "%{$params['name']}%"];
  199. }
  200. if ($params["card_number"]) {
  201. $where[] = ["ir.card_number", "like", "%{$params['card_number']}%"];
  202. }
  203. if ($params["phone"]) {
  204. $where[] = ["ir.phone", "like", "%{$params['phone']}%"];
  205. }
  206. if ($params["email"]) {
  207. $where[] = ["ir.email", "like", "%{$params['email']}%"];
  208. }
  209. if ($params["shareholder"]) {
  210. $where[] = ["ir.shareholder", "=", $params['shareholder']];
  211. }
  212. $count = IntegralRecord::alias("ir")->where($where)
  213. ->leftJoin("sys_batch b", "b.id=ir.batch_id")
  214. ->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")
  215. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=20 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ir.id")
  216. ->count();
  217. $list = IntegralRecord::alias("ir")->where($where)
  218. ->leftJoin("sys_batch b", "b.id=ir.batch_id")
  219. ->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")
  220. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=20 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ir.id")
  221. ->field("ir.*,e.name as enterpriseName,b.batch as apply_year,tl.state as real_state,tl.last_state,if(ir.updateTime is not null,ir.updateTime,ir.createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  222. foreach ($list as $key => $item) {
  223. $tmp_items = [];
  224. foreach ($item["detail"] as $_item) {
  225. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  226. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  227. }
  228. $list[$key]["details"] = implode(";", $tmp_items);
  229. $list[$key]["type"] = session("user")["type"];
  230. //$last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  231. //$list[$key]["real_state"] = $last_log["state"];
  232. //$list[$key]["last_state"] = $last_log["last_state"];
  233. }
  234. return ["total" => $count, "rows" => $list];
  235. }
  236. public static function checkIsEditable($id) {
  237. $info = self::getOne($id);
  238. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  239. return false;
  240. return true;
  241. }
  242. static public function chkIsOwner($id, $uid) {
  243. $info = self::getOne($id);
  244. if ($info["enterprise_id"] != $uid)
  245. return null;
  246. return $info;
  247. }
  248. /**
  249. * 导出
  250. * @param type $process
  251. * @param type $params
  252. * @return type
  253. */
  254. public static function getExportDatas($process, $params) {
  255. $where[] = [];
  256. //特殊字段处理
  257. $fields = [];
  258. $fields[] = "ir.id";
  259. foreach ($params as $param) {
  260. if (!in_array($param, ["enterpriseName", "street", "checkMsg", "project", "year"])) {
  261. $fields[] = "ir." . $param;
  262. }
  263. }
  264. $fields[] = "e.name as enterpriseName";
  265. $fields[] = "e.street";
  266. $fields[] = "tl.description as checkMsg";
  267. $fields[] = "b.batch as year";
  268. if (in_array("card_type", $params)) {
  269. $cardTypes = DictApi::selectByParentCode("card_type");
  270. }
  271. if (in_array("street", $params)) {
  272. $streets = DictApi::selectByParentCode("street");
  273. }
  274. $sex = [1 => "男", 2 => "女"];
  275. $where = [];
  276. $where[] = ["e.type", "=", session("user")["type"]];
  277. switch ($process) {
  278. case 1:
  279. $where = "ir.checkState in (" . IntegralState::SUBMIT . "," . IntegralState::VERIFY_FAIL . ")";
  280. break;
  281. case 2:
  282. $where = "ir.checkState in (" . IntegralState::VERIFY_PASS . "," . IntegralState::REVERIFY_FAIL . ")";
  283. break;
  284. case 3:
  285. $where = "ir.checkState >= " . IntegralState::REVERIFY_PASS;
  286. break;
  287. }
  288. $list = IntegralRecord::alias("ir")
  289. ->field($fields)
  290. ->leftJoin("un_enterprise e", "e.id=ir.enterprise_id")
  291. ->leftJoin("sys_batch b", "b.id=ir.batch_id")
  292. ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=20 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ir.id")
  293. //->leftJoin("new_talent_checklog tl", "tl.mainId=ti.id and tl.id=(select id from new_talent_checklog where mainId=ti.id and `step` is null and active=1 and typeFileId is null order by createTime desc limit 1)")
  294. ->whereRaw($where)
  295. ->select()->toArray();
  296. foreach ($list as &$item) {
  297. $item["card_type"] = $cardTypes[$item["card_type"]];
  298. $item["street"] = $streets[$item["street"]];
  299. $item["sex"] = $sex[$item["sex"]];
  300. $item["checkState"] = IntegralState::getStateName($item["checkState"]);
  301. $detail = \app\common\model\IntegralDetail::where("record_id", $item["id"])->select();
  302. $tmp_items = [];
  303. foreach ($detail as $_item) {
  304. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  305. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  306. }
  307. $item["project"] = implode(";", $tmp_items);
  308. }unset($item);
  309. return $list;
  310. }
  311. public static function getListByIds($ids) {
  312. $where[] = ["id", "in", $ids];
  313. return IntegralRecord::where($where)->select()->toArray();
  314. }
  315. /**
  316. * 计算积分
  317. * @param type $enterpriseId 企业id
  318. * @param type $cardType 证件类型
  319. * @param type $cardNumber 证件号码
  320. * @param type $itemId 标准id
  321. * @param type $amount 达成数额
  322. * @return \stdClass 完整积分记录对象
  323. */
  324. public static function calIntegral($enterprise_id, $cardType, $cardNumber, $itemId, $amount) {
  325. $returnObj = new \stdClass();
  326. $returnObj->amount = $amount;
  327. $item = getCacheById("IntegralItem", $itemId);
  328. $projectRemainderPoints = 0; //项目剩余总上限
  329. $itemRemainderPoints = 0; //标准剩余总上限
  330. $points = 0; //当前可获得积分
  331. if ($item) {
  332. $project = getCacheById("IntegralProject", $item["projectId"]);
  333. $projectRemainderPoints = $project["max"]; //初始化项目可获得剩余积分
  334. $itemRemainderPoints = $item["max"]; //初始化标准可获得剩余积分
  335. if ($project["limit"] == 1) {
  336. //项目下所有规则总上限
  337. $where = [];
  338. $where[] = ["r.enterprise_id", "=", $enterprise_id];
  339. $where[] = ["r.card_type", "=", $cardType];
  340. $where[] = ["r.card_number", "=", $cardNumber];
  341. $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
  342. $where[] = ["i.projectId", "=", $project["id"]];
  343. if ($project["yearly"] == 1) {
  344. //年度重置只算当年度
  345. $startTime = date("Y-01-01 00:00:00");
  346. $endTime = date("Y-12-31 23:59:59");
  347. $where[] = ["r.createTime", "between", [$startTime, $endTime]];
  348. $returnObj->projectYearly = 1;
  349. }
  350. $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");
  351. $projectRemainderPoints -= $totalPoints;
  352. $returnObj->projectMaxPoints = $project["max"];
  353. $returnObj->projectRemainderPoints = $projectRemainderPoints;
  354. }
  355. if ($item["limit"] == 1) {
  356. //规则上限
  357. $where = [];
  358. $where[] = ["r.enterprise_id", "=", $enterprise_id];
  359. $where[] = ["r.card_type", "=", $cardType];
  360. $where[] = ["r.card_number", "=", $cardNumber];
  361. $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
  362. $where[] = ["d.item_id", "=", $itemId];
  363. if ($item["yearly"] == 1) {
  364. //年度重置只算当年度
  365. $startTime = date("Y-01-01 00:00:00");
  366. $endTime = date("Y-12-31 23:59:59");
  367. $where[] = ["r.createTime", "between", [$startTime, $endTime]];
  368. $returnObj->itemYearly = 1;
  369. }
  370. $totalPoints = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->where($where)->sum("d.point");
  371. $itemRemainderPoints -= $totalPoints;
  372. $returnObj->itemMaxPoints = $item["max"];
  373. $returnObj->itemRemainderPoints = $itemRemainderPoints;
  374. }
  375. $where = [];
  376. $where[] = ["r.enterprise_id", "=", $enterprise_id];
  377. $where[] = ["r.card_type", "=", $cardType];
  378. $where[] = ["r.card_number", "=", $cardNumber];
  379. $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
  380. $where[] = ["d.item_id", "=", $itemId];
  381. $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();
  382. if ($item["stepNeedAmount"] && $item["stepGainPoints"]) {
  383. $returnObj->stepNeedAmount = $item["stepNeedAmount"];
  384. $returnObj->stepGainPoints = $item["stepGainPoints"];
  385. if ($fstGain) {
  386. $returnObj->fstGainRecordId = $fstGain["record_id"];
  387. $returnObj->fstGainDetailId = $fstGain["id"];
  388. //有配置增量积分
  389. if ($item["stepIsYear"] == 1) {
  390. //较上年度增量
  391. $where = [];
  392. $where[] = ["r.enterprise_id", "=", $enterprise_id];
  393. $where[] = ["r.card_type", "=", $cardType];
  394. $where[] = ["r.card_number", "=", $cardNumber];
  395. $where[] = ["r.checkState", ">=", IntegralState::SUCCESS];
  396. $where[] = ["d.item_id", "=", $itemId];
  397. $startTime = date("Y-m-d 00:00:00", strtotime("first day of last year"));
  398. $endTime = date("Y-12-31 23:59:59", strtotime("last day of last year"));
  399. $where[] = ["r.createTime", "between", [$startTime, $endTime]];
  400. $lastYearTotalAmount = Db::table("new_integral_detail")->alias("d")->leftJoin("new_integral_record r", "r.id=d.record_id")->where($where)->sum("d.amount");
  401. $newGainAmount = $amount - $lastYearTotalAmount;
  402. $times = floor($newGainAmount / $item["stepNeedAmount"]);
  403. $returnObj->stepIsYear = 1;
  404. $returnObj->lastYearTotalAmount = $lastYearTotalAmount;
  405. $returnObj->newGainAmount = $newGainAmount;
  406. } else {
  407. $times = floor($amount / $item["stepNeedAmount"]);
  408. $returnObj->stepAmount = $amount;
  409. }
  410. $points = $item["stepGainPoints"] * $times;
  411. $returnObj->times = $times;
  412. $returnObj->points = $returnObj->stepPoints = $points;
  413. } else {
  414. //首次
  415. $returnObj->fstNeedAmount = $item["fstNeedAmount"];
  416. $returnObj->fstGainPoints = $item["fstGainPoints"];
  417. $returnObj->fstAmount = $amount >= $item["fstNeedAmount"] ? $item["fstNeedAmount"] : $amount;
  418. $returnObj->fstPoints = $amount >= $item["fstNeedAmount"] ? $item["fstGainPoints"] : 0;
  419. if ($item["stepIsYear"] != 1) {
  420. //未设置较上年度增量时,首次还需计算增量部分
  421. $stepAmount = $amount - $item["fstNeedAmount"];
  422. if ($stepAmount > 0) {
  423. $times = floor($stepAmount / $item["stepNeedAmount"]);
  424. $returnObj->stepAmount = $stepAmount;
  425. $returnObj->times = $times;
  426. $returnObj->stepPoints = $item["stepGainPoints"] * $times;
  427. }
  428. } else {
  429. $returnObj->stepIsYear = 1;
  430. }
  431. $returnObj->points = $returnObj->stepPoints ? $returnObj->fstPoints + $returnObj->stepPoints : $returnObj->fstPoints;
  432. }
  433. } else {
  434. //仅首次可得积分
  435. if ($fstGain) {
  436. $returnObj->points = 0;
  437. $returnObj->msg = "仅首次能获得积分";
  438. } else {
  439. $returnObj->fstNeedAmount = $item["fstNeedAmount"];
  440. $returnObj->fstGainPoints = $item["fstGainPoints"];
  441. $returnObj->fstAmount = $amount >= $item["fstNeedAmount"] ? $item["fstNeedAmount"] : $amount;
  442. $returnObj->points = $returnObj->fstPoints = $amount >= $item["fstNeedAmount"] ? $item["fstGainPoints"] : 0;
  443. }
  444. }
  445. $point1 = $project["limit"] == 1 ? ($returnObj->projectRemainderPoints > $returnObj->points ? $returnObj->points : $returnObj->projectRemainderPoints) : $returnObj->points;
  446. $point2 = $item["limit"] == 1 ? ($returnObj->itemRemainderPoints > $returnObj->points ? $returnObj->points : $returnObj->itemRemainderPoints) : $returnObj->points;
  447. $returnObj->theoretical = $returnObj->points; //理论值
  448. $returnObj->points = $point1 > $point2 ? $point2 : $point1; //实际值,当有限额时,会与理论值有偏差
  449. }
  450. return $returnObj;
  451. }
  452. public static function setPublic($mainId, $state, $msg, $batch = null) {
  453. $data["id"] = $mainId;
  454. $data["checkState"] = $state;
  455. switch ($state) {
  456. case IntegralState::ZX_PASS:
  457. case IntegralState::ZX_FAIL:
  458. $data["isPublic"] = 2;
  459. break;
  460. case IntegralState::ANNOUNCED:
  461. $data["isPublic"] = 3;
  462. $data["publicBatch"] = $batch;
  463. break;
  464. case IntegralState::ANNOUNCED_REVERIFY_PASS:
  465. case IntegralState::ANNOUNCED_REVERIFY_FAIL:
  466. $data["isPublic"] = 3;
  467. break;
  468. case IntegralState::PUBLISH_PASS:
  469. $data["getTime"] = $batch;
  470. $data["isPublic"] = 4;
  471. break;
  472. case IntegralState::PUBLISH_FAIL:
  473. $data["isPublic"] = 4;
  474. break;
  475. }
  476. if (IntegralRecord::update($data)) {
  477. TalentLogApi::write(\app\common\state\ProjectState::INTEGRAL, $mainId, $state, $msg, 1);
  478. return true;
  479. }
  480. return false;
  481. }
  482. }