1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class GoodLog extends Model
- {
- /**
- * 记录库存的变化
- * @param $token
- * @param $data [{'stock_id':1,'stock_name':‘usable_stock’,'stock_remark':'','stock':10,'type':'cgd'}]
- * @param $action_type
- */
- public static function LogAdd($token,$data,$action_type){
- if (is_string($token)) {
- $user = GetUserInfo($token);
- $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
- $name = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
- } else {
- //主要是某些脚本调用时没有token
- $uid = isset($token['id']) ? $token['id'] : 0;
- $name = isset($token['nickname']) ? $token['nickname'] : '';
- }
- if(is_array($data)){
- $temp=[];
- if(isset($data['stock_id'])){
- $data['action_uid']=$uid;
- $data['action_name']=$name;
- $data['action_type']=$action_type;
- $data['addtime']=date("Y-m-d H:i:s");
- $temp[]=$data;
- }else{
- foreach ($data as $key=>$value){
- if(isset($value['stock_id'])){
- $value['action_uid']=$uid;
- $value['action_name']=$name;
- $value['action_type']=$action_type;
- $value['addtime']=date("Y-m-d H:i:s");
- $temp[]=$value;
- }
- }
- }
- self::insertAll($temp);
- }
- }
- }
|