GoodLog.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class GoodLog extends Model
  5. {
  6. /**
  7. * 记录库存的变化
  8. * @param $token
  9. * @param $data [{'stock_id':1,'stock_name':‘usable_stock’,'stock_remark':'','stock':10,'type':'cgd'}]
  10. * @param $action_type
  11. */
  12. public static function LogAdd($token,$data,$action_type){
  13. if (is_string($token)) {
  14. $user = GetUserInfo($token);
  15. $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  16. $name = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  17. } else {
  18. //主要是某些脚本调用时没有token
  19. $uid = isset($token['id']) ? $token['id'] : 0;
  20. $name = isset($token['nickname']) ? $token['nickname'] : '';
  21. }
  22. if(is_array($data)){
  23. $temp=[];
  24. if(isset($data['stock_id'])){
  25. $data['action_uid']=$uid;
  26. $data['action_name']=$name;
  27. $data['action_type']=$action_type;
  28. $data['addtime']=date("Y-m-d H:i:s");
  29. $temp[]=$data;
  30. }else{
  31. foreach ($data as $key=>$value){
  32. if(isset($value['stock_id'])){
  33. $value['action_uid']=$uid;
  34. $value['action_name']=$name;
  35. $value['action_type']=$action_type;
  36. $value['addtime']=date("Y-m-d H:i:s");
  37. $temp[]=$value;
  38. }
  39. }
  40. }
  41. self::insertAll($temp);
  42. }
  43. }
  44. }