IntegralRecordApi.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if ($result) {
  17. $result["items"] = $result->detail;
  18. }
  19. return $result;
  20. }
  21. public static function getList($params) {
  22. $where = [];
  23. $order = $params["order"] ?: "desc";
  24. $offset = $params["offset"] ?: 0;
  25. $limit = $params["limit"] ?: 10;
  26. if (session("user")["usertype"] == 2) {
  27. $where[] = ["enterprise_id", "=", session("user")["uid"]];
  28. }
  29. $where[] = ["delete", "=", 0];
  30. $count = IntegralRecord::where($where)->count();
  31. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  32. foreach ($list as $key => $item) {
  33. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  34. $tmp_items = [];
  35. foreach ($item["detail"] as $_item) {
  36. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  37. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  38. }
  39. $list[$key]["details"] = implode(",", $tmp_items);
  40. $list[$key]["type"] = session("user")["type"];
  41. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  42. $list[$key]["real_state"] = $last_log["state"];
  43. $list[$key]["last_state"] = $last_log["last_state"];
  44. }
  45. return ["total" => $count, "rows" => $list];
  46. }
  47. public static function checkIsEditable($id) {
  48. $info = self::getOne($id);
  49. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  50. return false;
  51. return true;
  52. }
  53. static public function chkIsOwner($id, $uid) {
  54. $info = self::getOne($id);
  55. if ($info["enterprise_id"] != $uid)
  56. return null;
  57. return $info;
  58. }
  59. }