ActionLog.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. use think\facade\Db;
  6. /**
  7. * @mixin \think\Model
  8. */
  9. class ActionLog extends Model
  10. {
  11. /**
  12. * 记录操作日志
  13. * @param $token
  14. * @param $order
  15. * @param $type
  16. * @param $status
  17. */
  18. static function logAdd($token,$order,$type,$status,$post){
  19. if(is_string($token)){
  20. $user = GetUserInfo($token);
  21. unset($post['token']);
  22. $uid = isset($user['data']['id']) ? $user['data']['id'] :0;
  23. $name = isset($user['data']['nickname']) ? $user['data']['nickname'] :'';
  24. }else{
  25. $uid = isset($token['id']) ? $token['id'] :0;
  26. $name = isset($token['nickname']) ? $token['nickname'] :'';
  27. }
  28. $roleid=0;
  29. if($uid!=0){
  30. $userrole = Db::name("user_role")->where(["uid"=>$uid,"is_del"=>0,"status"=>1])->find();
  31. $roleid = isset($userrole['roleid']) ? $userrole['roleid'] :0;
  32. }
  33. $data=[
  34. "action_id"=>$uid,
  35. "action_name"=>$name,
  36. "role_id"=>$roleid,
  37. "action_status"=>$status,
  38. "action_remark"=>isset($order[ 'remark']) ? trim($order['remark']) :"",
  39. "order_code"=>isset($order['order_code']) ? trim($order['order_code']."") :"",
  40. "order_type"=>$type,
  41. "action_type"=>isset($order['action_type']) ? trim($order['action_type']) :"",
  42. "action_data"=>json_encode($post),
  43. "order_status"=>isset($order['status']) ? $order['status'] :"",
  44. "addtime"=>date("Y-m-d H:i:s"),
  45. "updatetime"=>date("Y-m-d H:i:s")
  46. ];
  47. self::insert($data);
  48. }
  49. }