IntegralRecordApi.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. $count = IntegralRecord::where($where)->count();
  30. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  31. foreach ($list as $key => $item) {
  32. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  33. $tmp_items = [];
  34. foreach ($item["detail"] as $_item) {
  35. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  36. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  37. }
  38. $list[$key]["details"] = implode(",", $tmp_items);
  39. $list[$key]["type"] = session("user")["type"];
  40. }
  41. return ["total" => $count, "rows" => $list];
  42. }
  43. public static function checkIsEditable($id) {
  44. $info = self::getOne($id);
  45. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  46. return false;
  47. return true;
  48. }
  49. static public function chkIsOwner($id, $uid) {
  50. $info = self::getOne($id);
  51. if ($info["enterprise_id"] != $uid)
  52. return null;
  53. return $info;
  54. }
  55. }