IntegralRecordApi.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. foreach ($list as $key => $item) {
  25. var_dump($item->detail->toArray());exit();
  26. $list[$key]["detail"] = $item->detail();
  27. }
  28. return ["total" => $count, "rows" => $list];
  29. }
  30. public static function checkIsEditable($id) {
  31. $info = self::getOne($id);
  32. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  33. return false;
  34. return true;
  35. }
  36. static public function chkIsOwner($id, $uid) {
  37. $info = self::getOne($id);
  38. if ($info["enterprise_id"] != $uid)
  39. return null;
  40. return $info;
  41. }
  42. }