$param_data['num'] = 1000; $list = (new \app\common\model\Order())->get_user_list($param_data); $list = $list->toArray(); $list_data = $list['data']; $not_read_msg = []; if (!empty($list_data)){ $g_ids = array_column($list_data,'id'); // 判断 是否 有 未读 的 消息 $msg_where['is_source'] = ['=','order']; $msg_where['operate_id'] = ['in',$g_ids]; $msg_where['is_read'] = ['=',0]; $msg_where['is_admin'] = ['=',1]; $not_read_msg = (new LeaveMessage()) ->where($msg_where) // ->column('operate_id,count(id) as num') ->select(); $lists = json_decode( json_encode( $not_read_msg),true);//将对象转换成数组 if ($list){ $arr = array_column($lists, 'operate_id', 'id'); $not_read_msg = array_count_values($arr);//统计每一个商品出现的次数 } } //循环判断key是否一致 foreach ($list_data as $k=>$v){ foreach ($not_read_msg as $key=>$val){ if ($v['id'] == $key){ $list_data[$k]['tip_count'] = $val; } } }
数组循环的时候判断对应的订单id是否一致,一致的话重新赋值
最新推荐文章于 2024-03-23 16:00:24 发布