IntegralRecordApi.php 1.9 KB

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