IntegralRecordApi.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. $count = IntegralRecord::where($where)->count();
  23. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  24. return ["total" => $count, "rows" => $list];
  25. }
  26. public static function checkIsEditable($id) {
  27. $info = self::getOne($id);
  28. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  29. return false;
  30. return true;
  31. }
  32. static public function chkIsOwner($id, $uid) {
  33. $info = self::getOne($id);
  34. if ($info["enterprise_id"] != $uid)
  35. return null;
  36. return $info;
  37. }
  38. }